Deserialization
- f untrusted data in Java
Apostolos Giannakidis @apgiannakidis
Analysis, current solutions & a new approach
1
OWASP London Meetup 18th May 2017
Deserialization of untrusted data in Java Analysis, current - - PowerPoint PPT Presentation
Deserialization of untrusted data in Java Analysis, current solutions & a new approach Apostolos Giannakidis OWASP London Meetup @apgiannakidis 18th May 2017 1 Whois Security Architect at Waratek Application security
Apostolos Giannakidis @apgiannakidis
1
OWASP London Meetup 18th May 2017
security
2
3
4
5
6
7
”Allowing a class’s instances to be serializable can be as simple as adding the words “implements Serializable” to the class. This is a common misconception, the truth is far more complex.”
Effective Java
8
security permissions
9
10
Focus on attack techniques found by Gabriel Lawrence, Chris Frohoff, Steve Breen, Matthias Kaiser, Alvaro Muñoz
11
ActiveMQ, JBoss EAP, etc.)
12
Virtually everyone!
13
can result in malicious behavior
InputStream untrusted = request.getInputStream(); ObjectInputStream ois = new ObjectInputStream( untrusted ); SomeObject deserialized = (SomeObject) ois.readObject();
14
Transportation Agency
Deserialization RCE
Source: https://www.thesslstore.com, https://arstechnica.com
15
16
17
exploitable
18
public class SomeClass implements Serializable { private String cmd; private void readObject( ObjectInputStream stream ) throws Exception { stream.defaultReadObject(); Runtime.getRuntime().exec( cmd ); } }
19
public class SomeClass implements Serializable { private String cmd; private void readObject( ObjectInputStream stream ) throws Exception { stream.defaultReadObject(); Runtime.getRuntime().exec( cmd ); } }
20
21
22
23
24
control
25
26
HashMap<String, String> map = new HashMap<>(); map.put( “org.apache.commons.collections.functors.InvokerTransformer”, “calc.exe” ); FileOutputStream file = new FileOutputStream( "out.bin" ); ObjectOutputStream out = new ObjectOutputStream(file);
27
Silently Pwning Your Java Endpoints)
28
29
30
31
a new class: SomeClass
class SomeClass extends BaseClass { // nothing suspicious }
32
a new class: SomeClass
class SomeClass extends BaseClass { // nothing suspicious }
class BaseClass extends HashMap { }
33
34
finalize())
ObjectInputStream.readObject() AnnotationInvocationHandler.readObject() Map(Proxy).entrySet() AnnotationInvocationHandler.invoke() LazyMap.get() ChainedTransformer.transform() ... Method.invoke() Runtime.getRuntime() InvokerTransformer.transform() Method.invoke() Runtime.exec()
35
Source: Chris Frohoff Marshalling Pickles AppSecCali 2015
LinkedHashSet.readObject() ... LinkedHashSet.add() ... Proxy(Templates).equals() ... ClassLoader.defineClass() Class.newInstance() ... Runtime.exec()
36
Source: Chris Frohoff ysoserial
37
answer
38
39
CERT Secure Coding Standards
MITRE
privileges as late as possible, and drop them as soon as possible.
can be unambiguously drawn.
40
41
untrusted App then the runtime protection also cannot be trusted
hypervisor) to quarantine and control untrusted software
tainting
42
43
44
45
Runtime compartmentalization
such as deserialization
Privilege de-escalation
attacks Runtime virtualization
46
Apostolos Giannakidis @apgiannakidis