SlideShare a Scribd company logo
Insecure Java Deserialization
Hello!
● I’m Shiv Sahni
● Principal Security Consultant @ Confidential
● Author-The Grey Matter of Securing Android Applications
● OSCP/CREST CRT Certified Infosec Professional
Why is it TRENDING?
● OWASP Top 10 2017-A8-Insecure Deserialization
● Equifax’s major data breach affecting 143 million
customers.
● It virtually affects all apps that accept serialized
Java objects
The Process?
Serializable Objects
● The class must implement java.io.Serializable interface
● Serializable is a marker interface
Example
public class KRADeck implements java.io.Serializable {
public String KPI1;
public String KPI1Value;
public String KPI2;
public String KPI2Value;
public void calculateKRA() {
---
System.out.println("Mailing the scores to ");
---
}
}
Reading and Writing Objects
● The ObjectOutputStream class contains many write methods for writing
various data types, but one method in particular stands out −
public final void writeObject(Object x) throws IOException
● Similarly, the ObjectInputStream class contains the following method for
deserializing an object −
public final Object readObject() throws IOException, ClassNotFoundException
Example: Serializing an Object
---
FileOutputStream fileOut =new FileOutputStream("SijoKRAJuly.data");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close()
--
Example: Deserializing an Object
---
FileInputStream fileIn = new FileInputStream("SijoKRAJuly.data");
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (KRA) in.readObject();
in.close();
fileIn.close();
--
Java Serialization Algorithm
1. Write serialization magic data (“AC ED”).
2. Write description/metadata of the class associated with the object being
serialized.
3. The next step of the algorithm is to write the description of the parent class,
which is the immediate superclass of the class.
4. The algorithm recursively writes out the data until it finds java.lang.Object
class.
5. Once it finishes writing the description/metadata it then starts with writing the
actual data associated with the instance. However, this time it starts in the
reverse order.
Reference: Javaworld.com
Is Java Deserialization Secure?
Whenever an object is serialized, the
stream of bytes only contains the data, the
metadata, the object member values and
NO CODE!!
What is this?
Deserialization of Untrusted
Data?
Exploitation? How Deserialization works?
● The stream of bytes is used to reconstruct the object.
● The stream of bytes has all the information(data, metadata) required to build
the object.
● While deserializing the object, JVM reads the class metadata from stream of
bytes and checks if the bytecode of class whose object is deserialized is
present within JVM otherwise the ClassNotFoundException is thrown.
● Now JVM initiates the process of creation of the object. JVM sets the static
fields and then invokes the readObject method of the class[ The default
method is invoked if the method is not overridden]
● The deserialization object is finished once readObject() returns.
Gadget Classes
For abusing Java Deserialization attackers finds dangerous classes available in
the namespace and not necessarily used by the system. These classes are known
as Gadget classes.
These classes have following properties:
1. Implements Serializable/Externalizable
interface
2. Accessible from current code i.e. Present
in the namespace.
3. Use member fields during or after
deserialization.
Unrealistic Gadget
public class SomeClass implements Serializable{
private String cmd;
private void readObject(java.io.ObjectInputStream stream) throws IOException,
ClassNotFoundException{
stream.defaultReadObject();
Runtime.getRuntime().exec(cmd);
}
}
Gadget Chains
● Attackers can abuse deserialization of untrusted data by creating chain of
method calls which is known as Gadget Chains.
● These chains are SELF EXECUTING and are TRIGGERED during or after
deserialization.
Gadget Chains
● Most gadget chains utilize gadgets from the middlewares/third components
such as JBoss, IBM Websphere, Apache Commons Library etc.
● There are some gadget chains that do not contain any third party gadgets,
they are build using JRE gadget and hence are known as GOLDEN GADGET
CHAINS
Let’s see what OWASP suggests!
Cheat Sheet
Q&A Time
References
● OWASP London: Unsafe Deserialization Attacks In Java - Apostolos
Giannakidis
● Javaworld.com
● Wikipedia, Tutorials Point and Geeks for Geeks

More Related Content

