SlideShare a Scribd company logo
1 of 83
Download to read offline
Automated Discovery of
Deserialization Gadget
Chains
Ian Haken
DEF CON 26, 2018
Automated Discovery of Deserialization Gadget Chains Ian Haken
$ whoami
Senior Security Software Engineer on Netflix’s Platform Security team.
Netflix is a microservice ecosystem and we build security services and
libraries to keep those applications safe:
● Secrets at Scale
● Crypto as a service
● Netflix-wide Authorization
@ianhaken
https://github.com/JackOfMostTrades
Automated Discovery of Deserialization Gadget Chains Ian Haken
DeserializationGadgetChains
● What is a deserialization vulnerability?
● A brief history of deserialization vulnerabilities
● What is a deserialization gadget chain?
● Why focus on gadget chains?
● Building a tool to find gadget chains
● Exploits discovered
Automated Discovery of Deserialization Gadget Chains Ian Haken
W hatisaDeserializationVulnerability?
Automated Discovery of Deserialization Gadget Chains Ian Haken
In object oriented languages (like Java), data is contained in classes and classes
contain code.
W hatisaDeserializationVulnerability?
Automated Discovery of Deserialization Gadget Chains Ian Haken
In object oriented languages (like Java), data is contained in classes and classes
contain code.
Controlling Data Types => Controlling Code!
W hatisaDeserializationVulnerability?
Automated Discovery of Deserialization Gadget Chains Ian Haken
In object oriented languages (like Java), data is contained in classes and classes
contain code.
Controlling Data Types => Controlling Code!
W hatisaDeserializationVulnerability?
@POST
public String renderUser(
HttpServletRequest request) {
ObjectInputStream ois =
new ObjectInputStream(
request.getInputStream());
User user = (User) ois.readObject();
return user.render();
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
In object oriented languages (like Java), data is contained in classes and classes
contain code.
Controlling Data Types => Controlling Code!
W hatisaDeserializationVulnerability?
@POST
public String renderUser(
HttpServletRequest request) {
ObjectInputStream ois =
new ObjectInputStream(
request.getInputStream());
User user = (User) ois.readObject();
return user.render();
}
public class User {
private String name;
public String render() {
return name;
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
In object oriented languages (like Java), data is contained in classes and classes
contain code.
Controlling Data Types => Controlling Code!
W hatisaDeserializationVulnerability?
@POST
public String renderUser(
HttpServletRequest request) {
ObjectInputStream ois =
new ObjectInputStream(
request.getInputStream());
User user = (User) ois.readObject();
return user.render();
}
public class User {
private String name;
public String render() {
return name;
}
}
public class ThumbnailUser
extends User {
private File thumbnail;
public String render() {
return Files.read(thumbnail);
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1
● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and
Lawrence2
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1
● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and
Lawrence2
● 2016: Defending against Java Deserialization Vulnerabilities,
Bay Area OWASP Meetup, September 2016, Luca Carettoni3
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1
● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and
Lawrence2
● 2016: Defending against Java Deserialization Vulnerabilities,
Bay Area OWASP Meetup, September 2016, Luca Carettoni3
● 2017: Friday the 13th: JSON Attacks, Black Hat 2017, Muñoz
and Mirosh4
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1
● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and
Lawrence2
● 2016: Defending against Java Deserialization Vulnerabilities,
Bay Area OWASP Meetup, September 2016, Luca Carettoni3
● 2017: Friday the 13th: JSON Attacks, Black Hat 2017, Muñoz
and Mirosh4
● 2018: Deserialization: what, how and why [not], AppSec USA,
October 2018, Alexei Kojenov5
Deserialization?That’sso2016...
1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf
2 https://frohoff.github.io/appseccali-marshalling-pickles/
3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities
4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf
5 https://appsecus2018.sched.com/event/F04J
Automated Discovery of Deserialization Gadget Chains Ian Haken
Magic methods get executed automatically by
the deserializer, even before deserialization
finishes!
W hyareDeserializationVulnerabilitiessoBad?
Automated Discovery of Deserialization Gadget Chains Ian Haken
Magic methods get executed automatically by
the deserializer, even before deserialization
finishes!
W hyareDeserializationVulnerabilitiessoBad?
@POST
public String renderUser(
HttpServletRequest request) {
ObjectInputStream ois =
new ObjectInputStream(
request.getInputStream());
User user = (User) ois.readObject();
return user.render();
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
Magic methods get executed automatically by
the deserializer, even before deserialization
finishes!
W hyareDeserializationVulnerabilitiessoBad?
@POST
public String renderUser(
HttpServletRequest request) {
ObjectInputStream ois =
new ObjectInputStream(
request.getInputStream());
User user = (User) ois.readObject();
return user.render();
}
public class EvilClass {
public void readObject(
ObjectInputStream ois) {
Runtime.exec(ois.readObject());
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
● readObject() and readResolve() are the main ones…
○ But don’t forget about finalize()!
● Many serializable JDK classes implement these
magic methods and call other methods, so there’s a
lot of additional “known entrypoints.”
○ HashMap
■ Object.hashCode()
■ Object.equals()
○ PriorityQueue
■ Comparator.compare()
■ Comparable.compareTo()
Magicmethods?
Automated Discovery of Deserialization Gadget Chains Ian Haken
MagicMethodstoGadgetChains
public class HashMap<K,V> implements Map<K,V> {
private void readObject(ObjectInputStream s) {
int mappings = s.readInt();
for (int i = 0; i < mappings; i++) {
K key = (K) s.readObject();
V value = (V) s.readObject();
putVal(key.hashCode(), key, value);
}
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
MagicMethodstoGadgetChains
public class HashMap<K,V> implements Map<K,V> {
private void readObject(ObjectInputStream s) {
int mappings = s.readInt();
for (int i = 0; i < mappings; i++) {
K key = (K) s.readObject();
V value = (V) s.readObject();
putVal(key.hashCode(), key, value);
}
}
}
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
MagicMethodstoGadgetChains
public class HashMap<K,V> implements Map<K,V> {
private void readObject(ObjectInputStream s) {
int mappings = s.readInt();
for (int i = 0; i < mappings; i++) {
K key = (K) s.readObject();
V value = (V) s.readObject();
putVal(key.hashCode(), key, value);
}
}
}
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
MagicMethodstoGadgetChains
public class HashMap<K,V> implements Map<K,V> {
private void readObject(ObjectInputStream s) {
int mappings = s.readInt();
for (int i = 0; i < mappings; i++) {
K key = (K) s.readObject();
V value = (V) s.readObject();
putVal(key.hashCode(), key, value);
}
}
}
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
MagicMethodstoGadgetChains
public class HashMap<K,V> implements Map<K,V> {
private void readObject(ObjectInputStream s) {
int mappings = s.readInt();
for (int i = 0; i < mappings; i++) {
K key = (K) s.readObject();
V value = (V) s.readObject();
putVal(key.hashCode(), key, value);
}
}
}
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
public class FnEval implements IFn {
public Object invoke(Object arg) {
return Runtime.exec(arg);
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
ExamplePayload
{
“@class”: “java.util.HashMap”
“members”: [
2,
{
“@class”: “AbstractTableModel$ff19274a”
__clojureFnMap: {
hashCode: {
“@class”: “FnCompose”
f2: { “@class”: “FnConstant”, value: “/usr/bin/calc” },
f1: { “@class”: “FnEval” }
}
}
},
“val”
]
}
W hatgadgetchainsareinyour
applicationhasnothingtodo
withcodeyourapplicationis
calling!
Possiblegadgetchainsareinfluencedbythe
cumulativecollectionofalltransitive
dependenciesforyourapplication
Automated Discovery of Deserialization Gadget Chains Ian Haken
W hat(Java)LibrariesareVulnerable?
● JDK (ObjectInputStream)
● XStream (XML, JSON)
● Jackson (JSON)
● Genson (JSON)
● JSON-IO (JSON)
● FlexSON (JSON)
Libraries have different behavior about what classes they’ll deserialize
and what “magic methods” can automatically be invoked. Keep this in
mind for later…
Spend some time reading Muñoz and Mirosh!!
Automated Discovery of Deserialization Gadget Chains Ian Haken
FindingVulnerabilities
● Finding potential vulnerabilities is similar to
finding many application security issues:
○ Does untrusted input (e.g. a request’s body or input stream)
flow into one of the sinks for this vulnerability type?
○ Existing static and dynamic tools are pretty good at
discovery
ObjectInputStream.readObject()
XStream.fromXML()
ObjectMapper.readValue()
Automated Discovery of Deserialization Gadget Chains Ian Haken
RemediationOptions
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Why not use a better serialization strategy?
RemediationOptions
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Why not use a better serialization strategy?
○ “It’s 2016, there are better options.” -Luca Carettoni
RemediationOptions
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Why not use a better serialization strategy?
○ “It’s 2016, there are better options.” -Luca Carettoni
RemediationOptions
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Why not use a better serialization strategy?
○ “It’s 2016, there are better options.” -Luca Carettoni
RemediationOptions
● Is it worth the effort to remediate? How should we prioritize
remediation?
Is my deserialization vulnerability exploitable?
Automated Discovery of Deserialization Gadget Chains Ian Haken
FindingExploits
● Known exploits in a few projects:
○ ysoserial: Usually limited to chains in particular libraries and
focused on JDK ObjectInputStream
○ marshalsec: Wider breadth of exploits for alternative deserialization
libraries
● But what about…
○ The specific combination of libraries on my classpath?
○ The non-standard deserialization library that I’m using?
Automated Discovery of Deserialization Gadget Chains Ian Haken
ExistingGadgetChainTools
● ysoserial1
○ Collection of known gadget chains and exploits
● joogle2
○ Programatically query about types/methods on the classpath
● Java Deserialization Scanner3
○ Burp Suite plugin; uses known payloads (ysoserial) to discover and exploit vulns.
● marshalsec4
○ Deserialization payload generator for numerous libraries and gadget chains
● NCC Group Burp Plugin5
○ “Mainly based on the work of Muñoz and Mirosh’s Friday the 13th: JSON Attacks”
1 https://github.com/frohoff/ysoserial
2 https://github.com/Contrast-Security-OSS/joogle
3 https://techblog.mediaservice.net/2017/05/reliable-discovery-and-exploitation-of-java-deserialization-vulnerabilities/
4 https://github.com/mbechler/marshalsec
5 https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2018/june/finding-deserialisation-issues-has-never-been-easier-freddy-the-serialisation-killer/
Automated Discovery of Deserialization Gadget Chains Ian Haken
BuildingaNew TooltoFindGadgetChains
What we really want is a tool to evaluate risk.
How important is it to remediate this
vulnerability?
● Is a given deserialization vulnerability exploitable?
● What exploits are possible? RCE, SSRF, DoS?
● It doesn’t need to be perfect; a reasonable overestimation
of risk is useful in this context.
● Note: we don’t actually have to actually generate payloads.
Automated Discovery of Deserialization Gadget Chains Ian Haken
Requirements
● Not looking for vulnerabilities; assume we only use this
tool if we find a vulnerability
● It needs to look at the entire classpath of the application
● It should err on the side of false positives rather than false
negatives
● It should operate on bytecode; we usually have the entire
classpath packaged as a war and may not have sources
(especially if we’re including proprietary, third-party
libraries)
○ Plus it may include libraries written in Groovy, Scala, Clojure, ...
GadgetInspector
A Java bytecode analysis tool for finding gadget
chains.
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Operates on any given classpath, i.e. a particular library or an entire war
● Reports discovered gadget chains as a sequence of method invocations
● Performs some simplistic symbolic execution to understand possible
dataflow from method arguments to subsequent method invocations
● Makes a lot of simplifying assumptions that make code analysis easy
GadgetInspector
Gadget Inspector
● CertificateRevokedException.readObject()
● Collections$CheckedMap.put()
● TreeMap.put()
● scala/math/Ordering$$anon$5.compare()
● scala/PartialFunction$OrElse.apply()
● ...
app.war
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step1:Enumerateclass/methodhierarchy
app.war
● clojure/FnEval
○ clojure/IFn
○ java/io/Serializable
○ java/lang/Object
● clojure/FnConstant
○ clojure/IFn
○ java/io/Serializable
○ java/lang/Object
● clojure/FnCompose
○ clojure/IFn
○ java/io/Serializable
○ java/lang/Object
● AbstractTableModel$ff19274a
○ java/io/Serializable
○ java/lang/Object
WEB-INF/lib
WEB-INF/classes
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
● FnConstant.invoke() -> 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
public class FnDefault {
private FnConstant f;
public Object invoke(Object arg) {
return arg != null ? arg : f.invoke(arg);
}
}
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
● FnConstant.invoke() -> 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
public class FnDefault {
private FnConstant f;
public Object invoke(Object arg) {
return arg != null ? arg : f.invoke(arg);
}
}
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
● FnConstant.invoke() -> 0
Assumption #2: All branch conditions are satisfiable
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
public class FnDefault {
private FnConstant f;
public Object invoke(Object arg) {
return arg != null ? arg : f.invoke(arg);
}
}
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
● FnConstant.invoke() -> 0
Assumption #2: All branch conditions are satisfiable
● FnDefault.invoke() -> 1
● FnDefault.invoke() -> 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class FnConstant implements IFn {
private Object value;
public Object invoke(Object arg) {
return value;
}
}
Step2:Discover“Passthrough”Dataflow
public class FnDefault {
private FnConstant f;
public Object invoke(Object arg) {
return arg != null ? arg : f.invoke(arg);
}
}
Assumption #1: All members of a “tainted” object are also tainted (and
recursively, etc)
● FnConstant.invoke() -> 0
Assumption #2: All branch conditions are satisfiable
● FnDefault.invoke() -> 1
● FnDefault.invoke() -> 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step3:Enumerate“Passthrough”Callgraph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
public class FnCompose implements IFn {
private IFn f1, f2;
public Object invoke(Object arg) {
return f2.invoke(f1.invoke(arg));
}
}
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step4:EnumerateSourcesUsingKnownTricks
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step4:EnumerateSourcesUsingKnownTricks
AbstractTableModel$ff19274a.hashCode() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
public class AbstractTableModel$ff19274a {
private IPersistentMap __clojureFnMap;
public int hashCode() {
IFn f = __clojureFnMap.get("hashCode");
return (int)(f.invoke(this));
}
}
Step4:EnumerateSourcesUsingKnownTricks
AbstractTableModel$ff19274a.hashCode() @ 0
Limitation #1: Relies on known tricks. Some tricks (e.g. HashMap -> hashCode)
we could derive anyway, but others (like DynamicProxy) we could not.
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
● AbstractTableModel...hashCode() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Assumption #3: Any method implementation can be jumped to (as long as its
class is “serializable”)
● AbstractTableModel...hashCode() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Assumption #3: Any method implementation can be jumped to (as long as its
class is “serializable”)
● AbstractTableModel...hashCode() @ 0
● FnCompose.invoke() @ 0
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Assumption #3: Any method implementation can be jumped to (as long as its
class is “serializable”)
● AbstractTableModel...hashCode() @ 0
● FnCompose.invoke() @ 0
● FnEval @ 1
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Assumption #3: Any method implementation can be jumped to (as long as its
class is “serializable”)
● AbstractTableModel...hashCode() @ 0
● FnCompose.invoke() @ 0
● FnEval @ 1
● Runtime.exec() @ 1
Automated Discovery of Deserialization Gadget Chains Ian Haken
Step5:BFSonCallGraphforChains
Sources
● AbstractTableModel$ff19274a.hashCode() @ 0
Call Graph
AbstractTableModel$ff19274a.hashCode()
● 0 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
FnCompose.invoke()
● 1 -> IFn.invoke() @ 1
● 0 -> IFn.invoke() @ 0
● 0 -> IFn.invoke() @ 1
FnEval.invoke()
● 1 -> Runtime.exec() @ 1
Chain
Assumption #3: Any method implementation can be jumped to (as long as its
class is “serializable”)
● AbstractTableModel...hashCode() @ 0
● FnCompose.invoke() @ 0
● FnEval @ 1
● Runtime.exec() @ 1
Limitation #2: Chain discovery relies on a list of known “interesting” sinks
Automated Discovery of Deserialization Gadget Chains Ian Haken
Gadget Inspector supports some customization on the analysis
● What is considered “serializable”?
○ For JRE deserialization, anything implementing java.lang.Serializable
○ For XStream, it depends on the convertors that are enabled
■ And when using custom convertors, it gets even more subtle
○ For Jackson, any class with a no-arg constructor
● What are the deserialization sources (i.e. magic methods)?
○ For Jackson we only start in constructors
● What method implementations should we consider?
○ For JRE deserialization, all implementations in a serializable class
○ For Jackson, depends on annotations and configuration
DeserializationLibraryFlexibility
OSSLibraryResults
Automated Discovery of Deserialization Gadget Chains Ian Haken
Ran Gadget Inspector against the 100 most popular java
libraries (according to mvnrepository.com and javalibs.com)
looking for exploits against standard Java deserialization
● It did rediscover several known gadget chains
● Not that many libraries actually have classes implementing
java.io.Serializable...
○ But there were some interesting new findings!
● Had a handful of false positives but not as many as you’d expect
○ Mostly because reflection is hard to reason about
Results:OSSLibraryScans
Automated Discovery of Deserialization Gadget Chains Ian Haken
commons-collections » commons-collections
38th most popular maven dependency
1. ....corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl
invoke(Object, Method, Object[]) (0)
2. org.apache.commons.collections.map.LazyMap.get(Object) (0)
3. org.apache.commons.collections.functors.InvokerTransformer
transform(Object) (0)
4. java.lang.reflect.Method.invoke(Object, Object[]) (0)
Results:OldGadgetChains
https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/CommonsCollections1.java
Automated Discovery of Deserialization Gadget Chains Ian Haken
New GadgetChains:Clojure
org.clojure » clojure
6th most popular maven dependency
1. clojure.inspector.proxy$javax.swing.table.AbstractTableModel$ff19274a.hashCode() (0)
2. clojure.main$load_script.invoke(Object) (1)
3. clojure.main$load_script.invokeStatic(Object) (0)
4. clojure.lang.Compiler.loadFile(String) (0)
5. FileInputStream.<init>(String) (1)
Tweaked this result to invoke clojure.main$eval_opt instead of
clojure.main$load_script to invoke arbitrary code.
Reported to clojure-dev July 2017, affecting 1.8.0 and all earlier versions.
Serialization of AbstractTableModel$ff19274a disabled in 1.9.0 release
(Dec, 2017).
https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/Clojure.java
Automated Discovery of Deserialization Gadget Chains Ian Haken
New GadgetChains:Scala
org.scala-lang » scala-library
3rd most popular maven dependency
1. scala.math.Ordering$$anon$5.compare(Object, Object) (0)
2. scala.PartialFunction$OrElse.apply(Object) (0)
3. scala.sys.process.processInternal$$anonfun$onIOInterrupt$1
applyOrElse(Object, scala.Function1) (0)
4. scala.sys.process.ProcessBuilderImpl$FileOutput$$anonfun$$lessinit$greater$3.apply() (0)
5. java.io.FileOutputStream.<init>(File, boolean) (1)
Allows you to write/overwrite a file with 0 bytes.
Possible DoS? Zero-out a blacklist?
https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Scala.java
Automated Discovery of Deserialization Gadget Chains Ian Haken
New GadgetChains:Scala
1. scala.math.Ordering$$anon$5.compare(Object, Object) (0)
2. scala.PartialFunction$OrElse.apply(Object) (0)
3. scala.sys.process.processInternal$$anonfun$onIOInterrupt$1
applyOrElse(Object, scala.Function1) (0)
4. scala.sys.process.ProcessBuilderImpl$URLInput$$anonfun$
$lessinit$greater$1.apply() (0)
5. java.net.URL.openStream() (0)
SSRF: Causes application to perform a GET on
an arbitrary URL.
https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Scala.java
Automated Discovery of Deserialization Gadget Chains Ian Haken
New GadgetChains:Clojure2
In rerunning Gadget Inspector on the latest release (1.10.0-alpha4) in
preparation for this presentation, a different entry point was
discovered:
1. clojure.lang.ASeq.hashCode() (0)
2. clojure.lang.Iterate.first() (0)
3. clojure.main$load_script.invoke(Object) (1)
4. clojure.main$load_script.invokeStatic(Object) (0)
5. clojure.lang.Compiler.loadFile(String) (0)
6. FileInputStream.<init>(String) (1)
Confirmed the same tweak to clojure.main$eval_opt works for
arbitrary code execution. Affects all releases since 1.8.0.
https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Clojure2.java
NetflixAppResults
Automated Discovery of Deserialization Gadget Chains Ian Haken
Results:NetflixInternalWebapp1
Potentially dangerous use of Jackson deserialization:
public void doSomething(String body, String queryParam) {
Object requestObject = objectMapper.readValue(
body, Class.forName(queryParam));
● Can only deserialize classes with no-arg constructors
● The only entry points are no-arg constructors
But still, the app has ~200MB classpath. So maybe there’s something
there...
Automated Discovery of Deserialization Gadget Chains Ian Haken
Results:NetflixInternalWebapp1
Potentially dangerous use of Jackson deserialization:
public void doSomething(String body, String queryParam) {
Object requestObject = objectMapper.readValue(
body, Class.forName(queryParam));
● Can only deserialize classes with no-arg constructors
● The only entry points are no-arg constructors
But still, the app has ~200MB classpath. So maybe there’s something
there...
Result: A few false positives and nothing very interesting.
Take-away: Remediation is a low priority
Automated Discovery of Deserialization Gadget Chains Ian Haken
Results:NetflixInternalWebapp2
Used a non-standard deserialization library,
subject to some unique constraints
● Invokes readResolve() but not readObject()
● Serialized objects do not need to implement Serializable
● Member fields of serialized objects cannot have a $ in the
name.
○ Non-static inner classes always have an implicit $outer member name.
● No serialization support for arrays or generic maps
● No null member values
Automated Discovery of Deserialization Gadget Chains Ian Haken
1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0)
2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0)
3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0)
4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0)
5. clojure.lang.APersistentMap$KeySeq.iterator() (0)
6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0)
7. java.util.concurrent.Executors$RunnableAdapter.call() (0)
8. org.apache.commons.exec.StreamPumper.run() (0)
9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0)
10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0)
11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2)
12. java.io.FileOutputStream.<init>(File) (1)
Results:NetflixInternalWebapp2
Automated Discovery of Deserialization Gadget Chains Ian Haken
Results:NetflixInternalWebapp2
1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0)
2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0)
3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0)
4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0)
5. clojure.lang.APersistentMap$KeySeq.iterator() (0)
6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0)
7. java.util.concurrent.Executors$RunnableAdapter.call() (0)
8. org.apache.commons.exec.StreamPumper.run() (0)
9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0)
10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0)
11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2)
12. java.io.FileOutputStream.<init>(File) (1)
com.thoughtworks.xstream:xstream
commons-configuration:commons-configuration
org.clojure:clojure
netflix:netflix-utils
JRE
org.apache.commons:commons-exec
org.aspectj:aspectjtools
Automated Discovery of Deserialization Gadget Chains Ian Haken
1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0)
2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0)
3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0)
4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0)
5. clojure.lang.APersistentMap$KeySeq.iterator() (0)
6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0)
7. java.util.concurrent.Executors$RunnableAdapter.call() (0)
8. org.apache.commons.exec.StreamPumper.run() (0)
9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0)
10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0)
11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2)
12. java.io.FileOutputStream.<init>(File) (1)
Results:NetflixInternalWebapp2
Automated Discovery of Deserialization Gadget Chains Ian Haken
1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0)
2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0)
3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0)
4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0)
5. clojure.lang.APersistentMap$KeySeq.iterator() (0)
6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0)
7. java.util.concurrent.Executors$RunnableAdapter.call() (0)
8. org.apache.commons.exec.StreamPumper.run() (0)
○ is = java.io.StringBufferInputStream
■ buffer = <% String cmd="calc.exe"; ... %>
○ os = org.eclipse.core.internal.localstore.SafeChunkyOutputStream
■ isOpen = false
■ filePath = /webappdir/foo.jsp
Results:NetflixInternalWebapp2
Automated Discovery of Deserialization Gadget Chains Ian Haken
● Reflection
○ Most reflection calls are being treated as interesting, leading to FPs
■ E.g. you can control the class but not the method name, or vice-versa
○ Blind spots for call graph enumeration
■ foo.getClass().getMethod(“bar”).invoke(...)
● Assumptions
○ Even minor improvements would allow Gadget Inspector to make better decisions
around condition satisfiability or virtual method call resolution, leading to fewer
FPs.
● Limitations
○ Entry points are enumerated using “known tricks.” Original research can still help
us find lots of other clever ways to construct gadget chains.
○ Sinks with “interesting behavior” are hard-coded. Lots of room to discover and add
sinks.
Room forImprovement
Automated Discovery of Deserialization Gadget Chains Ian Haken
@ianhaken
https://github.com/JackOfMostTrades
● Automatic discovery for gadget chains is new territory
○ Gadget Inspector is a functional prototype; room for lots of improvement!
○ Gadget Inspector written for Java but techniques apply to other languages
● Gadget Inspector is open source
○ Fork it, submit PRs, or just check it out for more details about how it works
○ https://github.com/JackOfMostTrades/gadgetinspector
● Deserialization vulnerabilities aren’t going away yet
○ Exploits can and will be more complex as time goes on
○ Better tools will help us understand the risk of vulnerabilities
FinalThoughts

