
Command injection is an attack in which the attacker runs arbitrary operating-system commands on the server through a vulnerable application.
It is possible when an application passes unsafe user-supplied data, from forms, cookies or HTTP headers, to a system shell. The exact syntax depends on the server's operating system, such as Linux or Windows.
This demonstration uses the Damn Vulnerable Web Application (DVWA), a deliberately vulnerable application for practice, hosted on Windows. You can get DVWA from github.com/digininja/DVWA. Only test applications you own or are authorised to test.
Examples of input used in the demonstration, where a second command is appended to an expected IP address:
127.0.0.1 && dir127.0.0.1 | dir127.0.0.1 & calcping command.&, | and ; have no special meaning.&& and | is not enough, because there are many ways around a block-list.Avoid calling the shell with user input. Use library functions or pass arguments as a list without a shell, and allow-list any values you must accept.
Escaping is error-prone. Removing the shell from the code path is far safer.
Try Vooki Pro free for 7 days
Find command injection before it becomes a server takeover. The trial unlocks every feature for 7 days, and scanning runs on your own machine.
Related: Server-side template injection (SSTI) · Insecure deserialization