Skip to content
RCE Disclosed report Advanced

--libcurl code injection via trigraphs

The --libcurl option in curl generates C source code that does not escape question mark characters, allowing trigraph sequences to inject arbitrary code. An attacker who controls curl command-line options could cause the generated code to execute commands when compiled with trigraph support enabled.

nyymi Follow

Originally disclosed on HackerOne

  • Disclosed after 43 hours

Summary:

curl command --libcurl option can be tricked to generate C code that when compiled contains arbitrary code execution.

Steps To Reproduce:

  1. curl --libcurl client.c --user-agent "??/\");char c[]={'i','d',' ','>','x',0},m[]={'r',0};fclose(popen(c,m));//" http://example.invalid
  2. gcc -trigraphs client.c -lcurl -o client
  3. ./client
  4. ls -l x

Note: In this PoC older compiler is simulated by passing -trigraphs option to gcc.

To remedy this issue ? chars should be quoted to \? in the generated strings.

Impact

Code injection to generated source code.

However, the impact of this vulnerability is minimal due to difficultly in finding scenarios where it would be practically exploitable. To be even remotely plausible curl command should somehow be hooked into a system that uses --libcurl to generate, compile and finally execute the compiled code while also accepting external user input for the curl command options. This seems extremely unlikely to happen in real life.

Trigraph support has also largely been disabled by now (gcc and clang have it disabled by default at least).

I don't really mind if this is found to be "not a vulnerability" (or only self-exploitable). In this case just close this H1 ticket and create a regular GitHub issue / or fix it direct.

The original report as published on HackerOne, by nyymi. 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 generated C code does not escape question mark characters, so trigraph sequences can alter the code structure.

Impact

Code injection into generated source code is possible, but the impact is minimal because exploitation requires an unlikely setup where curl options are externally controlled and the generated code is compiled with trigraphs enabled.

What the attacker needed

Attacker controls curl command-line options; generated code compiled with trigraphs enabled; compiled code is executed

How it was found

  1. Run curl with --libcurl and a crafted user-agent containing trigraph sequences.
  2. Compile the generated C file with trigraph support enabled.
  3. Execute the compiled binary.
  4. Check that the injected command created a file.

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.

When you use curl with the --libcurl option, it writes a small C program that repeats your request. If your input contains three question marks in a row, an old C compiler feature called trigraphs can turn them into a backslash, which then breaks out of a string and lets an attacker add their own code. This only matters if someone else can control the curl options and the generated code is compiled with trigraphs turned on.

What is RCE?

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

More by nyymi

View all

51 more disclosed reports, 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.

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.