Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in Java
Vulnerabilities in Java
HackPra WS 2015
2015/10/28
Matthias Kaiser
About Code White
▪ This is not a reference how Serialization works, I skip details for speed. Read the spec.
▪ This talk does _not_ cover Privileged Deserialization (from @samikoivu) used to escape the
JVM Sandbox
▪ Custom Serialization Frameworks like XStream, Castor etc. won’t be discussed although the
exploitation vectors shown here can be applied to XStream
1 What is serialization?
5 Case-Study: CVE-2015-6576
(x) https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html
Class java.io.ObjectOutputStream
▪ Writes serialized data to an OutputStream
▪ Has methods writeObject(), writeChar(), writeShort(), writeUTF(), etc.
Class java.io.ObjectInputStream
▪ Reads serialized data from an InputStream
▪ Has methods readObject(), readChar(), readShort(), readUTF(), etc.
Customizing serialization
▪ Developers can customize how objects are serialized to bytes /deserialized from bytes
▪ Serializing
1. writeReplace() → Developer can provide a replacement object to be serialized
2. writeObject() → Full control over what will written to the stream
▪ Deserializing
1. readObject() → Full control over what will be read from the stream
2. readResolve() → Replacing a deserialized object with another one
CVE-2013-2186:
▪ Calls getTempFile()
▪ The TransformedMap transforms keys/values when stored into the map (put(), putAll())
▪ Therefore the keyTransformer/valueTransformer are invoked
▪ All elements of the Map are stored in a set of Map.Entry objects
1
1. Constructor takes the method to invoke,
argument types and the arguments
2. Invokes the method on the input object
and returns the method return value
2
1. Valid fingerprint
required
▪ We have some check but let’s see how easy it is to bypass them
1 1. Authentication is checked
2. If we are an Elastic Agent we pass
4 3. We are an Elastic Agent if our
5 agentType is “elastic”
4. Again!
5. Get the fingerprint
3
O
E M
D
2015/10/23 Exploiting Deserialization Vulnerabilities in Java 35
5 Case-Study: CVE-2015-6576