-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
One of the Java examples for Command Injections is not vulnerable.
Pecisely, this code is only vulnerable to Argument Injections, not to Command Injections:
// Vunerable
String input = "&& cat /etc/passwd"; // value supplied by user input
Runtime r = Runtime.getRuntime();
r.exec("some_tool -t param1 param2 " + input);This happens because under the hood Java:
- Splits the
execargument by the spaces. - Uses the first element of the array as the first argument of the
execvesyscall. - Uses all the remaining elements as the second argument of the
execvesyscall.
This means that the current example would become execve("some_tool", ["-t","param1","param2","&&","cat","/etc/passwd], ...), therefore the cat /etc/passwd command would not be executed.
Argument Injections are still possible and Command injections are also possible in case the first arguments are opening a shell and accepting a list of commands (e.g. "cmd /c" + input or "/bin/bash -c" + input).
Metadata
Metadata
Assignees
Labels
No labels