Command Injection

Command Injection Methods

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)


Other Injection 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

Bypass

Space

Other Blacklisted Characters

Linux

Windows

Character Shifting

Blacklisted Commands

Linux & Windows

Linux Only

Windows Only


Advance Command Obfuscation

Case Manipulation

Reversed Commands

Encoded Commands

More Payloads

PayloadsAllTheThingsarrow-up-right


Evasion Tools

Linux (Bashfuscator)

Installation

Usage

Windows (DOSfuscation)

Installation

Usage


Prevention

  • Avoid executing system commands

  • Input validation on both front-end and back-end

  • Input sanitization

  • Server configuration

    • use WAF

    • apply principle of least privilege (use www-data for example)

    • open_basedir = '/var/www/html'

    • Reject double-encoded requests and non-ASCII characters in URLs

    • Avoid the use of sensitive/outdated libraries and modules

Last updated