</> Command Injections
To check if Powershell or CMD:
Example of vulnerable code for command injection:
Automated
Linux (Bashfuscator)
To use:
But to fine-tune:
Windows (DOSfuscation)
To use
Detection
Command Injection Methods
Note: The only exception may be the semi-colon ;
, which will not work if the command was being executed with Windows Command Line (CMD), but would still work if it was being executed with Windows PowerShell.
Identifying filters
Invalid input from server side
If the error message displayed a different page, with information like our IP and our request, this may indicate that it was denied by a WAF. A php code for blacklisting characters may look like this:
Try all characters check if everything is blacklisted
Bypass Blacklisted Operators
If space is blacklisted:
Use %09 (Tab)
Use $IFS
Brace expension i.e
{ls,-la}
Linux
To list all environment variables use printenv
Example: 127.0.0.1${LS_COLORS:10:1}${IFS}
If /
or \
is blacklisted:
We can use environment variables:
echo ${PATH}
to check pathecho ${PATH:0:1}
to select/
NOTE: DONT USE ECHO IN COMMAND If
;
blacklisted:
Try something like
echo ${LS_COLORS:10:1}
Windows
If we need \
CMD
Use
echo %HOMEPATH:~6,-11%
(modify the start and end)
Powershell
$env:HOMEPATH[0]
$env:PROGRAMFILES[10]
We can also use Get-ChildItem Env: PowerShell command to print all environment variables and then pick one of them to produce a character we need
Character Shifting
Find ascii of the previous character of what is actually needed then
Bypass Blacklisted Commands
Example:
Linux & Windows
Add characters that are ignored by the shell like '
or "
Example: w'h'o'am'i
Linux only
Can add \
or $@
Example: who$@ami
w\ho\am\i
WIndows Only
We can user ^
Example: who^ami
Advanced Command Obfuscation
Like WAFs and these techniques won't work
Case manipulation
In windows CMD And Powershell commands are case-insensitive Example: WhOaMi
In linux we can find a command that turns uppercaase to lowercase:
$(tr "[A-Z]" "[a-z]"<<<"WhOaMi")
Burp POST Request
The above command failed due to usage of spaces
We can use $(a="WhOaMi";printf %s "${a,,}")
Reversed commands
Linux
To get reversed command: echo 'whoami' | rev
To execute: $(rev<<<'imaohw')
Tip: If you wanted to bypass a character filter with the above method, you'd have to reverse them as well, or include them when reversing the original command.
Windows
Powershell
To reverse: "whoami"[-1..-20] -join ''
To execute:
Encoded Commands
Linux
To encode:
Tip: Note that we are using <<< to avoid using a pipe |, which is a filtered character.
Windows
To base64 encode:
To execute:
Last updated