Skip to content

Commit 19beafe

Browse files
committed
scan_export_status patch for issue 5217
1 parent b6df023 commit 19beafe

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

lib/nessus/nessus-xmlrpc.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,7 @@ def scan_export_status(scan_id, file_id)
181181
request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status")
182182
request.add_field("X-Cookie", @token)
183183
res = @connection.request(request)
184-
if res.code == "200"
185-
return "ready"
186-
else
187-
res = JSON.parse(res.body)
188-
return res
189-
end
184+
return res.code, JSON.parse(res.body)
190185
end
191186

192187
def policy_delete(policy_id)

plugins/nessus.rb

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
module Msf
66

7-
PLUGIN_NAME = 'Nessus'
8-
PLUGIN_DESCRIPTION = 'Nessus Bridge for Metasploit'
9-
107
class Plugin::Nessus < Msf::Plugin
118

129
def name
13-
PLUGIN_NAME
10+
"Nessus"
11+
end
12+
13+
def desc
14+
"Nessus Bridge for Metasploit"
1415
end
1516

1617
class ConsoleCommandDispatcher
1718
include Msf::Ui::Console::CommandDispatcher
1819

1920
def name
20-
PLUGIN_NAME
21+
"Nessus"
2122
end
2223

2324
def xindex
@@ -450,7 +451,7 @@ def cmd_nessus_template_list(*args)
450451
print_status("Returns a list of information about the scan or policy templates..")
451452
return
452453
end
453-
if type.in?(['scan', 'policy'])
454+
if type.downcase.in?(['scan', 'policy'])
454455
list=@n.list_template(type)
455456
else
456457
print_error("Only scan and policy are valid templates")
@@ -1183,7 +1184,7 @@ def cmd_nessus_scan_details(*args)
11831184
when 2
11841185
scan_id = args[0]
11851186
category = args[1]
1186-
if category.in?(['info', 'hosts', 'vulnerabilities', 'history'])
1187+
if category.downcase.in?(['info', 'hosts', 'vulnerabilities', 'history'])
11871188
category = args[1]
11881189
else
11891190
print_error("Invalid category. The available categories are info, hosts, vulnerabilities, and history")
@@ -1274,9 +1275,13 @@ def cmd_nessus_scan_export(*args)
12741275
file_id = export["file"]
12751276
print_good("The export file ID for scan ID #{scan_id} is #{file_id}")
12761277
print_status("Checking export status...")
1277-
status = @n.scan_export_status(scan_id, file_id)
1278-
if status == "ready"
1279-
print_good("The status of scan ID #{scan_id} export is ready")
1278+
code, body = @n.scan_export_status(scan_id, file_id)
1279+
if code == "200"
1280+
if body =~ /ready/
1281+
print_good("The status of scan ID #{scan_id} export is ready")
1282+
else
1283+
print_status("Scan result not ready for download. Please check again after a few seconds")
1284+
end
12801285
else
12811286
print_error("There was some problem in exporting the scan. The error message is #{status}")
12821287
end
@@ -1301,19 +1306,33 @@ def cmd_nessus_scan_export_status(*args)
13011306
when 2
13021307
scan_id = args[0]
13031308
file_id = args[1]
1304-
status = @n.scan_export_status(scan_id, file_id)
1305-
if status == "ready"
1306-
print_status("The status of scan ID #{scan_id} export is ready")
1307-
else
1308-
print_error("There was some problem in exporting the scan. The error message is #{status}")
1309-
end
1309+
check_export_status(scan_id, file_id)
13101310
else
13111311
print_status("Usage: ")
13121312
print_status("nessus_scan_export_status <scan ID> <file ID>")
13131313
print_status("Use nessus_scan_export <scan ID> <format> to export a scan and get its file ID")
13141314
end
13151315
end
13161316

1317+
def check_export_status(scan_id, file_id, attempt = 0)
1318+
code, body = @n.scan_export_status(scan_id, file_id)
1319+
if code == "200"
1320+
if body.to_s =~ /ready/
1321+
print_status("The status of scan ID #{scan_id} export is ready")
1322+
else
1323+
if attempt < 3
1324+
print_status("Scan result not ready for download. Checking again...")
1325+
select(nil, nil, nil, 1)
1326+
attempt = attempt + 1
1327+
print_error("Current value of attempt is #{attempt}")
1328+
check_export_status(scan_id, file_id, attempt)
1329+
end
1330+
end
1331+
else
1332+
print_error("There was some problem in exporting the scan. The error message is #{body}")
1333+
end
1334+
end
1335+
13171336
def cmd_nessus_plugin_list(*args)
13181337
if args[0] == "-h"
13191338
print_status("nessus_plugin_list <Family ID>")
@@ -1668,7 +1687,7 @@ def nessus_verify_db
16681687
def initialize(framework, opts)
16691688
super
16701689
add_console_dispatcher(ConsoleCommandDispatcher)
1671-
print_status(PLUGIN_DESCRIPTION)
1690+
print_status("Nessus Bridge for Metasploit")
16721691
print_status("Type %bldnessus_help%clr for a command listing")
16731692
end
16741693

0 commit comments

Comments
 (0)