More Related Content

Similar to Automated Discovery of Deserialization Gadget Chains

Applied machine learning defeating modern malicious documents
Applied machine learning defeating modern malicious documentsApplied machine learning defeating modern malicious documents
Applied machine learning defeating modern malicious documentsPriyanka Aash
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDevexperts
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassCODE WHITE GmbH
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APIKevin Hakanson
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security ClassRich Helton
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}Anthony Levings
 
stackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure driftstackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure driftNETWAYS
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3Devexperts
 
Compass Framework
Compass FrameworkCompass Framework
Compass FrameworkLukas Vlcek
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization VulnerabilitiesLuca Carettoni
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesLeo Loobeek
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)Woonsan Ko
 
STIX Patterning: Viva la revolución!
STIX Patterning: Viva la revolución!STIX Patterning: Viva la revolución!
STIX Patterning: Viva la revolución!treyka
 

Similar to Automated Discovery of Deserialization Gadget Chains (20)

Applied machine learning defeating modern malicious documents
Applied machine learning defeating modern malicious documentsApplied machine learning defeating modern malicious documents
Applied machine learning defeating modern malicious documents
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programs
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography API
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security Class
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}
 
stackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure driftstackconf 2021 | Why you should take care of infrastructure drift
stackconf 2021 | Why you should take care of infrastructure drift
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
.Net 3.5
.Net 3.5.Net 3.5
.Net 3.5
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)
 
