The java program is:
import java.util.*;
import java.io.*;
public class test{
public static void main(String[] args){
try{
Process proc = (new ProcessBuilder("cmd.exe", "/c", "dir", args[0])).start();
proc.waitFor();
BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = r.readLine()) != null)
System.out.println(line);
r.close();
} catch(Exception e){
}
}
}
This program is vulnerable to command injection. As I run the following command:
java test ".&ipconfig"
this program will execute both dir .
and ipconfig
.
How do ProcessBuilder()
parse these arguments and execute them?
I noticed that the command line cmd.exe /c dir ".&ipconfig"
outputs different results in CMD (fail) and powershell (success).