Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 45 minutesFree account

Command Injection

OS command injection via semicolons, pipes, and backticks with filter bypass.

  • command-injection
  • owasp-top-10
  • commix
  • filter-bypass
On this page 9 sections
  1. ·Build the target
  2. 1What is Command Injection?
  3. 2Detecting the Vulnerability
  4. Locked: Basic Payloads
  5. Locked: Blind Command Injection
  6. Locked: Filter Bypasses
  7. Locked: Getting a Reverse Shell
  8. Locked: Commix (Automated)
  9. Locked: Injection Operator Reference

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-data

Step 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.

Related