使用Java执行metasploit命令

时间:2018-04-02 20:07:24

标签: java metasploit interactive-shell

我正在尝试使用Java开发基于UI的应用程序以使用Metasploit(操作系统:Kali Linux)。基本上我想启动终端并运行命令“msfconsole”,然后一旦Metasploit Framework Console启动,我想在其中执行命令。

使用ProcessBuilder Java类我可以打开一个终端并启动Metasploit Framework Console但是我无法在Framework下执行任何命令。我是Runtime和ProcessBuilder类的Java新手。启动Framework Console后,我尝试执行Metasploit Framework的“help”命令,但该命令直接在终端下执行,因此显示了终端帮助。所以有人可以帮我解决这个问题吗?代码段如下。此外,我还在本文末尾附上了支持图片。

    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();

我已经包围了我要输入命令的部分。该图显示了在终端窗口内运行的Metasploit Console:

I have encircled the part where I want to enter the commands. The image shows Metasploit Console running inside a terminal window.

0 个答案:

没有答案