某RCE漏洞复现、排查与监测

一
漏洞复现
1、基础环境
测试服务器:Win7虚拟机
测试服务器IP:192.168.220.134
软件版本:SunloginClient_11.0.0.33162_X64
EXP下载地址:https://github.com/Mr-xn/sunlogin_rce (感谢开源作者)
2、复现流程
在Win7虚拟机里执行 SunloginClient_11.0.0.33162_X64.exe
查看对外开放端口,这里为49218,这个端口不是固定的,重启程序会变。
配合查找的命令:
netstat -ano | findstr LISTEN
tasklist | findstr SunloginClient
测试exp,命令执行成功,是system权限:
二
漏洞原理分析
1、EXP源码分析
其实直接看exp源码,也能猜个差不多,莫过于:
(1)授权认证出了问题,任意用户可以获得访问令牌;
(2)存在命令注入问题。
对导致命令执行的url进行url解码可以看的更清楚些:
2、流量分析
执行exp,并使用wireshark抓包。
抓包时可以使用bpf语句过滤掉无关的报文,如:
host 192.168.220.134 and tcp port 49168


命令执行,存在命令注入的问题:

3、为了定位命令执行的关键代码位置
(1)行为分析
使用 Procmon 对程序进行行为分析,找到命令执行的关键函数,CreateProcessA。其实不用找,大概也能猜出来,可以把常见造成命令执行的函数都下个断点,断下来之后再进行判断。


(2)动态调试
PsExec64.exe -i -s cmd

调试->高级->隐藏调试器(PEB)

(3)静态分析

三
渗透测试
编写Goby脚本
(1)配置“漏洞信息”:

这里的指纹信息十分关键,Goby在扫描的时候,会先扫描资产,这个指纹就是用来判断资产种类的,匹配上指纹之后,才会打对应的poc。指纹的好坏,直接决定了扫描速度。
body="Verification failure" && body="false" && header="Cache-Control: no-cache" && header="Content-Length: 46" && header="Content-Type: application/json"
(2)配置“扫描测试”
Test1

指纹判断,如果访问成功,则根据正则提取CID:

可以用python快速测试正则:
import re
a=r'''{"__code":0,"enabled":"1","verify_string":"ysDRmcQu37usMmdA60fniHTv3cJzlWHz","code":0}'''
filter=re.compile(r'''"verify_string":"(\S+?)",''')
res = filter.findall(a)
print(res)
Test2


(3)测试效果

测试过程可以使用wireshark抓包来辅助poc编写,也可以参考老的poc脚本,其目录在goby-win-x64-1.8.293\golib\exploits\user,或者通过poc管理导出来也是可以的。

四
态势感知
1、流量监测
(1)尽可能多的生成多种形式的攻击流量
考虑合理变形,尽可能多的生成多种形式的攻击流量,以便用来测试检测规则。

(2)编写规则并测试
/\/check?.*cmd[\s]*?=(?:ping|nslookup).*?(?:\.\.\/|\.\.\\)/
[\s]*?= 匹配任意个空白符,非贪婪匹配,匹配最近的“=”
(?:ping|nslookup) 匹配 ping 或 nslookup,?:表示不获取匹配结果
(?:\.\.\/|\.\.\\) 匹配 ../ 或 ..\
apt install pcre2-utils
pcre2test

此规则可以应对正常攻击和部分变形,但依然存在被绕过的可能。规则写严了容易漏报,写松了容易误报,另外还应该要考虑报文分片传输、丢包的问题。
vim /etc/suricata/rules/test.rules
alert http any any -> any any (msg:"CNVD-2022-10270 SunloginClient RCE"; pcre:"/\/check?.*cmd[\s]*?=(?:ping|nslookup).*?(?:\.\.\/|\.\.\\)/U"; classtype:attempted-admin; sid:22022801; rev:2;)
rule-files:
#- suricata.rules
- test.rules
suricata -r sunlogin_rce_multi_payload.pcap

https://suricata.readthedocs.io/en/suricata-6.0.0/rules/
https://rocknsm.io/
https://github.com/arkime/arkime
2、终端监测
Sysmon64.exe -i

事件查看器 ->应用程序和服务日志 ->Microsoft ->Windows ->Sysmon

https://www.sysgeek.cn/sysmon/;
https://www.maliciouskr.cc/2018/11/15/使用OSSEC构建主机层入侵检测/
https://blog.csdn.net/single7_/article/details/110038117
看雪ID:Jtian
https://bbs.pediy.com/user-home-598931.htm

# 往期推荐


球分享

球点赞

球在看

点击“阅读原文”,了解更多!
[广告]赞助链接:
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
- 小米互联服务上架苹果App Store:同账号设备可互传文件
- 骁龙 X 曼联|红魔球星定制壁纸,助你一展宏图
- 乱下载软件致MBR锁机,逆向分析自救
- 严重PHP漏洞使威联通设备面临远程代码执行风险
- Amazon Linux 2022 来袭,AWS 承诺后续每两年更新一次
- 百家智库 | 诸子项目:13个项目发布招募并实施
- 诸子笔会 | 刘顺:企业数据安全体系建设实践
- 区块链生态系统将崩溃、Rust 超越 Go、无服务器成主导,这十大计算机预测将成真?
- 又拍云出席全球云计算大会,入选云鼎奖“云鼎奖”最具潜力企业奖
- 如何成为一名更出色的开发者?
- @所有技术人,快来翻开属于你的2021定制日历!
- 如何满足微信小程序的HTTPS要求