1

I'm trying to make myself a wrapper around some of the Metasploit's scanners so I won't have to copy/paste so many things. I have this list of ips that I want Ms to scan and I try to start a Java Process and communicate with it via BufferedReader and BufferedWriter

This is my code:

ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "whoami && msfconsole");
processBuilder.redirectErrorStream(true);

try {
 process = processBuilder.start();
 process.waitFor();

 BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
 BufferedWriter output = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

 String line;
 while ((line = input.readLine()) != null) {
  System.out.println(line);
 }
} catch (IOException | InterruptedException e) {
 e.printStackTrace();
}

Although I can start Ms from a normal terminal this code me gives the following output:

Connected to the target VM, address: '127.0.0.1:36325', transport: 'socket'
danny
fatal: Not a git repository (or any of the parent directories): .git
/var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find i18n-0.8.1 in any of the sources (Bundler::GemNotFound)
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/spec_set.rb:80:in `map!'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/spec_set.rb:80:in `materialize'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/definition.rb:176:in `specs'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/definition.rb:235:in `specs_for'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/definition.rb:224:in `requested_specs'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:118:in `block in definition_method'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:19:in `setup'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler.rb:100:in `setup'
    from /var/lib/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/setup.rb:20:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from /opt/metasploit-framework/config/boot.rb:26:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/bin/msfconsole:45:in `<main>'
Disconnected from the target VM, address: '127.0.0.1:36325', transport: 'socket'

Process finished with exit code 0 

I inserted a whoami to check the user java uses to start Ms and it's my user. How could I make this work?

Daniel Bejan
  • 1,468
  • 1
  • 15
  • 39

0 Answers0