mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 15:10:43 +08:00
refactor: simplify server options
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.reajason.javaweb;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/7/21
|
||||
*/
|
||||
public class GenerationException extends RuntimeException {
|
||||
public GenerationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public GenerationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -27,17 +27,14 @@ public enum Server {
|
||||
*/
|
||||
Jetty(new JettyShell()),
|
||||
/**
|
||||
* JBoss AS 中间件,JBoss 6.4-EAP 也使用的当前方式 <a href="https://jbossas.jboss.org/downloads">JBoss AS</a>
|
||||
* JBoss 中间件,JBoss 6.4-EAP 也使用的当前方式 <a href="https://jbossas.jboss.org/downloads">JBoss AS</a>
|
||||
*/
|
||||
JBossAS(new JbossShell()),
|
||||
JBossEAP6(new JbossShell()),
|
||||
JBoss(new JbossShell()),
|
||||
/**
|
||||
* Undertow,对应是 Wildfly 以及 JBoss EAP,也有可能是 SpringBoot 用的
|
||||
* Undertow,对应是 Wildfly 以及 JBossEAP7,也有可能是 SpringBoot 用的
|
||||
* <a href="https://developers.redhat.com/products/eap/download">JBossEAP</a>
|
||||
*/
|
||||
Undertow(new UndertowShell()),
|
||||
JBossEAP7(new UndertowShell()),
|
||||
WildFly(new UndertowShell()),
|
||||
|
||||
/**
|
||||
* SpringMVC 框架
|
||||
@@ -68,25 +65,21 @@ public enum Server {
|
||||
* GlassFish 中间件
|
||||
*/
|
||||
GlassFish(new GlassFishShell()),
|
||||
Payara(new GlassFishShell()),
|
||||
|
||||
/**
|
||||
* 宝兰德中间件
|
||||
* 宝兰德中间件,9.5.2+ 企业版
|
||||
*/
|
||||
BES(new BesShell()),
|
||||
|
||||
/**
|
||||
* 东方通中间件
|
||||
*/
|
||||
TongWeb6(new TongWeb6Shell()),
|
||||
TongWeb7(new TongWeb7Shell()),
|
||||
TongWeb8(new TongWeb8Shell()),
|
||||
TongWeb(new TongWebShell()),
|
||||
|
||||
/**
|
||||
* 金蝶天燕中间件
|
||||
* 金蝶天燕中间件,only 9
|
||||
*/
|
||||
Apusic9(new ApusicShell()),
|
||||
Apusic10(new GlassFishShell()),
|
||||
Apusic(new ApusicShell()),
|
||||
|
||||
/**
|
||||
* 中创中间件
|
||||
|
||||
@@ -2,12 +2,12 @@ package com.reajason.javaweb.memshell.config;
|
||||
|
||||
import com.reajason.javaweb.memshell.Server;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
@@ -21,17 +21,23 @@ public class ShellConfig {
|
||||
/**
|
||||
* 目标服务类型
|
||||
*/
|
||||
Server server;
|
||||
private Server server;
|
||||
|
||||
/**
|
||||
* 目标服务版本
|
||||
*/
|
||||
@Builder.Default
|
||||
private String serverVersion = "unknown";
|
||||
|
||||
/**
|
||||
* 内存马功能
|
||||
*/
|
||||
ShellTool shellTool;
|
||||
private ShellTool shellTool;
|
||||
|
||||
/**
|
||||
* 内存马类型
|
||||
*/
|
||||
String shellType;
|
||||
private String shellType;
|
||||
|
||||
/**
|
||||
* 生成类的目标 JRE 版本
|
||||
@@ -63,7 +69,7 @@ public class ShellConfig {
|
||||
|
||||
|
||||
public boolean isJakarta() {
|
||||
return StringUtils.containsIgnoreCase(shellType, "jakarta");
|
||||
return shellType.startsWith(ShellType.JAKARTA);
|
||||
}
|
||||
|
||||
public boolean needByPassJavaModule() {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public abstract class ByteBuddyShellGenerator<T extends ShellToolConfig> impleme
|
||||
}
|
||||
|
||||
if (ShellType.VALVE.equals(shellType) || ShellType.JAKARTA_VALVE.equals(shellType)) {
|
||||
builder = ValveGenerator.build(builder, shell);
|
||||
builder = ValveGenerator.build(builder, shell, shellConfig.getServerVersion());
|
||||
}
|
||||
|
||||
if (shellConfig.isJakarta()) {
|
||||
|
||||
+11
-5
@@ -1,6 +1,9 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.memshell.server.*;
|
||||
import com.reajason.javaweb.GenerationException;
|
||||
import com.reajason.javaweb.memshell.server.AbstractShell;
|
||||
import com.reajason.javaweb.memshell.server.BesShell;
|
||||
import com.reajason.javaweb.memshell.server.TongWebShell;
|
||||
import net.bytebuddy.asm.AsmVisitorWrapper;
|
||||
import net.bytebuddy.description.field.FieldDescription;
|
||||
import net.bytebuddy.description.field.FieldList;
|
||||
@@ -27,18 +30,21 @@ public class ValveGenerator {
|
||||
public static final String TONGWEB7_VALVE_PACKAGE = "com.tongweb.catalina";
|
||||
public static final String TONGWEB8_VALVE_PACKAGE = "com.tongweb.server";
|
||||
|
||||
public static DynamicType.Builder<?> build(DynamicType.Builder<?> builder, AbstractShell shell) {
|
||||
public static DynamicType.Builder<?> build(DynamicType.Builder<?> builder, AbstractShell shell, String serverVersion) {
|
||||
String packageName = null;
|
||||
if (shell instanceof TongWeb6Shell) {
|
||||
if (serverVersion.equals("6")) {
|
||||
packageName = TONGWEB6_VALVE_PACKAGE;
|
||||
} else if (shell instanceof TongWeb7Shell) {
|
||||
} else if (serverVersion.equals("7")) {
|
||||
packageName = TONGWEB7_VALVE_PACKAGE;
|
||||
} else if (shell instanceof TongWeb8Shell) {
|
||||
} else if (serverVersion.equals("8")) {
|
||||
packageName = TONGWEB8_VALVE_PACKAGE;
|
||||
} else if (shell instanceof BesShell) {
|
||||
packageName = BES_VALVE_PACKAGE;
|
||||
}
|
||||
if (StringUtils.isEmpty(packageName)) {
|
||||
if (shell instanceof TongWebShell) {
|
||||
throw new GenerationException("serverVersion is needed for TongWeb valve shell, please use 6/7/8 for shellConfig.serverVersion");
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
return builder.visit(new ValveRenameVisitorWrapper(packageName));
|
||||
|
||||
@@ -2,12 +2,10 @@ package com.reajason.javaweb.memshell.server;
|
||||
|
||||
import com.reajason.javaweb.memshell.injector.glassfish.GlassFishContextValveAgentInjector;
|
||||
import com.reajason.javaweb.memshell.injector.glassfish.GlassFishFilterChainAgentInjector;
|
||||
import com.reajason.javaweb.memshell.injector.jboss.JbossProxyValveInjector;
|
||||
import com.reajason.javaweb.memshell.injector.jboss.JbossValveInjector;
|
||||
import com.reajason.javaweb.memshell.injector.tomcat.TomcatContextValveAgentInjector;
|
||||
import com.reajason.javaweb.memshell.injector.tomcat.TomcatFilterChainAgentInjector;
|
||||
import com.reajason.javaweb.memshell.injector.glassfish.GlassFishValveInjector;
|
||||
import com.reajason.javaweb.memshell.injector.tomcat.TomcatFilterInjector;
|
||||
import com.reajason.javaweb.memshell.injector.tomcat.TomcatListenerInjector;
|
||||
import com.reajason.javaweb.memshell.injector.tomcat.TomcatProxyValveInjector;
|
||||
|
||||
import static com.reajason.javaweb.memshell.ShellType.*;
|
||||
|
||||
@@ -27,8 +25,8 @@ public class JbossShell extends AbstractShell {
|
||||
return InjectorMapping.builder()
|
||||
.addInjector(LISTENER, TomcatListenerInjector.class)
|
||||
.addInjector(FILTER, TomcatFilterInjector.class)
|
||||
.addInjector(VALVE, JbossValveInjector.class)
|
||||
.addInjector(PROXY_VALVE, JbossProxyValveInjector.class)
|
||||
.addInjector(VALVE, GlassFishValveInjector.class)
|
||||
.addInjector(PROXY_VALVE, TomcatProxyValveInjector.class)
|
||||
.addInjector(AGENT_FILTER_CHAIN, GlassFishFilterChainAgentInjector.class)
|
||||
.addInjector(CATALINA_AGENT_CONTEXT_VALVE, GlassFishContextValveAgentInjector.class)
|
||||
.build();
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.reajason.javaweb.memshell.server;
|
||||
|
||||
import com.reajason.javaweb.memshell.injector.tongweb.*;
|
||||
|
||||
import static com.reajason.javaweb.memshell.ShellType.*;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/27
|
||||
*/
|
||||
public class TongWeb7Shell extends AbstractShell {
|
||||
|
||||
@Override
|
||||
public Class<?> getListenerInterceptor() {
|
||||
return TomcatShell.ListenerInterceptor.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InjectorMapping getShellInjectorMapping() {
|
||||
return InjectorMapping.builder()
|
||||
.addInjector(LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(JAKARTA_LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(JAKARTA_FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(VALVE, TongWebValveInjector.class)
|
||||
.addInjector(JAKARTA_VALVE, TongWebValveInjector.class)
|
||||
.addInjector(AGENT_FILTER_CHAIN, TongWebFilterChainAgentInjector.class)
|
||||
.addInjector(CATALINA_AGENT_CONTEXT_VALVE, TongWebContextValveAgentInjector.class)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.reajason.javaweb.memshell.server;
|
||||
|
||||
import com.reajason.javaweb.memshell.injector.tongweb.*;
|
||||
|
||||
import static com.reajason.javaweb.memshell.ShellType.*;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/27
|
||||
*/
|
||||
public class TongWeb8Shell extends AbstractShell {
|
||||
|
||||
@Override
|
||||
public Class<?> getListenerInterceptor() {
|
||||
return TomcatShell.ListenerInterceptor.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InjectorMapping getShellInjectorMapping() {
|
||||
return InjectorMapping.builder()
|
||||
.addInjector(LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(JAKARTA_LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(JAKARTA_FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(VALVE, TongWebValveInjector.class)
|
||||
.addInjector(JAKARTA_VALVE, TongWebValveInjector.class)
|
||||
.addInjector(AGENT_FILTER_CHAIN, TongWebFilterChainAgentInjector.class)
|
||||
.addInjector(CATALINA_AGENT_CONTEXT_VALVE, TongWebContextValveAgentInjector.class)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -8,7 +8,7 @@ import static com.reajason.javaweb.memshell.ShellType.*;
|
||||
* @author ReaJason
|
||||
* @since 2024/12/26
|
||||
*/
|
||||
public class TongWeb6Shell extends AbstractShell {
|
||||
public class TongWebShell extends AbstractShell {
|
||||
|
||||
@Override
|
||||
public Class<?> getListenerInterceptor() {
|
||||
@@ -19,11 +19,8 @@ public class TongWeb6Shell extends AbstractShell {
|
||||
public InjectorMapping getShellInjectorMapping() {
|
||||
return InjectorMapping.builder()
|
||||
.addInjector(LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(JAKARTA_LISTENER, TongWebListenerInjector.class)
|
||||
.addInjector(FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(JAKARTA_FILTER, TongWebFilterInjector.class)
|
||||
.addInjector(VALVE, TongWebValveInjector.class)
|
||||
.addInjector(JAKARTA_VALVE, TongWebValveInjector.class)
|
||||
.addInjector(AGENT_FILTER_CHAIN, TongWebFilterChainAgentInjector.class)
|
||||
.addInjector(CATALINA_AGENT_CONTEXT_VALVE, TongWebContextValveAgentInjector.class)
|
||||
.build();
|
||||
@@ -110,8 +110,6 @@ public class CommonUtil {
|
||||
packageName = "org.eclipse.jetty.servlet.handlers";
|
||||
break;
|
||||
case Undertow:
|
||||
case JBossEAP7:
|
||||
case WildFly:
|
||||
packageName = "io.undertow.servlet.handlers";
|
||||
break;
|
||||
case SpringWebMvc:
|
||||
|
||||
Reference in New Issue
Block a user