SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
Remote code
execution via
Java native
deserialization
Introduction
● I am not a pen tester. High school dropout, no
formal training or education in security.
● Software engineer for 17 years, climatology domain
● Last 5 years focusing on security, mainly Java
● Managed Red Hat's Java middleware security team
● Now an engineering manager for a SDN company
● I love finding new 0day and popping shells!
Outline
● Java (de)serialization
● RCE via XML deserialization
● RCE via native deserialization
● RCE via XML <-> binary mapping vector
● Other InvocationHandlers?
● “Property-oriented programming” and gadgets
● Where lies the vulnerability?
Java (de)serialization
● Java has multiple serialization implementations
● XML serialization: XXE and RCE possible in multiple
implementations
● Native serialization: binary data format, with RCE
possible depending on what's on the classpath
● Dozer, Kryo and other frameworks
● Common thread: don't deserialize untrusted input
(duh!)
RCE – XML deserialization
● Alternative XML-based serialization formats
● JAXB is the standard (no known flaws)
● Other XML serialization libraries exist, and have
exposed security issues leading to RCE
● These are commonly used by big applications and
XML REST API frameworks
● We’ll look at just two examples: XMLDecoder and
XStream
● NOT reliant on classes implementing Serializable
XMLDecoder
● XMLDecoder’s XML format can represent a series of
methods that will be called to reconstruct an object
● If XMLDecoder is used to deserialize untrusted
input, arbitrary code can be injected into the XML
● Live demo: Restlet CVE-2013-4221. Fixed by
removing vulnerable functionality.
XStream
● Reflection-based deserialization
● Has a special handler for dynamic proxies
(implementations of interfaces)
● Spring OXM, Sonatype Nexus, Jenkins affected
XStream
● Attackers can provide XML representing a dynamic
proxy class, which implements the interface of a
class the application might expect
● Dynamic proxy implements an EventHandler that
calls arbitrary code when any members of the
deserialized class are called
XStream in Jenkins
● Jenkins XML API uses XStream to deserialize input
● Access to XML API -> RCE (but not such a huge
deal)
● Live demo: Jenkins
● Solution: blocked DynamicProxyConverter in
XStream wrapper class
● Upstream solution: whitelisting, with dynamic
proxies excluded by default
● More information:
https://securityblog.redhat.com/2014/01/23/java-
deserialization-flaws-part-2-xml-deserialization/
RCE – binary deserialization
● Java contains a native serialization mechanism,
that converts objects to binary data
● When deserializing, the readObject() and
readResolve() methods of the class will be called
● This can lead to vulnerabilities if a class on the
classpath has something exploitable in
readObject() or readResolve()
● How can an attacker provide binary serialized
objects?
RCE – binary deserialization
● Serialization is used as a format for transferring
objects over networks, e.g. via REST APIs
● Example #1: RichFaces state (CVE-2013-2165,
Takeshi Terada, MBSD)
● Example #2: Restlet REST framework
● Live demo: Restlet PoC
● What kind of issue could exist in
readResolve()/readObject() that would be
exploitable?
CVE-2011-2894: Spring
● Discovered by Wouter Coekaerts in Spring AOP
● Serializable InvocationHandler exposed
● Allows mapping a proxy to ANY method call on the
proxy interface
● Similar exploit to EventHandler, but more complex
setup of the serialized object graph
● More info:
http://www.pwntester.com/blog/2013/12/16/cve-
2011-2894-deserialization-spring-rce/
commons-fileupload
● Component to simplify file uploads in Java apps
● DiskFileItem class implements readObject()
● The readObject method creates a tmp file on disk:
– tempFile = new File(tempDir, tempFileName);
● tempDir is read from the repository private attribute
of the class, exposing a poison null byte flaw (file-
writing code is native, now patched)
● An attacker can provide a serialized instance of DFI
with a null-terminated full path value for the
repository attribute: /path/to/file.txt0
● commons-fileupload code embedded in Tomcat
Restlet + DFI
● Upload a JSP shell to achieve RCE
● Solution #1: don't deserialize untrusted content
● Solution #2: don't introduce flaws in
readObject()/readResolve()
● Solution #3: type checking with look-ahead
deserialization (Pierre Ernst):
http://www.ibm.com/developerworks/java/library/se
-lookahead/index.html
● Or notsoserial:
https://tersesystems.com/2015/11/08/closing-the-
open-door-of-java-object-serialization/
Dozer XML ↔ Binary Mapper
● Uses reflection-based approach to type conversion
● Used by e.g. Apache Camel to map types
● If used to map user-supplied objects, then an
attacker can provide a dynamic proxy
● There must either be an object being mapped to with
a getter/setter method that matches a method in an
interface on the server classpath, or a manual XML
mapping that allows an attacker to force the issue.
● InvocationHandler must be serializable (implements
Serializable)
● EventHandler is not
Dozer CVE-2014-9515
● Wouter Coekaerts reported a serializable
InvocationHandler in older versions of Spring: CVE-
2011-2894
● Using Alvaro Munoz's CVE-2011-2894 exploit, I was
able to develop a working Dozer exploit. It is only
exploitable if all the aforementioned conditions are
met, and vuln Spring JARs are on the classpath
● Live demo: Dozer RCE
https://github.com/pentestingforfunandprofit/resear
ch/tree/master/dozer-rce
● Reported upstream since Dec 2014, no response:
https://github.com/DozerMapper/dozer/issues/217
Other InvocationHandlers
● Any common component is useful, but in the JDK
itself means universally exploitable
● Three other InvocationHandlers in Java 7/8:
● CompositeDataInvocationHandler
● MbeanServerInvocationHandler
● RemoteObjectInvocationHandler
● CompositeDataInvocationHandler: forwards getter
methods to a CompositeData instance. No use.
MBeanServerInvocationHandler
● Proxy to an MBean on the server. Potentially useful,
e.g. if MBeans used by JBoss Worm are present.
● Problem 1: attacker must specify correct JMX URL
● Solution 1: JMX is exposed locally on port 1099
● Solution 2: Brute force JMX URL via Java PID
● Problem 2: attacker cannot control code that is run
for any method call, on specific method calls
● EventHandler exploits work no matter which
method is invoked on the proxy object.
MBeanServerInvocationHandler simply calls the
method of the same name on the MBean.
RemoteObjectInvocationHandler
● Proxy to a remote object exported via RMI
● Problem 1: attacker must know details of a remote
object exported to the server
● Solution: JMX registry is exposed via RMI. If JMX
is exposed locally on port 1099, the attacker
could craft an object instance that points to the
JMX RMI URL
● Problem 2: attacker cannot control code that is run
for any method call, on specific method calls
● Future work: look for more potentially exploitable
InvocationHandlers
Property-oriented programming
● Instantiate a complex object graph whose root
node is serializable
● Similar to ROP, exploit conditions in classes on the
classpath so deserialization of the object graph
lands in execution of arbitrary code
● Shouts to Stefan Esser for considering this in PHP
first
● http://www.slideshare.net/frohoff1/appseccali-2015-
marshalling-pickles Slides 45 onwards
Gadget: commons-collection
● Serializable InvocationHandler in a library that is
almost universally on the classpath
● Presented at AppSecCali and still unpatched:
http://www.slideshare.net/codewhitesec/exploiting-
deserialization-vulnerabilities-in-java-54707478
● FoxGlove reported multiple vectors for untrusted
deserialization in JBoss, WebSphere, Jenkins,
WebLogic, etc.:
http://foxglovesecurity.com/2015/11/06/what-do-
weblogic-websphere-jboss-jenkins-opennms-and-
your-application-have-in-common-this-vulnerability/
Tools & future research
● Ysoserial for finding flaws and aggregating
payloads
● Look-ahead deserialization tools
● PoC by Pierre Ernst @ IBM
● Notsoserial
● Serialkiller
● More gadgets, more deserialization vectors
● Gadget entirely in the JDK would be awesome
Where lies the vulnerability?
● When at Red Hat, I assigned CVEs to vulnerable
classes, and publicly stated:
Where lies the vulnerability?
● I was wrong!
● The vulnerability lies in the application performing
deserialization of untrusted data without look-
ahead type validation
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Christian Schneider
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)CODE WHITE GmbH
 
