netrc crlf injection
Curl allows carriage return and line feed characters in the login and password fields of a netrc file. An attacker who can influence the contents of that file could inject extra FTP commands, such as deleting a file.
- Disclosed after 8 months
Summary:
Curl allows CR and LF characters to be encoded in login and password netrc fields. This allows an attacker who can affect contents of the netrc entry to inject FTP commands by injecting CRLF to the login or password. POP3 is likely affected as well, but hasn't been tested.
The only situation in which this could be considered a vulnerability is when someone can choose their username or password freely which will then be injected to a netrc file. This could happen for example if some app constructs the netrc file from user provided input.
This likely is considered "Local attackers already present" category issue. However, I leave it to the project to decide. If not deemed a security issue, I'll close the ticket and the issue can fixed outside of the security process as a normal bug.
Steps To Reproduce:
- Have netrc file with:
machine localhost
login alice
password "alicespassword\r\nDELE pocfile.txt"
echo -ne "220 \r\n331 \r\n" | nc -v -l -p 9999curl -v --netrc-file netrc ftp://localhost:9999
Remediation suggestion
Do not allow CR or LF in the username or password when constructing commands for protocols that use these characters as separator (FTP, POP3, others?).
Impact
FTP/POP3 command injection.
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, curl does not reject or escape carriage return and line feed characters when building protocol commands from netrc login and password fields.
Impact
An attacker who can affect the netrc entry could inject FTP commands; POP3 is likely affected as well but has not been tested.
What the attacker needed
Attacker can influence netrc login or password; curl uses the crafted netrc file
The fix
Curl should reject carriage return and line feed characters in the username or password when constructing commands for protocols that use these characters as separators.
How it was found
- Create a netrc file with a login and a password containing carriage return and line feed characters followed by an FTP command.
- Start a simple listener that responds with FTP greeting and password-required codes.
- Run curl using that netrc file against the listener.
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.
A netrc file stores login details for automatic use by programs like curl. If those details contain special line-break characters, curl may treat part of the password as a separate command. This means someone who can control the username or password could make curl send extra commands to an FTP server.
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.