CVE-2022-27781: CERTINFO never-ending busy-loop
When curl uses the NSS TLS library and the CERTINFO option is enabled, a malicious server can supply a certificate chain containing a loop, causing curl to enter an endless loop while counting certificates. This results in a denial of service, consuming nearly 100% CPU.
- Triaged in 18 hours
- Fixed in 10 days
- Disclosed after 16 days
Summary:
Curl is prone to a DoS attack in case the NSS TLS library is used and the CERTINFO option is enabled. Using maliciously crafted certificates on a server, an attacker can make curl run into an endless loop when connecting to the server. The bug is located in the following code segment (https://github.com/curl/curl/blob/master/lib/vtls/nss.c#L1014):
/* Count certificates in chain. */
int i = 1;
now = PR_Now();
if(!cert->isRoot) {
cert2 = CERT_FindCertIssuer(cert, now, certUsageSSLCA);
while(cert2) {
i++;
if(cert2->isRoot) {
CERT_DestroyCertificate(cert2);
break;
}
cert3 = CERT_FindCertIssuer(cert2, now, certUsageSSLCA);
CERT_DestroyCertificate(cert2);
cert2 = cert3;
}
}
When CERTINFO is set, display_conn_info() executes the above shown code, which tries to count the certificates in the chain received from servers via TLS. To this end, display_conn_info() starts with the leaf certificate and attempts to find its issuer certificate in the chain. The issuer certificate then becomes the origin for the next iteration. This step is repeated until there either is no issuer certificate or a root (= self-signed) certificate is found. However, if the received certificate chain contains a loop, this exit condition is never reached and display_conn_info() runs into an endless loop. To craft a loop, it is sufficient to have two CA certificates that mutually list each other as issuers (see attached PoC).
Steps To Reproduce:
I have implemented a small PoC where a Webserver uses a maliciously crafted certificate chain that contains a loop. To this end, the end-entity certificate for localhost is issued by CA2, whose certificate is issued by CA1, whose certificate in turn is issued by CA2 (-> loop). The Python script for the Webserver and the certificate chain are attached to this report. To trigger the DoS in curl, the following steps need to be executed:
- Modify URL in certinfo example (https://github.com/curl/curl/blob/master/docs/examples/certinfo.c#L46) to point to
https://localhost:4443/instead ofhttps://www.example.com/(url_easy_setopt(curl, CURLOPT_URL, "https://localhost:4443/")) - Build curl with NSS TLS library (./configure --with-nss) and with examples (make examples)
- Execute python script attached to this report to start the attacker's Webserver
- Execute certinfo (doc/examples/certinfo)
Supporting Material/References:
[list any additional material (e.g. screenshots, logs, etc.)]
- https_server.py (poc webserver)
- key.pem (poc webserver key)
- combined_loop.pem (poc webserver certificate chain)
Impact
An attacker who controls a server that a libcurl-using application (with NSS and enabled CERTINFO) connects to, can trigger a DoS. In this case, the application runs into an infinite loop and consumes nearly 100% CPU.
Using the CVSS calculator, I initially came up with medium severity (5.3). However, because the vulnerabilities relies on CERTINFO being enabled and NSS being used, which is not that popular and will soon be deprecated (https://curl.se/dev/deprecate.html), I eventually estimate the severity to be low.
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
The certificate chain counting loop lacks a check for cycles, so a chain with a loop never terminates.
Impact
An attacker controlling a server that a libcurl-using application (with NSS and CERTINFO enabled) connects to can trigger a denial of service, causing the application to consume nearly 100% CPU.
What the attacker needed
Curl built with NSS TLS library; CERTINFO option enabled; attacker controls the server
How it was found
- Modify the URL in the certinfo example to point to the attacker's server.
- Build curl with the NSS TLS library and with examples.
- Run the provided Python script to start the attacker's web server.
- Execute the certinfo example.
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 for transferring data, and it can use different libraries to handle secure connections. One such library, NSS, has a feature that lists certificate details. If a server sends a certificate chain where two certificates point to each other as issuers, curl keeps following the chain forever, freezing the program. This only happens if the CERTINFO option is turned on and NSS is used.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.