The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!Luca Carettoni
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization VulnerabilitiesLuca Carettoni
 
Deserialization vulnerabilities
Deserialization vulnerabilitiesDeserialization vulnerabilities
Deserialization vulnerabilitiesGreenD0g
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you pownedDinis Cruz
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfacesjuanvazquezslides
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...joaomatosf_
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx FranceDavid Delabassee
 
Advanced JS Deobfuscation
Advanced JS DeobfuscationAdvanced JS Deobfuscation
Advanced JS DeobfuscationMinded Security
 
Java concurrency in practice
Java concurrency in practiceJava concurrency in practice
Java concurrency in practiceMikalai Alimenkou
 
Build, logging, and unit test tools
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test toolsAllan Huang
 
Breakfast cereal for advanced beginners
Breakfast cereal for advanced beginnersBreakfast cereal for advanced beginners
Breakfast cereal for advanced beginnersTruptiranjan Nayak
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS EngineZongXian Shen
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013midnite_runr
 

Was ist angesagt? (20)

Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
 
The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Deserialization vulnerabilities
Deserialization vulnerabilitiesDeserialization vulnerabilities
Deserialization vulnerabilities
 
Fixing the Java Serialization Mess
Fixing the Java Serialization Mess Fixing the Java Serialization Mess
Fixing the Java Serialization Mess
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
Advanced JS Deobfuscation
Advanced JS DeobfuscationAdvanced JS Deobfuscation
Advanced JS Deobfuscation
 
Exploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systemsExploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systems
 
Java concurrency in practice
Java concurrency in practiceJava concurrency in practice
Java concurrency in practice
 
Build, logging, and unit test tools
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test tools
 
Breakfast cereal for advanced beginners
Breakfast cereal for advanced beginnersBreakfast cereal for advanced beginners
Breakfast cereal for advanced beginners
 
JavaSecure
JavaSecureJavaSecure
JavaSecure
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 
Class loaders
Class loadersClass loaders
Class loaders
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 

Ähnlich wie SyScan 2016 - Remote code execution via Java native deserialization

Auscert 2022 - log4shell and history of Java deserialisation RCE
Auscert 2022 - log4shell and history of Java deserialisation RCEAuscert 2022 - log4shell and history of Java deserialisation RCE
Auscert 2022 - log4shell and history of Java deserialisation RCEDavid Jorm
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolGabor Paller
 
Helidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptxHelidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptxDmitry Kornilov
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil FrameworkVeilFramework
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Sonali Parab
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in Javakoji lin
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin Vasil Remeniuk
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 
NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)Ron Munitz
 
Security of OpenDaylight platform
Security of OpenDaylight platformSecurity of OpenDaylight platform
Security of OpenDaylight platformOpenDaylight
 
Looking for Vulnerable Code. Vlad Savitsky
Looking for Vulnerable Code. Vlad SavitskyLooking for Vulnerable Code. Vlad Savitsky
Looking for Vulnerable Code. Vlad SavitskyVlad Savitsky
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_viNico Ludwig
 
The dedexer disassembler
The dedexer disassemblerThe dedexer disassembler
The dedexer disassemblerGabor Paller
 
31c3 Presentation - Virtual Machine Introspection
31c3 Presentation - Virtual Machine Introspection31c3 Presentation - Virtual Machine Introspection
31c3 Presentation - Virtual Machine IntrospectionTamas K Lengyel
 
Open stack HA - Theory to Reality
Open stack HA -  Theory to RealityOpen stack HA -  Theory to Reality
Open stack HA - Theory to RealitySriram Subramanian
 
Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Mauricio Velazco
 
DEF CON 27 - workshop - MAURICIO VELAZCO - writing custom paylods
DEF CON 27 - workshop - MAURICIO VELAZCO - writing  custom paylodsDEF CON 27 - workshop - MAURICIO VELAZCO - writing  custom paylods
DEF CON 27 - workshop - MAURICIO VELAZCO - writing custom paylodsFelipe Prado
 

Ähnlich wie SyScan 2016 - Remote code execution via Java native deserialization (20)

