SlideShare une entreprise Scribd logo
1  sur  28
JAVA
SH3LL C0DE

EXECUTION
Me
Me
Ryan Wincey
-Security Researcher
-Coder
-Penetration Tester
WHY JAVA
WHY JAVA
WHY JAVA
•CROSSPLATFORM
WHY JAVA
•CROSSPLATFORM
•EXTENSIVE
LIBRARY
WHY JAVA
•CROSSPLATFORM
•EXTENSIVE
LIBRARY
•WIDELY
DEPLOYED
PROBLEM:
PROBLEM:
HOW CAN I RUN
SHELLCODE FROM JAVA?
#NOPS
char shellcode[] = "x90x90x90x90”
int main(int argc, char **argv){
int (*f)();
f = (int (*)())shellcode;
(int)(*f)();
}
http://blog.strategiccyber.com/2013/08/29/how-to-inject-shellcode-from-java/
https://github.com/schierlm/JavaPayload.
package javapayload.stage;
/*
* Running shellcode from Java
without JNI (i. e. loading a DLL
from disk).
(c) 2011 Michael Schierl <schierlm
at gmx dot de> (Twitter @mihi42)
* This version has been tested on:
*
* Oracle 1.4.2_11 Win32 (-client, -server)
* Oracle 1.5.0_06 Win32 (-client, -server)
* Oracle 1.6.0_19 Win32 (-client, -server)
* Oracle 1.7.0_01 Win32 (-client, -server)
*
* Oracle 1.6.0_26 Linux32 (-client, -server)
* Oracle 1.7.0_01 Linux32 (-client, -server)
http://www.research.ibm.com/trl/projects/jit/index_e.htm
DEMO
//===========================================================================
/**
* Java method that gets overwritten by shellcode
* The native method pointer is then overwritten with a
* pointer to this method
*/
private static void jitme() {
executed = true;
// On x86: each volatile inc/dec needs 18 bytes,
// all 320 of them need 5760 bytes,
// whole JIT method needs 5842 bytes.
// if you need more shellcode, make a longer method
v1++; v2++; v3++; v4++; v5++;
v1++; v2++; v3++; v4++; v5--;
v1++; v2++; v3++; v4--; v5++;
v1++; v2++; v3++; v4--; v5--;
v1++; v2++; v3--; v4++; v5++;
v1++; v2++; v3--; v4++; v5--;
v1++; v2++; v3--; v4--; v5++;
v1++; v2++; v3--; v4--; v5--;
v1++; v2--; v3++; v4++; v5++;
v1++; v2--; v3++; v4++; v5--;
v1++; v2--; v3++; v4--; v5++;
v1++; v2--; v3++; v4--; v5--;
v1++; v2--; v3--; v4++; v5++;
v1++; v2--; v3--; v4++; v5--;
v1++; v2--; v3--; v4--; v5++;
v1++; v2--; v3--; v4--; v5--;
executed = true;
DEMO
2
Questions?
Contacts
Ryan Wincey @rwincey
winceyr@gmail.com
https://github.com/rwincey
Michael Schierl @mihi42
https://github.com/schierlm/JavaPayload

Contenu connexe

Tendances

Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Cyber Security Alliance
 

Tendances (20)

5 Important Secure Coding Practices
5 Important Secure Coding Practices5 Important Secure Coding Practices
5 Important Secure Coding Practices
 
Building an Empire with PowerShell
Building an Empire with PowerShellBuilding an Empire with PowerShell
Building an Empire with PowerShell
 
Secure code
Secure codeSecure code
Secure code
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL Applications
 
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa Workshop
 
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java Deserialization
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
 
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...
 
Security Code Review 101
Security Code Review 101Security Code Review 101
Security Code Review 101
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Harnessing the Power of AI in AWS Pentesting.pdf
Harnessing the Power of AI in AWS Pentesting.pdfHarnessing the Power of AI in AWS Pentesting.pdf
Harnessing the Power of AI in AWS Pentesting.pdf
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019
 
Weaponizing Recon - Smashing Applications for Security Vulnerabilities & Profits
Weaponizing Recon - Smashing Applications for Security Vulnerabilities & ProfitsWeaponizing Recon - Smashing Applications for Security Vulnerabilities & Profits
Weaponizing Recon - Smashing Applications for Security Vulnerabilities & Profits
 
Black Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized CommunicationBlack Hat EU 2010 - Attacking Java Serialized Communication
Black Hat EU 2010 - Attacking Java Serialized Communication
 
OWASP Secure Coding
OWASP Secure CodingOWASP Secure Coding
OWASP Secure Coding
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 

En vedette

Design and implementation_of_shellcodes
Design and implementation_of_shellcodesDesign and implementation_of_shellcodes
Design and implementation_of_shellcodes
Amr Ali
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneyc
Z Chen
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Michele Orru
 

En vedette (20)

Design and implementation_of_shellcodes
Design and implementation_of_shellcodesDesign and implementation_of_shellcodes
Design and implementation_of_shellcodes
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters
 
Anatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAnatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineering
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassembling
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneyc
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentExploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writing
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
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
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades short
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterExploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 Egghunter
 
One Shellcode to Rule Them All: Cross-Platform Exploitation
One Shellcode to Rule Them All: Cross-Platform ExploitationOne Shellcode to Rule Them All: Cross-Platform Exploitation
One Shellcode to Rule Them All: Cross-Platform Exploitation
 
Software Exploits
Software ExploitsSoftware Exploits
Software Exploits
 
Shellcode injection
Shellcode injectionShellcode injection
Shellcode injection
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
 

Similaire à Java Shellcode Execution

Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
QUONTRASOLUTIONS
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
Anton Arhipov
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 

Similaire à Java Shellcode Execution (20)

Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
 
Automating Security Testing with the OWTF
Automating Security Testing with the OWTFAutomating Security Testing with the OWTF
Automating Security Testing with the OWTF
 
javacourse in c.pdf
javacourse in c.pdfjavacourse in c.pdf
javacourse in c.pdf
 
javacourse in c.pdf
javacourse in c.pdfjavacourse in c.pdf
javacourse in c.pdf
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
 
Certifications Java
Certifications JavaCertifications Java
Certifications Java
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
Introduction to YouDebug - Scriptable Java Debugger
Introduction to YouDebug - Scriptable Java DebuggerIntroduction to YouDebug - Scriptable Java Debugger
Introduction to YouDebug - Scriptable Java Debugger
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 

Dernier

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
vu2urc
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 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...
 

Java Shellcode Execution

Notes de l'éditeur

  1. REMEMBER TO USE PRESENTER VIEW
  2. I’m Ryan Wincey, I’m a developer and pentration tester. This is my first presentation on.. Pretty much Anything. So bare with me. It might be a little dry, and technical.I’m going to give you a little of my background to provide some back story on my talk today. I’ve been writing code professionally for about 6 years, with a primary focus on enterprise level remote system administration. The target operating environment for the software projects I’ve been a part of has been mixed, with mostly Windows systems and a handful of Solaris and Linux systems. Given the diversity in operating systems and architecture, Java was our programming language of choice.So with my current job, I’m not developing full time anymore, but I do write a fair amount of code to aid in pentesting and maintaining persistence on computers that we compromise. So once again I’ve found myself in the situation where I have a mixed target base that my software has to run on. So I decided to go with what I was used to, and write tools using Java.
  3. So why Java.
  4. So why Java. I definetly found the people on the internet that have a distaste for it.
  5. It runs on just about everything. Phones, Tablets, Laptops, Desktops, Servers, u name it.
  6. I’m super lazy and don’t want to have to write anymore code than I have to. Tons of resources online to borrow code snippets…etc.
  7. Sun’s claims “3 billion devices” have Java installed on it. Good chance it will be on a system that you are targeting. It also blends in well because all java programs look the same from the task manager. People see Java running, they probably don’t think much of it.
  8. So let’s fast forward to the topic of this talk, I found myself with a assortment of Java based security tools, some I’ve written, some open-source. Then I came across a pretty serious limitation I was used to be able to do with native languages.
  9. How do I run shellcode directly from a Java application. So just as a quick refresher, shellcode is pretty much compiled native code that can be injected directly into memory and executed. I’d say it’s most common use is for software exploitation … but it can also be used to load code into a program without that code ever being written to disk, Which can be pretty important when you are trying to avade an antivirus.Searching the Internet didn’t provideIn C, this is a pretty trivial exercise
  10. In C, this is a pretty trivial exercise as shown aboveAfter searching the Internet, I can up with a couple options. The first technique involves writing a native library in ( C/C++) and using either JNI (Java Native Interface) or JNA ( Java Native Access ) to pass the shellcode from Java to the DLL to execute it. This technique is rather clunky since a DLL has to be transported alongside the Java code and also adds one more artifact on disk that a virus signature could be made for.https://github.com/schierlm/JavaPayload
  11. After searching the Internet, I came up with a couple options. The first technique involves writing a native library in ( C/C++) and using either JNI (Java Native Interface) or JNA ( Java Native Access ) to pass the shellcode from Java to the DLL to execute it. This technique is rather clunky since the DLL has to be transported alongside the Java code and also adds an additional artifact on disk that a virus signature could be created for.
  12. The other option I came across was buried in a project on SourceForge called JavaPayload written by Michael Schierl. After perusing the source code a little bit I found a class called JITShellCodeRunnerhttp://javapayload.sourceforge.net/, also located on GitHub at https://github.com/schierlm/JavaPayload. I read
  13. Inside the JavaPayload/payload/stage package I found a class named JITShellCodeRunner that had these comments at the top. I downloaded the source and executed the calculator executing shellcode on my machine running the latest JVM from Oracle. Unfortunately all I got JVM crash.
  14. I read through more of the comments and noticed that the most recent JVM the code had been tested on was Java 1.7 update 1. So I downloaded Java 7 update 1 dated (Oct 18, 2011) and upon execution I got this. Success.
  15. Success. A welcome sight for those that have much experience writing exploits. Now I knew that this voodoo was possible, I tried to dive deeper into the inner workings of this class so I could try and get it to work across all JVMs. The comments in the code yielded very little insight into what was actually going on so I emailed Mr. Schierl hoping for an explanation. Mr. Schierl was very helpful and explained in detail what he had done.
  16. Just to give a little refresher, Java is an interpreted language that compiles Java instructions into byte code. Byte code is then interpreted by the JVM into native instructions and executed on a system. To increase performance, the Just-In-Time (JIT) compiler inside the JVM will compile frequently used methods from byte code into native code on the fly, and cache them in memory.
  17. So now we know that the JVM not only executes byte code, but also caches natively compiled shellcode. If only we could find a way to replace the native code compiled by the JIT, with some of our own, and then execute it. Turns out there is, and Java provides it, Kinda.
  18. The Unsafe class. The Unsafe class is a Sun proprietary class that can be used to access memory directly. As the name suggest, it is extremely unsafe to use because any native exceptions that are raised while trying to access memory cannot be caught, and will cause the JVM to crash. The generalprocess for locating the a method’s native pointer consist of walking the memory structure of the Java Class instance using the Unsafe class functions. The original algorithm that was implemented by Mr. Schierl begins by first obtaining the base address of a static field in the Class
  19. That pointer references another structure that contains a pointer to an array of all of the methods in the class. The arrows point at the fields surrounding the method array pointer that act as indicators for locating the correct pointer.
  20. Each pointer in that array, then points to a structure that contains a pointer to a structure representing the native function.
  21. Lastly the native function structure contains the pointer to the entry point for the JIT compiled code. Once this pointer has been located, the shellcode can be inserted into native memory space using the Unsafe class. All that’s left is to call the method.Now for the fun part, I started exploring why this novel technique didn’t seem to work anymore. I found that there are several inconsistencies in the class layout across the various architectures and releases that would make it difficult to make a comprehensive solution. Although the sequence of fields in a class appears to be fairly consistent, the offsets to the fields tended to change across JVM releases. In all likely-hood this because new fields or members are being added or removed to the underling classes. Another compatibility issue was the introduction of compressed pointers in the 64bit JVMs that required an additional call to the Unsafe class to decompress the pointer if it was compressed.The most significant issue I found was the realignment of the base memory object starting in Java 1.7. Since this is the first step in the process, choosing the wrong initial pointer throws off the rest of the memory walk. What makes this significant is an incorrect offset into the class memory can cause the JVM to crash since it will cause a native exception to be thrown.
  22. To mitigate this problem, I added code to brute force the initial offset by spawning a separate JVM for each attempt. This technique protects the original JVM while the correct offset is located.
  23. Just a few technical notes, for those that might look at this code later. The java method who’s native code is replaced, is filled with what appear to be a arbitrary set of operations. However these operations are responsible for the size of memory that is allocated for the native code produced when it is JIT compiled. The operations are sequenced in this manner so that the operations will not be optimized when the Java code is compiled.Another caveat that needs attention when using this technique is to properly align the stack after running the desired shellcode. If this is not done, the JVM will crash. This might not be a concern but it should be noted.
  24. In case I had time I wanted to show what kinds of things can be done with this technique to extend some known penetration tools.
  25. Each pointer in that array, then points to a structure that contains a pointer to a structure for its JIT compiler code.
  26. For those that want to try the code out, I’ve sent my updates to Mr. Schierl to merge into the JavaPayload project, but also plan on putting the updated code on my Github this weekend.Thanks for letting me come talk about everything. I wanted to thank Micheal Schierl for the great research and for being an expert reference on how this stuff works.Also wanted to thank my boss for going through the hassle of getting this talk approved to be presented.