CVE-2023-38545: A SOCKS Issue sets a High Rated curl Vulnerability
The curl library issued an anticipated security advisory addressing CVE-2023-38545, which identifies a high-rated heap buffer overflow vulnerability within its SOCKS5 proxy implementation. Prompting the release of libcurl version 8.4.0, Jay Satiro explains the SOCKS5 issue is due to when "curl is asked to pass along the hostname to the SOCKS5 proxy to allow that to resolve the address instead of it getting done by curl itself, the maximum length that hostname can be is 255 bytes." Thus, the issue arises if "the hostname is detected to be longer than 255 bytes, curl switches to local name resolving and instead passes on the resolved address only to the proxy. Due to a bug, the local variable that means "let the host resolve the name" could get the wrong value during a slow SOCKS5 handshake, and contrary to the intention, copy the too long hostname to the target buffer instead of copying just the resolved address there."
Daniel Stenberg, an open-source developer and curl maintainer, provides an example of the abuse of the vulnerability. In this scenario, an attacker leveraging an HTTPS server can manipulate it to send a crafted redirect to a client using libcurl via a SOCKS5 proxy. The crafted redirect includes a long hostname (up to 64KB) in the Location header. "If the libcurl using client has automatic redirect-following enabled, and the SOCKS5 proxy is “slow enough” to trigger the local variable bug, it will copy the crafted host name into the too small allocated buffer and into the adjacent heap memory," Stenberg explains resulting in a heap buffer overflow.
With the release of curl version 8.4.0, a fix has been implemented: when encountering names exceeding the constrained length, curl will no longer default to local resolve mode but will appropriately issue an error message.