冰蝎、哥斯拉 内存马应急排查
内存马的排查方式汇总。内存马的原理分析网上有很多文章,这里就不介绍了。通过实验分析如何在实战环境中快速定位内存马。
实验环境
- Centos / tomcat 7.0.76
- 冰蝎v4.0.5
- 哥斯拉v4.0.1
- Arthas 3.6.6
环境搭建
安装tomcat
通过yum安装tomcat。
yum install -y tomcat tomcat-webapps tomcat-admin-webapps systemctl start tomcat
启动后访问8080端口,看到tomcat起来了。
![](https://zgao.top/wp-content/uploads/2022/10/image-33-1024x391.png)
安装 Arthas
https://github.com/alibaba/arthas/releases
下载压缩包解压执行
wget https://github.com/alibaba/arthas/releases/download/arthas-all-3.6.6/arthas-bin.zip unzip arthas-bin.zip java -jar arthas-boot.jar
![](https://zgao.top/wp-content/uploads/2022/10/image-37-1024x521.png)
哥斯拉 内存马
用哥斯拉生成🐴。
![](https://zgao.top/wp-content/uploads/2022/10/image-34-1024x443.png)
放到网站根目录下面。
![](https://zgao.top/wp-content/uploads/2022/10/image-35-1024x537.png)
植入内存马之前查看内存中mbean信息。
mbean | grep "name=/"
![](https://zgao.top/wp-content/uploads/2022/10/image-38-1024x473.png)
FilterShell
连上哥斯拉的webshell可以看到提供了memoryShell和FilterShell两种🐴。
![](https://zgao.top/wp-content/uploads/2022/10/image-39-1024x636.png)
![](https://zgao.top/wp-content/uploads/2022/10/image-40-1024x481.png)
可以看到哥斯拉的Filter内存马name中都带有时间戳。
sc *.Filter sc -d org.apache.coyote.SerializationConfig
![](https://zgao.top/wp-content/uploads/2022/10/image-41-864x1024.png)
使用jad反编译我们认为可疑的类。
jad org.apache.coyote.SerializationConfig
![](https://zgao.top/wp-content/uploads/2022/10/image-43-1024x949.png)
![](https://zgao.top/wp-content/uploads/2022/10/image-44-1024x703.png)
代码中大量运用invoke反射来实现。
MemoryShell
![](https://zgao.top/wp-content/uploads/2022/10/image-45-1024x554.png)
添加该内存马后通过mbean可以看到多了几个servlet。
mbean | grep "name=/" sc *.Servlet
![](https://zgao.top/wp-content/uploads/2022/10/image-46-1024x370.png)
![](https://zgao.top/wp-content/uploads/2022/10/image-47-1024x624.png)
可疑的classloader。
![](https://zgao.top/wp-content/uploads/2022/10/image-48-1024x425.png)
冰蝎 内存马
冰蝎内存马由于对底层函数做了hook的操作,所以特征更弱一些。
先生成冰蝎4.0的服务端。
![](https://zgao.top/wp-content/uploads/2022/10/image-49-1024x681.png)
上传后连接注入内存马。
![](https://zgao.top/wp-content/uploads/2022/10/image-50-1024x501.png)
开启冰蝎的防检测功能。
![](https://zgao.top/wp-content/uploads/2022/10/image-51-1024x376.png)
连上内存马。
![](https://zgao.top/wp-content/uploads/2022/10/image-52-1024x507.png)
冰蝎的classloader。
![](https://zgao.top/wp-content/uploads/2022/10/image-53-1024x441.png)
![](https://zgao.top/wp-content/uploads/2022/10/image-54-1024x720.png)
冰蝎🐴属于Servlet类型的,不过并不是加载内存马之后才有的,而是连接冰蝎服务端的时候就有的。
反编译冰蝎的马,可以看到明显AES加密的key。
![](https://zgao.top/wp-content/uploads/2022/10/image-55-1024x669.png)
但是有个终极排查思路,就是内存dump。
heapdump 内存排查
不管冰蝎的内存马如何hook,但是内存🐴肯定是在内存中的。并且访问的时候是有路由映射的。那么内存dump出来的文件肯定会有记录。
heapdump strings /var/cache/tomcat/temp/heapdump2022-10-19-12-464292342944555007800.hprof | grep "POST /"
![](https://zgao.top/wp-content/uploads/2022/10/image-56-1024x625.png)
还有另外一种方法排查冰蝎内存🐴,就是查找内存中web目录的可疑路径。
strings /var/cache/tomcat/temp/heapdump2022-10-19-12-464292342944555007800.hprof | grep -E "/webapps/.*?\!" | sort -u
![](https://zgao.top/wp-content/uploads/2022/10/image-57-1024x429.png)
Arthas 排查内存马命令总结
classloader sc *.Filter sc *.Servlet jad heapdump
注意事项
使用Arthas可能会遇到下面的报错。
Unable to open socket file: target process not responding or HotSpot VM not loaded
![](https://zgao.top/wp-content/uploads/2022/10/image-58-1024x369.png)
该报错是因为tomcat是以tomcat用户运行的,而我们用arthas是用root用户运行的。JVM 只能 attach 同样用户下的 java 进程。
使用runuser命令即可以tomcat用户运行arthas。
runuser -l tomcat -c "java -jar /usr/share/tomcat/arthas-boot.jar"
![](https://zgao.top/wp-content/uploads/2022/10/image-59-1024x488.png)
微信赞赏
支付宝赞赏
3条评论