⚠️ 流程不一定具有普适性,仅抛砖引玉。可能存在Bug,大佬们轻拍。

网上有不少文章也是提到过用Arthas做手工排查,但几乎都停留在把Filter之类的列出来,一个个看。在某些场景下是否有捷径呢。

攻击工具:shiro_attack-4.5-SNAPSHOT-all.jar + Behinder_v3.0_Beta_11.t00ls
测试流程:CommonsBeanutils1_192链->AllEcho回显->BehinderFilter内存马->冰蝎连接->冰蝎命令执行->冰蝎反弹shell(执行失败)->修改ShiroKey(执行失败)

手工排查Trick

  1. 打开Arthas直奔classloader,可以立刻发现异常,即TransletClassloader和BehinderFilter。

Screen Shot 2021-12-14 at 10.49.18 PM.png
classloader -l可以获取到hash,可以用此快速查询加载关系。
Screen Shot 2021-12-14 at 11.10.14 PM.png

  1. 加载关系查询

Screen Shot 2021-12-14 at 11.15.07 PM.png

  1. 类基本信息查询

Screen Shot 2021-12-14 at 10.54.32 PM.png
Screen Shot 2021-12-14 at 11.07.20 PM.png

  1. dump+反编译可疑类分析code即可。

    分析示例

    【这组结果的测试过程中由于在冰蝎中多次执行了命令,导致多个RunCMD的注入】
    [1][HIGH] - Behinder.RunCMD - 序列6
    ClassName: org.urhfml.kbkm.Mldrqqyja
    ClassLoader: com.summersec.x.BehinderFilter
    RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[2][HIGH] - Behinder.RunCMD - 序列6
ClassName: sun.sqa.Yxrlub
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[3][HIGH] - Behinder.RunCMD - 序列6
ClassName: com.zyr.Fuzayjv
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[4][HIGH] - Behinder.RunCMD - 序列6
ClassName: org.dzwjjy.psznmm.okjqp.Bzil
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[5][HIGH] - Behinder.RunCMD - 序列6
ClassName: sun.ygwhg.dyne.rprd.Hponerrk
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[6][HIGH] - Behinder.RunCMD - 序列6
ClassName: org.ivomwm.qmpecc.sco.Fjyiv
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[7][HIGH] - Behinder.RunCMD - 序列6
ClassName: com.rrnckzs.ixfjcjs.kjztoj.Szdssch
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[8][HIGH] - Behinder.RunCMD - 序列6
ClassName: sun.wkkt.Jfzpi
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[9][HIGH] - Behinder.RunCMD - 序列6
ClassName: com.meuicbu.Azki
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[10][HIGH] - Behinder.RunCMD - 序列6
ClassName: com.kpyk.cndtyrf.hnti.Lberajy
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[11][HIGH] - Behinder.RunCMD - 序列6
ClassName: net.rjykxz.Lsoqzclznb
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Common High-Risk Malicious Code Snippets, Dangerous SubClass]

[12][HIGH] - Behinder.BasicInfo - 序列5
ClassName: net.rbtzqii.Rwdpkv
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Dangerous SubClass]

[13][HIGH] - Behinder.Echo - 序列4
ClassName: com.nvtkfw.jxkb.Ecerpaprz
ClassLoader: com.summersec.x.BehinderFilter
RiskInfo: [No ClassFile, Dangerous SubClass]

[14][HIGH] - 用于冰蝎连接的filter内存马 - 序列3
ClassName: com.summersec.x.BehinderFilter
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Suspicious Class Name, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]

[15][HIGH] - 反序列化攻击痕迹 - InjectMemTool - 序列2 - 负责加载BehinderFilter
ClassName: com.summersec.x.Test13503889287361
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]

[16][HIGH] - 反序列化攻击痕迹 - AllEcho - 序列1
ClassName: com.summersec.x.Test13473692431012
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]

测试流程

【攻击测试过程中出现了亿点点的事故,在使用冰蝎的反弹shell功能时往JVM里ddos了387个ReversePortMap,估计是死循环bug之类的,虽然我用冰蝎测完就立马关掉了。】

shiro_attack

需要先填key或爆破出key,就是正常的poc式测试,这一步分析省略。

1. 利用链检测

image.png
image.png

2. 利用链爆破

WeChatWorkScreenshot_3f05f4a5-ea33-4e41-bc51-c2dce4510883.png
对库中所支持的利用链+回显排列组合,逐一尝试。
WeChatWorkScreenshot_5dcd16d8-645d-4bc4-a76b-ba3573d362f2.png
该情景下CB1_192+AllEcho测试成功,此时会直接通过反序列化向内存define一个用于回显的AllEcho:
[1][HIGH] - 反序列化攻击痕迹 - AllEcho - 序列1
ClassName: com.summersec.x.Test20192865287774
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]

3. 执行注入

WeChatWorkScreenshot_27598515-2794-4c12-a98b-85bbff7051cd.png
WeChatWorkScreenshot_6aed15cf-e6e5-4c92-9dcb-5f41fd4a37f6.png
[2][HIGH] - 反序列化攻击痕迹 - InjectMemTool - 序列2 - 负责加载BehinderFilter
ClassName: com.summersec.x.Test22479024922353
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]
[3][HIGH] - 用于冰蝎连接的filter内存马 - 序列3
ClassName: com.summersec.x.BehinderFilter
ClassLoader: com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl$TransletClassLoader
RiskInfo: [No ClassFile, Suspicious Class Name, Dangerous ClassLoader, Common High-Risk Malicious Code Snippets]
这两个类的define实际在一次请求中,详见AttackService.injectMem中的逻辑,filter内存马的字节序列编码后放置在请求的参数中。即该工具每进行一次内存马注入,都会生成一个x.Testxxxxxx和其注入的内存马。
WeChatWorkScreenshot_82c565fe-eed0-4198-8bbb-3eda5b0087db.png
x.Testxxxxxx获取请求参数中内存马的字节码编码,并解码对内存马进行define,调用内存马类的equals函数处会执行对应内存马的注册流程。
WeChatWorkScreenshot_1e0df8b2-7f1a-468f-a58a-6babfdfac6f3.png

Behinder

WeChatWorkScreenshot_841de48b-3208-4456-9db0-ed1ebe31cf0a.png
当double-click某个shell的时,会调用MainController.openShell,随后触发ShellService.echo和ShellService.getBasicInfo�的调用。
有意思的是,冰蝎会间隔一段时间(未知是否规律)去调用一次ShellService.echo,而每一次调用,JVM中都会新增一个Echo(net.rebeyond.behinder.payload.java.Echo)类。
在执行命令时,每次会触发ShellService.runCmd的调用,且每次调用,JVM中都会新增一个Cmd(net.rebeyond.behinder.payload.java.Cmd)�类。
WeChatWorkScreenshot_dc17e25d-c3cb-45a1-8517-0f23cbc1a089.png
例如分别执行了两次命令,runCmd会被触发两次:
wecom-temp-3516bb87362d5858a7ecf454cca85275.png
wecom-temp-f20450165b7b830062f5f5086f62f3d4.png

暂未解决的疑问

  1. 冰蝎不定时进行echo的心跳检测是必要的吗?每次执行某个操作都会向JVM新define一个类是否属于敏感操作?是否必要?如何优化?会不会触发一些类似RASP安全设备的告警?是否会在某些类中暴露可溯源信息?
  2. 针对以classloader入手/作为特征的检测方式,反序列化攻击和内存马植入有什么规避手段?