Auscert 2022 - log4shell and history of Java deserialisation RCE
Auscert 2022 - log4shell and history of Java deserialisation RCEAuscert 2022 - log4shell and history of Java deserialisation RCE
Auscert 2022 - log4shell and history of Java deserialisation RCE
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer tool
 
Helidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptxHelidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptx
 
Java RMI
Java RMIJava RMI
Java RMI
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in Java
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)
 
Security of OpenDaylight platform
Security of OpenDaylight platformSecurity of OpenDaylight platform
Security of OpenDaylight platform
 
Looking for Vulnerable Code. Vlad Savitsky
Looking for Vulnerable Code. Vlad SavitskyLooking for Vulnerable Code. Vlad Savitsky
Looking for Vulnerable Code. Vlad Savitsky
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
The dedexer disassembler
The dedexer disassemblerThe dedexer disassembler
The dedexer disassembler
 
31c3 Presentation - Virtual Machine Introspection
31c3 Presentation - Virtual Machine Introspection31c3 Presentation - Virtual Machine Introspection
31c3 Presentation - Virtual Machine Introspection
 
Open stack HA - Theory to Reality
Open stack HA -  Theory to RealityOpen stack HA -  Theory to Reality
Open stack HA - Theory to Reality
 
Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#
 
CORBA & RMI in java
CORBA & RMI in javaCORBA & RMI in java
CORBA & RMI in java
 
DEF CON 27 - workshop - MAURICIO VELAZCO - writing custom paylods
DEF CON 27 - workshop - MAURICIO VELAZCO - writing  custom paylodsDEF CON 27 - workshop - MAURICIO VELAZCO - writing  custom paylods
DEF CON 27 - workshop - MAURICIO VELAZCO - writing custom paylods
 
Dynamic Proxy by Java
Dynamic Proxy by JavaDynamic Proxy by Java
Dynamic Proxy by Java
 

Mehr von David Jorm

AusCERT 2016: CVE and alternatives
AusCERT 2016: CVE and alternativesAusCERT 2016: CVE and alternatives
AusCERT 2016: CVE and alternativesDavid Jorm
 
44CON & Ruxcon: SDN security
44CON & Ruxcon: SDN security44CON & Ruxcon: SDN security
44CON & Ruxcon: SDN securityDavid Jorm
 
OWASP Brisbane - SDN Security
OWASP Brisbane - SDN SecurityOWASP Brisbane - SDN Security
OWASP Brisbane - SDN SecurityDavid Jorm
 
Building world-class security response and secure development processes
Building world-class security response and secure development processesBuilding world-class security response and secure development processes
Building world-class security response and secure development processesDavid Jorm
 
OpenDaylight Brisbane User Group - OpenDaylight Security
OpenDaylight Brisbane User Group - OpenDaylight SecurityOpenDaylight Brisbane User Group - OpenDaylight Security
OpenDaylight Brisbane User Group - OpenDaylight SecurityDavid Jorm
 
Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARsDavid Jorm
 

Mehr von David Jorm (6)

AusCERT 2016: CVE and alternatives
AusCERT 2016: CVE and alternativesAusCERT 2016: CVE and alternatives
AusCERT 2016: CVE and alternatives
 
44CON & Ruxcon: SDN security
44CON & Ruxcon: SDN security44CON & Ruxcon: SDN security
44CON & Ruxcon: SDN security
 
OWASP Brisbane - SDN Security
OWASP Brisbane - SDN SecurityOWASP Brisbane - SDN Security
OWASP Brisbane - SDN Security
 
Building world-class security response and secure development processes
Building world-class security response and secure development processesBuilding world-class security response and secure development processes
Building world-class security response and secure development processes
 
OpenDaylight Brisbane User Group - OpenDaylight Security
OpenDaylight Brisbane User Group - OpenDaylight SecurityOpenDaylight Brisbane User Group - OpenDaylight Security
OpenDaylight Brisbane User Group - OpenDaylight Security
 
Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARs
 

