@@ -677,6 +677,7 @@ def cmd_creds_help
677
677
print_line " -s <svc names> List creds matching comma-separated service names"
678
678
print_line " -u,--user <regex> List users that match this regex"
679
679
print_line " -t,--type <type> List creds that match the following types: (password,ntlm,hash)"
680
+ print_line " -R,--rhosts Set RHOSTS from the results of the search"
680
681
681
682
print_line
682
683
print_line "Examples, listing:"
@@ -762,6 +763,9 @@ def creds_search(*args)
762
763
host_ranges = [ ]
763
764
port_ranges = [ ]
764
765
svcs = [ ]
766
+ rhosts = [ ]
767
+
768
+ set_rhosts = false
765
769
766
770
#cred_table_columns = [ 'host', 'port', 'user', 'pass', 'type', 'proof', 'active?' ]
767
771
cred_table_columns = [ 'host' , 'service' , 'public' , 'private' , 'realm' , 'private_type' ]
@@ -808,6 +812,8 @@ def creds_search(*args)
808
812
end
809
813
when "-d"
810
814
mode = :delete
815
+ when '-R' , '--rhosts'
816
+ set_rhosts = true
811
817
else
812
818
# Anything that wasn't an option is a host to search for
813
819
unless ( arg_host_range ( arg , host_ranges ) )
@@ -879,6 +885,7 @@ def creds_search(*args)
879
885
core . private ? core . private . class . model_name . human : "" ,
880
886
]
881
887
else
888
+ rhosts = [ ]
882
889
core . logins . each do |login |
883
890
if svcs . present? && !svcs . include? ( login . service . name )
884
891
next
@@ -896,6 +903,7 @@ def creds_search(*args)
896
903
next
897
904
end
898
905
row = [ login . service . host . address ]
906
+ rhosts << login . service . host . address
899
907
if login . service . name . present?
900
908
row << "#{ login . service . port } /#{ login . service . proto } (#{ login . service . name } )"
901
909
else
@@ -924,7 +932,8 @@ def creds_search(*args)
924
932
::File . open ( output_file , "wb" ) { |f | f . write ( tbl . to_csv ) }
925
933
print_status ( "Wrote creds to #{ output_file } " )
926
934
end
927
-
935
+
936
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
928
937
print_status ( "Deleted #{ delete_count } creds" ) if delete_count > 0
929
938
}
930
939
end
0 commit comments