Skip to content

Commit d8743ea

Browse files
committed
Land rapid7#4539, @Meatballs1's creds cmd now supports type filters, -R for search
2 parents e4547eb + 7c4b86c commit d8743ea

File tree

1 file changed

+32
-1
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def deprecated_commands
6868
]
6969
end
7070

71+
def allowed_cred_types
72+
%w(password ntlm hash)
73+
end
74+
7175
#
7276
# Returns true if the db is connected, prints an error and returns
7377
# false if not.
@@ -676,13 +680,16 @@ def cmd_creds_help
676680
print_line " -p,--port <portspec> List creds with logins on services matching this port spec"
677681
print_line " -s <svc names> List creds matching comma-separated service names"
678682
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"
679685

680686
print_line
681687
print_line "Examples, listing:"
682688
print_line " creds # Default, returns all credentials"
683689
print_line " creds 1.2.3.4/24 # nmap host specification"
684690
print_line " creds -p 22-25,445 # nmap port specification"
685691
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"
686693
print_line
687694

688695
print_line
@@ -760,6 +767,9 @@ def creds_search(*args)
760767
host_ranges = []
761768
port_ranges = []
762769
svcs = []
770+
rhosts = []
771+
772+
set_rhosts = false
763773

764774
#cred_table_columns = [ 'host', 'port', 'user', 'pass', 'type', 'proof', 'active?' ]
765775
cred_table_columns = [ 'host', 'service', 'public', 'private', 'realm', 'private_type' ]
@@ -806,6 +816,8 @@ def creds_search(*args)
806816
end
807817
when "-d"
808818
mode = :delete
819+
when '-R', '--rhosts'
820+
set_rhosts = true
809821
else
810822
# Anything that wasn't an option is a host to search for
811823
unless (arg_host_range(arg, host_ranges))
@@ -822,6 +834,20 @@ def creds_search(*args)
822834
pass_regex = Regexp.compile(pass)
823835
end
824836

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+
825851
# normalize
826852
ports = port_ranges.flatten.uniq
827853
svcs.flatten!
@@ -839,6 +865,9 @@ def creds_search(*args)
839865

840866
query.each do |core|
841867

868+
# Exclude creds that don't match the given type
869+
next if type.present? && !core.private.kind_of?(type)
870+
842871
# Exclude creds that don't match the given user
843872
if user_regex.present? && !core.public.username.match(user_regex)
844873
next
@@ -880,6 +909,7 @@ def creds_search(*args)
880909
next
881910
end
882911
row = [ login.service.host.address ]
912+
rhosts << login.service.host.address
883913
if login.service.name.present?
884914
row << "#{login.service.port}/#{login.service.proto} (#{login.service.name})"
885915
else
@@ -908,7 +938,8 @@ def creds_search(*args)
908938
::File.open(output_file, "wb") { |f| f.write(tbl.to_csv) }
909939
print_status("Wrote creds to #{output_file}")
910940
end
911-
941+
942+
set_rhosts_from_addrs(rhosts.uniq) if set_rhosts
912943
print_status("Deleted #{delete_count} creds") if delete_count > 0
913944
}
914945
end

0 commit comments

Comments
 (0)