Skip to content

Commit 30d5b22

Browse files
David MaloneyDavid Maloney
authored andcommitted
Land rapid7#7093 , nessus_scan_workspace
lands sjcaldwell's pr for the nessus_scan_workspace command
2 parents 3f9540d + 7144d2c commit 30d5b22

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

plugins/nessus.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def commands
7171
"nessus_index" => "Manually generates a search index for exploits",
7272
"nessus_template_list" => "List all the templates on the server",
7373
"nessus_db_scan" => "Create a scan of all IP addresses in db_hosts",
74+
"nessus_db_scan_workspace" => "Create a scan of all IP addresses in db_hosts for a given workspace",
7475
"nessus_db_import" => "Import Nessus scan to the Metasploit connected database",
7576
"nessus_save" => "Save credentials of the logged in user to nessus.yml",
7677
"nessus_folder_list" => "List folders configured on the Nessus server",
@@ -256,6 +257,7 @@ def cmd_nessus_help(*args)
256257
tbl << [ "Nessus Database Commands", "" ]
257258
tbl << [ "-----------------", "-----------------" ]
258259
tbl << [ "nessus_db_scan", "Create a scan of all IP addresses in db_hosts" ]
260+
tbl << [ "nessus_db_scan_workspace", "Create a scan of all IP addresses in db_hosts for a given workspace" ]
259261
tbl << [ "nessus_db_import", "Import Nessus scan to the Metasploit connected database" ]
260262
tbl << [ "", ""]
261263
tbl << [ "Reports Commands", "" ]
@@ -1091,6 +1093,59 @@ def cmd_nessus_db_scan(*args)
10911093
end
10921094
end
10931095

1096+
def cmd_nessus_db_scan_workspace(*args)
1097+
if args[0] == "-h"
1098+
print_status("nessus_db_scan_workspace <policy ID> <scan name> <scan description> <workspace>")
1099+
print_status("Creates a scan based on all the hosts listed in db_hosts for a given workspace.")
1100+
print_status("Use nessus_policy_list to list all available policies with their corresponding policy IDs")
1101+
return
1102+
end
1103+
if !nessus_verify_db
1104+
return
1105+
end
1106+
if !nessus_verify_token
1107+
return
1108+
end
1109+
case args.length
1110+
when 4
1111+
policy_id = args[0]
1112+
name = args[1]
1113+
desc = args[2]
1114+
new_workspace = framework.db.find_workspace(args[3])
1115+
else
1116+
print_status("Usage: ")
1117+
print_status("nessus_db_scan_workspace <policy ID> <scan name> <scan description> <workspace>")
1118+
print_status("Use nessus_policy_list to list all available policies with their corresponding policy IDs")
1119+
return
1120+
end
1121+
if !valid_policy(policy_id)
1122+
print_error("That policy does not exist.")
1123+
return
1124+
end
1125+
if new_workspace.nil?
1126+
print_error("That workspace does not exist.")
1127+
return
1128+
end
1129+
framework.db.workspace = new_workspace
1130+
print_status("Switched workspace: #{framework.db.workspace.name}")
1131+
targets = ""
1132+
framework.db.hosts.each do |host|
1133+
targets << host.address
1134+
targets << ","
1135+
print_status("Targets: #{targets}")
1136+
end
1137+
targets.chop!
1138+
print_status("Creating scan from policy #{policy_id}, called \"#{name}\" and scanning all hosts in #{framework.db.workspace.name}")
1139+
scan = @n.scan_create(policy_id, name, desc, targets)
1140+
if !scan["error"]
1141+
scan = scan["scan"]
1142+
print_status("Scan ID #{scan['id']} successfully created")
1143+
print_status("Run nessus_scan_launch #{scan['id']} to launch the scan")
1144+
else
1145+
print_error(JSON.pretty_generate(scan))
1146+
end
1147+
end
1148+
10941149
def cmd_nessus_db_import(*args)
10951150
if args[0] == "-h"
10961151
print_status("nessus_db_import <scan ID>")

0 commit comments

Comments
 (0)