Skip to content
Crypto Disclosed report Intermediate

Incorrect IPv6 literal parsing leads to validated connection to unexpected https server.

The curl library's parsing of IPv6 literal hostnames is incomplete, allowing a URL with a crafted IPv6 literal to connect to an unexpected HTTPS server. An attacker could exploit this to confuse users into connecting to a wrong hostname.

thomas_v Follow

Originally disclosed on HackerOne

Medium 6.3 View original
  • Disclosed after 16 months

Summary:

The IPv6 ip address can be specified with square brackets like [fe80::3]. There can also be a zone id specified like [fe80::3%15]. A URL can specify its hostname with IPv6 literal,

It seems that the parsing in curl library is not complete. For instance, it is possible for particular IPv6 literals to trigger an http or https request on rather unexpected hostname.

See for instance the potentially misleading hostname: https://[ab.be%google.com]/query

When used with the available online sample program 'simple.c', there is no error. The https request is performed on the Belgian website 'https://ab.be' and the SSL certificate is properly validated against 'ab.be', not 'google.com'.

Steps To Reproduce:

  1. Build attached modified simple.c
  2. gcc simple.c && ./a.out https://[ab.be%google.com]/query
  3. Check with Wireshark actual DNS / IP traffic, actually is https and corresponds to 'ab.be'
  • The command line 'curl' binary itself is performing sanities so the url above is rejected.
  • The 'Host:' header field happens to contain square brackets. An attacker would have an http server handling that detail. Currently 'ab.be' responds with error 400 bad request.

Supporting Material/References:

simple.c

C
#include <stdio.h>
#include <curl/curl.h>
 
int main(int argc, char*argv[])
{
  CURL *curl;
  CURLcode res;
 
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    /* example.com is redirected, so we tell libcurl to follow redirection */ 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
 
    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl);
    /* Check for errors */ 
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
 
    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }  
  return 0; 
}

Impact

User might get confused and connect on the wrong hostname.

The original report as published on HackerOne, by thomas_v. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 IPv6 literal parsing in curl does not properly validate the zone ID portion, allowing a hostname-like string to be interpreted as part of the address.

Impact

A user could be confused and connect to the wrong hostname.

What the attacker needed

Use of curl library with crafted URL; attacker provides malicious URL

How it was found

  1. Build the modified simple.c program.
  2. Compile and run it with the crafted URL.
  3. Observe the actual network traffic to confirm the connection goes to the unexpected host.

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 type a web address, your browser or tool must figure out which server to contact. This report shows that a library called curl can be tricked by a specially formatted address into contacting a different server than the one you might expect, which could confuse you about where you are connecting.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by thomas_v

View all

3 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.