forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nessus.rb
1881 lines (1795 loc) · 65.8 KB
/
nessus.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# $Id$ $Revision$
require 'nessus_rest'
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
end
def desc
"Nessus Bridge for Metasploit"
end
class ConsoleCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
def name
PLUGIN_NAME
end
def xindex
"#{Msf::Config.get_config_root}/nessus_index"
end
def nessus_yaml
"#{Msf::Config.get_config_root}/nessus.yaml"
end
def msf_local
"#{Msf::Config.local_directory}"
end
def commands
{
"nessus_connect" => "Connect to a nessus server: nconnect username:password@hostname:port <verify_ssl>",
"nessus_admin" => "Checks if user is an admin",
"nessus_help" => "Get help on all commands",
"nessus_logout" => "Terminate the session",
"nessus_server_status" => "Check the status of your Nessus server",
"nessus_server_properties" => "Nessus server properties such as feed type, version, plugin set and server UUID",
"nessus_report_download" => "Download a report from the nessus server in either Nessus, HTML, PDF, CSV, or DB format",
"nessus_report_vulns" => "Get list of vulns from a report",
"nessus_report_hosts" => "Get list of hosts from a report",
"nessus_report_host_details" => "Get detailed information from a report item on a host",
"nessus_scan_list" => "List of currently running Nessus scans",
"nessus_scan_new" => "Create a new Nessus scan",
"nessus_scan_launch" => "Launch a previously added scan",
"nessus_scan_pause" => "Pause a running Nessus scan",
"nessus_scan_pause_all" => "Pause all running Nessus scans",
"nessus_scan_stop" => "Stop a running or paused Nessus scan",
"nessus_scan_stop_all" => "Stop all running or paused Nessus scans",
"nessus_scan_resume" => "Resume a paused Nessus scan",
"nessus_scan_resume_all" => "Resume all paused Nessus scans",
"nessus_scan_details" => "Return detailed information of a given scan",
"nessus_scan_export" => "Export a scan result in either Nessus, HTML, PDF, CSV, or DB format",
"nessus_scan_export_status" => "Check the status of scan export",
"nessus_user_list" => "List of Nessus users",
"nessus_user_add" => "Add a new Nessus user",
"nessus_user_del" => "Delete a Nessus user",
"nessus_user_passwd" => "Change Nessus Users Password",
"nessus_plugin_details" => "List details of a particular plugin",
"nessus_plugin_list" => "Display plugin details in a particular plugin family",
"nessus_policy_list" => "List all polciies",
"nessus_policy_del" => "Delete a policy",
"nessus_index" => "Manually generates a search index for exploits",
"nessus_template_list" => "List all the templates on the server",
"nessus_db_scan" => "Create a scan of all IP addresses in db_hosts",
"nessus_db_scan_workspace" => "Create a scan of all IP addresses in db_hosts for a given workspace",
"nessus_db_import" => "Import Nessus scan to the Metasploit connected database",
"nessus_save" => "Save credentials of the logged in user to nessus.yml",
"nessus_folder_list" => "List folders configured on the Nessus server",
"nessus_scanner_list" => "List the configured scanners on the Nessus server",
"nessus_family_list" => "List all the plugin families along with their corresponding family IDs and plugin count"
}
end
def ncusage
print_status("%redYou must do this before any other commands.%clr")
print_status("Usage: ")
print_status("nessus_connect username:password@hostname:port <ssl_verify>")
print_status("Example:> nessus_connect msf:[email protected]:8834")
print_status("OR")
print_status("nessus_connect username@hostname:port ssl_verify")
print_status("Example:> nessus_connect [email protected]:8834 ssl_verify")
print_status("OR")
print_status("nessus_connect hostname:port ssl_verify")
print_status("Example:> nessus_connect 192.168.1.10:8834 ssl_verify")
print_status("OR")
print_status("nessus_connect")
print_status("Example:> nessus_connect")
print_status("This only works after you have saved creds with nessus_save")
return
end
#creates the index of exploit details to make searching for exploits much faster.
def create_xindex
start = Time.now
print_status("Creating Exploit Search Index - (#{xindex}) - this won't take long.")
count = 0
#Use Msf::Config.get_config_root as the location.
File.open("#{xindex}", "w+") do |f|
#need to add version line.
f.puts(Msf::Framework::Version)
framework.exploits.sort.each { |refname, mod|
stuff = ""
o = nil
begin
o = mod.new
rescue ::Exception
end
stuff << "#{refname}|#{o.name}|#{o.platform_to_s}|#{o.arch_to_s}"
next if not o
o.references.map do |x|
if !(x.ctx_id == "URL")
if (x.ctx_id == "MSB")
stuff << "|#{x.ctx_val}"
else
stuff << "|#{x.ctx_id}-#{x.ctx_val}"
end
end
end
stuff << "\n"
f.puts(stuff)
}
end
total = Time.now - start
print_status("It has taken : #{total} seconds to build the exploits search index")
end
def nessus_index
if File.exist?("#{xindex}")
#check if it's version line matches current version.
File.open("#{xindex}") { |f|
line = f.readline
line.chomp!
if line.to_i == Msf::Framework::RepoRevision
print_good("Exploit Index - (#{xindex}) - is valid.")
else
create_xindex
end
}
else
create_xindex
end
end
def nessus_login
if !((@user and @user.length > 0) and (@host and @host.length > 0) and (@port and @port.length > 0 and @port.to_i > 0) and (@pass and @pass.length > 0))
print_status("You need to connect to a server first.")
ncusage
return
end
@url = "https://#{@host}:#{@port}/"
print_status("Connecting to #{@url} as #{@user}")
verify_ssl=false
if @sslv == "verify_ssl" then
verify_ssl=true
end
@n = NessusREST::Client.new(:url=>@url,:username=>@user,:password=>@pass,:ssl_verify=>verify_ssl)
if @n.authenticated
print_status("User #{@user} authenticated successfully.")
@token = 1
else
print_error("Error connecting/logging to the server!")
return
end
end
def nessus_verify_token
if @token.nil? or @token == ''
ncusage
return false
end
true
end
def valid_policy(*args)
case args.length
when 1
pid = args[0]
else
print_error("No Policy ID supplied.")
return
end
pol = @n.list_policies
pol["policies"].each { |p|
if p["template_uuid"] == pid
return true
end
}
return false
end
def nessus_verify_db
if !(framework.db and framework.db.active)
print_error("No database has been configured, please use db_create/db_connect first")
return false
end
true
end
def check_scan(*args)
case args.length
when 1
scan_id = args[0]
else
print_error("No scan ID supplied")
return
end
scans = @n.scan_list
scans.each { |scan|
if scan["scans"]["id"] == scan_id && scan["scans"]["status"] == "completed"
return true
end
}
return false
end
def is_scan_complete(scan_id)
complete = false
status = @n.scan_list
status["scans"].each { |scan|
if scan["id"] == scan_id.to_i && (scan["status"] == "completed" || scan["status"] == "imported")
complete = true
end
}
complete
end
def cmd_nessus_help(*args)
tbl = Rex::Text::Table.new(
'Columns' => [
"Command",
"Help Text"
],
'SortIndex' => -1
)
tbl << [ "Generic Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_connect", "Connect to a Nessus server" ]
tbl << [ "nessus_logout", "Logout from the Nessus server" ]
tbl << [ "nessus_login", "Login into the connected Nesssus server with a different username and password"]
tbl << [ "nessus_save", "Save credentials of the logged in user to nessus.yml"]
tbl << [ "nessus_help", "Listing of available nessus commands" ]
tbl << [ "nessus_server_properties", "Nessus server properties such as feed type, version, plugin set and server UUID." ]
tbl << [ "nessus_server_status", "Check the status of your Nessus Server" ]
tbl << [ "nessus_admin", "Checks if user is an admin" ]
tbl << [ "nessus_template_list", "List scan or policy templates" ]
tbl << [ "nessus_folder_list", "List all configured folders on the Nessus server" ]
tbl << [ "nessus_scanner_list", "List all the scanners configured on the Nessus server" ]
tbl << [ "Nessus Database Commands", "" ]
tbl << [ "-----------------", "-----------------" ]
tbl << [ "nessus_db_scan", "Create a scan of all IP addresses in db_hosts" ]
tbl << [ "nessus_db_scan_workspace", "Create a scan of all IP addresses in db_hosts for a given workspace" ]
tbl << [ "nessus_db_import", "Import Nessus scan to the Metasploit connected database" ]
tbl << [ "", ""]
tbl << [ "Reports Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_report_hosts", "Get list of hosts from a report" ]
tbl << [ "nessus_report_vulns", "Get list of vulns from a report" ]
tbl << [ "nessus_report_host_details", "Get detailed information from a report item on a host" ]
tbl << [ "", ""]
tbl << [ "Scan Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_scan_list", "List of all current Nessus scans" ]
tbl << [ "nessus_scan_new", "Create a new Nessus Scan" ]
tbl << [ "nessus_scan_launch", "Launch a newly created scan. New scans need to be manually launched through this command" ]
tbl << [ "nessus_scan_pause", "Pause a running Nessus scan" ]
tbl << [ "nessus_scan_pause_all", "Pause all running Nessus scans" ]
tbl << [ "nessus_scan_stop", "Stop a running or paused Nessus scan" ]
tbl << [ "nessus_scan_stop_all", "Stop all running or paused Nessus scans" ]
tbl << [ "nessus_scan_resume", "Resume a pasued Nessus scan" ]
tbl << [ "nessus_scan_resume_all", "Resume all paused Nessus scans" ]
tbl << [ "nessus_scan_details", "Return detailed information of a given scan" ]
tbl << [ "nessus_scan_export", "Export a scan result in either Nessus, HTML, PDF, CSV, or DB format" ]
tbl << [ "nessus_scan_export_status", "Check the status of an exported scan" ]
tbl << [ "", ""]
tbl << [ "Plugin Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_plugin_list", "List all plugins in a particular plugin family." ]
tbl << [ "nessus_family_list", "List all the plugin families along with their corresponding family IDs and plugin count." ]
tbl << [ "nessus_plugin_details", "List details of a particular plugin" ]
tbl << [ "", ""]
tbl << [ "User Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_user_list", "Show Nessus Users" ]
tbl << [ "nessus_user_add", "Add a new Nessus User" ]
tbl << [ "nessus_user_del", "Delete a Nessus User" ]
tbl << [ "nessus_user_passwd", "Change Nessus Users Password" ]
tbl << [ "", ""]
tbl << [ "Policy Commands", "" ]
tbl << [ "-----------------", "-----------------"]
tbl << [ "nessus_policy_list", "List all polciies" ]
tbl << [ "nessus_policy_del", "Delete a policy" ]
print_line ""
print_line tbl.to_s
print_line ""
end
def cmd_nessus_index
nessus_index
end
def cmd_nessus_connect(*args)
# Check if config file exists and load it
if !args[0]
if File.exist?(nessus_yaml)
lconfig = YAML.load_file(nessus_yaml)
@user = lconfig['default']['username'].to_s
@pass = lconfig['default']['password'].to_s
@host = lconfig['default']['server'].to_s
@port = lconfig['default']['port'].to_s
nessus_login
return
else
ncusage
return
end
end
if args[0] == "-h"
print_status("%redYou must do this before any other commands.%clr")
print_status("Usage: ")
print_status("nessus_connect username:password@hostname:port <ssl_verify/ssl_ignore>")
print_status("%bldusername%clr and %bldpassword%clr are the ones you use to login to the nessus web front end")
print_status("%bldhostname%clr can be an IP address or a DNS name of the Nessus server.")
print_status("%bldport%clr is the RPC port that the Nessus web front end runs on. By default it is TCP port 8834.")
print_status("The \"ssl_verify\" to verify the SSL certificate used by the Nessus front end. By default the server")
print_status("use a self signed certificate, therefore, users should use ssl_ignore.")
return
end
if !@token == ''
print_error("You are already authenticated. Call nessus_logout before authenticating again")
return
end
if(args.length == 0 or args[0].empty?)
ncusage
return
end
@user = @pass = @host = @port = @sslv = nil
case args.length
when 1,2
if args[0].include? "@"
cred,targ = args[0].split('@', 2)
@user,@pass = cred.split(':', 2)
targ ||= '127.0.0.1:8834'
@host,@port = targ.split(':', 2)
@port ||= '8834'
@sslv = args[1]
else
@host,@port = args[0].split(':', 2)
@port ||= '8834'
@sslv = args[1]
end
when 3,4,5
ncusage
return
else
ncusage
return
end
if /\/\//.match(@host)
ncusage
return
end
if !@user
print_error("Missing Username")
ncusage
return
end
if !@pass
print_error("Missing Password")
ncusage
return
end
if !((@user and @user.length > 0) and (@host and @host.length > 0) and (@port and @port.length > 0 and @port.to_i > 0) and (@pass and @pass.length > 0))
ncusage
return
end
nessus_login
end
def cmd_nessus_logout
logout = @n.user_logout
status = logout.to_s
if status == "200"
print_good("User account logged out successfully")
@token = ""
elsif status == "403"
print_status("No user session to logout")
else
print_error("There was some problem in logging out the user #{@user}")
end
return
end
def cmd_nessus_save(*args)
#if we are logged in, save session details to nessus.yaml
if args[0] == "-h"
print_status(" nessus_save")
return
end
if args[0]
print_status("Usage: ")
print_status("nessus_save")
return
end
group = "default"
if ((@user and @user.length > 0) and (@host and @host.length > 0) and (@port and @port.length > 0 and @port.to_i > 0) and (@pass and @pass.length > 0))
config = Hash.new
config = {"#{group}" => {'username' => @user, 'password' => @pass, 'server' => @host, 'port' => @port}}
File.open("#{nessus_yaml}", "w+") do |f|
f.puts YAML.dump(config)
end
print_good("#{nessus_yaml} created.")
else
print_error("Missing username/password/server/port - relogin and then try again.")
return
end
end
def cmd_nessus_server_properties(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_server_properties")
print_status("Example:> nessus_server_properties -S searchterm")
print_status("Returns information about the feed type and server version.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
end
end
resp = @n.server_properties
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Feed',
'Type',
'Nessus Version',
'Nessus Web Version',
'Plugin Set',
'Server UUID'
])
tbl << [ resp["feed"], resp["nessus_type"], resp["server_version"], resp["nessus_ui_version"], resp["loaded_plugin_set"], resp["server_uuid"] ]
print_line tbl.to_s
end
def cmd_nessus_server_status(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_server_status")
print_status("Example:> nessus_server_status -S searchterm")
print_status("Returns some status items for the server..")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
end
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Status',
'Progress'
])
list = @n.server_status
tbl << [ list["progress"], list["status"] ]
print_line tbl.to_s
end
def cmd_nessus_admin(*args)
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_admin")
print_status("Example:> nessus_admin")
print_status("Checks to see if the current user is an admin")
print_status("Use nessus_user_list to list all users")
return
end
end
if !nessus_verify_token
return
end
if [email protected]_admin
print_error("Your Nessus user is not an admin")
else
print_good("Your Nessus user is an admin")
end
end
def cmd_nessus_template_list(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_template_list <scan> | <policy>")
print_status("Example:> nessus_template_list scan -S searchterm")
print_status("OR")
print_status("nessus_template_list policy")
print_status("Returns a list of information about the scan or policy templates..")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
else
type = arg
end
end
if !nessus_verify_token
return
end
if type.in?(['scan', 'policy'])
[email protected]_templates(type)
else
print_error("Only scan and policy are valid templates")
return
end
if list.empty?
print_status("No templates created")
return
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Name',
'Title',
'Description',
'Subscription Only',
'Cloud Only'
])
list["templates"].each { |template|
tbl << [ template["name"], template["title"], template["desc"], template["subscription_only"], template["cloud_only"] ]
}
print_line
print_line tbl.to_s
end
def cmd_nessus_folder_list(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-S', '--search'
search_term = /#{args.shift}/nmi
end
end
if !nessus_verify_token
return
end
list = @n.list_folders
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
"ID",
"Name",
"Type"
])
list["folders"].each { |folder|
tbl << [ folder["id"], folder["name"], folder["type"] ]
}
print_line
print_line tbl.to_s
end
def cmd_nessus_scanner_list(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_scanner_list")
print_status("Example:> nessus_scanner_list -S searchterm")
print_status("Returns information about the feed type and server version.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
end
end
if !nessus_verify_token
return
end
if [email protected]_admin
return
end
list = @n.list_scanners
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
"ID",
"Name",
"Status",
"Platform",
"Plugin Set",
"UUID"
])
list.each { |scanner|
tbl << [ scanner["id"], scanner["name"], scanner["status"], scanner["platform"], scanner["loaded_plugin_set"], scanner["uuid"] ]
}
print_line tbl.to_s
end
def cmd_nessus_report_hosts(*args)
search_term = nil
scan_id = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_report_hosts <scan ID> -S searchterm")
print_status("Use nessus_scan_list to get a list of all the scans. Only completed scans can be reported.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
else
scan_id = arg
end
end
if scan_id.nil?
print_status("Usage: ")
print_status("nessus_report_hosts <scan ID> -S searchterm")
print_status("Use nessus_scan_list to get a list of all the scans. Only completed scans can be reported.")
return
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
"Host ID",
"Hostname",
"% of Critical Findings",
"% of High Findings",
"% of Medium Findings",
"% of Low Findings"
])
if is_scan_complete(scan_id)
details = @n.scan_details(scan_id)
details["hosts"].each { |host|
tbl << [ host["host_id"], host["hostname"], host["critical"], host["high"], host["medium"], host["low"] ]
}
print_line
print_line tbl.to_s
else
print_error("Only completed scans can be used for host reporting")
return
end
end
def cmd_nessus_report_vulns(*args)
search_term = nil
scan_id = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_report_vulns <scan ID> -S searchterm")
print_status("Use nessus_scan_list to get a list of all the scans. Only completed scans can be reported.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
else
scan_id = arg
end
end
if scan_id.nil?
print_status("Usage: ")
print_status("nessus_report_vulns <scan ID>")
print_status("Use nessus_scan_list to get a list of all the scans. Only completed scans can be reported.")
return
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
"Plugin ID",
"Plugin Name",
"Plugin Family",
"Vulnerability Count"
])
if is_scan_complete(scan_id)
details = @n.scan_details(scan_id)
details["vulnerabilities"].each { |vuln|
tbl << [ vuln["plugin_id"], vuln["plugin_name"], vuln["plugin_family"], vuln["count"] ]
}
print_line
print_line tbl.to_s
return
else
print_error("Only completed scans can be used for vulnerability reporting")
return
end
end
def cmd_nessus_report_host_details(*args)
search_term = nil
search_vuln = nil
scan_id = nil
host_id = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_report_host_details <scan ID> <host ID>")
print_status("Example:> nessus_report_host_details 10 5 -S hostinfo -SV vulninfo")
print_status("Use nessus_scan_list to get list of all scans. Only completed scans can be used for reporting.")
print_status("Use nessus_report_hosts to get a list of all the hosts along with their corresponding host IDs.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
when '-SV', '--search-vuln'
search_vuln = /#{args.shift}/nmi
else
scan_id = arg,
host_id = args.shift
end
end
if [scan_id, host_id].any?(&:nil?)
print_status("Usage: ")
print_status("nessus_report_host_detail <scan ID> <host ID>")
print_status("Example:> nessus_report_host_detail 10 5")
print_status("Use nessus_scan_list to get list of all scans. Only completed scans can be used for reporting.")
print_status("Use nessus_report_hosts <scan ID> to get a list of all the hosts along with their corresponding host IDs.")
return
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Plugin Name',
'Plugin Famil',
'Severity'
])
[email protected]_detail(scan_id, host_id)
print_line
print_status("Host information")
print_line("IP Address: #{details['info']['host-ip']}")
print_line("Hostname: #{details['info']['host-name']}")
print_line("Operating System: #{details['info']['operating-system']}")
print_line
print_status("Vulnerability information")
details["vulnerabilities"].each { |vuln|
tbl << [ vuln["plugin_name"], vuln["plugin_family"], vuln["severity"] ]
}
print_line tbl.to_s
tbl2 = Rex::Text::Table.new(
'SearchTerm' => search_vuln,
'Columns' => [
'Plugin Name',
'Plugin Famil',
'Severity'
])
print_status("Compliance information")
details["compliance"].each { |comp|
tbl2 << [ comp["plugin_name"], comp["plugin_family"], comp["severity"] ]
}
print_line tbl2.to_s
end
def cmd_nessus_report_download(*args)
if args[0] == "-h"
print_status("nessus_scan_report_download <scan_id> <file ID> ")
print_status("Use nessus_scan_export_status <scan ID> <file ID> to check the export status.")
print_status("Use nessus_scan_list -c to list all completed scans along with their corresponding scan IDs")
return
end
if !nessus_verify_token
return
end
case args.length
when 2
scan_id = args[0]
file_id = args[1]
if is_scan_complete(scan_id)
report = @n.report_download(scan_id, file_id)
File.open("#{msf_local}/#{scan_id}-#{file_id}","w+") do |f|
f.puts report
print_status("Report downloaded to #{msf_local} directory")
end
else
print_error("Only completed scans can be downloaded")
end
else
print_status("Usage: ")
print_status("nessus_scan_report_download <scan_id> <file ID> ")
print_status("Use nessus_scan_export_status <scan ID> <file ID> to check the export status.")
print_status("Use nessus_scan_list -c to list all completed scans along with their corresponding scan IDs")
end
end
def cmd_nessus_report_host_ports(*args)
search_term = nil
rid = nil
host = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_report_host_ports <hostname> <report id>")
print_status("Example:> nessus_report_host_ports 192.168.1.250 f0eabba3-4065-7d54-5763-f191e98eb0f7f9f33db7e75a06ca -S searchterm")
print_status("Returns all the ports associated with a host and details about their vulnerabilities")
print_status("Use nessus_report_hosts to list all available hosts for a report")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
else
scan_id = arg
end
end
if [host,rid].any?(&:nil?)
print_status("Usage: ")
print_status("nessus_report_host_ports <hostname> <report id>")
print_status("Use nessus_report_list to list all available reports")
return
end
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Port',
'Protocol',
'Severity',
'Service Name',
'Sev 0',
'Sev 1',
'Sev 2',
'Sev 3'
])
[email protected]_host_ports(rid, host)
ports.each { |port|
tbl << [ port['portnum'], port['protocol'], port['severity'], port['svcname'], port['sev0'], port['sev1'], port['sev2'], port['sev3'] ]
}
print_good("Host Info")
print_good "\n"
print_line tbl.to_s
print_status("You can:")
print_status("Get detailed scan infromation about a specfic port: nessus_report_host_detail <hostname> <port> <protocol> <report id>")
end
def cmd_nessus_report_del(*args)
if args[0] == "-h"
print_status("nessus_report_del <reportname>")
print_status("Example:> nessus_report_del f0eabba3-4065-7d54-5763-f191e98eb0f7f9f33db7e75a06ca")
print_status("Must be an admin to del reports.")
print_status("Use nessus_report_list to list all reports")
return
end
if !nessus_verify_token
return
end
if [email protected]_admin
print_error("Your Nessus user is not an admin")
return
end
case args.length
when 1
rid = args[0]
else
print_status("Usage: ")
print_status("nessus_report_del <report ID>")
print_status("nessus_report_list to find the id.")
return
end
del = @n.report_del(rid)
status = del.root.elements['status'].text
if status == "OK"
print_good("Report #{rid} has been deleted")
else
print_error("Report #{rid} was not deleted")
end
end
def cmd_nessus_scan_list(*args)
search_term = nil
while (arg = args.shift)
case arg
when '-h', '--help'
print_status("nessus_scan_list")
print_status("Example:> nessus_scan_list -S searchterm")
print_status("Returns a list of information about currently running scans.")
return
when '-S', '--search'
search_term = /#{args.shift}/nmi
end
end
if !nessus_verify_token
return
end
[email protected]_list
if list.to_s.empty?
print_status("No scans performed.")
return
else
tbl = Rex::Text::Table.new(
'SearchTerm' => search_term,
'Columns' => [
'Scan ID',
'Name',
'Owner',
'Started',
'Status',
'Folder'
])
list["scans"].each { |scan|
if args[0] == "-r"
if scan["status"] == "running"
tbl << [ scan["id"], scan["name"], scan["owner"], scan["starttime"], scan["status"], scan["folder_id"] ]
end
elsif args[0] == "-p"
if scan["status"] == "paused"
tbl << [ scan["id"], scan["name"], scan["owner"], scan["starttime"], scan["status"], scan["folder_id"] ]
end
elsif args[0] == "-c"
if scan["status"] == "completed"
tbl << [ scan["id"], scan["name"], scan["owner"], scan["starttime"], scan["status"], scan["folder_id"] ]
end
elsif args[0] == "-a"
if scan["status"] == "canceled"
tbl << [ scan["id"], scan["name"], scan["owner"], scan["starttime"], scan["status"], scan["folder_id"] ]
end
else
tbl << [ scan["id"], scan["name"], scan["owner"], scan["starttime"], scan["status"], scan["folder_id"] ]
end
}
print_line tbl.to_s
end
end
def cmd_nessus_scan_new(*args)
if args[0] == "-h"
print_status("nessus_scan_new <UUID of Policy> <Scan name> <Description> <Targets>")
print_status("Use nessus_policy_list to list all available policies with their corresponding UUIDs")
return
end
if !nessus_verify_token
return
end
case args.length
when 4
uuid = args[0]
scan_name = args[1]
description = args[2]
targets = args[3]
else
print_status("Usage: ")
print_status("nessus_scan_new <UUID of Policy> <Scan name> <Description> <Targets>")
print_status("Use nessus_policy_list to list all available policies with their corresponding UUIDs")
return
end
if valid_policy(uuid)
print_status("Creating scan from policy number #{uuid}, called #{scan_name} - #{description} and scanning #{targets}")
et = {
'enabled' => false,
'launch' => 'ONETIME',
'name' => scan_name,
'text_targets' => targets,
'description' => description,
'launch_now' => false
}
scan = @n.scan_create(uuid, et)
tbl = Rex::Text::Table.new(
'Columns' => [
"Scan ID",
"Scanner ID",
"Policy ID",
"Targets",
"Owner"
])
print_status("New scan added")
tbl << [ scan["scan"]["id"], scan["scan"]["scanner_id"], scan["scan"]["policy_id"], scan["scan"]["custom_targets"], scan["scan"]["owner"] ]
print_status("Use nessus_scan_launch #{scan['scan']['id']} to launch the scan")
print_line tbl.to_s
else
print_error("The policy does not exist")
end
end
def cmd_nessus_scan_launch(*args)
if args[0] == "-h"
print_status("nessus_scan_launch <scan ID>")
print_status("Use nessus_scan_list to list all the availabla scans with their corresponding scan IDs")
end
if !nessus_verify_token
return
end
case args.length
when 1
scan_id = args[0]
else
print_status("Usage: ")
print_status("nessus_scan_launch <scan ID>")