Command injection
Source-based lab referenceNetCheck accepts a host for a ping check. Its PHP handler removes one character, then asks a shell to interpret the rest. The core lesson is the boundary between input data and a command.
This guide explains the supplied Command Injection with Weak Filters lab. It is based on the PHP source, Docker configuration, README, and technical notes. It does not launch the container, make requests, or execute supplied code.
What the lab is about
The application presents a network diagnostics form. The user supplies a host in the ip field; the server constructs a ping command, runs it, and displays captured output. The lab demonstrates why removing a single shell character does not make arbitrary input safe to place inside a shell command.
- Request
POST ip=…User-controlled host field - Filter
trim() → delete ";"No host-format validation - Command string
"ping -c 1 " . $ip_filteredData enters shell grammar here - Shell execution
shell_exec($cmd . " 2>&1")Output is then HTML-escaped
Learning goals
Find the trust boundary
Trace the POST value from input, through its filter, into the command string.
Explain the failure
Distinguish shell syntax from ordinary argument data, and understand why a character blacklist is brittle.
Read evidence carefully
Separate behavior established by source from results claimed by the write-up.
Choose a safer design
Prefer a non-shell API, fixed command choices, and strict validation for the expected host format.
What a complete solve means
- Identify
POST /ping.phpand theipfield, including the method and empty-input checks. - Explain why
127.0.0.1;idis mutated into one host string, not rejected or executed as two commands. - Choose a surviving operator and account for its exit-status, expansion, and output behavior.
- Explain how a process can read
/flag.txteven though Apache does not serve that path from the web root. - Separate an author-disclosed flag from proof of retrieval through the vulnerable HTTP handler.
What was reviewed—and what was not run
The six supplied files in Command-Injection/ were read as text and this guide was compared with madx.html and its-a-fly.html. Official documentation informed the corrections. No project file was executed, no HTML was opened, no container was built or started, and no lab request was sent. Examples below are inert reference text.
Scope
The supplied lab is an intentionally vulnerable training target. Any future hands-on use belongs inside an owned, isolated lab. This HTML has no request form, command runner, or connection to the service. “Authorized Personnel Only” is presentation text; the supplied handler does not enforce authentication.