Practice library / Web attacks
Lab · Medium · 45 minutesFree account
Command Injection
OS command injection via semicolons, pipes, and backticks with filter bypass.
On this page 9 sections
Before you start
Command injection happens when a web application passes user input into a shell command without filtering it. An attacker who finds the injection point can run any program the web server can run. Famous incidents, including Shellshock and many router compromises, began with exactly this flaw. The lab injects commands through semicolons, pipes, and backticks, defeats a naive blocklist, and escalates to a full reverse shell.
Lab Objectives
- Understand how command injection vulnerabilities arise
- Detect injection points in web applications
- Use command chaining operators to inject commands
- Exploit blind command injection using time delays and out-of-band
- Escalate to a reverse shell from command injection
Build the target
KaliRange hosts no target web application. Run every command below against a web application you install yourself, one with a ping or lookup feature that passes your input into a shell command — the pattern in Step 1's PHP example.
Build it from a free, legal part: DVWA (Damn Vulnerable Web Application), published by the DVWA team on GitHub, has a Command Injection module with exactly this flaw. Install it with Docker Compose on your own machine, and use target.com in the commands below as the address of your own DVWA instance (for example 127.0.0.1).
Run every command in this lab only against a target you own or have written permission to test, such as your own DVWA instance.
Step 1: What is Command Injection?
Command injection occurs when an application passes user-controlled input to a system shell without proper sanitisation. The attacker injects OS commands that the server executes with the application's privileges.
# Vulnerable PHP code example:
$ip = $_GET['ip'];
system("ping -c 1 " . $ip);
# Normal usage:
GET /ping?ip=8.8.8.8
→ runs: ping -c 1 8.8.8.8
# Injected:
GET /ping?ip=8.8.8.8; whoami
→ runs: ping -c 1 8.8.8.8; whoami
→ Output includes: www-dataStep 2: Detecting the Vulnerability
# Common injection points:
# - Ping / traceroute tools
# - DNS lookup tools
# - File conversion tools
# - Any field that takes input and does something on the server
# Test with simple time delay (safe, leaves no output)
; sleep 5
| sleep 5
&& sleep 5
`sleep 5`
$(sleep 5)
# If the page takes 5 extra seconds → vulnerable!Sign in to continue
6 more sections are for signed-in members. It is free: sign in with Google.