mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 07:00:43 +08:00
refactor: separate generate config
This commit is contained in:
+2
-18
@@ -1,21 +1,12 @@
|
||||
package com.reajason.javaweb.integration;
|
||||
|
||||
import com.reajason.javaweb.GeneratorMain;
|
||||
import com.reajason.javaweb.config.CommandShellConfig;
|
||||
import com.reajason.javaweb.config.GenerateResult;
|
||||
import com.reajason.javaweb.config.Server;
|
||||
import com.reajason.javaweb.config.ShellTool;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import com.reajason.javaweb.memsell.tomcat.TomcatShell;
|
||||
import com.reajason.javaweb.config.CommandConfig;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -27,15 +18,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*/
|
||||
@Slf4j
|
||||
public class CommandShellTool {
|
||||
|
||||
public static String generate(Server server, CommandShellConfig config, String shellType, int targetJdkVersion, Packer.INSTANCE packer) {
|
||||
ShellTool shellTool = ShellTool.Command;
|
||||
GenerateResult generateResult = GeneratorMain.generate(server, shellTool, shellType, config, targetJdkVersion);
|
||||
return new String(packer.getPacker().pack(generateResult));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void testIsOk(String entrypoint, CommandShellConfig shellConfig) {
|
||||
public static void testIsOk(String entrypoint, CommandConfig shellConfig) {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
HttpUrl url = Objects.requireNonNull(HttpUrl.parse(entrypoint))
|
||||
.newBuilder()
|
||||
|
||||
+3
-23
@@ -1,12 +1,10 @@
|
||||
package com.reajason.javaweb.integration;
|
||||
|
||||
import com.reajason.javaweb.GeneratorMain;
|
||||
import com.reajason.javaweb.config.GenerateResult;
|
||||
import com.reajason.javaweb.config.GodzillaShellConfig;
|
||||
import com.reajason.javaweb.config.Server;
|
||||
import com.reajason.javaweb.config.ShellTool;
|
||||
import com.reajason.javaweb.config.*;
|
||||
import com.reajason.javaweb.godzilla.GodzillaManager;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import com.reajason.javaweb.memsell.tomcat.TomcatShell;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -18,25 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*/
|
||||
public class GodzillaShellTool {
|
||||
|
||||
public static String generate(Server server, GodzillaShellConfig config, String shellType, int targetJdkVersion, Packer.INSTANCE packer) {
|
||||
ShellTool shellTool = ShellTool.Godzilla;
|
||||
GenerateResult generateResult = GeneratorMain.generate(server, shellTool, shellType, config, targetJdkVersion);
|
||||
return new String(packer.getPacker().pack(generateResult));
|
||||
}
|
||||
|
||||
public static String generateJSP(Server server, GodzillaShellConfig config, String shellType, int targetJdkVersion) {
|
||||
ShellTool shellTool = ShellTool.Godzilla;
|
||||
GenerateResult generateResult = GeneratorMain.generate(server, shellTool, shellType, config, targetJdkVersion);
|
||||
return new String(Packer.INSTANCE.JSP.getPacker().pack(generateResult));
|
||||
}
|
||||
|
||||
public static String generateJS(Server server, GodzillaShellConfig config, String shellType, int targetJdkVersion) {
|
||||
ShellTool shellTool = ShellTool.Godzilla;
|
||||
GenerateResult generateResult = GeneratorMain.generate(server, shellTool, shellType, config, targetJdkVersion);
|
||||
return new String(Packer.INSTANCE.ScriptEngine.getPacker().pack(generateResult));
|
||||
}
|
||||
|
||||
public static void testIsOk(String entrypoint, GodzillaShellConfig shellConfig) {
|
||||
public static void testIsOk(String entrypoint, GodzillaConfig shellConfig) {
|
||||
try (GodzillaManager godzillaManager = GodzillaManager.builder()
|
||||
.entrypoint(entrypoint).pass(shellConfig.getPass())
|
||||
.key(shellConfig.getKey()).header(shellConfig.getHeaderName()
|
||||
|
||||
+22
-13
@@ -1,12 +1,12 @@
|
||||
package com.reajason.javaweb.integration;
|
||||
|
||||
import com.reajason.javaweb.config.CommandShellConfig;
|
||||
import com.reajason.javaweb.config.GodzillaShellConfig;
|
||||
import com.reajason.javaweb.config.Server;
|
||||
import com.reajason.javaweb.config.ShellTool;
|
||||
import com.reajason.javaweb.GeneratorMain;
|
||||
import com.reajason.javaweb.config.*;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/5
|
||||
@@ -14,28 +14,37 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class ShellAssertionTool {
|
||||
public static void testShellInjectAssertOk(String url, Server server, String shellType, ShellTool shellTool, int targetJdkVersion, Packer.INSTANCE packer) {
|
||||
InjectorConfig injectorConfig = new InjectorConfig();
|
||||
|
||||
ShellConfig shellConfig = ShellConfig.builder()
|
||||
.server(server)
|
||||
.shellTool(shellTool)
|
||||
.shellType(shellType)
|
||||
.targetJdkVersion(targetJdkVersion)
|
||||
.build();
|
||||
|
||||
String shellUrl;
|
||||
switch (shellTool) {
|
||||
case Godzilla:
|
||||
String pass = "pass" + shellType;
|
||||
String key = "key" + shellType;
|
||||
String pass = "pass";
|
||||
String key = "key";
|
||||
String headerValue = "Godzilla" + shellType + packer.name();
|
||||
GodzillaShellConfig shellConfig = GodzillaShellConfig.builder()
|
||||
GodzillaConfig godzillaConfig = GodzillaConfig.builder()
|
||||
.pass(pass).key(key)
|
||||
.headerName("User-Agent").headerValue(headerValue)
|
||||
.build();
|
||||
log.info("generated {} godzilla with pass: {}, key: {}, headerValue: {}", shellType, pass, key, headerValue);
|
||||
String godzillaContent = GodzillaShellTool.generate(server, shellConfig, shellType, targetJdkVersion, packer);
|
||||
String godzillaContent = new String(Objects.requireNonNull(GeneratorMain.generate(shellConfig, injectorConfig, godzillaConfig, packer)));
|
||||
shellUrl = assertInjectIsOk(url, shellType, shellTool, godzillaContent, packer);
|
||||
GodzillaShellTool.testIsOk(shellUrl, shellConfig);
|
||||
GodzillaShellTool.testIsOk(shellUrl, godzillaConfig);
|
||||
break;
|
||||
case Command:
|
||||
String paramName = "Command" + shellType + packer.name();
|
||||
CommandShellConfig config = CommandShellConfig.builder().paramName(paramName).build();
|
||||
String commandContent = CommandShellTool.generate(server, config, shellType, targetJdkVersion, packer);
|
||||
log.info("generated {} command shell with paramName: {}", shellType, config.getParamName());
|
||||
CommandConfig commandConfig = CommandConfig.builder().paramName(paramName).build();
|
||||
String commandContent = new String(Objects.requireNonNull(GeneratorMain.generate(shellConfig, injectorConfig, commandConfig, packer)));
|
||||
log.info("generated {} command shell with paramName: {}", shellType, commandConfig.getParamName());
|
||||
shellUrl = assertInjectIsOk(url, shellType, shellTool, commandContent, packer);
|
||||
CommandShellTool.testIsOk(shellUrl, config);
|
||||
CommandShellTool.testIsOk(shellUrl, commandConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user