curl 任意文件写入漏洞分析与技术解析

本文详细分析了curl工具中dumpeasysrc函数存在的未受控文件写入漏洞,攻击者可通过--libcurl参数指定任意路径覆盖系统敏感文件,并提供了完整的PoC验证步骤和技术细节。

Report #3250117 - Uncontrolled File Write/Arbitrary File Creation

漏洞描述

提供的代码片段中的dumpeasysrc函数允许攻击者通过global->libcurl变量指定任意文件路径来输出生成的libcurl源代码。如果global->libcurl值未经过适当清理或限制,恶意用户可以提供敏感系统文件(例如/etc/passwd/etc/cron.d/malicious_job、用户的.bashrc等)或设备文件(例如/dev/null/dev/random)的路径。

核心问题在于直接调用fopen(o, FOPEN_WRITETEXT),其中o = global->libcurl,且未对提供的路径进行任何检查。

漏洞代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void dumpeasysrc(struct GlobalConfig *global)
{
  struct curl_slist *ptr;
  char *o = global->libcurl; // <--- 'o' 保存用户提供的文件路径

  FILE *out;
  bool fopened = FALSE;
  if(strcmp(o, "-")) {
    out = fopen(o, FOPEN_WRITETEXT); // <--- 在fopen()中直接使用用户提供的路径
    fopened = TRUE;
  }
  else
    out = stdout;
  // ... 函数其余部分将数据写入'out'
}

概念验证(PoC)步骤

我将演示在标准临时目录中覆盖用户创建的非关键文件。这易于复现,并清晰显示了完整性影响,而无需尝试直接破坏关键系统文件(普通用户可能因操作系统权限而被阻止)。

  1. 在临时位置创建一个独特的虚拟文件:
1
2
3
echo "This is the ORIGINAL content of the file." > /tmp/curl_test_overwrite.txt
ls -l /tmp/curl_test_overwrite.txt
cat /tmp/curl_test_overwrite.txt
  1. 执行易受攻击的curl命令覆盖文件: 假设您的curl可执行文件(使用易受攻击代码构建的版本)可在PATH中访问,或者您正在使用./curl运行它。

Curl版本信息:

1
2
3
4
5
6
7
└─# ./curl -V                                                        
WARNING: this libcurl is Debug-enabled, do not use in production

curl 8.15.0-DEV (x86_64-pc-linux-gnu) libcurl/8.15.0-DEV zlib/1.3.1 libpsl/0.21.2
Release-Date: [unreleased]
Protocols: dict file ftp gopher http imap ipfs ipns mqtt pop3 rtsp smtp telnet tftp ws
Features: alt-svc AsynchDNS Debug IPv6 Largefile libz PSL threadsafe TrackMemory UnixSockets

执行覆盖命令:

1
./curl --libcurl /tmp/curl_test_overwrite.txt http://example.com

使用http://example.comgoogle.com更好,因为它避免了潜在的重定向,并使curl输出更简单,专注于--libcurl方面。

  1. 验证curl执行后文件的内容:
1
cat /tmp/curl_test_overwrite.txt

/tmp/curl_test_overwrite.txt的内容将被生成的libcurl C代码替换。

影响

数据损坏/丢失: 任意文件可以被生成的libcurl C源代码覆盖。

时间线

  • tryhackplanet 向curl提交报告

    • 2025年7月13日 下午4:50 UTC
  • bagder curl staff 发表评论

    • 2025年7月13日 下午5:04 UTC
    • “不,这是curl按设计工作。用户提供文件名让curl创建源代码。这不是攻击。”
  • bagder curl staff 关闭报告并将状态更改为"不适用"

    • 2025年7月13日 下午5:06 UTC
  • bagder curl staff 请求披露此报告

    • 2025年7月13日 下午5:06 UTC
    • “根据项目的透明政策,我们希望所有报告都被披露并公开。”
  • jimfuller2024 curl staff 发表评论

    • 2025年7月13日 下午5:07 UTC
    • “也许我漏掉了什么 - 我也没看到这里有任何安全问题。”
  • bagder curl staff 发表评论

    • 2025年7月13日 下午5:12 UTC
    • “curl可以在操作系统允许的文件系统中的任何位置创建文件,使用许多不同的命令行选项。这是设计使然。”
  • bagder curl staff 披露此报告

    • 2025年7月13日 下午5:12 UTC

报告详情

  • 报告时间: 2025年7月13日 下午4:50 UTC
  • 报告者: tryhackplanet
  • 报告对象: curl
  • 报告ID: #3250117
  • 严重性: 高 (7 ~ 8.9)
  • 披露时间: 2025年7月13日 下午5:12 UTC
  • 弱点: 代码注入
  • CVE ID:
  • 赏金:
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计