Credential leak on redirect due to improper state clearing when parsing macdef in netrc.c
When curl parses a netrc file containing a macdef block, previously loaded credentials are not cleared, so a later redirect causes those credentials to be sent to the new host. An attacker who controls the redirect could receive the victim's netrc username and password.
- Disclosed after 2 days
Summary :
-When parsing a netrc. file, the macdef keyword fails to clear previously loaded credentials. If a redirect follows, these credentials are leaked to the new host. This is a new variant of CVE-2024-11053, triggered by a different code path ('macdef' instead of 'default').
##No, this vulnerability was discovered through manual code analysis and testing
Affected version :
curl 8.15.0-DEV (x86_64-pc-linux-gnu) libcurl/8.15.0-DEV OpenSSL/3.5.0 zlib/1.3.1 libpsl/0.21.2 Release-Date: [unreleased] Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss Features: alt-svc AsynchDNS Debug HSTS HTTPS-proxy IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP TrackMemory UnixSockets
Steps To Reproduce :
Setup two listeners: 1- nc -l -p 9000 2-echo -e "HTTP/1.1 301 Moved Permanently\nLocation: http://localhost:9000" | nc -l -p 8000 -q 1 3-Create (poc_netrc.txt) file with the following content :
machine localhost login admin password SuperSecretPassword123
macdef foobar echo "malicious macro"
default login not_admin
4-Execute curl to trigger the leak: ./src/curl -L --netrc-file poc_netrc.txt http://localhost:8000
5-echo YWRtaW46U3VwZXJTZWNyZXRQYXNzd29yZDEyMw== > temp_output.txt 6-base64 -d < temp_output.txt
-result : admin:SuperSecretPassword123
Supporting Material/References
The output on the (Attacker Server) terminal (the one listening on port 9000) will show the leaked Authorization header containing the credentials for localhost. This proves that the credentials persisted across the redirect.
Impact
##Impact: If an attacker controls the redirect, they can trick curl into sending the victim’s .netrc username and password to the wrong server. This can happen without the user noticing, especially in scripts or CI pipelines where curl runs automatically using .netrc for login.
Attachments
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 netrc parser does not reset the in-memory credentials when it encounters a macdef block, so stale credentials survive into a redirected request.
Impact
If an attacker controls the redirect, they could receive the victim's netrc username and password without the user noticing, particularly in scripts or CI pipelines.
What the attacker needed
Victim uses a netrc file with credentials; netrc contains a macdef block; attacker controls the redirect target
How it was found
- Start a listener on one port to capture the redirected request.
- Start a second listener that answers with a redirect to the first listener.
- Create a netrc file containing a machine entry with credentials, a macdef block, and a default entry.
- Run curl with redirect following enabled and the crafted netrc file against the redirecting listener.
- Observe the captured request on the first listener and decode the leaked credentials.
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 so a command-line tool can log in automatically. curl reads it before making a request, and when a server redirects to another address, curl should forget the old login. Here it kept the login in memory and sent it to the second server, which could be controlled by an attacker.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.