This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Deserialization of untrusted data"

From OWASP
Jump to: navigation, search
(Related Controls)
Line 8: Line 8:
 
==Description==
 
==Description==
  
Data which is untrusted cannot be trusted to be well formed.
+
Data which is untrusted cannot be trusted to be well formed. Malformed data could be used to abuse application logic, deny service, or execute arbitrary code.
  
 
'''Consequences'''
 
'''Consequences'''
  
* Availability: If a function is making an assumption on when to terminate, based on a sentry in a string, it could easily never terminate.
+
* Availability: The logic of deserialization could be abused to create recursive object graphs or never provide data expected to terminate reading.
 
* Authorization: Potentially code could make assumptions that information in the deserialized object about the data is valid. Functions which make this dangerous assumption could be exploited.
 
* Authorization: Potentially code could make assumptions that information in the deserialized object about the data is valid. Functions which make this dangerous assumption could be exploited.
 +
* Access control (instruction processing): malicious objects can abuse the logic of custom deserializers in order to affect code execution.
  
 
'''Exposure period'''
 
'''Exposure period'''
Line 25: Line 26:
 
'''Platform'''
 
'''Platform'''
  
* Languages: C, C++, Java
+
* Languages: C, C++, Java, Python, Ruby
 
* Operating platforms: Any
 
* Operating platforms: Any
  
Line 34: Line 35:
 
'''Severity'''
 
'''Severity'''
  
Medium
+
High
  
 
'''Likelihood of exploit'''
 
'''Likelihood of exploit'''
Line 43: Line 44:
  
 
An attempt to serialize and then deserialize a class containing transient fields will result in NULLs where the non-transient data should be. This is an excellent way to prevent time, environment-based, or sensitive variables from being carried over and used improperly.
 
An attempt to serialize and then deserialize a class containing transient fields will result in NULLs where the non-transient data should be. This is an excellent way to prevent time, environment-based, or sensitive variables from being carried over and used improperly.
 
  
 
==Risk Factors==
 
==Risk Factors==
  
TBD
+
* Does the deserialization take place before authentication?
 +
* Does the deserialization limit which types can be deserialized?
 +
