Page cover
githubEdit

syringeCommand Injection

chevron-rightCommon Vulnerable Parametershashtag
  • IP/hostname inputs: ping, nslookup, dig, traceroute, whois

  • File operations: backup, download, upload, convert, compress functions

  • System utilities: git, zip, tar, imagemagick, ffmpeg

  • Network tools: curl, wget, netstat

  • Scheduled tasks: cron expressions, at commands

?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}
?file={payload}
?dest={payload}
?path={payload}
?folder={payload}
?url={payload}
?source={payload}
?email={payload}
?ip={payload}
chevron-rightPHP Direct Functions and backtick operatorhashtag
triangle-exclamation
circle-info

Determine the Context

Is your input inside a quoted string or not?

circle-info

Injection Operators

  • This are the standard breakout character. You use it to stop the current command execution so you can inject your command afterward.

Semicolon ;

  • Runs commands sequentially regardless of success/failure

  • Example: ; whoami

  • Usage: ping -c 1 8.8.8.8; cat /etc/passwd

Pipe |

  • Passes the output of command A as input to command B

  • Example: | cat /etc/passwd

  • Usage: ping -c 1 8.8.8.8 | cat /etc/passwd

AND operator &&

  • Runs command B only if command A succeeds

  • Example: && cat /etc/passwd

  • Usage: ping -c 1 8.8.8.8 && cat /etc/passwd

OR operator ||

  • Runs command B only if command A fails

  • Example: || cat /etc/passwd

  • Usage: ping -c 1 invalid-host || cat /etc/passwd

Command Substitution $()

  • Executes a command and substitutes its output in place

  • Example: $(whoami)

  • Usage: ping -c 1 $(cat /etc/hostname) or echo $(ls)

circle-info

Handle the rest of the Line

If the code adds characters after your injection ( echo $input . " --option"), you must neutralize them.

  • The Hash #: Comments out the rest of the line:

  • The Quote ': Turns trailing characters into a harmless string:

  • The OR operator ||: Often used to ensure the shell continues even if the previous command fails, or to handle the rest of the injected string:

chevron-rightPHP Callback Injectionhashtag

These functions don't run commands themselves. However, if you can control the arguments passed to them, you can force them to call a command function for you.

circle-info

preg_replace()

Used in PHP to perform regular expression-based replacements.

  • Syntax: preg_replace(pattern, replacement, subject);

  • If the /e modifier (or PREG_REPLACE_EVAL) is used, the replacement string can be executed as PHP code before the replacement occurs.

Attack Technique

  • While the /e modifier may not be explicitly present in the original code, it can be injected into the regular expression pattern through user input.

  • If user input is used directly in the preg_replace() function, attackers can manipulate requests to inject the /e modifier into the pattern, causing arbitrary PHP code execution.

  • The /e modifier was deprecated in PHP 5.5.0 and removed in PHP 7.0, so this is primarily a legacy vulnerability now.

  • Look for regex patterns on POST requests (/)

  • Some payload examples:

chevron-rightBlind Injectionshashtag
circle-info

Time-based Detection

circle-info

Out-of-Band (OOB) Detection

circle-info

Error-based Detection

  • Input special characters: ', ", ;, |, &

chevron-rightPython - eval()hashtag
circle-info

The vulnerability arises from unsanitized user input being passed to the eval() function.

triangle-exclamation
chevron-rightExploiting Curlhashtag
circle-exclamation
circle-info

Test outbound connections

Set a listener and curl your host to see if you can receive connections

circle-info
  • The flag -o allows to save the output of curl to a file

  • If you have access to a web path as /uploads you may be able to call a webshell

chevron-rightFilter Bypasseshashtag
circle-info

${IFS} Bypass

  • IFS stands for Internal Field Separator. It is a variable used in Unix/Linux shells to determine how the shell splits strings into separate arguments (tokens).

  • By default, IFS is set to whitespace characters: space, tab, and newline.

  • Use ${IFS} wherever they would normally use a space

circle-info

Bypassing Space Filters

circle-info

Bypassing Slash Filters

circle-info

Command Obfuscation

circle-info

Wildcards & Globbing

circle-info

Alternative Commands

  • cat tac, head, tail, nl, more, less

  • ls dir, echo *

  • whoami id, who

circle-info

Encoding Bypasses

circle-info

Variable Expansion

circle-info

Bypassing Character Limits

chevron-rightBash Arithmetic Injectionhashtag
circle-info
  • In Bash, the [[ ... ]] construct and $(( ... )) operator perform arithmetic evaluation. When user input is placed inside these constructs without proper sanitization, Bash will:

    1. Evaluate the arithmetic expression

    2. Execute any command substitutions within that expression

When the input contains $(command) or backticks, Bash executes the command before performing arithmetic evaluation.

If you control $user_input:

circle-info

Detection Checklist

circle-info

Payload Examples

circle-info

Exploitation Scripts

circle-info

Mitigation

Last updated