mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
feat: support tomcat suo5 shell
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
plugins {
|
||||
id "io.freefair.lombok" version "8.11"
|
||||
}
|
||||
|
||||
|
||||
group = 'com.reajason.javaweb.tools'
|
||||
version = rootProject.version
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation project(":common")
|
||||
|
||||
implementation 'net.bytebuddy:byte-buddy'
|
||||
|
||||
implementation 'commons-io:commons-io'
|
||||
implementation 'org.apache.commons:commons-lang3'
|
||||
implementation 'commons-codec:commons-codec'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp'
|
||||
|
||||
testImplementation platform('org.junit:junit-bom')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.reajason.javaweb.suo5;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/2/12
|
||||
*/
|
||||
public class Suo5Manager {
|
||||
|
||||
public static final String suo5Command;
|
||||
|
||||
static {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
String arch = System.getProperty("os.arch").toLowerCase();
|
||||
boolean isMac = os.contains("mac") || os.contains("darwin");
|
||||
boolean isArm = arch.contains("arm") || arch.contains("aarch64");
|
||||
|
||||
String osType = isMac ? "darwin" : "linux";
|
||||
String osArch = isArm ? "arm64" : "amd64";
|
||||
Path pwd = Paths.get(System.getProperty("user.dir"));
|
||||
if (!pwd.endsWith("MemShellParty")) {
|
||||
pwd = pwd.getParent();
|
||||
}
|
||||
suo5Command = pwd.resolve(Paths.get("asserts", "suo5", "suo5-" + osType + "-" + osArch)).toAbsolutePath().toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(suo5Command);
|
||||
boolean test = test("http://localhost:8081/app/test", "test");
|
||||
System.out.println(test);
|
||||
}
|
||||
|
||||
public static boolean test(String targetUrl, String ua) {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(
|
||||
suo5Command, "-t", targetUrl, "--timeout", "5", "-ua", ua
|
||||
);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
|
||||
Future<Boolean> future = executor.submit(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
if (line.contains("FTAL")) {
|
||||
process.destroy();
|
||||
return false;
|
||||
}
|
||||
if (line.contains("congratulations!")) {
|
||||
process.destroy();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
try {
|
||||
return future.get(10, TimeUnit.SECONDS);
|
||||
} catch (TimeoutException e) {
|
||||
process.destroy();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user