* Does the deserialization host have types available which can be repurposed towards malicious ends? Sometimes, these types are called "gadgets", considering their similarity to abusable bits of code that already exist in machine code in [[https://en.wikipedia.org/wiki/Return-oriented_programming|Return-Oriented-Programming]] attacks.
  
 +
==Examples==
  
==Examples==
+
The following is an example from Adobe's BlazeDS AMF deserialization vulnerability. You can specify arbitrary classes and properties for a BlazeDS application to deserialize. This particular payload creates an instance of a JFrame on the target server. The created JFrame will have a "defaultCloseOperation" of value 3 -- which indicates that the JVM should exit when this JFrame window is closed.
 +
 
 +
<pre>
 +
[RemoteClass(alias="javax.swing.JFrame")]
 +
public class JFrame {
 +
  public var title:String = "Gotcha!";
 +
  public var defaultCloseOperation:int = 3;
 +
  public var visible:Boolean = true;
 +
}
 +
</pre>
  
In Java:
+
The next example is one that is much more likely to be seen in custom code. It reads an object from an untrusted source, and then casts it to an AcmeObject.
  
 
<pre>
 
<pre>
  try {
+
InputStream is = request.getInputStream();
    File file = new File("object.obj");
+
ObjectInputStream ois = new ObjectInputStream(is);
    ObjectInputStream in = new ObjectInputStream(new
+
AcmeObject acme = (AcmeObject)ois.readObject();
        FileInputStream(file));
 
    javax.swing.JButton button = (javax.swing.JButton)
 
        in.readObject();
 
    in.close();
 
    byte[] bytes = getBytesFromFile(file);
 
    in = new ObjectInputStream(new ByteArrayInputStream(bytes));
 
    button = (javax.swing.JButton) in.readObject();
 
    in.close();
 
  }
 
 
</pre>
 
</pre>
 +
 +
Unfortunately, the casting operation to AcmeObject occurs after the deserialization process ends. Therefore, it's not useful in preventing any attacks that happen during deserialization from occurring.
  
 
==Related [[Attacks]]==
 
==Related [[Attacks]]==
Line 108: Line 113:
  
 
==References==
 
==References==
TBD
+
[[http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere|FoxGlove vulnerability announcement]]
 
+
[[http://wouter.coekaerts.be/2011/amf-arbitrary-code-execution|JFrame DoS example by Wouter Coekaerts]]
 
[[Category:FIXME|add links
 
[[Category:FIXME|add links
  

Revision as of 19:06, 16 November 2015

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.


Last revision (mm/dd/yy): 11/16/2015

Vulnerabilities Table of Contents

Description

Data which is untrusted cannot be trusted to be well formed. Malformed data could be used to abuse application logic, deny service, or execute arbitrary code.

Consequences

  • Availability: The logic of deserialization could be abused to create recursive object graphs or never provide data expected to terminate reading.
  • Authorization: Potentially code could make assumptions that information in the deserialized object about the data is valid. Functions which make this dangerous assumption could be exploited.
  • Access control (instruction processing): malicious objects can abuse the logic of custom deserializers in order to affect code execution.

Exposure period

  • Requirements specification: A deserialization library could be used which provides a cryptographic framework to seal serialized data.
  • Implementation: Not using the safe deserialization/serializing data features of a language can create data integrity problems.
  • Implementation: Not using the protection accessor functions of an object can cause data integrity problems
  • Implementation: Not protecting your objects from default overloaded functions - which may provide for raw output streams of objects - may cause data confidentiality problems.
  • Implementation: Not making fields transient can often may cause data confidentiality problems.

Platform

  • Languages: C, C++, Java, Python, Ruby
  • Operating platforms: Any

Required resources

Any

Severity

High

Likelihood of exploit

Medium

It is often convenient to serialize objects for convenient communication or to save them for later use. However, deserialized data or code can often be modified without using the provided accessor functions if it does not use cryptography to protect itself. Furthermore, any cryptography would still be client-side security - which is of course a dangerous security assumption.

An attempt to serialize and then deserialize a class containing transient fields will result in NULLs where the non-transient data should be. This is an excellent way to prevent time, environment-based, or sensitive variables from being carried over and used improperly.

Risk Factors

  • Does the deserialization take place before authentication?
  • Does the deserialization limit which types can be deserialized?
  • Does the deserialization host have types available which can be repurposed towards malicious ends? Sometimes, these types are called "gadgets", considering their similarity to abusable bits of code that already exist in machine code in [[1]] attacks.

Examples

The following is an example from Adobe's BlazeDS AMF deserialization vulnerability. You can specify arbitrary classes and properties for a BlazeDS application to deserialize. This particular payload creates an instance of a JFrame on the target server. The created JFrame will have a "defaultCloseOperation" of value 3 -- which indicates that the JVM should exit when this JFrame window is closed.

[RemoteClass(alias="javax.swing.JFrame")]
public class JFrame {
   public var title:String = "Gotcha!";
   public var defaultCloseOperation:int = 3;
   public var visible:Boolean = true;
}

The next example is one that is much more likely to be seen in custom code. It reads an object from an untrusted source, and then casts it to an AcmeObject.

InputStream is = request.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is);
AcmeObject acme = (AcmeObject)ois.readObject();

Unfortunately, the casting operation to AcmeObject occurs after the deserialization process ends. Therefore, it's not useful in preventing any attacks that happen during deserialization from occurring.

Related Attacks


Related Vulnerabilities


Related Controls

  • Control 1
  • Control 2
  • Requirements specification: A deserialization library could be used which provides a cryptographic framework to seal serialized data.
  • Implementation: Use the signing features of a language to assure that deserialized data has not been tainted.
  • Implementation: When deserializing data, populate a new object rather than just deserializing. The result is that the data flows through safe input validation and that the functions are safe.
  • Implementation: Explicitly define final readObject() to prevent deserialization.

An example of this is:

private final void readObject(ObjectInputStream in)
throws java.io.IOException {
     throw new java.io.IOException("Cannot be deserialized");
}
  • Implementation: Make fields transient to protect them from deserialization.

Related Technical Impacts


References

[vulnerability announcement] [DoS example by Wouter Coekaerts]