STIX Patterning: Viva la revolución!
STIX Patterning: Viva la revolución!STIX Patterning: Viva la revolución!
STIX Patterning: Viva la revolución!
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 

More from Priyanka Aash

Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
 
Verizon Breach Investigation Report (VBIR).pdf
Verizon Breach Investigation Report (VBIR).pdfVerizon Breach Investigation Report (VBIR).pdf
Verizon Breach Investigation Report (VBIR).pdfPriyanka Aash
 
Top 10 Security Risks .pptx.pdf
Top 10 Security Risks .pptx.pdfTop 10 Security Risks .pptx.pdf
Top 10 Security Risks .pptx.pdfPriyanka Aash
 
Simplifying data privacy and protection.pdf
Simplifying data privacy and protection.pdfSimplifying data privacy and protection.pdf
Simplifying data privacy and protection.pdfPriyanka Aash
 
Generative AI and Security (1).pptx.pdf
Generative AI and Security (1).pptx.pdfGenerative AI and Security (1).pptx.pdf
Generative AI and Security (1).pptx.pdfPriyanka Aash
 
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdf
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdfEVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdf
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdfPriyanka Aash
 
Cyber Truths_Are you Prepared version 1.1.pptx.pdf
Cyber Truths_Are you Prepared version 1.1.pptx.pdfCyber Truths_Are you Prepared version 1.1.pptx.pdf
Cyber Truths_Are you Prepared version 1.1.pptx.pdfPriyanka Aash
 
