Skip to content
SSRF Disclosed report Intermediate CVE-2012-1823CVE-2024-4577

Incorrect Encoding Conversion in hostname results in indeterminate SSRF vulnerabilities

curl on Chinese-language operating systems converts certain Unicode characters in hostnames to ASCII digits using a best-fit mapping, so a hostname like one containing superscript digits is resolved to 127.0.0.1. An attacker could use this to bypass host-based blocklists and reach internal services, leading to SSRF.

z3r0yu Follow

Originally disclosed on HackerOne

  • Disclosed after 4 days

Summary:

Best-Fit is a character mapping strategy designed to resolve the issue when characters in the source code page lack a direct equivalent in the target code page. During the conversion of characters from a Unicode code page to a non-Unicode code page, if a corresponding character cannot be located, the conversion is carried out using a predefined Best-Fit conversion table.

For instance, the Best-Fit Mapping conversion table for GBK encoding (cp936) can be found at: https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit936.txt

This table contains some intriguing character conversions, such as 0xb9 being mapped to 1 and 0xb2 being mapped to 2. By exploiting this conversion feature, it is possible to construct a hostname that causes curl to initiate network requests to unintended locations, potentially resulting in an SSRF vulnerability.

Initially, this parsing feature was utilized by orange from the DEVCORE team to circumvent the defenses in CVE-2012-1823 and subsequently discover the vulnerability CVE-2024-4577. However, our research team’s testing has revealed that curl supports partial best-fit conversion features on all Chinese operating systems. By exploiting this parsing issue, it is possible to create certain security impacts.

Details

Affected components

The vulnerable component is:

The operating systems affected are:

This feature is supported on Windows, macOS, and Ubuntu (Linux) operating systems with Traditional Chinese, Simplified Chinese, and Japanese language settings.

Steps To Reproduce:

We constructed the following payload:

http://¹²7.0.0.1

The character mapping relationships are as follows:

0xb9 --> displayed as ¹ --> parsed by curl as 1

0xb2 --> displayed as ² --> parsed by curl as 2

The parsing behavior of curl clearly adheres to CODEPAGE 936

image-20240614154339276.png
image-20240614154339276.png From the original on HackerOne

We are uncertain whether the display of ¹² varies across different operating systems, but here is a comparison result provided by Python, demonstrating that ¹² != 12.

image-20240614154930952.png
image-20240614154930952.png From the original on HackerOne

Test

The PoC used for testing here is shown below.

Python
curl -g 'http://¹²7.0.0.1' -v -o /dev/null

I set up an HTTP server on my local machine using port 80 with the following Python code. Upon a successful request, the server will return the string "FindVuln".

Python
from flask import Flask

app = Flask(__name__)
@app.route("/")
def index():
    return "FindVuln"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, threaded=True)

Figure 1 illustrates the parsing behavior of curl on a Chinese Ubuntu system. It can be observed that a request was successfully made to 127.0.0.1, even though the input hostname was different [¹²7.0.0.1].

image-20240614155923543.png
image-20240614155923543.png From the original on HackerOne

Figure 2 illustrates the parsing behavior of curl on an English Ubuntu system. It shows that the best-fit encoding conversion was not followed, which is expected since the English operating system does not support GBK encoding.

image-20240614161214560.png
image-20240614161214560.png From the original on HackerOne

Figure 3 illustrates the parsing behavior of curl on a Chinese macOS system.

image-20240614161157157.png
image-20240614161157157.png From the original on HackerOne

Figure 4 illustrates the parsing behavior of curl on a Chinese Windows system.

image-20240614161119610.png
image-20240614161119610.png From the original on HackerOne

Impact

The impact of this vulnerability is huge because the curl is widely used. In many cases, developers need a blocklist to block on some IPs. However, the vulnerability will help attackers bypass the protections that developers have set up for schemes and hosts. The vulnerability will lead to SSRF[1] and RCE[2] vulnerabilities in several cases.

Impact

Attackers can exploit this parsing difference to initiate requests to unexpected locations, thereby causing potential SSRF vulnerability threats.

The original report as published on HackerOne, by z3r0yu. 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, curl applies a best-fit character conversion to hostnames on Chinese-language systems, mapping non-ASCII characters to ASCII digits before resolution, which changes the effective host.

Impact

Attackers could bypass host blocklists and cause curl to request internal addresses, potentially leading to SSRF; the behaviour depends on the operating system language setting.

What the attacker needed

Curl 8.7.1 or below; Chinese or Japanese system locale; attacker controls a hostname passed to curl

How it was found

  1. Set up a local HTTP server on port 80 that returns a known string.
  2. Run curl with the crafted hostname containing superscript digits and verbose output.
  3. Observe that the request reaches [redacted] on a Chinese-language system, but not on an English-language system.

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 computer converts text between character sets, it sometimes replaces a character with a similar-looking one. curl does this for hostnames on Chinese-language systems, so a hostname that looks unusual can actually point to a local address like 127.0.0.1. This means a security filter that blocks certain addresses can be tricked into allowing a request to an internal service.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

More by z3r0yu

View all

2 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.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.