@@ -68,6 +68,10 @@ def deprecated_commands
68
68
]
69
69
end
70
70
71
+ def allowed_cred_types
72
+ %w( password ntlm hash )
73
+ end
74
+
71
75
#
72
76
# Returns true if the db is connected, prints an error and returns
73
77
# false if not.
@@ -676,13 +680,16 @@ def cmd_creds_help
676
680
print_line " -p,--port <portspec> List creds with logins on services matching this port spec"
677
681
print_line " -s <svc names> List creds matching comma-separated service names"
678
682
print_line " -u,--user <regex> List users that match this regex"
683
+ print_line " -t,--type <type> List creds that match the following types: #{ allowed_cred_types . join ( ',' ) } "
684
+ print_line " -R,--rhosts Set RHOSTS from the results of the search"
679
685
680
686
print_line
681
687
print_line "Examples, listing:"
682
688
print_line " creds # Default, returns all credentials"
683
689
print_line " creds 1.2.3.4/24 # nmap host specification"
684
690
print_line " creds -p 22-25,445 # nmap port specification"
685
691
print_line " creds -s ssh,smb # All creds associated with a login on SSH or SMB services"
692
+ print_line " creds -t ntlm # All NTLM creds"
686
693
print_line
687
694
688
695
print_line
@@ -760,6 +767,9 @@ def creds_search(*args)
760
767
host_ranges = [ ]
761
768
port_ranges = [ ]
762
769
svcs = [ ]
770
+ rhosts = [ ]
771
+
772
+ set_rhosts = false
763
773
764
774
#cred_table_columns = [ 'host', 'port', 'user', 'pass', 'type', 'proof', 'active?' ]
765
775
cred_table_columns = [ 'host' , 'service' , 'public' , 'private' , 'realm' , 'private_type' ]
@@ -806,6 +816,8 @@ def creds_search(*args)
806
816
end
807
817
when "-d"
808
818
mode = :delete
819
+ when '-R' , '--rhosts'
820
+ set_rhosts = true
809
821
else
810
822
# Anything that wasn't an option is a host to search for
811
823
unless ( arg_host_range ( arg , host_ranges ) )
@@ -822,6 +834,20 @@ def creds_search(*args)
822
834
pass_regex = Regexp . compile ( pass )
823
835
end
824
836
837
+ if ptype
838
+ type = case ptype
839
+ when 'password'
840
+ Metasploit ::Credential ::Password
841
+ when 'hash'
842
+ Metasploit ::Credential ::PasswordHash
843
+ when 'ntlm'
844
+ Metasploit ::Credential ::NTLMHash
845
+ else
846
+ print_error ( "Unrecognized credential type #{ ptype } -- must be one of #{ allowed_cred_types . join ( ',' ) } " )
847
+ return
848
+ end
849
+ end
850
+
825
851
# normalize
826
852
ports = port_ranges . flatten . uniq
827
853
svcs . flatten!
@@ -839,6 +865,9 @@ def creds_search(*args)
839
865
840
866
query . each do |core |
841
867
868
+ # Exclude creds that don't match the given type
869
+ next if type . present? && !core . private . kind_of? ( type )
870
+
842
871
# Exclude creds that don't match the given user
843
872
if user_regex . present? && !core . public . username . match ( user_regex )
844
873
next
@@ -880,6 +909,7 @@ def creds_search(*args)
880
909
next
881
910
end
882
911
row = [ login . service . host . address ]
912
+ rhosts << login . service . host . address
883
913
if login . service . name . present?
884
914
row << "#{ login . service . port } /#{ login . service . proto } (#{ login . service . name } )"
885
915
else
@@ -908,7 +938,8 @@ def creds_search(*args)
908
938
::File . open ( output_file , "wb" ) { |f | f . write ( tbl . to_csv ) }
909
939
print_status ( "Wrote creds to #{ output_file } " )
910
940
end
911
-
941
+
942
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
912
943
print_status ( "Deleted #{ delete_count } creds" ) if delete_count > 0
913
944
}
914
945
end
0 commit comments