Cyber Crisis Management.pdf
Cyber Crisis Management.pdfCyber Crisis Management.pdf
Cyber Crisis Management.pdfPriyanka Aash
 
CISOPlatform journey.pptx.pdf
CISOPlatform journey.pptx.pdfCISOPlatform journey.pptx.pdf
CISOPlatform journey.pptx.pdfPriyanka Aash
 
Chennai Chapter.pptx.pdf
Chennai Chapter.pptx.pdfChennai Chapter.pptx.pdf
Chennai Chapter.pptx.pdfPriyanka Aash
 
Cloud attack vectors_Moshe.pdf
Cloud attack vectors_Moshe.pdfCloud attack vectors_Moshe.pdf
Cloud attack vectors_Moshe.pdfPriyanka Aash
 
Stories From The Web 3 Battlefield
Stories From The Web 3 BattlefieldStories From The Web 3 Battlefield
Stories From The Web 3 BattlefieldPriyanka Aash
 
Lessons Learned From Ransomware Attacks
Lessons Learned From Ransomware AttacksLessons Learned From Ransomware Attacks
Lessons Learned From Ransomware AttacksPriyanka Aash
 
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)Emerging New Threats And Top CISO Priorities In 2022 (Chennai)
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)Priyanka Aash
 
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)Priyanka Aash
 
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)Priyanka Aash
 
Cloud Security: Limitations of Cloud Security Groups and Flow Logs
Cloud Security: Limitations of Cloud Security Groups and Flow LogsCloud Security: Limitations of Cloud Security Groups and Flow Logs
Cloud Security: Limitations of Cloud Security Groups and Flow LogsPriyanka Aash
 
Cyber Security Governance
Cyber Security GovernanceCyber Security Governance
Cyber Security GovernancePriyanka Aash
 

More from Priyanka Aash (20)

Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
 
Verizon Breach Investigation Report (VBIR).pdf
Verizon Breach Investigation Report (VBIR).pdfVerizon Breach Investigation Report (VBIR).pdf
Verizon Breach Investigation Report (VBIR).pdf
 
Top 10 Security Risks .pptx.pdf
Top 10 Security Risks .pptx.pdfTop 10 Security Risks .pptx.pdf
Top 10 Security Risks .pptx.pdf
 
Simplifying data privacy and protection.pdf
Simplifying data privacy and protection.pdfSimplifying data privacy and protection.pdf
Simplifying data privacy and protection.pdf
 
