curl - SOCKS5 heap buffer overflow - CVE-2023-38545
A heap buffer overflow in curl's SOCKS5 proxy handshake occurs when a hostname longer than 255 bytes is used and the handshake is slow, causing the hostname to be copied into a buffer instead of the resolved address. An attacker could potentially trigger this via a malicious server redirecting to a crafted URL, leading to memory corruption.
curl.se
Published on curl.se
curl / Docs / curl CVEs / SOCKS5 heap buffer overflow
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a state machine bug where a local variable indicating remote name resolution gets the wrong value during a slow SOCKS5 handshake, causing the too-long hostname to be copied into the target buffer.
Impact
An attacker could cause a heap buffer overflow, potentially leading to memory corruption and possibly code execution, though the overflow requires a slow handshake and a hostname longer than the buffer.
What the attacker needed
Curl built with SOCKS5 support; use of socks5h:// proxy or CURLPROXY_SOCKS5_HOSTNAME; hostname longer than buffer size; slow SOCKS5 handshake
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 write-up has not been written yet. The Original tab links to the source.
When curl connects through a SOCKS5 proxy, it can ask the proxy to resolve the hostname. If the hostname is very long, curl is supposed to resolve it locally instead. But a bug causes curl to copy the long hostname into a fixed-size buffer, which can overflow and corrupt memory. This could let an attacker crash the program or possibly run malicious code.
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.