PDF
Exploiting Deserialization Vulnerabilities in Java
PDF
Java Deserialization Vulnerabilities - The Forgotten Bug Class
PDF
とある診断員とSQLインジェクション
PDF
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
PPT
Spring Core
PDF
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
PDF
Spring Framework - AOP
PDF
Spring Framework - Core
Exploiting Deserialization Vulnerabilities in Java
Java Deserialization Vulnerabilities - The Forgotten Bug Class
とある診断員とSQLインジェクション
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
Spring Core
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Spring Framework - AOP
Spring Framework - Core

What's hot (20)

PDF
Defending against Java Deserialization Vulnerabilities
PPT
XSS - Attacks & Defense
PDF
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
PPTX
Cross Site Scripting(XSS)
PDF
Spring Boot
PDF
とある診断員と色々厄介な脆弱性達
PDF
Java collections
PDF
Sql Injection - Vulnerability and Security
PPTX
Introduction à spring boot
PDF
Hibernate Presentation
PPTX
Webアプリって奥が深いんです
PPTX
Java Constructors
PDF
Spring Security
PDF
A Hacker's perspective on AEM applications security
PDF
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
PPTX
Spring boot - an introduction
PDF
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
PPTX
Java RMI Presentation
PDF
Spring boot
Defending against Java Deserialization Vulnerabilities
XSS - Attacks & Defense
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Cross Site Scripting(XSS)
Spring Boot
とある診断員と色々厄介な脆弱性達
Java collections
Sql Injection - Vulnerability and Security
Introduction à spring boot
Hibernate Presentation
Webアプリって奥が深いんです
Java Constructors
Spring Security
A Hacker's perspective on AEM applications security
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Spring boot - an introduction
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
Java RMI Presentation
Spring boot
Ad

Similar to Insecure Java Deserialization (20)

