Skip to content

Commit 3803706

Browse files
committed
Land rapid7#5115, vulns -R support
2 parents 298b20b + bd21364 commit 3803706

File tree

2 files changed

+23
-7
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+23
-7
lines changed

lib/msf/ui/console/command_dispatcher/db.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def cmd_hosts(*args)
355355
onlyup = true
356356
when '-o'
357357
output = args.shift
358-
when '-R','--rhosts'
358+
when '-R', '--rhosts'
359359
set_rhosts = true
360360
when '-S', '--search'
361361
search_term = /#{args.shift}/nmi
@@ -483,7 +483,7 @@ def cmd_hosts(*args)
483483

484484
tbl << columns
485485
if set_rhosts
486-
addr = (host.scope ? host.address + '%' + host.scope : host.address )
486+
addr = (host.scope ? host.address + '%' + host.scope : host.address)
487487
rhosts << addr
488488
end
489489
if mode == [:delete]
@@ -523,7 +523,7 @@ def cmd_services(*args)
523523
mode = :search
524524
onlyup = false
525525
output_file = nil
526-
set_rhosts = nil
526+
set_rhosts = false
527527
col_search = ['port', 'proto', 'name', 'state', 'info']
528528
default_columns = ::Mdm::Service.column_names.sort
529529
default_columns.delete_if {|v| (v[-2,2] == "id")}
@@ -581,7 +581,7 @@ def cmd_services(*args)
581581
return
582582
end
583583
output_file = ::File.expand_path(output_file)
584-
when '-R','--rhosts'
584+
when '-R', '--rhosts'
585585
set_rhosts = true
586586
when '-S', '--search'
587587
search_term = /#{args.shift}/nmi
@@ -668,7 +668,7 @@ def cmd_services(*args)
668668
columns = [host.address] + col_names.map { |n| service[n].to_s || "" }
669669
tbl << columns
670670
if set_rhosts
671-
addr = (host.scope ? host.address + '%' + host.scope : host.address )
671+
addr = (host.scope ? host.address + '%' + host.scope : host.address)
672672
rhosts << addr
673673
end
674674

@@ -705,6 +705,7 @@ def cmd_vulns_help
705705
print_line " -h,--help Show this help information"
706706
print_line " -p,--port <portspec> List vulns matching this port spec"
707707
print_line " -s <svc names> List vulns matching these service names"
708+
print_line " -R,--rhosts Set RHOSTS from the results of the search"
708709
print_line " -S,--search Search string to filter by"
709710
print_line " -i,--info Display Vuln Info"
710711
print_line
@@ -721,8 +722,11 @@ def cmd_vulns(*args)
721722
host_ranges = []
722723
port_ranges = []
723724
svcs = []
725+
rhosts = []
726+
724727
search_term = nil
725728
show_info = false
729+
set_rhosts = false
726730

727731
# Short-circuit help
728732
if args.delete "-h"
@@ -750,6 +754,8 @@ def cmd_vulns(*args)
750754
return
751755
end
752756
svcs = service.split(/[\s]*,[\s]*/)
757+
when '-R', '--rhosts'
758+
set_rhosts = true
753759
when '-S', '--search'
754760
search_term = /#{args.shift}/nmi
755761
when '-i', '--info'
@@ -784,15 +790,22 @@ def cmd_vulns(*args)
784790
# Same for service names
785791
next unless svcs.empty? or svcs.include?(vuln.service.name)
786792
print_status("Time: #{vuln.created_at} Vuln: host=#{host.address} name=#{vuln.name} refs=#{reflist.join(',')} #{(show_info && vuln.info) ? "info=#{vuln.info}" : ""}")
787-
788793
else
789794
# This vuln has no service, so it can't match
790795
next unless ports.empty? and svcs.empty?
791796
print_status("Time: #{vuln.created_at} Vuln: host=#{host.address} name=#{vuln.name} refs=#{reflist.join(',')} #{(show_info && vuln.info) ? "info=#{vuln.info}" : ""}")
792797
end
798+
if set_rhosts
799+
addr = (host.scope ? host.address + '%' + host.scope : host.address)
800+
rhosts << addr
801+
end
793802
end
794803
end
795804
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
796809
}
797810
end
798811

@@ -1099,6 +1112,8 @@ def creds_search(*args)
10991112
print_status("Wrote creds to #{output_file}")
11001113
end
11011114

1115+
# Finally, handle the case where the user wants the resulting list
1116+
# of hosts to go into RHOSTS.
11021117
set_rhosts_from_addrs(rhosts.uniq) if set_rhosts
11031118
print_status("Deleted #{delete_count} creds") if delete_count > 0
11041119
}
@@ -1303,7 +1318,7 @@ def cmd_notes(*args)
13031318
host = note.host
13041319
msg << " host=#{note.host.address}"
13051320
if set_rhosts
1306-
addr = (host.scope ? host.address + '%' + host.scope : host.address )
1321+
addr = (host.scope ? host.address + '%' + host.scope : host.address)
13071322
rhosts << addr
13081323
end
13091324
end

spec/lib/msf/ui/console/command_dispatcher/db_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
" -h,--help Show this help information",
525525
" -p,--port <portspec> List vulns matching this port spec",
526526
" -s <svc names> List vulns matching these service names",
527+
" -R,--rhosts Set RHOSTS from the results of the search",
527528
" -S,--search Search string to filter by",
528529
" -i,--info Display Vuln Info",
529530
"Examples:",

0 commit comments

Comments
 (0)