SlideShare a Scribd company logo
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)
Java Shellcode Execution
http://www.research.ibm.com/trl/projects/jit/index_e.htm
Java Shellcode Execution
Java Shellcode Execution
Java Shellcode Execution
Java Shellcode Execution
Java Shellcode Execution
Java Shellcode Execution
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

More Related Content

What's hot (20)

PDF
PostgreSQL Unconference #29 Unicode IVS
Noriyoshi Shinoda
 
PDF
alphorm.com - Formation PostgreSQL administration
Alphorm
 
PDF
Load Balancing with Nginx
Marian Marinov
 
PPTX
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Lucas Jellema
 
PDF
Understanding of Apache kafka metrics for monitoring
SANG WON PARK
 
PDF
I'm in your cloud... reading everyone's email. Hacking Azure AD via Active Di...
DirkjanMollema
 
PDF
Common issues with Apache Kafka® Producer
confluent
 
PDF
MySQLレプリケーションあれやこれや
yoku0825
 
PDF
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
Jo Hoon
 
PDF
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
PDF
Embulk, an open-source plugin-based parallel bulk data loader
Sadayuki Furuhashi
 
PDF
Percona Xtrabackup - Highly Efficient Backups
Mydbops
 
PDF
Oracle Client Failover - Under The Hood
Ludovico Caldara
 
PPTX
Waf bypassing Techniques
Avinash Thapa
 
PDF
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
PPTX
PHP と SAPI と ZendEngine3 と
do_aki
 
PPTX
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
ScyllaDB
 
PDF
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder
 
PDF
JVMのGCアルゴリズムとチューニング
佑哉 廣岡
 
PDF
Using Vault to decouple MySQL Secrets
Derek Downey
 
PostgreSQL Unconference #29 Unicode IVS
Noriyoshi Shinoda
 
alphorm.com - Formation PostgreSQL administration
Alphorm
 
Load Balancing with Nginx
Marian Marinov
 
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Lucas Jellema
 
Understanding of Apache kafka metrics for monitoring
SANG WON PARK
 
I'm in your cloud... reading everyone's email. Hacking Azure AD via Active Di...
DirkjanMollema
 
Common issues with Apache Kafka® Producer
confluent
 
MySQLレプリケーションあれやこれや
yoku0825
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
Jo Hoon
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Embulk, an open-source plugin-based parallel bulk data loader
Sadayuki Furuhashi
 
Percona Xtrabackup - Highly Efficient Backups
Mydbops
 
Oracle Client Failover - Under The Hood
Ludovico Caldara
 
Waf bypassing Techniques
Avinash Thapa
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
PHP と SAPI と ZendEngine3 と
do_aki
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
ScyllaDB
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder
 
JVMのGCアルゴリズムとチューニング
佑哉 廣岡
 
Using Vault to decouple MySQL Secrets
Derek Downey
 

Viewers also liked (20)

ODP
Design and implementation_of_shellcodes
Amr Ali
 
PPTX
07 - Bypassing ASLR, or why X^W matters
Alexandre Moneger
 
PDF
Anatomy of A Shell Code, Reverse engineering
Abhineet Ayan
 
PDF
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
PDF
Linux Shellcode disassembling
Harsh Daftary
 
PDF
Shellcode and heapspray detection in phoneyc
Z Chen
 
PPTX
05 - Bypassing DEP, or why ASLR matters
Alexandre Moneger
 
PPTX
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Ajin Abraham
 
PDF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Michele Orru
 
PDF
Talking about exploit writing
sbha0909
 
PPTX
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
midnite_runr
 
PDF
Hacking school computers for fun profit and better grades short
Vincent Ohprecio
 
PDF
Shellcode Analysis - Basic and Concept
Julia Yu-Chin Cheng
 
PPTX
Exploit Research and Development Megaprimer: Win32 Egghunter
Ajin Abraham
 
PDF
One Shellcode to Rule Them All: Cross-Platform Exploitation
Quinn Wilton
 
PPT
Software Exploits
KevinCSmallwood
 
PDF
Shellcode injection
Dhaval Kapil
 
PPT
Writing Metasploit Plugins
amiable_indian
 
PDF
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Michele Orru
 
Design and implementation_of_shellcodes
Amr Ali
 
07 - Bypassing ASLR, or why X^W matters
Alexandre Moneger
 
Anatomy of A Shell Code, Reverse engineering
Abhineet Ayan
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
Linux Shellcode disassembling
Harsh Daftary
 
Shellcode and heapspray detection in phoneyc
Z Chen
 
05 - Bypassing DEP, or why ASLR matters
Alexandre Moneger
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Ajin Abraham
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Michele Orru
 
Talking about exploit writing
sbha0909
 
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
midnite_runr
 
Hacking school computers for fun profit and better grades short
Vincent Ohprecio
 
Shellcode Analysis - Basic and Concept
Julia Yu-Chin Cheng
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Ajin Abraham
 
One Shellcode to Rule Them All: Cross-Platform Exploitation
Quinn Wilton
 
Software Exploits
KevinCSmallwood
 
Shellcode injection
Dhaval Kapil
 
Writing Metasploit Plugins
amiable_indian
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Michele Orru
 
Ad

Similar to Java Shellcode Execution (7)

PPTX
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
PPTX
Java is a new language on the mainframe
Michael Erichsen
 
PDF
Beyond JVM - YOW Melbourne 2013
Charles Nutter
 
PPTX
Java JIT Performance Testing and Results
Adam Feldscher
 
PPTX
The latest features coming to Java 12
NexSoftsys
 
PDF
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
PDF
Beyond JVM - YOW! Brisbane 2013
Charles Nutter
 
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
Java is a new language on the mainframe
Michael Erichsen
 
Beyond JVM - YOW Melbourne 2013
Charles Nutter
 
Java JIT Performance Testing and Results
Adam Feldscher
 
The latest features coming to Java 12
NexSoftsys
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
Beyond JVM - YOW! Brisbane 2013
Charles Nutter
 
Ad

Recently uploaded (20)

PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Practical Applications of AI in Local Government
OnBoard
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 

Java Shellcode Execution

Editor's Notes

  • #2: REMEMBER TO USE PRESENTER VIEW
  • #4: 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.
  • #5: So why Java.
  • #6: So why Java. I definetly found the people on the internet that have a distaste for it.
  • #7: It runs on just about everything. Phones, Tablets, Laptops, Desktops, Servers, u name it.
  • #8: 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.
  • #9: 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.
  • #10: 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.
  • #11: 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
  • #12: 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
  • #13: 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.
  • #14: 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
  • #15: 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.
  • #16: 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.
  • #17: 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.
  • #18: 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.
  • #19: 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.
  • #20: 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
  • #21: 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.
  • #22: Each pointer in that array, then points to a structure that contains a pointer to a structure representing the native function.
  • #23: 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.
  • #24: 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.
  • #26: 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.
  • #27: 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.
  • #28: Each pointer in that array, then points to a structure that contains a pointer to a structure for its JIT compiler code.
  • #29: 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.