scan_export_status patch for issue 5217

This commit is contained in:
root 2015-04-23 12:04:02 +05:00
parent b6df023c99
commit 19beafe009
2 changed files with 37 additions and 23 deletions

View File

@ -181,12 +181,7 @@ module Nessus
request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status")
request.add_field("X-Cookie", @token)
res = @connection.request(request)
if res.code == "200"
return "ready"
else
res = JSON.parse(res.body)
return res
end
return res.code, JSON.parse(res.body)
end
def policy_delete(policy_id)

View File

@ -4,20 +4,21 @@ require 'rex/parser/nessus_xml'
module Msf
PLUGIN_NAME = 'Nessus'
PLUGIN_DESCRIPTION = 'Nessus Bridge for Metasploit'
class Plugin::Nessus < Msf::Plugin
def name
PLUGIN_NAME
"Nessus"
end
def desc
"Nessus Bridge for Metasploit"
end
class ConsoleCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
def name
PLUGIN_NAME
"Nessus"
end
def xindex
@ -450,7 +451,7 @@ module Msf
print_status("Returns a list of information about the scan or policy templates..")
return
end
if type.in?(['scan', 'policy'])
if type.downcase.in?(['scan', 'policy'])
list=@n.list_template(type)
else
print_error("Only scan and policy are valid templates")
@ -1183,7 +1184,7 @@ module Msf
when 2
scan_id = args[0]
category = args[1]
if category.in?(['info', 'hosts', 'vulnerabilities', 'history'])
if category.downcase.in?(['info', 'hosts', 'vulnerabilities', 'history'])
category = args[1]
else
print_error("Invalid category. The available categories are info, hosts, vulnerabilities, and history")
@ -1274,9 +1275,13 @@ module Msf
file_id = export["file"]
print_good("The export file ID for scan ID #{scan_id} is #{file_id}")
print_status("Checking export status...")
status = @n.scan_export_status(scan_id, file_id)
if status == "ready"
print_good("The status of scan ID #{scan_id} export is ready")
code, body = @n.scan_export_status(scan_id, file_id)
if code == "200"
if body =~ /ready/
print_good("The status of scan ID #{scan_id} export is ready")
else
print_status("Scan result not ready for download. Please check again after a few seconds")
end
else
print_error("There was some problem in exporting the scan. The error message is #{status}")
end
@ -1301,12 +1306,7 @@ module Msf
when 2
scan_id = args[0]
file_id = args[1]
status = @n.scan_export_status(scan_id, file_id)
if status == "ready"
print_status("The status of scan ID #{scan_id} export is ready")
else
print_error("There was some problem in exporting the scan. The error message is #{status}")
end
check_export_status(scan_id, file_id)
else
print_status("Usage: ")
print_status("nessus_scan_export_status <scan ID> <file ID>")
@ -1314,6 +1314,25 @@ module Msf
end
end
def check_export_status(scan_id, file_id, attempt = 0)
code, body = @n.scan_export_status(scan_id, file_id)
if code == "200"
if body.to_s =~ /ready/
print_status("The status of scan ID #{scan_id} export is ready")
else
if attempt < 3
print_status("Scan result not ready for download. Checking again...")
select(nil, nil, nil, 1)
attempt = attempt + 1
print_error("Current value of attempt is #{attempt}")
check_export_status(scan_id, file_id, attempt)
end
end
else
print_error("There was some problem in exporting the scan. The error message is #{body}")
end
end
def cmd_nessus_plugin_list(*args)
if args[0] == "-h"
print_status("nessus_plugin_list <Family ID>")
@ -1668,7 +1687,7 @@ module Msf
def initialize(framework, opts)
super
add_console_dispatcher(ConsoleCommandDispatcher)
print_status(PLUGIN_DESCRIPTION)
print_status("Nessus Bridge for Metasploit")
print_status("Type %bldnessus_help%clr for a command listing")
end