Skip to content
Smuggling / CRLF Disclosed report Intermediate

SMTP Command Injection via CRLF in libcurl MAIL_FROM / MAIL_RCPT (lib/smtp.c)

libcurl's SMTP implementation fails to sanitise CRLF sequences in the MAIL_FROM and MAIL_RCPT options, allowing an attacker to inject arbitrary SMTP commands. This can lead to unauthorised recipient injection, manipulation of the SMTP transaction, and injection of full email content.

divsz Follow

Originally disclosed on HackerOne

  • Disclosed after 13 hours

Summary

libcurl’s SMTP implementation fails to properly sanitize CRLF sequences in user-controlled inputs passed via CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT.

The function smtp_parse_address() (lib/smtp.c:277) extracts any data following the closing > character as a raw suffix and incorporates it directly into SMTP commands using Curl_pp_sendf() without filtering control characters.

This behavior enables SMTP command injection, allowing an attacker to inject arbitrary SMTP commands when applications pass unsanitized input to these options.

Notably, other parts of the SMTP implementation (e.g., domain parsing at line 198 and custom commands at line 215) correctly enforce sanitization using REJECT_CTRL, highlighting an inconsistency in input validation.

Tested Versions curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 Platform: Ubuntu 24.04.4 LTS

The issue was also confirmed in the current git HEAD (commit 5fdb35a3bc) via source code review. The vulnerable logic in smtp_parse_address() remains unchanged.

Root Cause At lib/smtp.c:277, the suffix portion of an email address is extracted and used without validation or sanitization of control characters (e.g., \r, \n).

Unlike other code paths (lines 198 and 215), this path does not apply REJECT_CTRL, allowing CRLF injection into the SMTP command stream.

Steps To Reproduce Start a local SMTP listener: nc -l -p 2525 > /tmp/smtp_raw.txt &

Send a request with CRLF injection in MAIL FROM: curl --url "smtp://127.0.0.1:2525"
--mail-from $'[email protected]\r\nRCPT TO:[email protected]'
--mail-rcpt "[email protected]"
--upload-file /dev/null

Inspect captured traffic: cat /tmp/smtp_raw.txt

Expected Behavior MAIL FROM:[email protected] RCPT TO:[email protected]

Actual Behavior MAIL FROM:[email protected] RCPT TO:[email protected] RCPT TO:[email protected] The injected RCPT TO command is interpreted as a valid SMTP instruction.

Additional Injection Vectors Injection via CURLOPT_MAIL_RCPT: curl --url "smtp://127.0.0.1:2525"
--mail-from "[email protected]"
--mail-rcpt $'[email protected]\r\nRCPT TO:[email protected]'
--upload-file /dev/null

Full SMTP Transaction Injection: curl --url "smtp://127.0.0.1:2525"
--mail-from $'[email protected]\r\nRCPT TO:[email protected]\r\nDATA\r\nSubject: injected\r\n\r\ninjected body\r\n.'
--mail-rcpt "[email protected]"
--upload-file /dev/null This allows full control over the SMTP session, including message headers and body.

Recommendation Apply consistent input validation to the suffix portion of parsed email addresses in smtp_parse_address():

Reject or sanitize control characters (\r, \n) Apply the same REJECT_CTRL logic used in other SMTP parsing paths Ensure that only valid SMTP address syntax is accepted

Impact

Summary:

An attacker controlling input to CURLOPT_MAIL_FROM or CURLOPT_MAIL_RCPT can inject arbitrary SMTP commands, leading to:

Unauthorized recipient injection (e.g., additional RCPT TO) Manipulation of SMTP transaction flow Injection of full email content (headers and body) Potential abuse for spam, phishing, or data exfiltratio

The original report as published on HackerOne, by divsz. 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 function smtp_parse_address() extracts the suffix after the closing '>' and uses it without validating or sanitising control characters, unlike other SMTP parsing paths that apply REJECT_CTRL.

Impact

An attacker controlling input to CURLOPT_MAIL_FROM or CURLOPT_MAIL_RCPT can inject arbitrary SMTP commands, leading to unauthorised recipient injection, manipulation of the SMTP transaction flow, and injection of full email content, with potential abuse for spam, phishing, or data exfiltration.

What the attacker needed

Attacker controls MAIL_FROM or MAIL_RCPT input; application uses libcurl SMTP

The fix

Apply consistent input validation to the suffix portion of parsed email addresses in smtp_parse_address(), rejecting or sanitising control characters and using the same REJECT_CTRL logic as other SMTP parsing paths.

How it was found

  1. Start a local SMTP listener to capture traffic.
  2. Send a request with CRLF injection in the MAIL FROM option.
  3. Inspect the captured traffic to see the injected command.

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 a program sends email using libcurl, it can specify the sender and recipient addresses. If an attacker can control these addresses, they can sneak in extra line breaks and commands, tricking the email server into sending the message to unintended recipients or adding malicious content. This happens because libcurl does not check for special characters that should not appear in email addresses.

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