Cmd Injection
Where Would You Find Command Injection
In the following places:
Text boxes that take in input
Hidden URLs that take input
E.g.
/execute/command-nameOr through queries e.g.
/location?parameter=commandWhen using URLs, remember to URL encode the characters that aren’t accepted
Hidden ports:
Some frameworks open debug ports that take in arbitrary commands
Local-only Command Endpoints
Internal admin or dev services may only bind to loopback. If you have SSH access, forward the local service and test suspicious query-only hints like http://host/?.
ssh user@TARGET -L 8888:127.0.0.1:80
curl 'http://127.0.0.1:8888/?whoami'PowerShell HttpListener wrappers sometimes execute the raw query string as a command. A successful response may look like:
nt authority\systemIf file upload or transfer is available, drop a payload and execute it by passing the full path:
Overview
Use command line symbols within the input to alter the executed command
Pay close attention to functions within an application that tend to be performed by an OS command
Two forms exist, blind command injection --> you do not see the returned output, and non-blind cmd injection --> the system command output gets returned back to you
Ensure you use the proper system commands per the OS
Try to start with reading a world readable file

Injection Operators Table
;
%3b
Both
\n (newline)
%0a
Both
&
%26
Both (2nd shown first)
| (pipe)
%7c
Both (only 2nd output)
&&
%26%26
Both (only if 1st succeeds)
||
%7c%7c
2nd (only if 1st fails)
` (backtick)
%60%60
Both (Linux only)
$()
%24%28%29
Both (Linux only)
#
%23
Truncates (Linux only)
Note: ; doesn't work in Windows CMD, but works in PowerShell.
Using # (Hash) to Truncate Commands
In bash, # starts a comment, which means anything after it on the same line is ignored. This is extremely useful in command injection when your injected payload is concatenated with additional characters that would break your command.
Example scenario: The backend command is:
If you inject into username, the @hostname part would break your payload. Using # truncates the rest:
Real-world example:
The # prevents the rest of the backend command from being interpreted, allowing your payload to execute cleanly.
Non-Blind CMD Inj.
At the most basic level:
Use command line symbols within the input to alter the executed command
Once you have identified a potential injection point, use command line symbols within the input to alter the executed command

Once you have exploited non-blind cmd injection, escalate to a reverse shell.
Blind CMD Injection
Identification
ICMP and DNS are useful to determine blind cmd injection
Can also try to ping yourself, however many corporate environments have firewalls in place to stop this, so doesn't always mean blind cmd injection isn't taking place
Use
tcpdumpto capture theicmpecho requests.


This proves blind cmd injection, escalate to reverse shell
Burp Collaborator
Launch Burp, and choose:

Press
Poll Nowto see if the request came through

If the above worked, move down to Data Exfil section
Data Exfil via DNS and Burp Collaborator
Once you have your Burp Collaborator Domain, try your command injection
Press Poll now and you should have something returned like this:
Then type the following in your local terminal
If this fails as
Invalid Base32add 1, or 2 equal signs at the end for padding
Bypassing Character Blocklist with ffuf
If you see that some special characters are banned, create a burp request to the resource you want to test
It should be a post request
Identify the parameter that it is using to post the data to the server
Swap out the command injection attempt that is getting blocked in the burp request with:
Save the burp request to your local machine in a file
You usually will have to ignore the
&character as many webservers will think you are going to pass in another parameterNow that you have your results back you must filter out the most common side that you see being returned
-fs 724Can comma seperate filter size i.e. you see alot of 724 and 726 returned saying that character you posted is blocked
-fs 724,726Ensure you also
-mc allor match code to see all the different http status codes returned, look for 5XX errorsIf you see errors on:
IFS Bypass No Spaces CmdInjection
whitespace bypass
can see above that the username (our injection point) cannot contain spaces, we can use
{IFS}to bypass this restriction and get cmd injectionGaining a reverse shell, encode your payload and have it decode and execute to avoid special character issues
Space Bypass Techniques
Tab
%09
Both
${IFS}
cat${IFS}/etc/passwd
Linux
$IFS$9
cat$IFS$9/etc/passwd
Linux
Brace Expansion
{cat,/etc/passwd}
Linux
< redirect
cat</etc/passwd
Linux
Slash (/) Bypass
Linux - Using Environment Variables
Windows CMD
Windows PowerShell
Semicolon (;) Bypass
Character Shifting (Linux)
Command Obfuscation
Quote Insertion (Linux & Windows)
Linux-Only Characters
Windows Caret
Case Manipulation
Windows (case insensitive)
Linux (needs tr)
Reversed Commands
Linux
Windows PowerShell
Base64 Encoded Commands
Linux
Windows PowerShell
Encode for PowerShell from Linux
Obfuscation Tools
Bashfuscator (Linux)
DOSfuscation (Windows)
Newline Bypass
Often not blacklisted - use %0a:
Newline + Quote Bypass (Double Filter)
When both newline characters and spaces are filtered, combine %0a with single-quote insertion and ${IFS} for spaces. The quote must come right after the %0a with no gap to bypass the filter:
Response confirms command injection:
Final payload reading a file with cat obfuscated via quotes and ${IFS} for spaces:
commix (Automated Command Injection)
commix automates command injection discovery and exploitation. Use * as an injection marker in the request file, or let it auto-detect.
Basic Usage with Request File
With OS, Prefix, and Batch Mode
When you know the OS and need a specific injection prefix (e.g. newline bypass):
Example Challenge Payload
Breakdown:
%09= tab (space bypass)$(rev<<<'tac')= reversedcatcommand${PATH:0:1}=/character
Netcat Port Parameter Injection
When PHP uses escapeshellcmd() instead of escapeshellarg(), you can inject additional arguments.
Vulnerable Code Pattern
Exploitation
The intval() function extracts the leading integer, so 1234 -e /bin/bash becomes 1234 for validation but the full string is used in the command.
Payload:
Resulting command:
Listener:
Key Points
intval("1234 -e /bin/bash")returns1234(passes validation)Original
$portvariable retains full payloadescapeshellcmd()doesn't prevent argument injection, only escapes shell metacharactersAlways look for type coercion bugs where sanitized values aren't used in final command
Last updated