Generative AI and Security (1).pptx.pdf
Generative AI and Security (1).pptx.pdfGenerative AI and Security (1).pptx.pdf
Generative AI and Security (1).pptx.pdf
 
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdf
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdfEVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdf
EVERY ATTACK INVOLVES EXPLOITATION OF A WEAKNESS.pdf
 
DPDP Act 2023.pdf
DPDP Act 2023.pdfDPDP Act 2023.pdf
DPDP Act 2023.pdf
 
Cyber Truths_Are you Prepared version 1.1.pptx.pdf
Cyber Truths_Are you Prepared version 1.1.pptx.pdfCyber Truths_Are you Prepared version 1.1.pptx.pdf
Cyber Truths_Are you Prepared version 1.1.pptx.pdf
 
Cyber Crisis Management.pdf
Cyber Crisis Management.pdfCyber Crisis Management.pdf
Cyber Crisis Management.pdf
 
CISOPlatform journey.pptx.pdf
CISOPlatform journey.pptx.pdfCISOPlatform journey.pptx.pdf
CISOPlatform journey.pptx.pdf
 
Chennai Chapter.pptx.pdf
Chennai Chapter.pptx.pdfChennai Chapter.pptx.pdf
Chennai Chapter.pptx.pdf
 
Cloud attack vectors_Moshe.pdf
Cloud attack vectors_Moshe.pdfCloud attack vectors_Moshe.pdf
Cloud attack vectors_Moshe.pdf
 
Stories From The Web 3 Battlefield
Stories From The Web 3 BattlefieldStories From The Web 3 Battlefield
Stories From The Web 3 Battlefield
 
Lessons Learned From Ransomware Attacks
Lessons Learned From Ransomware AttacksLessons Learned From Ransomware Attacks
Lessons Learned From Ransomware Attacks
 
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)Emerging New Threats And Top CISO Priorities In 2022 (Chennai)
Emerging New Threats And Top CISO Priorities In 2022 (Chennai)
 
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)
Emerging New Threats And Top CISO Priorities In 2022 (Mumbai)
 
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)
Emerging New Threats And Top CISO Priorities in 2022 (Bangalore)
 
Cloud Security: Limitations of Cloud Security Groups and Flow Logs
Cloud Security: Limitations of Cloud Security Groups and Flow LogsCloud Security: Limitations of Cloud Security Groups and Flow Logs
Cloud Security: Limitations of Cloud Security Groups and Flow Logs
 
