@@ -355,7 +355,7 @@ def cmd_hosts(*args)
355
355
onlyup = true
356
356
when '-o'
357
357
output = args . shift
358
- when '-R' , '--rhosts'
358
+ when '-R' , '--rhosts'
359
359
set_rhosts = true
360
360
when '-S' , '--search'
361
361
search_term = /#{ args . shift } /nmi
@@ -483,7 +483,7 @@ def cmd_hosts(*args)
483
483
484
484
tbl << columns
485
485
if set_rhosts
486
- addr = ( host . scope ? host . address + '%' + host . scope : host . address )
486
+ addr = ( host . scope ? host . address + '%' + host . scope : host . address )
487
487
rhosts << addr
488
488
end
489
489
if mode == [ :delete ]
@@ -523,7 +523,7 @@ def cmd_services(*args)
523
523
mode = :search
524
524
onlyup = false
525
525
output_file = nil
526
- set_rhosts = nil
526
+ set_rhosts = false
527
527
col_search = [ 'port' , 'proto' , 'name' , 'state' , 'info' ]
528
528
default_columns = ::Mdm ::Service . column_names . sort
529
529
default_columns . delete_if { |v | ( v [ -2 , 2 ] == "id" ) }
@@ -581,7 +581,7 @@ def cmd_services(*args)
581
581
return
582
582
end
583
583
output_file = ::File . expand_path ( output_file )
584
- when '-R' , '--rhosts'
584
+ when '-R' , '--rhosts'
585
585
set_rhosts = true
586
586
when '-S' , '--search'
587
587
search_term = /#{ args . shift } /nmi
@@ -668,7 +668,7 @@ def cmd_services(*args)
668
668
columns = [ host . address ] + col_names . map { |n | service [ n ] . to_s || "" }
669
669
tbl << columns
670
670
if set_rhosts
671
- addr = ( host . scope ? host . address + '%' + host . scope : host . address )
671
+ addr = ( host . scope ? host . address + '%' + host . scope : host . address )
672
672
rhosts << addr
673
673
end
674
674
@@ -705,6 +705,7 @@ def cmd_vulns_help
705
705
print_line " -h,--help Show this help information"
706
706
print_line " -p,--port <portspec> List vulns matching this port spec"
707
707
print_line " -s <svc names> List vulns matching these service names"
708
+ print_line " -R,--rhosts Set RHOSTS from the results of the search"
708
709
print_line " -S,--search Search string to filter by"
709
710
print_line " -i,--info Display Vuln Info"
710
711
print_line
@@ -721,8 +722,11 @@ def cmd_vulns(*args)
721
722
host_ranges = [ ]
722
723
port_ranges = [ ]
723
724
svcs = [ ]
725
+ rhosts = [ ]
726
+
724
727
search_term = nil
725
728
show_info = false
729
+ set_rhosts = false
726
730
727
731
# Short-circuit help
728
732
if args . delete "-h"
@@ -750,6 +754,8 @@ def cmd_vulns(*args)
750
754
return
751
755
end
752
756
svcs = service . split ( /[\s ]*,[\s ]*/ )
757
+ when '-R' , '--rhosts'
758
+ set_rhosts = true
753
759
when '-S' , '--search'
754
760
search_term = /#{ args . shift } /nmi
755
761
when '-i' , '--info'
@@ -784,15 +790,22 @@ def cmd_vulns(*args)
784
790
# Same for service names
785
791
next unless svcs . empty? or svcs . include? ( vuln . service . name )
786
792
print_status ( "Time: #{ vuln . created_at } Vuln: host=#{ host . address } name=#{ vuln . name } refs=#{ reflist . join ( ',' ) } #{ ( show_info && vuln . info ) ? "info=#{ vuln . info } " : "" } " )
787
-
788
793
else
789
794
# This vuln has no service, so it can't match
790
795
next unless ports . empty? and svcs . empty?
791
796
print_status ( "Time: #{ vuln . created_at } Vuln: host=#{ host . address } name=#{ vuln . name } refs=#{ reflist . join ( ',' ) } #{ ( show_info && vuln . info ) ? "info=#{ vuln . info } " : "" } " )
792
797
end
798
+ if set_rhosts
799
+ addr = ( host . scope ? host . address + '%' + host . scope : host . address )
800
+ rhosts << addr
801
+ end
793
802
end
794
803
end
795
804
end
805
+
806
+ # Finally, handle the case where the user wants the resulting list
807
+ # of hosts to go into RHOSTS.
808
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
796
809
}
797
810
end
798
811
@@ -1099,6 +1112,8 @@ def creds_search(*args)
1099
1112
print_status ( "Wrote creds to #{ output_file } " )
1100
1113
end
1101
1114
1115
+ # Finally, handle the case where the user wants the resulting list
1116
+ # of hosts to go into RHOSTS.
1102
1117
set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
1103
1118
print_status ( "Deleted #{ delete_count } creds" ) if delete_count > 0
1104
1119
}
@@ -1303,7 +1318,7 @@ def cmd_notes(*args)
1303
1318
host = note . host
1304
1319
msg << " host=#{ note . host . address } "
1305
1320
if set_rhosts
1306
- addr = ( host . scope ? host . address + '%' + host . scope : host . address )
1321
+ addr = ( host . scope ? host . address + '%' + host . scope : host . address )
1307
1322
rhosts << addr
1308
1323
end
1309
1324
end
0 commit comments