This article is a detailed technical walkthrough of DVWA Lab 16, which teaches command injection filter bypass techniques across three security levels. It demonstrates how blacklist-based defenses fail systematically by showing specific gaps in Medium and High security filters, and contrasts these failures against proper allowlist validation. The article matters because it teaches both the offensive methodology (reading source code, identifying gaps, testing alternatives) and the defensive principle that will appear in professional penetration test reports.
- Blacklist gaps in Medium securityDVWA Medium security only blocks two strings: '&&' and ';'. The article demonstrates that pipe (|), URL-encoded newline (%0a), backtick, subshell $(), and logical OR (||) all pass through unfiltered. This single fact immediately enables five different bypass techniques, showing how incomplete blacklists create a false sense of protection.
- Reading source before testingThe article emphasizes viewing the PHP source code first to see the exact blacklist entries rather than attempting payloads blindly. Knowing Medium only strips two characters means the first bypass attempt succeeds immediately rather than wasting time testing blocked separators. This methodology — read, identify gaps, test alternatives — directly applies to real applications.
- IFS substitution bypasses space filtersThe Internal Field Separator (IFS) is a shell variable defaulting to whitespace. When the shell processes ${IFS}, it expands to a space without the payload containing a literal space character. The payload 'cat${IFS}/etc/passwd' passes through space filters, then the shell correctly expands it to 'cat /etc/passwd'. This demonstrates how shell variable substitution defeats character-level filtering.
- High security's space-position vulnerabilityHigh security blacklist includes '| ' (pipe followed by space) but not ' |' (space followed by pipe). The payload '127.0.0.1 |cat /etc/passwd' bypasses the filter because it contains ' |' not '| ' — these are different strings to the blacklist's string-matching function, yet the Linux shell executes them identically. This single-character-order distinction exemplifies why blacklist gaps are inevitable.
- Multiple command separator alternativesBeyond the basic && and semicolon, the article documents pipe (chains command output), URL-encoded newline (creates new command line), backtick (command substitution), subshell $() (alternative to backtick), and logical OR (||) as separators. Each performs command chaining without appearing in a typical two or three-entry blacklist.
- Allowlist validation defeats all bypassesThe article presents the correct fix: filter_var($target, FILTER_VALIDATE_IP) in PHP validates that input matches a valid IPv4 address format. No separator, encoding, IFS trick, or character arrangement makes '127.0.0.1|cat /etc/passwd' match a valid IP regex. This single check provides complete protection across all three security levels, replacing the entire blacklist arms race.
- Why blacklists fundamentally failLinux shell syntax is too rich and flexible for any complete blacklist. The article explains this as an arms race: developer adds two entries, attacker finds three bypasses; developer adds six more, attacker finds encoding bypasses. The correct defense is allowlist-based validation that defines what valid input should be rather than attempting to predict all invalid variations.
- Three-level comparison shows escalation patternLow security has no filter, Medium blocks only && and ;, High extends the blacklist substantially. Yet at each level, the fundamental problem repeats: the blacklist addition closes one gap while leaving others open. The space-position bypass works at High security specifically because the developer blocked one arrangement but not the equivalent arrangement with reversed character order.
Bottom line: Reading source code to identify specific blacklist gaps, then testing alternative separators (pipe, newline, backtick, IFS substitution) systematically, bypasses command injection filters at every level — but proper defense requires allowlist validation that accepts only the expected input format, making all separator bypasses impossible. This methodology and remediation approach directly transfers to professional penetration testing and real application assessments.
FREE
Part of the DVWA Lab Series — 30 Labs
🎯 What You’ll Learn in Lab 16
⏱️ 40 min · 3 terminal exercises
✅ Prerequisites
- DVWA running locally (Lab 1: Setup)
- Lab 3: Command Injection basics — Low security RCE understood
- Lab 14: Security Levels — comfortable reading PHP source
📋 DVWA Command Injection Advanced Lab 16 Contents — Filter Bypass
In Lab 3 you achieved RCE using basic separators at Low security. Lab 16 extends that with filter bypass techniques used in professional web application assessments. The same methodology — read the source, identify the gaps, test alternatives systematically — applies to real applications in the DVWA Lab Series.
Medium Security — Reading the Blacklist
Always read the source before testing. At Medium security, DVWA’s blacklist is two entries: && and ;. That is it. Pipe, newline, backtick, subshell, logical OR, and URL-encoded variants of everything are entirely absent from the filter. Knowing this before sending a single payload means your first bypass attempt succeeds rather than wasting time testing things the filter does not block.
⏱️ Time: 10 minutes · DVWA at Medium security
📸 Screenshot the pipe bypass showing /etc/passwd output at Medium security. Share in #dvwa-labs on Discord.
Alternative Separator Bypasses
IFS Variable Substitution
The Internal Field Separator (IFS) is a shell variable that defaults to whitespace (space, tab, newline). When the shell encounters ${IFS} in a command, it substitutes the IFS value — a space. If a filter strips literal spaces from input, ${IFS} passes through the filter as a non-space string, then expands to a space when the shell processes the command.
⏱️ Time: 15 minutes · DVWA Medium and High security
📸 Screenshot the High security bypass working and share in #dvwa-labs on Discord.
High Security — Combined Bypass
At High security, the blacklist grows significantly. $ is blocked (defeats IFS), () is blocked (defeats subshell), backtick is blocked (defeats command substitution), and || is blocked. The key insight from reading the source: '| ' (pipe with a trailing space) is blocked, but ' |' (space before pipe) is not. Moving the space from after the pipe to before it bypasses this specific filter while achieving identical execution.
⏱️ Time: 12 minutes · DVWA — cycle through Low, Medium, High
📸 Screenshot all three levels with their working bypass payloads and share in #dvwa-labs on Discord. Tag #cmdinjection2026
Why Blacklists Always Fail — The Correct Fix
Every security level in DVWA’s command injection module demonstrates the same fundamental problem: blacklist filtering is a losing arms race. The developer adds two entries — an attacker finds three bypasses. The developer adds six more entries — an attacker finds encoding bypasses. Linux shell syntax is too rich and too flexible for any blacklist to be complete.
The correct defence is allowlist validation: define exactly what valid input looks like (a valid IPv4 address matches the regex ^(\d{1,3}\.){3}\d{1,3}$) and reject everything that does not match. No separator, no IFS trick, no URL encoding makes 127.0.0.1|cat /etc/passwd match a valid IPv4 regex. One check. Complete protection. This is what DVWA Impossible security implements, and what every command injection remediation section should recommend.
🧠 QUICK CHECK — Lab 16
📋 Lab 16 Key Takeaways
🏆 Mark Lab 16 as Complete
Lab 16 demonstrates why blacklist filtering is fundamentally insufficient for command injection defence — and gives you the systematic approach (read source, identify gaps, test alternatives) that applies to any application with command injection filtering. The allowlist remediation recommendation from this lab appears in professional penetration test reports verbatim.
❓ Frequently Asked Questions
What does DVWA Medium security filter?
What is the IFS trick for command injection?
What command separators bypass basic blacklists?
Why do blacklists always fail for command injection?
What comes after Lab 16?
Lab 15: DVWA Brute Force Advanced
Lab 17: DVWA File Inclusion Advanced
📚 Further Reading
- DVWA Command Injection Lab 2026 — Lab 3 covers Low security RCE using basic separators — the foundation that Lab 16 extends to bypass Medium and High security filtering.
- Command Injection Hub — The complete command injection category covering blind injection, out-of-band exfiltration, real bug bounty findings, and remediation patterns for PHP, Python, Java, and Node.js applications.
- DVWA Labs Hub — All 30 DVWA labs in sequence — Lab 16’s filter bypass methodology applies directly to the file inclusion, upload, and SQL injection filter bypass labs in the series ahead.
- OWASP Command Injection — The official OWASP command injection reference — attack examples, bypass techniques, and the definitive remediation guidance including allowlist validation and parameterised function calls for PHP, Python, Java, and .NET.
- PortSwigger OS Command Injection Labs — PortSwigger Web Academy command injection labs covering blind OS injection, output redirection, and time-based detection — the real-world application of the filter bypass techniques from this DVWA lab.

