2011-08-24 18:47:35 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
|
|
require 'optparse'
|
|
|
|
require 'msfrpc-client'
|
|
|
|
require 'rex/ui'
|
|
|
|
|
|
|
|
def usage(ropts)
|
2013-09-30 18:47:53 +00:00
|
|
|
$stderr.puts ropts
|
|
|
|
|
|
|
|
if @rpc and @rpc.token
|
|
|
|
wspaces = @rpc.call("pro.workspaces") rescue {}
|
|
|
|
if wspaces.keys.length > 0
|
|
|
|
$stderr.puts "Active Projects:"
|
|
|
|
wspaces.each_pair do |k,v|
|
|
|
|
$stderr.puts "\t#{k}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
exit(1)
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
|
|
|
|
# Parse script-specific options
|
|
|
|
parser = Msf::RPC::Client.option_parser(opts)
|
|
|
|
parser.separator('Task Options:')
|
|
|
|
|
|
|
|
parser.on("--path PATH") do |path|
|
2013-09-30 18:47:53 +00:00
|
|
|
opts[:path] = path
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
parser.on("--project PROJECT") do |project|
|
2013-09-30 18:47:53 +00:00
|
|
|
opts[:project] = project
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
parser.on("--help") do
|
2013-09-30 18:47:53 +00:00
|
|
|
$stderr.puts parser
|
|
|
|
exit(1)
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
parser.separator('')
|
|
|
|
|
|
|
|
parser.parse!(ARGV)
|
|
|
|
@rpc = Msf::RPC::Client.new(opts)
|
|
|
|
|
|
|
|
if not @rpc.token
|
2013-09-30 18:47:53 +00:00
|
|
|
$stderr.puts "Error: Invalid RPC server options specified"
|
|
|
|
$stderr.puts parser
|
|
|
|
exit(1)
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
project = opts[:project] || usage(parser)
|
|
|
|
path = opts[:path] || usage(parser)
|
|
|
|
user = @rpc.call("pro.default_admin_user")['username']
|
|
|
|
task = @rpc.call("pro.start_import", {
|
2013-09-30 18:47:53 +00:00
|
|
|
'workspace' => project,
|
|
|
|
'username' => user,
|
|
|
|
'DS_PATH' => path
|
2011-08-24 18:47:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if not task['task_id']
|
2013-09-30 18:47:53 +00:00
|
|
|
$stderr.puts "[-] Error starting the task: #{task.inspect}"
|
|
|
|
exit(0)
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
puts "[*] Creating Task ID #{task['task_id']}..."
|
|
|
|
while true
|
2013-09-30 18:47:53 +00:00
|
|
|
select(nil, nil, nil, 0.50)
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
stat = @rpc.call("pro.task_status", task['task_id'])
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
if stat['status'] == 'invalid'
|
|
|
|
$stderr.puts "[-] Error checking task status"
|
|
|
|
exit(0)
|
|
|
|
end
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
info = stat[ task['task_id'] ]
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
if not info
|
|
|
|
$stderr.puts "[-] Error finding the task"
|
|
|
|
exit(0)
|
|
|
|
end
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
if info['status'] == "error"
|
|
|
|
$stderr.puts "[-] Error generating report: #{info['error']}"
|
|
|
|
exit(0)
|
|
|
|
end
|
2011-08-24 18:47:35 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
break if info['progress'] == 100
|
2011-08-24 18:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
$stdout.puts "[+] Task Complete!"
|