I am trying to develop a UI based app in Java to use Metasploit (OS: Kali Linux). Basically I want to start a terminal and run the command "msfconsole" and then once the Metasploit Framework Console starts I want to execute commands in it.
Using ProcessBuilder Class of Java I am able to open up a terminal and start the Metasploit Framework Console but I am unable to execute any commands under the Framework. I am new to Runtime and ProcessBuilder class of Java. After starting the Framework Console, I did try executing the "help" command of the Metasploit Framework but that command was directly executed under the terminal and hence terminal help was displayed. So can anyone help me out with this? The code snippet is given below. Also I have included a supporting image at the end of this post.
String line;
Scanner scan = new Scanner(System.in);
ProcessBuilder builder = new ProcessBuilder("/bin/bash");
builder.redirectErrorStream(true);
Process process = builder.start();
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
String input = scan.nextLine();
input += "\n";
writer.write(input);
writer.flush()
input = scan.nextLine();
input += "\n";
writer.write(input);
writer.flush();
while ((line = reader.readLine()) != null) {
System.out.println("Stdout: " + line);
}
writer.close();
I have encircled the part where I want to enter the commands. The image shows Metasploit Console running inside a terminal window: