CVE-2023-27535: FTP too eager connection reuse
libcurl's FTP connection reuse logic did not consider the FTP account or alternative-to-user options, so a connection authenticated with one account could be reused for a request specifying a different account. An attacker could potentially access content using the wrong cached credentials.
- Triaged in 4 days
- Fixed in 14 days
- Disclosed after 17 days
Summary:
libcurl FTP(S) protocol will reuse connection even if different CURLOPT_FTP_ACCOUNT (libcurl) or --ftp-account (curl) is specified for different connections and the server requests account authentication via reply code 332. It appears that STRING_FTP_ALTERNATIVE_TO_USER (libcurl) or --ftp-alternative-to-user (curl) is also affected and should also result in caching being refused.
Steps To Reproduce:
- terminal 1:
echo -e "foo\n" | nc -v -l -p 9998; echo -e "bar\n" | nc -v -l -p 9998 - terminal 2:
echo -ne "220 a\n331 b\n332 c\n230 d\n257 \"/\"\n229 (|||9998|)\n200 e\n213 4\n150 f\n226 g\n229 (|||9998|)\n213 4\n150 f\n226 g\n" | nc -v -l -p 9999 - terminal 3:
curl -v --ftp-account alice "ftp://ftp@server:9999/file1" -: --ftp-account bob "ftp://ftp@server:9999/file2"
As a result connection authenticated as user alice will be used when fetching file2 regardless that user bob was specified for fetching it.
Remediation
- Don't reuse connection if
CURLOPT_FTP_ACCOUNTorSTRING_FTP_ALTERNATIVE_TO_USERare different.
Supporting Material/References:
Impact
Accessing content with wrong cached credentials.
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 connection reuse cache key did not include the FTP account or alternative-to-user settings, so connections were considered interchangeable despite different credentials.
Impact
Accessing content with wrong cached credentials.
What the attacker needed
Different FTP account specified for a connection; server requests account via 332
How it was found
- Set up a listener that accepts two connections and sends 'foo' then 'bar'.
- Set up a fake FTP server that responds with a sequence including a 332 code requesting an account.
- Run curl with two different --ftp-account values for two file URLs on the same server.
- Observe that the connection authenticated as the first account is reused for the second 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.
When you connect to an FTP server, you sometimes need to provide an account name. libcurl, a library for transferring data, keeps connections open to reuse them for later requests. This report shows that libcurl would reuse a connection even if the new request asked for a different account, so the server might treat you as the previous user.
What is Account takeover?
Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.