我试图让自己成为一些Metasploit扫描仪的包装器,所以我不必复制/粘贴这么多东西。我有这个我希望Ms扫描的ips列表,我尝试启动Java Process
并通过BufferedReader
和BufferedWriter
这是我的代码:
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();
}
虽然我可以从普通终端启动Ms,但这段代码给出了以下输出:
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
我插入whoami
来检查用户java用来启动Ms,它是我的用户。我怎么能做这个工作?