Kürzlich hochgeladen

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Kürzlich hochgeladen (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
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...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

SyScan 2016 - Remote code execution via Java native deserialization

  • 1. Remote code execution via Java native deserialization
  • 2. Introduction ● I am not a pen tester. High school dropout, no formal training or education in security. ● Software engineer for 17 years, climatology domain ● Last 5 years focusing on security, mainly Java ● Managed Red Hat's Java middleware security team ● Now an engineering manager for a SDN company ● I love finding new 0day and popping shells!
  • 3. Outline ● Java (de)serialization ● RCE via XML deserialization ● RCE via native deserialization ● RCE via XML <-> binary mapping vector ● Other InvocationHandlers? ● “Property-oriented programming” and gadgets ● Where lies the vulnerability?
  • 4. Java (de)serialization ● Java has multiple serialization implementations ● XML serialization: XXE and RCE possible in multiple implementations ● Native serialization: binary data format, with RCE possible depending on what's on the classpath ● Dozer, Kryo and other frameworks ● Common thread: don't deserialize untrusted input (duh!)
  • 5. RCE – XML deserialization ● Alternative XML-based serialization formats ● JAXB is the standard (no known flaws) ● Other XML serialization libraries exist, and have exposed security issues leading to RCE ● These are commonly used by big applications and XML REST API frameworks ● We’ll look at just two examples: XMLDecoder and XStream ● NOT reliant on classes implementing Serializable
  • 6. XMLDecoder ● XMLDecoder’s XML format can represent a series of methods that will be called to reconstruct an object ● If XMLDecoder is used to deserialize untrusted input, arbitrary code can be injected into the XML ● Live demo: Restlet CVE-2013-4221. Fixed by removing vulnerable functionality.
  • 7. XStream ● Reflection-based deserialization ● Has a special handler for dynamic proxies (implementations of interfaces) ● Spring OXM, Sonatype Nexus, Jenkins affected
  • 8. XStream ● Attackers can provide XML representing a dynamic proxy class, which implements the interface of a class the application might expect ● Dynamic proxy implements an EventHandler that calls arbitrary code when any members of the deserialized class are called
  • 9. XStream in Jenkins ● Jenkins XML API uses XStream to deserialize input ● Access to XML API -> RCE (but not such a huge deal) ● Live demo: Jenkins ● Solution: blocked DynamicProxyConverter in XStream wrapper class ● Upstream solution: whitelisting, with dynamic proxies excluded by default ● More information: https://securityblog.redhat.com/2014/01/23/java- deserialization-flaws-part-2-xml-deserialization/
  • 10. RCE – binary deserialization ● Java contains a native serialization mechanism, that converts objects to binary data ● When deserializing, the readObject() and readResolve() methods of the class will be called ● This can lead to vulnerabilities if a class on the classpath has something exploitable in readObject() or readResolve() ● How can an attacker provide binary serialized objects?
  • 11. RCE – binary deserialization ● Serialization is used as a format for transferring objects over networks, e.g. via REST APIs ● Example #1: RichFaces state (CVE-2013-2165, Takeshi Terada, MBSD) ● Example #2: Restlet REST framework ● Live demo: Restlet PoC ● What kind of issue could exist in readResolve()/readObject() that would be exploitable?
  • 12. CVE-2011-2894: Spring ● Discovered by Wouter Coekaerts in Spring AOP ● Serializable InvocationHandler exposed ● Allows mapping a proxy to ANY method call on the proxy interface ● Similar exploit to EventHandler, but more complex setup of the serialized object graph ● More info: http://www.pwntester.com/blog/2013/12/16/cve- 2011-2894-deserialization-spring-rce/
  • 13. commons-fileupload ● Component to simplify file uploads in Java apps ● DiskFileItem class implements readObject() ● The readObject method creates a tmp file on disk: – tempFile = new File(tempDir, tempFileName); ● tempDir is read from the repository private attribute of the class, exposing a poison null byte flaw (file- writing code is native, now patched) ● An attacker can provide a serialized instance of DFI with a null-terminated full path value for the repository attribute: /path/to/file.txt0 ● commons-fileupload code embedded in Tomcat
  • 14. Restlet + DFI ● Upload a JSP shell to achieve RCE ● Solution #1: don't deserialize untrusted content ● Solution #2: don't introduce flaws in readObject()/readResolve() ● Solution #3: type checking with look-ahead deserialization (Pierre Ernst): http://www.ibm.com/developerworks/java/library/se -lookahead/index.html ● Or notsoserial: https://tersesystems.com/2015/11/08/closing-the- open-door-of-java-object-serialization/
  • 15. Dozer XML ↔ Binary Mapper ● Uses reflection-based approach to type conversion ● Used by e.g. Apache Camel to map types ● If used to map user-supplied objects, then an attacker can provide a dynamic proxy ● There must either be an object being mapped to with a getter/setter method that matches a method in an interface on the server classpath, or a manual XML mapping that allows an attacker to force the issue. ● InvocationHandler must be serializable (implements Serializable) ● EventHandler is not
  • 16. Dozer CVE-2014-9515 ● Wouter Coekaerts reported a serializable InvocationHandler in older versions of Spring: CVE- 2011-2894 ● Using Alvaro Munoz's CVE-2011-2894 exploit, I was able to develop a working Dozer exploit. It is only exploitable if all the aforementioned conditions are met, and vuln Spring JARs are on the classpath ● Live demo: Dozer RCE https://github.com/pentestingforfunandprofit/resear ch/tree/master/dozer-rce ● Reported upstream since Dec 2014, no response: https://github.com/DozerMapper/dozer/issues/217
  • 17. Other InvocationHandlers ● Any common component is useful, but in the JDK itself means universally exploitable ● Three other InvocationHandlers in Java 7/8: ● CompositeDataInvocationHandler ● MbeanServerInvocationHandler ● RemoteObjectInvocationHandler ● CompositeDataInvocationHandler: forwards getter methods to a CompositeData instance. No use.
  • 18. MBeanServerInvocationHandler ● Proxy to an MBean on the server. Potentially useful, e.g. if MBeans used by JBoss Worm are present. ● Problem 1: attacker must specify correct JMX URL ● Solution 1: JMX is exposed locally on port 1099 ● Solution 2: Brute force JMX URL via Java PID ● Problem 2: attacker cannot control code that is run for any method call, on specific method calls ● EventHandler exploits work no matter which method is invoked on the proxy object. MBeanServerInvocationHandler simply calls the method of the same name on the MBean.
  • 19. RemoteObjectInvocationHandler ● Proxy to a remote object exported via RMI ● Problem 1: attacker must know details of a remote object exported to the server ● Solution: JMX registry is exposed via RMI. If JMX is exposed locally on port 1099, the attacker could craft an object instance that points to the JMX RMI URL ● Problem 2: attacker cannot control code that is run for any method call, on specific method calls ● Future work: look for more potentially exploitable InvocationHandlers
  • 20. Property-oriented programming ● Instantiate a complex object graph whose root node is serializable ● Similar to ROP, exploit conditions in classes on the classpath so deserialization of the object graph lands in execution of arbitrary code ● Shouts to Stefan Esser for considering this in PHP first ● http://www.slideshare.net/frohoff1/appseccali-2015- marshalling-pickles Slides 45 onwards
  • 21. Gadget: commons-collection ● Serializable InvocationHandler in a library that is almost universally on the classpath ● Presented at AppSecCali and still unpatched: http://www.slideshare.net/codewhitesec/exploiting- deserialization-vulnerabilities-in-java-54707478 ● FoxGlove reported multiple vectors for untrusted deserialization in JBoss, WebSphere, Jenkins, WebLogic, etc.: http://foxglovesecurity.com/2015/11/06/what-do- weblogic-websphere-jboss-jenkins-opennms-and- your-application-have-in-common-this-vulnerability/
  • 22. Tools & future research ● Ysoserial for finding flaws and aggregating payloads ● Look-ahead deserialization tools ● PoC by Pierre Ernst @ IBM ● Notsoserial ● Serialkiller ● More gadgets, more deserialization vectors ● Gadget entirely in the JDK would be awesome
  • 23. Where lies the vulnerability? ● When at Red Hat, I assigned CVEs to vulnerable classes, and publicly stated:
  • 24. Where lies the vulnerability? ● I was wrong! ● The vulnerability lies in the application performing deserialization of untrusted data without look- ahead type validation