PDF
Unsafe Deserialization Attacks In Java and A New Approach To Protect The JVM ...
PDF
Breakfast cereal for advanced beginners
PDF
[Wroclaw #7] Why So Serial?
PPTX
Fixing the Java Serialization Mess
PPTX
Deserialization vulnerabilities
PDF
Automated Discovery of Deserialization Gadget Chains
PDF
(De)serial Killers - BSides Las Vegas & AppSec IL 2018
PPTX
(De)serial Killers - BSides Las Vegas & AppSec IL 2018
PPTX
File Handling - Serialization.pptx
PPTX
Gulshan serialization inJava PPT ex.pptx
PPTX
Serialization in java
PDF
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
PPTX
Java Serialization Facts and Fallacies
PDF
Serialization & De-serialization in Java
PDF
Automated Discovery of Deserialization Gadget Chains
PDF
Automated Discovery of Deserialization Gadget Chains
PDF
Android Serialization Vulnerabilities Revisited
PDF
IO Streams, Serialization, de-serialization, autoboxing
PDF
Mitigating Java Deserialization attacks from within the JVM
PDF
Mitigating Java Deserialization attacks from within the JVM (improved version)
Unsafe Deserialization Attacks In Java and A New Approach To Protect The JVM ...
Breakfast cereal for advanced beginners
[Wroclaw #7] Why So Serial?
Fixing the Java Serialization Mess
Deserialization vulnerabilities
Automated Discovery of Deserialization Gadget Chains
(De)serial Killers - BSides Las Vegas & AppSec IL 2018
(De)serial Killers - BSides Las Vegas & AppSec IL 2018
File Handling - Serialization.pptx
Gulshan serialization inJava PPT ex.pptx
Serialization in java
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Serialization Facts and Fallacies
Serialization & De-serialization in Java
Automated Discovery of Deserialization Gadget Chains
Automated Discovery of Deserialization Gadget Chains
Android Serialization Vulnerabilities Revisited
IO Streams, Serialization, de-serialization, autoboxing
Mitigating Java Deserialization attacks from within the JVM
Mitigating Java Deserialization attacks from within the JVM (improved version)
Ad

Recently uploaded (20)

PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
web development for engineering and engineering
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Lecture Notes Electrical Wiring System Components
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
additive manufacturing of ss316l using mig welding
DOCX
573137875-Attendance-Management-System-original
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Geodesy 1.pptx...............................................
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
web development for engineering and engineering
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Lecture Notes Electrical Wiring System Components
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Model Code of Practice - Construction Work - 21102022 .pdf
OOP with Java - Java Introduction (Basics)
CYBER-CRIMES AND SECURITY A guide to understanding
Embodied AI: Ushering in the Next Era of Intelligent Systems
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
CH1 Production IntroductoryConcepts.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
additive manufacturing of ss316l using mig welding
573137875-Attendance-Management-System-original
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Geodesy 1.pptx...............................................

Insecure Java Deserialization

  • 2. Hello! ● I’m Shiv Sahni ● Principal Security Consultant @ Confidential ● Author-The Grey Matter of Securing Android Applications ● OSCP/CREST CRT Certified Infosec Professional
  • 3. Why is it TRENDING? ● OWASP Top 10 2017-A8-Insecure Deserialization ● Equifax’s major data breach affecting 143 million customers. ● It virtually affects all apps that accept serialized Java objects
  • 5. Serializable Objects ● The class must implement java.io.Serializable interface ● Serializable is a marker interface
  • 6. Example public class KRADeck implements java.io.Serializable { public String KPI1; public String KPI1Value; public String KPI2; public String KPI2Value; public void calculateKRA() { --- System.out.println("Mailing the scores to "); --- } }
  • 7. Reading and Writing Objects ● The ObjectOutputStream class contains many write methods for writing various data types, but one method in particular stands out − public final void writeObject(Object x) throws IOException ● Similarly, the ObjectInputStream class contains the following method for deserializing an object − public final Object readObject() throws IOException, ClassNotFoundException
  • 8. Example: Serializing an Object --- FileOutputStream fileOut =new FileOutputStream("SijoKRAJuly.data"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close() --
  • 9. Example: Deserializing an Object --- FileInputStream fileIn = new FileInputStream("SijoKRAJuly.data"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (KRA) in.readObject(); in.close(); fileIn.close(); --
  • 10. Java Serialization Algorithm 1. Write serialization magic data (“AC ED”). 2. Write description/metadata of the class associated with the object being serialized. 3. The next step of the algorithm is to write the description of the parent class, which is the immediate superclass of the class. 4. The algorithm recursively writes out the data until it finds java.lang.Object class. 5. Once it finishes writing the description/metadata it then starts with writing the actual data associated with the instance. However, this time it starts in the reverse order. Reference: Javaworld.com
  • 11. Is Java Deserialization Secure? Whenever an object is serialized, the stream of bytes only contains the data, the metadata, the object member values and NO CODE!!
  • 12. What is this? Deserialization of Untrusted Data?
  • 13. Exploitation? How Deserialization works? ● The stream of bytes is used to reconstruct the object. ● The stream of bytes has all the information(data, metadata) required to build the object. ● While deserializing the object, JVM reads the class metadata from stream of bytes and checks if the bytecode of class whose object is deserialized is present within JVM otherwise the ClassNotFoundException is thrown. ● Now JVM initiates the process of creation of the object. JVM sets the static fields and then invokes the readObject method of the class[ The default method is invoked if the method is not overridden] ● The deserialization object is finished once readObject() returns.
  • 14. Gadget Classes For abusing Java Deserialization attackers finds dangerous classes available in the namespace and not necessarily used by the system. These classes are known as Gadget classes. These classes have following properties: 1. Implements Serializable/Externalizable interface 2. Accessible from current code i.e. Present in the namespace. 3. Use member fields during or after deserialization.
  • 15. Unrealistic Gadget public class SomeClass implements Serializable{ private String cmd; private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException{ stream.defaultReadObject(); Runtime.getRuntime().exec(cmd); } }
  • 16. Gadget Chains ● Attackers can abuse deserialization of untrusted data by creating chain of method calls which is known as Gadget Chains. ● These chains are SELF EXECUTING and are TRIGGERED during or after deserialization.
  • 17. Gadget Chains ● Most gadget chains utilize gadgets from the middlewares/third components such as JBoss, IBM Websphere, Apache Commons Library etc. ● There are some gadget chains that do not contain any third party gadgets, they are build using JRE gadget and hence are known as GOLDEN GADGET CHAINS
  • 18. Let’s see what OWASP suggests! Cheat Sheet
  • 20. References ● OWASP London: Unsafe Deserialization Attacks In Java - Apostolos Giannakidis ● Javaworld.com ● Wikipedia, Tutorials Point and Geeks for Geeks