CVE-2023-38546: cookie injection with none file
When curl duplicates an easy handle, it re-initialises the cookie engine using the stored cookie filename, which defaults to the literal string 'none' if no file was set. If a file named 'none' exists in the current working directory, its contents are loaded as cookies and injected into requests made with the duplicated handle.
- Triaged in 22 hours
- Fixed in 27 days
- Disclosed after 27 days
When curl_easy_duphandle() is used to duplicate an easy handle it is possible to inject cookies
into that duplicated handle if a file none exists in the current working directory.
PoC / Steps to reproduce:
- Open 2 terminals
- compile F2699218
- in terminal 1:
nc -l -p 8888 127.0.0.1 - in terminal 2:
echo -e "127.0.0.1\tTRUE\t/\tFALSE\t0\tname\tvalue" > none/path/to/poc_cookieinj
(poc_cookieinj does not have to be in the same directory as the file none)
Supporting Material/References:
The flaw is in Curl_cookie_init()
if(!inc) {
/* we didn't get a struct, create one */
c = calloc(1, sizeof(struct CookieInfo));
if(!c)
return NULL; /* failed to get memory */
c->filename = strdup(file?file:"none"); /* copy the name just in case */
if(!c->filename)
goto fail; /* failed to get memory */
and in curl_easy_duphandle() the injection happens
if(data->cookies) {
/* If cookies are enabled in the parent handle, we enable them
in the clone as well! */
outcurl->cookies = Curl_cookie_init(data,
data->cookies->filename,
outcurl->cookies,
data->set.cookiesession);
if(!outcurl->cookies)
goto fail;
}
Impact
cookies injection into an http request
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 cookie filename defaults to the literal string 'none' rather than being unset, so duplicating a handle re-reads a file from the current working directory.
Impact
An attacker who can place a file named 'none' in the working directory could inject cookies into HTTP requests made through a duplicated handle.
What the attacker needed
Ability to write a file named 'none' in the working…; program uses curl_easy_duphandle()
How it was found
- Open two terminals and compile the proof-of-concept program.
- In the first terminal, start a listener on the loopback address.
- In the second terminal, create a file named 'none' containing a cookie line.
- Run the proof-of-concept binary, which need not be in the same directory as the file.
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.
curl is a tool and library for making web requests. When a program copies a curl 'handle' (its internal state for a connection), curl re-reads a cookie file whose name defaults to the word 'none'. If an attacker can place a file called 'none' in the folder the program runs from, its contents get treated as cookies and sent with requests.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.