mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-02-16 00:24:29 +01:00
Handle discrepance of process launching on Windows between different versions of Java
This commit is contained in:
parent
dc3021e1c0
commit
f1fcfd6176
@ -67,12 +67,10 @@ public class stdapi_sys_process_execute implements Command {
|
|||||||
|
|
||||||
// On Windows, Java quote-escapes _some_ arguments (like those with spaces), but doesn't deal correctly with some
|
// On Windows, Java quote-escapes _some_ arguments (like those with spaces), but doesn't deal correctly with some
|
||||||
// edge cases; e.g. empty strings, strings that already have quotes.
|
// edge cases; e.g. empty strings, strings that already have quotes.
|
||||||
protected String escapeArg(String arg) {
|
protected String escapeArgWindows(String arg) {
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String osName = System.getProperty("os.name");
|
|
||||||
if (osName != null && osName.toLowerCase().contains("windows")) {
|
|
||||||
if (arg.equals("")) {
|
if (arg.equals("")) {
|
||||||
return "\"\"";
|
return "\"\"";
|
||||||
} else {
|
} else {
|
||||||
@ -117,21 +115,36 @@ public class stdapi_sys_process_execute implements Command {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
return arg;
|
|
||||||
|
protected Process executeWindows(String cmd, ArrayList<String> args) throws IOException {
|
||||||
|
StringBuilder cmdString = new StringBuilder();
|
||||||
|
cmdString.append(cmd);
|
||||||
|
if (args.size() > 0) {
|
||||||
|
for (String arg : args) {
|
||||||
|
cmdString.append(" ");
|
||||||
|
cmdString.append(escapeArgWindows(arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return execute(cmdString.toString());
|
||||||
|
}
|
||||||
|
|
||||||
protected Process execute(String cmd, ArrayList<String> args) throws IOException {
|
protected Process execute(String cmd, ArrayList<String> args) throws IOException {
|
||||||
|
String osName = System.getProperty("os.name");
|
||||||
|
if (osName != null && osName.toLowerCase().contains("windows")) {
|
||||||
|
return executeWindows(cmd, args);
|
||||||
|
} else {
|
||||||
ArrayList<String> cmdAndArgs = new ArrayList<String>();
|
ArrayList<String> cmdAndArgs = new ArrayList<String>();
|
||||||
cmdAndArgs.add(cmd);
|
cmdAndArgs.add(cmd);
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
cmdAndArgs.add(escapeArg(arg));
|
cmdAndArgs.add(arg);
|
||||||
}
|
}
|
||||||
ProcessBuilder builder = new ProcessBuilder(cmdAndArgs);
|
ProcessBuilder builder = new ProcessBuilder(cmdAndArgs);
|
||||||
builder.directory(Loader.getCWD());
|
builder.directory(Loader.getCWD());
|
||||||
return builder.start();
|
return builder.start();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Process execute(String cmdstr) throws IOException {
|
protected Process execute(String cmdstr) throws IOException {
|
||||||
Process proc = Runtime.getRuntime().exec(cmdstr);
|
Process proc = Runtime.getRuntime().exec(cmdstr);
|
||||||
|
Loading…
Reference in New Issue
Block a user