CVE-2023-28319: UAF in SSH sha256 fingerprint check
A use-after-free flaw exists in curl's SSH fingerprint check: the code frees a fingerprint string and then uses it in a failure log message. An attacker could potentially crash the application or leak memory contents into the log.
- Triaged in 44 hours
- Fixed in 57 days
- Disclosed after 2 months
Summary:
The fingerprint_b64 pointer is as parameter for failure logging after it is freed.
Steps To Reproduce:
- git clone https://github.com/curl/curl
- vim curl/lib/vssh/libssh2.c
- search for the string 'free(fingerprint_b64)' and note that fingerprint_b64 is used as parameter immediately after it is freed.
Supporting Material/References:
The following are the details of the code.
git commit a51f90ec0f74176776f5d14b99689f9241660eaa (HEAD -> master, origin/master, origin/HEAD)
In curl/lib/vssh/libssh2.c 653 static CURLcode ssh_check_fingerprint(struct Curl_easy *data) 654 { ... 667 char *fingerprint_b64 = NULL; ... 729 if((pub_pos != b64_pos) || 730 strncmp(fingerprint_b64, pubkey_sha256, pub_pos)) { 731 free(fingerprint_b64); 732 733 failf(data, 734 "Denied establishing ssh session: mismatch sha256 fingerprint. " 735 "Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256);
According to git blame, the following commits were involved:
d1e7d9197b lib/vssh/libssh2.c (Mats Lindestam 2021-09-26 23:20:53 +0200 731) free(fingerprint_b64); d1e7d9197b lib/vssh/libssh2.c (Mats Lindestam 2021-09-26 23:20:53 +0200 732) d1e7d9197b lib/vssh/libssh2.c (Mats Lindestam 2021-09-26 23:20:53 +0200 733) failf(data, ff2f3e8367 lib/vssh/libssh2.c (Daniel Stenberg 2022-04-25 11:41:20 +0200 734) "Denied establishing ssh session: mismatch sha256 fingerprint. " ff2f3e8367 lib/vssh/libssh2.c (Daniel Stenberg 2022-04-25 11:41:20 +0200 735) "Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256);
Impact
Depends on which memory is the pointer fingerprint_b64 pointing to at the time failf() is called, it may either crash the application or it may print out whatever was in memory at the time leading to information leak in the fail log.
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
Impact
Depending on the memory contents, this could crash the application or leak information in the failure log.
What the attacker needed
SSH connection with fingerprint mismatch
How it was found
- Clone the curl repository.
- Open the file lib/vssh/libssh2.c.
- Search for 'free(fingerprint_b64)' and observe that the pointer is used right after being freed.
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 a program frees memory, it should not use that memory again. Here, the code frees a string and then immediately uses it in an error message. This can cause a crash or leak old data from memory.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.