Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Injection : Grep #4

Open
Rudra92 opened this issue May 14, 2019 · 1 comment
Open

Command Injection : Grep #4

Rudra92 opened this issue May 14, 2019 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@Rudra92
Copy link

Rudra92 commented May 14, 2019

I assumed mkdir should not be able to create directories with invalid characters that
allow for command injections. This was not specified by the project description so it
is my assumption.
Mkdir does not sanitize the name of the directory and thus an attacker is able to write a command injection as the name of the directory. Later on functions may use the absolute path without checking for invalid characters and they will perform the injected command.
We can see in their function ​ mkdir ​ in systemcmd.cpp :

std::string command = cmd +" "+ dirname;
system​ (command.​ c_str​ ());

Then function ​ void grep(conn& conn, std::string pattern)​ in file
commands.cpp (line 523) is able to trigger the command injection.
First it will create a vector containing all files’ strings using
fetch_all_files_from_dir()​ in file filefetching.cp. This function will
itself call ​ command_with_output()​ from systemcmd.cpp which contains the
following line (48) :

if (0 == (fpipe = (FILE*)popen((cmd + " " + dirname).c_str(),"r")))

We can see that the corrupted directory name is appended without
sanitization and thus will potentially cause a command injection.
This allows an attacker to do the following suite of commands to spawn a calculator:
login KevinMitnick
pass FreeKevin
mkdir ;xcalc
cd ;xcalc
grep "rekt"

@LukasGelbmann LukasGelbmann added the duplicate This issue or pull request already exists label May 21, 2019
@LukasGelbmann
Copy link
Owner

Thanks for the report. Duplicate of #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants