curl successfully matches IP address literal in URL against IP address literal in certificate Common Name
curl accepted a certificate whose Common Name was a string IP when the URL used an IP literal, instead of requiring a matching IP in subjectAltName; the reporter is unsure this is exploitable.
- Disclosed after 15 months
Summary:
A user may invoke the curl command line utility with an IP address literal in the URL, such as
https://192.168.124.2/...
If the HTTPS server presents a certificate whose Common Name matches this IP address literal as a string (that is, Common Name is the ASCII string 192.168.124.2), then curl accepts the certificate (assuming it is properly signed by a trusted CA).
This is wrong. Per RFC-2818, section 3.1. Server Identity:
In some cases, the URI is specified as an IP address rather than a
hostname. In this case, the iPAddress subjectAltName must be present
in the certificate and must exactly match the IP in the URI.
That is, if the user-specified URL contains an IPv4 or IPv6 address literal, then the server certificate may only match the URL if the certificate contains the same numeric IP address in the SAN, as a GEN_IP entry.
Curl should first attempt X509_VERIFY_PARAM_set_ip_asc(), and call X509_VERIFY_PARAM_set1_host() only if the former fails.
Steps To Reproduce:
- Generate a new certificate request, for example with the
genkeyutility, specifying the server's IPv4 or IPv6 address on the command line / in the Common Name field. (Mygenkeyis fromcrypto-utils-2.4.1-42.el7.x86_64.) - Sign the certificate request with a local CA such that
curltrust the local CA. - Configure Apache's
mod_sslsuch that it listen on the IPv4 or IPv6 address in question. - Fetch an URI with curl from the web server, using the
httpsscheme, and the IP address. - Curl accepts the certificate.
Supporting Material/References:
This issue with curl popped up while discussing the edk2 patch series mitigating CVE-2019-14553:
https://bugzilla.tianocore.org/show_bug.cgi?id=960 http://mid.mail-archive.com/[email protected]
Impact
I'm not sure this problem can be used for an attack. It's just that string representations of IP addresses are not unique. URL to Subject Name matching should use canonical representations only.
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 curl used hostname matching (X509_VERIFY_PARAM_set1_host) for IP address literals instead of first trying IP address matching (X509_VERIFY_PARAM_set_ip_asc), so it compared the textual representation rather than the numeric IP in the subjectAltName.
Impact
The reporter is not sure this can be used for an attack, but because string representations of IP addresses are not unique, certificate matching could be fooled.
What the attacker needed
Certificate with IP as Common Name; certificate signed by a trusted CA; curl used to connect to an IP address
How it was found
- Generate a certificate request with the server's IP address as the Common Name.
- Sign the request with a local CA that curl trusts.
- Configure Apache mod_ssl to listen on that IP address.
- Use curl to fetch an HTTPS URL containing the IP address.
- Observe that curl accepts the certificate.
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.
For numeric addresses, the rules say the certificate must contain that exact number in subjectAltName. curl instead compared the number as plain text against the Common Name, which is less strict; the reporter is unsure this is exploitable.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.