Cyber Security Governance
Cyber Security GovernanceCyber Security Governance
Cyber Security Governance
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Automated Discovery of Deserialization Gadget Chains

  • 1. Automated Discovery of Deserialization Gadget Chains Ian Haken DEF CON 26, 2018
  • 2. Automated Discovery of Deserialization Gadget Chains Ian Haken $ whoami Senior Security Software Engineer on Netflix’s Platform Security team. Netflix is a microservice ecosystem and we build security services and libraries to keep those applications safe: ● Secrets at Scale ● Crypto as a service ● Netflix-wide Authorization @ianhaken https://github.com/JackOfMostTrades
  • 3. Automated Discovery of Deserialization Gadget Chains Ian Haken DeserializationGadgetChains ● What is a deserialization vulnerability? ● A brief history of deserialization vulnerabilities ● What is a deserialization gadget chain? ● Why focus on gadget chains? ● Building a tool to find gadget chains ● Exploits discovered
  • 4. Automated Discovery of Deserialization Gadget Chains Ian Haken W hatisaDeserializationVulnerability?
  • 5. Automated Discovery of Deserialization Gadget Chains Ian Haken In object oriented languages (like Java), data is contained in classes and classes contain code. W hatisaDeserializationVulnerability?
  • 6. Automated Discovery of Deserialization Gadget Chains Ian Haken In object oriented languages (like Java), data is contained in classes and classes contain code. Controlling Data Types => Controlling Code! W hatisaDeserializationVulnerability?
  • 7. Automated Discovery of Deserialization Gadget Chains Ian Haken In object oriented languages (like Java), data is contained in classes and classes contain code. Controlling Data Types => Controlling Code! W hatisaDeserializationVulnerability? @POST public String renderUser( HttpServletRequest request) { ObjectInputStream ois = new ObjectInputStream( request.getInputStream()); User user = (User) ois.readObject(); return user.render(); }
  • 8. Automated Discovery of Deserialization Gadget Chains Ian Haken In object oriented languages (like Java), data is contained in classes and classes contain code. Controlling Data Types => Controlling Code! W hatisaDeserializationVulnerability? @POST public String renderUser( HttpServletRequest request) { ObjectInputStream ois = new ObjectInputStream( request.getInputStream()); User user = (User) ois.readObject(); return user.render(); } public class User { private String name; public String render() { return name; } }
  • 9. Automated Discovery of Deserialization Gadget Chains Ian Haken In object oriented languages (like Java), data is contained in classes and classes contain code. Controlling Data Types => Controlling Code! W hatisaDeserializationVulnerability? @POST public String renderUser( HttpServletRequest request) { ObjectInputStream ois = new ObjectInputStream( request.getInputStream()); User user = (User) ois.readObject(); return user.render(); } public class User { private String name; public String render() { return name; } } public class ThumbnailUser extends User { private File thumbnail; public String render() { return Files.read(thumbnail); } }
  • 10. Automated Discovery of Deserialization Gadget Chains Ian Haken Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 11. Automated Discovery of Deserialization Gadget Chains Ian Haken ● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1 Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 12. Automated Discovery of Deserialization Gadget Chains Ian Haken ● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1 ● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and Lawrence2 Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 13. Automated Discovery of Deserialization Gadget Chains Ian Haken ● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1 ● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and Lawrence2 ● 2016: Defending against Java Deserialization Vulnerabilities, Bay Area OWASP Meetup, September 2016, Luca Carettoni3 Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 14. Automated Discovery of Deserialization Gadget Chains Ian Haken ● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1 ● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and Lawrence2 ● 2016: Defending against Java Deserialization Vulnerabilities, Bay Area OWASP Meetup, September 2016, Luca Carettoni3 ● 2017: Friday the 13th: JSON Attacks, Black Hat 2017, Muñoz and Mirosh4 Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 15. Automated Discovery of Deserialization Gadget Chains Ian Haken ● 2006: Pentesting J2EE, Black Hat 2006, Marc Schönefeld1 ● 2015: Marshalling Pickles, AppSecCali 2015, Frohoff and Lawrence2 ● 2016: Defending against Java Deserialization Vulnerabilities, Bay Area OWASP Meetup, September 2016, Luca Carettoni3 ● 2017: Friday the 13th: JSON Attacks, Black Hat 2017, Muñoz and Mirosh4 ● 2018: Deserialization: what, how and why [not], AppSec USA, October 2018, Alexei Kojenov5 Deserialization?That’sso2016... 1 http://www.blackhat.com/presentations/bh-federal-06/BH-Fed-06-Schoenefeld-up.pdf 2 https://frohoff.github.io/appseccali-marshalling-pickles/ 3 https://www.slideshare.net/ikkisoft/defending-against-java-deserialization-vulnerabilities 4 https://www.blackhat.com.docs.us-17.thursday.us-17-Munoz-Friday-The-13th-Json-Attacks.pdf 5 https://appsecus2018.sched.com/event/F04J
  • 16. Automated Discovery of Deserialization Gadget Chains Ian Haken Magic methods get executed automatically by the deserializer, even before deserialization finishes! W hyareDeserializationVulnerabilitiessoBad?
  • 17. Automated Discovery of Deserialization Gadget Chains Ian Haken Magic methods get executed automatically by the deserializer, even before deserialization finishes! W hyareDeserializationVulnerabilitiessoBad? @POST public String renderUser( HttpServletRequest request) { ObjectInputStream ois = new ObjectInputStream( request.getInputStream()); User user = (User) ois.readObject(); return user.render(); }
  • 18. Automated Discovery of Deserialization Gadget Chains Ian Haken Magic methods get executed automatically by the deserializer, even before deserialization finishes! W hyareDeserializationVulnerabilitiessoBad? @POST public String renderUser( HttpServletRequest request) { ObjectInputStream ois = new ObjectInputStream( request.getInputStream()); User user = (User) ois.readObject(); return user.render(); } public class EvilClass { public void readObject( ObjectInputStream ois) { Runtime.exec(ois.readObject()); } }
  • 19. Automated Discovery of Deserialization Gadget Chains Ian Haken ● readObject() and readResolve() are the main ones… ○ But don’t forget about finalize()! ● Many serializable JDK classes implement these magic methods and call other methods, so there’s a lot of additional “known entrypoints.” ○ HashMap ■ Object.hashCode() ■ Object.equals() ○ PriorityQueue ■ Comparator.compare() ■ Comparable.compareTo() Magicmethods?
  • 20. Automated Discovery of Deserialization Gadget Chains Ian Haken MagicMethodstoGadgetChains public class HashMap<K,V> implements Map<K,V> { private void readObject(ObjectInputStream s) { int mappings = s.readInt(); for (int i = 0; i < mappings; i++) { K key = (K) s.readObject(); V value = (V) s.readObject(); putVal(key.hashCode(), key, value); } } }
  • 21. Automated Discovery of Deserialization Gadget Chains Ian Haken MagicMethodstoGadgetChains public class HashMap<K,V> implements Map<K,V> { private void readObject(ObjectInputStream s) { int mappings = s.readInt(); for (int i = 0; i < mappings; i++) { K key = (K) s.readObject(); V value = (V) s.readObject(); putVal(key.hashCode(), key, value); } } } public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } }
  • 22. Automated Discovery of Deserialization Gadget Chains Ian Haken MagicMethodstoGadgetChains public class HashMap<K,V> implements Map<K,V> { private void readObject(ObjectInputStream s) { int mappings = s.readInt(); for (int i = 0; i < mappings; i++) { K key = (K) s.readObject(); V value = (V) s.readObject(); putVal(key.hashCode(), key, value); } } } public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } }
  • 23. Automated Discovery of Deserialization Gadget Chains Ian Haken MagicMethodstoGadgetChains public class HashMap<K,V> implements Map<K,V> { private void readObject(ObjectInputStream s) { int mappings = s.readInt(); for (int i = 0; i < mappings; i++) { K key = (K) s.readObject(); V value = (V) s.readObject(); putVal(key.hashCode(), key, value); } } } public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } } public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } }
  • 24. Automated Discovery of Deserialization Gadget Chains Ian Haken MagicMethodstoGadgetChains public class HashMap<K,V> implements Map<K,V> { private void readObject(ObjectInputStream s) { int mappings = s.readInt(); for (int i = 0; i < mappings; i++) { K key = (K) s.readObject(); V value = (V) s.readObject(); putVal(key.hashCode(), key, value); } } } public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } } public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } public class FnEval implements IFn { public Object invoke(Object arg) { return Runtime.exec(arg); } }
  • 25. Automated Discovery of Deserialization Gadget Chains Ian Haken ExamplePayload { “@class”: “java.util.HashMap” “members”: [ 2, { “@class”: “AbstractTableModel$ff19274a” __clojureFnMap: { hashCode: { “@class”: “FnCompose” f2: { “@class”: “FnConstant”, value: “/usr/bin/calc” }, f1: { “@class”: “FnEval” } } } }, “val” ] }
  • 27. Automated Discovery of Deserialization Gadget Chains Ian Haken W hat(Java)LibrariesareVulnerable? ● JDK (ObjectInputStream) ● XStream (XML, JSON) ● Jackson (JSON) ● Genson (JSON) ● JSON-IO (JSON) ● FlexSON (JSON) Libraries have different behavior about what classes they’ll deserialize and what “magic methods” can automatically be invoked. Keep this in mind for later… Spend some time reading Muñoz and Mirosh!!
  • 28. Automated Discovery of Deserialization Gadget Chains Ian Haken FindingVulnerabilities ● Finding potential vulnerabilities is similar to finding many application security issues: ○ Does untrusted input (e.g. a request’s body or input stream) flow into one of the sinks for this vulnerability type? ○ Existing static and dynamic tools are pretty good at discovery ObjectInputStream.readObject() XStream.fromXML() ObjectMapper.readValue()
  • 29. Automated Discovery of Deserialization Gadget Chains Ian Haken RemediationOptions
  • 30. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Why not use a better serialization strategy? RemediationOptions
  • 31. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Why not use a better serialization strategy? ○ “It’s 2016, there are better options.” -Luca Carettoni RemediationOptions
  • 32. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Why not use a better serialization strategy? ○ “It’s 2016, there are better options.” -Luca Carettoni RemediationOptions
  • 33. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Why not use a better serialization strategy? ○ “It’s 2016, there are better options.” -Luca Carettoni RemediationOptions ● Is it worth the effort to remediate? How should we prioritize remediation? Is my deserialization vulnerability exploitable?
  • 34. Automated Discovery of Deserialization Gadget Chains Ian Haken FindingExploits ● Known exploits in a few projects: ○ ysoserial: Usually limited to chains in particular libraries and focused on JDK ObjectInputStream ○ marshalsec: Wider breadth of exploits for alternative deserialization libraries ● But what about… ○ The specific combination of libraries on my classpath? ○ The non-standard deserialization library that I’m using?
  • 35. Automated Discovery of Deserialization Gadget Chains Ian Haken ExistingGadgetChainTools ● ysoserial1 ○ Collection of known gadget chains and exploits ● joogle2 ○ Programatically query about types/methods on the classpath ● Java Deserialization Scanner3 ○ Burp Suite plugin; uses known payloads (ysoserial) to discover and exploit vulns. ● marshalsec4 ○ Deserialization payload generator for numerous libraries and gadget chains ● NCC Group Burp Plugin5 ○ “Mainly based on the work of Muñoz and Mirosh’s Friday the 13th: JSON Attacks” 1 https://github.com/frohoff/ysoserial 2 https://github.com/Contrast-Security-OSS/joogle 3 https://techblog.mediaservice.net/2017/05/reliable-discovery-and-exploitation-of-java-deserialization-vulnerabilities/ 4 https://github.com/mbechler/marshalsec 5 https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2018/june/finding-deserialisation-issues-has-never-been-easier-freddy-the-serialisation-killer/
  • 36. Automated Discovery of Deserialization Gadget Chains Ian Haken BuildingaNew TooltoFindGadgetChains What we really want is a tool to evaluate risk. How important is it to remediate this vulnerability? ● Is a given deserialization vulnerability exploitable? ● What exploits are possible? RCE, SSRF, DoS? ● It doesn’t need to be perfect; a reasonable overestimation of risk is useful in this context. ● Note: we don’t actually have to actually generate payloads.
  • 37. Automated Discovery of Deserialization Gadget Chains Ian Haken Requirements ● Not looking for vulnerabilities; assume we only use this tool if we find a vulnerability ● It needs to look at the entire classpath of the application ● It should err on the side of false positives rather than false negatives ● It should operate on bytecode; we usually have the entire classpath packaged as a war and may not have sources (especially if we’re including proprietary, third-party libraries) ○ Plus it may include libraries written in Groovy, Scala, Clojure, ...
  • 38. GadgetInspector A Java bytecode analysis tool for finding gadget chains.
  • 39. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Operates on any given classpath, i.e. a particular library or an entire war ● Reports discovered gadget chains as a sequence of method invocations ● Performs some simplistic symbolic execution to understand possible dataflow from method arguments to subsequent method invocations ● Makes a lot of simplifying assumptions that make code analysis easy GadgetInspector Gadget Inspector ● CertificateRevokedException.readObject() ● Collections$CheckedMap.put() ● TreeMap.put() ● scala/math/Ordering$$anon$5.compare() ● scala/PartialFunction$OrElse.apply() ● ... app.war
  • 40. Automated Discovery of Deserialization Gadget Chains Ian Haken Step1:Enumerateclass/methodhierarchy app.war ● clojure/FnEval ○ clojure/IFn ○ java/io/Serializable ○ java/lang/Object ● clojure/FnConstant ○ clojure/IFn ○ java/io/Serializable ○ java/lang/Object ● clojure/FnCompose ○ clojure/IFn ○ java/io/Serializable ○ java/lang/Object ● AbstractTableModel$ff19274a ○ java/io/Serializable ○ java/lang/Object WEB-INF/lib WEB-INF/classes
  • 41. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow
  • 42. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc)
  • 43. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc) ● FnConstant.invoke() -> 0
  • 44. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow public class FnDefault { private FnConstant f; public Object invoke(Object arg) { return arg != null ? arg : f.invoke(arg); } } Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc) ● FnConstant.invoke() -> 0
  • 45. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow public class FnDefault { private FnConstant f; public Object invoke(Object arg) { return arg != null ? arg : f.invoke(arg); } } Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc) ● FnConstant.invoke() -> 0 Assumption #2: All branch conditions are satisfiable
  • 46. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow public class FnDefault { private FnConstant f; public Object invoke(Object arg) { return arg != null ? arg : f.invoke(arg); } } Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc) ● FnConstant.invoke() -> 0 Assumption #2: All branch conditions are satisfiable ● FnDefault.invoke() -> 1 ● FnDefault.invoke() -> 0
  • 47. Automated Discovery of Deserialization Gadget Chains Ian Haken public class FnConstant implements IFn { private Object value; public Object invoke(Object arg) { return value; } } Step2:Discover“Passthrough”Dataflow public class FnDefault { private FnConstant f; public Object invoke(Object arg) { return arg != null ? arg : f.invoke(arg); } } Assumption #1: All members of a “tainted” object are also tainted (and recursively, etc) ● FnConstant.invoke() -> 0 Assumption #2: All branch conditions are satisfiable ● FnDefault.invoke() -> 1 ● FnDefault.invoke() -> 0
  • 48. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph
  • 49. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0
  • 50. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0
  • 51. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0
  • 52. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } }
  • 53. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } }
  • 54. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } }
  • 55. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step3:Enumerate“Passthrough”Callgraph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 public class FnCompose implements IFn { private IFn f1, f2; public Object invoke(Object arg) { return f2.invoke(f1.invoke(arg)); } }
  • 56. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step4:EnumerateSourcesUsingKnownTricks
  • 57. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step4:EnumerateSourcesUsingKnownTricks AbstractTableModel$ff19274a.hashCode() @ 0
  • 58. Automated Discovery of Deserialization Gadget Chains Ian Haken public class AbstractTableModel$ff19274a { private IPersistentMap __clojureFnMap; public int hashCode() { IFn f = __clojureFnMap.get("hashCode"); return (int)(f.invoke(this)); } } Step4:EnumerateSourcesUsingKnownTricks AbstractTableModel$ff19274a.hashCode() @ 0 Limitation #1: Relies on known tricks. Some tricks (e.g. HashMap -> hashCode) we could derive anyway, but others (like DynamicProxy) we could not.
  • 59. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain
  • 60. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain ● AbstractTableModel...hashCode() @ 0
  • 61. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain Assumption #3: Any method implementation can be jumped to (as long as its class is “serializable”) ● AbstractTableModel...hashCode() @ 0
  • 62. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain Assumption #3: Any method implementation can be jumped to (as long as its class is “serializable”) ● AbstractTableModel...hashCode() @ 0 ● FnCompose.invoke() @ 0
  • 63. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain Assumption #3: Any method implementation can be jumped to (as long as its class is “serializable”) ● AbstractTableModel...hashCode() @ 0 ● FnCompose.invoke() @ 0 ● FnEval @ 1
  • 64. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain Assumption #3: Any method implementation can be jumped to (as long as its class is “serializable”) ● AbstractTableModel...hashCode() @ 0 ● FnCompose.invoke() @ 0 ● FnEval @ 1 ● Runtime.exec() @ 1
  • 65. Automated Discovery of Deserialization Gadget Chains Ian Haken Step5:BFSonCallGraphforChains Sources ● AbstractTableModel$ff19274a.hashCode() @ 0 Call Graph AbstractTableModel$ff19274a.hashCode() ● 0 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 FnCompose.invoke() ● 1 -> IFn.invoke() @ 1 ● 0 -> IFn.invoke() @ 0 ● 0 -> IFn.invoke() @ 1 FnEval.invoke() ● 1 -> Runtime.exec() @ 1 Chain Assumption #3: Any method implementation can be jumped to (as long as its class is “serializable”) ● AbstractTableModel...hashCode() @ 0 ● FnCompose.invoke() @ 0 ● FnEval @ 1 ● Runtime.exec() @ 1 Limitation #2: Chain discovery relies on a list of known “interesting” sinks
  • 66. Automated Discovery of Deserialization Gadget Chains Ian Haken Gadget Inspector supports some customization on the analysis ● What is considered “serializable”? ○ For JRE deserialization, anything implementing java.lang.Serializable ○ For XStream, it depends on the convertors that are enabled ■ And when using custom convertors, it gets even more subtle ○ For Jackson, any class with a no-arg constructor ● What are the deserialization sources (i.e. magic methods)? ○ For Jackson we only start in constructors ● What method implementations should we consider? ○ For JRE deserialization, all implementations in a serializable class ○ For Jackson, depends on annotations and configuration DeserializationLibraryFlexibility
  • 68. Automated Discovery of Deserialization Gadget Chains Ian Haken Ran Gadget Inspector against the 100 most popular java libraries (according to mvnrepository.com and javalibs.com) looking for exploits against standard Java deserialization ● It did rediscover several known gadget chains ● Not that many libraries actually have classes implementing java.io.Serializable... ○ But there were some interesting new findings! ● Had a handful of false positives but not as many as you’d expect ○ Mostly because reflection is hard to reason about Results:OSSLibraryScans
  • 69. Automated Discovery of Deserialization Gadget Chains Ian Haken commons-collections » commons-collections 38th most popular maven dependency 1. ....corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl invoke(Object, Method, Object[]) (0) 2. org.apache.commons.collections.map.LazyMap.get(Object) (0) 3. org.apache.commons.collections.functors.InvokerTransformer transform(Object) (0) 4. java.lang.reflect.Method.invoke(Object, Object[]) (0) Results:OldGadgetChains https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/CommonsCollections1.java
  • 70. Automated Discovery of Deserialization Gadget Chains Ian Haken New GadgetChains:Clojure org.clojure » clojure 6th most popular maven dependency 1. clojure.inspector.proxy$javax.swing.table.AbstractTableModel$ff19274a.hashCode() (0) 2. clojure.main$load_script.invoke(Object) (1) 3. clojure.main$load_script.invokeStatic(Object) (0) 4. clojure.lang.Compiler.loadFile(String) (0) 5. FileInputStream.<init>(String) (1) Tweaked this result to invoke clojure.main$eval_opt instead of clojure.main$load_script to invoke arbitrary code. Reported to clojure-dev July 2017, affecting 1.8.0 and all earlier versions. Serialization of AbstractTableModel$ff19274a disabled in 1.9.0 release (Dec, 2017). https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/Clojure.java
  • 71. Automated Discovery of Deserialization Gadget Chains Ian Haken New GadgetChains:Scala org.scala-lang » scala-library 3rd most popular maven dependency 1. scala.math.Ordering$$anon$5.compare(Object, Object) (0) 2. scala.PartialFunction$OrElse.apply(Object) (0) 3. scala.sys.process.processInternal$$anonfun$onIOInterrupt$1 applyOrElse(Object, scala.Function1) (0) 4. scala.sys.process.ProcessBuilderImpl$FileOutput$$anonfun$$lessinit$greater$3.apply() (0) 5. java.io.FileOutputStream.<init>(File, boolean) (1) Allows you to write/overwrite a file with 0 bytes. Possible DoS? Zero-out a blacklist? https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Scala.java
  • 72. Automated Discovery of Deserialization Gadget Chains Ian Haken New GadgetChains:Scala 1. scala.math.Ordering$$anon$5.compare(Object, Object) (0) 2. scala.PartialFunction$OrElse.apply(Object) (0) 3. scala.sys.process.processInternal$$anonfun$onIOInterrupt$1 applyOrElse(Object, scala.Function1) (0) 4. scala.sys.process.ProcessBuilderImpl$URLInput$$anonfun$ $lessinit$greater$1.apply() (0) 5. java.net.URL.openStream() (0) SSRF: Causes application to perform a GET on an arbitrary URL. https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Scala.java
  • 73. Automated Discovery of Deserialization Gadget Chains Ian Haken New GadgetChains:Clojure2 In rerunning Gadget Inspector on the latest release (1.10.0-alpha4) in preparation for this presentation, a different entry point was discovered: 1. clojure.lang.ASeq.hashCode() (0) 2. clojure.lang.Iterate.first() (0) 3. clojure.main$load_script.invoke(Object) (1) 4. clojure.main$load_script.invokeStatic(Object) (0) 5. clojure.lang.Compiler.loadFile(String) (0) 6. FileInputStream.<init>(String) (1) Confirmed the same tweak to clojure.main$eval_opt works for arbitrary code execution. Affects all releases since 1.8.0. https://github.com/JackOfMostTrades/ysoserial/blob/master/src/main/java/ysoserial/payloads/Clojure2.java
  • 75. Automated Discovery of Deserialization Gadget Chains Ian Haken Results:NetflixInternalWebapp1 Potentially dangerous use of Jackson deserialization: public void doSomething(String body, String queryParam) { Object requestObject = objectMapper.readValue( body, Class.forName(queryParam)); ● Can only deserialize classes with no-arg constructors ● The only entry points are no-arg constructors But still, the app has ~200MB classpath. So maybe there’s something there...
  • 76. Automated Discovery of Deserialization Gadget Chains Ian Haken Results:NetflixInternalWebapp1 Potentially dangerous use of Jackson deserialization: public void doSomething(String body, String queryParam) { Object requestObject = objectMapper.readValue( body, Class.forName(queryParam)); ● Can only deserialize classes with no-arg constructors ● The only entry points are no-arg constructors But still, the app has ~200MB classpath. So maybe there’s something there... Result: A few false positives and nothing very interesting. Take-away: Remediation is a low priority
  • 77. Automated Discovery of Deserialization Gadget Chains Ian Haken Results:NetflixInternalWebapp2 Used a non-standard deserialization library, subject to some unique constraints ● Invokes readResolve() but not readObject() ● Serialized objects do not need to implement Serializable ● Member fields of serialized objects cannot have a $ in the name. ○ Non-static inner classes always have an implicit $outer member name. ● No serialization support for arrays or generic maps ● No null member values
  • 78. Automated Discovery of Deserialization Gadget Chains Ian Haken 1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0) 2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0) 3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0) 4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0) 5. clojure.lang.APersistentMap$KeySeq.iterator() (0) 6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0) 7. java.util.concurrent.Executors$RunnableAdapter.call() (0) 8. org.apache.commons.exec.StreamPumper.run() (0) 9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0) 10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0) 11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2) 12. java.io.FileOutputStream.<init>(File) (1) Results:NetflixInternalWebapp2
  • 79. Automated Discovery of Deserialization Gadget Chains Ian Haken Results:NetflixInternalWebapp2 1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0) 2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0) 3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0) 4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0) 5. clojure.lang.APersistentMap$KeySeq.iterator() (0) 6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0) 7. java.util.concurrent.Executors$RunnableAdapter.call() (0) 8. org.apache.commons.exec.StreamPumper.run() (0) 9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0) 10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0) 11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2) 12. java.io.FileOutputStream.<init>(File) (1) com.thoughtworks.xstream:xstream commons-configuration:commons-configuration org.clojure:clojure netflix:netflix-utils JRE org.apache.commons:commons-exec org.aspectj:aspectjtools
  • 80. Automated Discovery of Deserialization Gadget Chains Ian Haken 1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0) 2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0) 3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0) 4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0) 5. clojure.lang.APersistentMap$KeySeq.iterator() (0) 6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0) 7. java.util.concurrent.Executors$RunnableAdapter.call() (0) 8. org.apache.commons.exec.StreamPumper.run() (0) 9. org.eclipse.core.internal.localstore.SafeFileOutputStream.close() (0) 10. org.eclipse.core.internal.localstore.SafeFileOutputStream.commit() (0) 11. org.eclipse.core.internal.localstore.SafeFileOutputStream.copy(File, File) (2) 12. java.io.FileOutputStream.<init>(File) (1) Results:NetflixInternalWebapp2
  • 81. Automated Discovery of Deserialization Gadget Chains Ian Haken 1. com.thoughtworks.xstream.mapper.AbstractAttributeAliasingMapper.readResolve() (0) 2. org.apache.commons.configuration.ConfigurationMap$ConfigurationSet.iterator() (0) 3. ...configuration.ConfigurationMap$ConfigurationSet$ConfigurationSetIterator.<init>() (0) 4. org.apache.commons.configuration.CompositeConfiguration.getKeys() (0) 5. clojure.lang.APersistentMap$KeySeq.iterator() (0) 6. com.netflix.internal.utils.collections.IteratorWrapper$CallableWrapper.iterator() (0) 7. java.util.concurrent.Executors$RunnableAdapter.call() (0) 8. org.apache.commons.exec.StreamPumper.run() (0) ○ is = java.io.StringBufferInputStream ■ buffer = <% String cmd="calc.exe"; ... %> ○ os = org.eclipse.core.internal.localstore.SafeChunkyOutputStream ■ isOpen = false ■ filePath = /webappdir/foo.jsp Results:NetflixInternalWebapp2
  • 82. Automated Discovery of Deserialization Gadget Chains Ian Haken ● Reflection ○ Most reflection calls are being treated as interesting, leading to FPs ■ E.g. you can control the class but not the method name, or vice-versa ○ Blind spots for call graph enumeration ■ foo.getClass().getMethod(“bar”).invoke(...) ● Assumptions ○ Even minor improvements would allow Gadget Inspector to make better decisions around condition satisfiability or virtual method call resolution, leading to fewer FPs. ● Limitations ○ Entry points are enumerated using “known tricks.” Original research can still help us find lots of other clever ways to construct gadget chains. ○ Sinks with “interesting behavior” are hard-coded. Lots of room to discover and add sinks. Room forImprovement
  • 83. Automated Discovery of Deserialization Gadget Chains Ian Haken @ianhaken https://github.com/JackOfMostTrades ● Automatic discovery for gadget chains is new territory ○ Gadget Inspector is a functional prototype; room for lots of improvement! ○ Gadget Inspector written for Java but techniques apply to other languages ● Gadget Inspector is open source ○ Fork it, submit PRs, or just check it out for more details about how it works ○ https://github.com/JackOfMostTrades/gadgetinspector ● Deserialization vulnerabilities aren’t going away yet ○ Exploits can and will be more complex as time goes on ○ Better tools will help us understand the risk of vulnerabilities FinalThoughts