Command Injection
http://localhost/DVWA/vulnerabilities/exec/
http://localhost/DVWA/vulnerabilities/exec/
Using BurpSuite and the FoxyProxy extension is recommended.
We've a form with an input type text:
that ask us to enter and IP address to ping.
Inserting an IP address we can confirm that will do a ping request to it:
As always we can start to analyze source code:
There'is a condition to check if input value has been inserted
The operating system in use is checked to evaluate exactly which ping should be entered (win or *nix OS)
In the end, there's generate feedback for the end user.
The input is not sanitized, so I can execute any (potentially malicious) command.
using it, we ping machine with IP 127.0.0.1 and join two extra commands using ; or another join char as |, to take a whoami and see /etc/passwd file:
There's a classic control of input text submitted
An eventually blacklist word (&& and ;) is replace with a '' black char
The operating system in use is checked to evaluate exactly which ping should be entered (win or *nix OS)
In the end, there's generate feedback for the end user.
The input is not sanitized because blacklist words are eventually removed only one time and not recursevely and we can use others join chars to add a new commands such as |.
We've replaced ;
or &&
with |
:
;
will be replace by '' and will submit this prohibit payload:
This command isn't write correctly, it has an extra space '|
'
The input is not sanitized, so I can execute any (potentially malicious) command.
Payload
Without leaving a white space after | we can use this payload:
The input is sanitized and it's not vulnerable to a command injection attack.
For the making of this solution the following resource were used: