How NTLM Relay Ruins Your Exchange Servers

Tianze Ding (Tencent)

HITBSecConf2023 - Phuket · Day 1 · Track 2

Overview

In this compelling talk, Tianze Ding from Tencent Security Xuanwu Lab delves into the persistent and critical threat of NTLM Relay attacks against Microsoft Exchange Server environments. The presentation meticulously details how attackers can leverage this decades-old technique, combined with modern Exchange architecture vulnerabilities, to achieve escalating levels of compromise. From initially gaining control over arbitrary mailboxes, the talk progresses to demonstrating Remote Code Execution (RCE) on Exchange servers, culminating in a sophisticated privilege escalation path to Domain Administrator within an Active Directory environment.

Watch on YouTube

Visual summary for How NTLM Relay Ruins Your Exchange Servers by Tianze Ding
Visual summary for How NTLM Relay Ruins Your Exchange Servers by Tianze Ding

Key moments

  1. 0:00 Introduction to NTLM Relay and its impact
  2. 4:00 Why Exchange Server is a high-value target
  3. 11:30 First exploit demo: Arbitrary mailbox takeover
  4. 14:00 Microsoft's patch introduces a new, powerful bypass
  5. 25:00 Remote Code Execution (RCE) via Exchange PowerShell
  6. 31:00 Final extended protection patch and mitigation details
  7. 39:50 Privilege escalation to Domain Administrator
  8. 50:00 Q&A: Why a new domain admin escalation method?

How NTLM Relay Ruins Your Exchange Servers

Speakers: Tianze Ding, Security Researcher, Tencent

Conference: HITB Phuket

YouTube: https://www.youtube.com/watch?v=Lrt2_NHJeWc

Overview

In this compelling talk, Tianze Ding from Tencent Security Xuanwu Lab delves into the persistent and critical threat of NTLM Relay attacks against Microsoft Exchange Server environments. The presentation meticulously details how attackers can leverage this decades-old technique, combined with modern Exchange architecture vulnerabilities, to achieve escalating levels of compromise. From initially gaining control over arbitrary mailboxes, the talk progresses to demonstrating Remote Code Execution (RCE) on Exchange servers, culminating in a sophisticated privilege escalation path to Domain Administrator within an Active Directory environment.

Ding's research highlights that despite ongoing efforts to mitigate NTLM Relay, fundamental design choices and patch implementations in Exchange have inadvertently created new attack surfaces. The talk underscores the severe implications for enterprises, as Exchange servers frequently house sensitive information and are deeply integrated with Active Directory, making them prime targets for adversaries. This detailed analysis serves as a crucial warning to defenders, urging a re-evaluation of security postures and the adoption of comprehensive mitigation strategies against NTLM Relay.

It is important to note that some of the vulnerabilities discussed were independently discovered by Orange Tsai, who named his findings "ProxyRelay." Tianze Ding acknowledges Orange Tsai as a co-discoverer in his presentation, highlighting the parallel research efforts in this critical area.

Background

▶ Watch: Introduction to NTLM Relay and its impact (0:00)

The NTLM Relay attack is a classic man-in-the-middle (MitM) technique that has plagued Windows environments for many years. At its core, an attacker intercepts an NTLM authentication message from a victim, relays it to a target service, and then authenticates to that service as the victim. The success of an NTLM Relay attack hinges on several conditions: the relayed credentials must be considered valid by the target, and those credentials must possess sufficient privileges to perform harmful actions on the target. Attackers commonly trigger victims to authenticate to attacker-controlled servers using well-known RPC APIs like PrinterBug (via the Printer Service) or PetitPotam (via the EFS service), which are often enabled by default and callable by low-privileged domain accounts.

Mitigations against NTLM Relay include NTLM reflection protection, SMB signing, and Extended Protection for Authentication (EPA). EPA is particularly relevant for web-based services, utilizing Channel Binding Tokens (CBTs) to tie authentication to the TLS channel and Service Principal Name (SPN) checks to prevent relaying to unintended services. However, these mitigations are not always universally applied or correctly implemented.

Microsoft Exchange Server is a high-value target due to its central role in enterprise communication, containing vast amounts of sensitive data. Its deep integration with Active Directory (AD) means that compromising Exchange can provide a gateway to broader network control. Exchange utilizes AD authentication mechanisms like NTLM and Kerberos, and various Exchange-specific user groups possess elevated privileges within the AD forest. The architecture of Exchange features a front-end (default website, acting as a proxy) and a back-end (where mailbox processing occurs). Clients authenticate to the front-end, which then forwards requests to the back-end. Crucially, the front-end communicates with the back-end using the Exchange machine account (e.g., EXCHANGE_SERVER_NAME$) and the Local System account. This machine account is a member of the Exchange Servers group and possesses the Token Serialization right on Exchange servers, granting it significant power. In clustered environments, front-ends can proxy requests to back-ends on other Exchange servers, and all Exchange machine accounts share similar high privileges across the cluster.

Key Findings

▶ Watch: First exploit demo: Arbitrary mailbox takeover (11:30)

Tianze Ding's research unveiled a series of critical vulnerabilities and attack paths stemming from NTLM Relay against Exchange:

  1. Initial Mailbox Takeover via EWS: The first finding involved relaying an Exchange machine account's NTLM authentication to the Exchange Web Services (EWS) endpoint on a different Exchange server. Since Exchange machine accounts possess the Token Serialization right, the attacker could then impersonate any user, leading to arbitrary mailbox takeover (e.g., reading administrator emails).
  1. Patch Bypass and New Vulnerability: A Microsoft patch intended to fix the initial vulnerability introduced a critical bypass. While the patch prevented machine accounts from directly logging into the front-end, it inadvertently allowed the front-end to directly forward a forged Common Access Token from a client request to the back-end. This new vulnerability was more potent, affecting all front-end endpoints that support NTLM authentication and mailbox access, enabling impersonation of any user.
  1. Extension to Back-end Endpoints: The attacker demonstrated that direct NTLM Relay to back-end Exchange endpoints (typically on port 444) was also feasible. Extended Protection for Authentication (EPA), a key mitigation, is disabled by default on back-end endpoints and cannot be enabled without breaking the legitimate communication between the front-end and back-end, leaving these critical management interfaces exposed.
  1. Remote Code Execution (RCE) on Exchange:
  • Via PowerShell and ECP: By relaying to the back-end PowerShell or ECP (Exchange Control Panel) endpoints, an attacker could impersonate an administrator. The Add-RoleGroupMember cmdlet could then be used to add the attacker's low-privileged account to the Organization Management role group, which grants local administrator privileges on all Exchange servers. With local admin, RCE is trivial via techniques like WinRM/WMI.
  • Via DCOM NTLM Relay: Leveraging the fact that Exchange machine accounts are members of the Exchange Trusted Subsystem group and thus local administrators on all Exchange servers, the attacker could relay NTLM authentication to DCOM (Distributed Component Object Model) services. By setting the RPC authentication level to RPC_C_AUTHN_LEVEL_CONNECT, signing and encryption could be bypassed. The MMC20.Application COM object was then abused to execute arbitrary commands, achieving RCE.
  1. Privilege Escalation to Domain Administrator:
  • Abusing Exchange's AD Privileges: The Exchange Trusted Subsystem group holds powerful Write Distinguished Name and Write Name rights on almost all domain users and computers in Active Directory. The Exchange Windows Permissions group can create Organizational Units (OUs) and manipulate user/computer objects.
  • DC Takeover via OU Manipulation: The attacker could create a new "evil OU," set GenericAll permissions with inheritance on it, and then move a Domain Controller (DC) computer object into this OU. This grants the attacker GenericAll rights on the DC, allowing them to use techniques like Shadow Credentials or Resource-Based Constrained Delegation (RBCD) to gain control of the DC and achieve Domain Admin privileges. This attack path requires the target domain to have at least one DC running Windows Server 2012 or later for the RBCD/Shadow Credentials part.
  • GPO Abuse for RCE: Alternatively, the Exchange Windows Permissions group can add members to Group Policy Creator Owners. This allows creating malicious Group Policy Objects (GPOs) and linking them to OUs containing victim computers, leading to RCE as SYSTEM when policies update.

Technical Deep Dive

▶ Watch: Remote Code Execution (RCE) via Exchange PowerShell (25:00)

The attack chain begins with causing an Exchange machine account to authenticate to an attacker-controlled server. This is typically achieved using well-known techniques like PetitPotam or PrinterBug, which can force a remote machine to authenticate via NTLM to an arbitrary UNC path. The attacker then intercepts this NTLM authentication request.

Exchange Architecture and Initial Vulnerability:

Exchange's front-end acts as a proxy, forwarding client requests to the back-end where mailbox operations occur. The communication between the front-end and back-end uses the Exchange machine account, which is a member of the Exchange Servers group. This group is granted the Token Serialization right on Exchange servers, which is crucial for impersonation. The Token Serialization right allows a user to create a new user token with the identity of another user, provided they supply a serialized security context containing the target user's SID and group SIDs.

The initial vulnerability exploited this by relaying the Exchange machine account's NTLM authentication to the front-end EWS endpoint of another Exchange server. Since the relayed machine account had Token Serialization rights on the target, the attacker could then forge a serialized security context for any target user (e.g., an administrator) and impersonate them to access their mailbox via EWS.

The Patch Bypass and New Attack Surface:

Microsoft's initial patch aimed to prevent machine accounts from logging into the front-end directly. However, Tianze Ding discovered a critical flaw in the AddProtocolSpecificHeadersToServerRequest function. This function was intended to process HTTP headers before forwarding requests to the back-end. The patch introduced new logic:

This if branch effectively bypassed the intended protection. If the identity in the Common Access Token (a structure containing username, SID, and group SIDs) was not a machine account, the front-end would directly forward the attacker-supplied Common Access Token to the back-end. The back-end would then create a new user token based on this forged token, granting the attacker impersonation capabilities. This new vulnerability was more severe as it affected all front-end endpoints supporting NTLM authentication and mailbox access (including EWS, MAPI over HTTP, REST API, OWA, ActiveSync, and RPC/HTTP), allowing arbitrary mailbox takeover.

Direct Access to Back-end Endpoints and RCE:

Attackers could also bypass the front-end entirely and directly target back-end endpoints (typically on TCP port 444). A key observation was that Extended Protection for Authentication (EPA), which uses Channel Binding Tokens (CBTs) to prevent NTLM Relay, is disabled by default on back-end endpoints. Furthermore, it cannot be enabled without breaking legitimate communication between the front-end and back-end because the front-end does not generate CBTs when sending Kerberos authentication requests to the back-end. This leaves back-end endpoints like ECP and PowerShell vulnerable to NTLM Relay.

  • RCE via PowerShell/ECP:

By relaying an Exchange machine account's NTLM authentication to the back-end PowerShell endpoint, an attacker can impersonate any user, including an Exchange administrator. Exchange PowerShell cmdlets, while not directly executing arbitrary Windows commands, can be abused. The Add-RoleGroupMember cmdlet allows adding a user to an Exchange role group. Specifically, adding the attacker's account to the Organization Management role group grants that account local administrator privileges on all Exchange servers. Once local administrator, RCE is straightforward using standard Windows administration tools like WinRM (Windows Remote Management) or WMI (Windows Management Instrumentation).

For the ECP endpoint, a specific HTTP header, X-OWA-VirtualDirectory-ID, is required. This ID can be obtained by any user with View-Only Configuration role using the Get-ECPVirtualDirectory cmdlet. The RCE path is then similar to PowerShell, adding the attacker to Organization Management.

  • RCE via DCOM NTLM Relay:

The Exchange Trusted Subsystem group, to which all Exchange machine accounts belong, has local administrator privileges on all Exchange servers in the same Active Directory forest. While SMB signing usually prevents NTLM Relay over SMB, other Windows services can be leveraged. DCOM (Distributed Component Object Model), which uses MSRPC over TCP, is a prime target. DCOM allows the client to specify the authentication level, and an attacker can set it to RPC_C_AUTHN_LEVEL_CONNECT (or RPC_C_AUTHN_LEVEL_NONE), effectively bypassing signing and encryption requirements. The relay process involves authenticating to TCP port 135 (the endpoint mapper) and then to a dynamically assigned DCOM port. The MMC20.Application COM object, known for its ExecuteShellCommand API, can then be invoked by the relayed Exchange machine account (as a local admin) to execute arbitrary commands remotely on the target Exchange server.

Privilege Escalation to Domain Administrator:

The research uncovered pathways to escalate from RCE on an Exchange server to full Domain Administrator privileges. This leverages specific Active Directory permissions granted to Exchange security groups:

  1. Exchange Trusted Subsystem (ETS) Group: Members of ETS possess Write Distinguished Name and Write Name rights on almost all domain user and computer objects in Active Directory (excluding objects with AdminCount=1).
  2. Exchange Windows Permissions (EWP) Group: Members of EWP have the right to create new Organizational Units (OUs) and to delete/create user and computer objects.

The attack path for Domain Admin involves:

  • Creating an evil OU: The attacker, having RCE and thus privileges of ETS/EWP, creates a new OU in Active Directory.
  • Setting GenericAll with Inheritance: The attacker sets a GenericAll Access Control Entry (ACE) on this evil OU with inheritance enabled. This means any object moved into this OU will inherit these powerful permissions.
  • Moving a Domain Controller: The attacker then moves a Domain Controller (DC) computer object into the evil OU. This grants the attacker GenericAll rights on the DC's computer object.
  • DC Compromise: With GenericAll on a DC computer object, the attacker can then perform various attacks, such as Shadow Credentials (creating a new key credential for the DC) or Resource-Based Constrained Delegation (RBCD) (configuring delegation for the DC to itself), to gain control over the DC and achieve Domain Administrator privileges. This specific method requires the target domain to have at least one DC running Windows Server 2012 or later for RBCD/Shadow Credentials.

An alternative privilege escalation path involves the Exchange Windows Permissions group adding itself to the Group Policy Creator Owners group. This allows the attacker to create malicious Group Policy Objects (GPOs) and link them to OUs, then move victim computers/users into those OUs to trigger RCE as SYSTEM or the logged-on user.

Demo / Proof of Concept

▶ Watch: Final extended protection patch and mitigation details (31:00)

Tianze Ding presented several live demonstrations to illustrate the severity of these vulnerabilities:

  1. Arbitrary Mailbox Takeover: The first demo showed the attacker leveraging the NTLM Relay to impersonate a victim administrator. By obtaining the administrator's SID, forging a Common Access Token, and relaying it to the OWA front-end endpoint, the attacker successfully accessed and read the administrator's emails. The talk mentioned that further demos for other affected front-end endpoints (EWS, MAPI, REST, etc.) were available online due to time constraints.
  1. Remote Code Execution (RCE) on Exchange Server:
  • Via PowerShell: The attacker demonstrated gaining RCE by first relaying to the back-end PowerShell endpoint, impersonating an administrator, and then using Add-RoleGroupMember to add their own low-privileged account to the Organization Management role group. After confirming the privilege escalation, the attacker executed a command (e.g., launching calc.exe) on the Exchange server using standard administrative tools like WinRM/WMI, showcasing full control.
  • Via DCOM: Another RCE demo involved relaying an Exchange machine account's NTLM authentication to the DCOM service on a target Exchange server. This allowed the attacker to invoke MMC20.Application's ExecuteShellCommand API, resulting in a calculator process being launched on the target server, confirming RCE.
  1. Privilege Escalation to Domain Administrator: This intricate demo began with the attacker already having RCE on an Exchange server and being a member of the Exchange Trusted Subsystem group. The attacker then:
  • Attempted to create a new machine account with sAMAccountName spoofing (rbcd attack) against a Domain Controller, which initially failed due to insufficient privileges.
  • Created an "evil OU" in Active Directory.
  • Set GenericAll permissions with inheritance on the evil OU.
  • Moved the Domain Controller's computer object into the evil OU.
  • After the move, the attacker re-attempted the sAMAccountName spoofing attack against the DC's computer object (now inheriting GenericAll rights), which succeeded.
  • Finally, the attacker used Kerberos authentication to execute commands on the Domain Controller as a Domain Admin, demonstrating full compromise of the Active Directory forest.

These demonstrations underscored the practical feasibility and devastating impact of the NTLM Relay attack chain against Exchange and Active Directory.

Defensive Implications

▶ Watch: Q&A: Why a new domain admin escalation method? (50:00)

The findings presented by Tianze Ding highlight critical areas for defense against NTLM Relay attacks targeting Exchange Server and Active Directory:

  1. Enable Extended Protection for Authentication (EPA): This is the most crucial mitigation for NTLM Relay over HTTPS. Microsoft released a comprehensive patch in August 2022, which includes EPA for Exchange. However, this patch is not enabled automatically and must be manually configured. Microsoft provides PowerShell scripts to assist administrators in enabling EPA across all Exchange servers with recommended settings. Failure to enable EPA leaves Exchange endpoints vulnerable to NTLM Relay. It's important to note that EPA primarily protects HTTPS; HTTP transport for certain endpoints (like front-end RPC) may still be vulnerable if not explicitly disabled or if SSLOffloading is incorrectly configured.
  1. Keep Windows Servers and Exchange Up-to-Date: Regularly patching both the Exchange Server software and the underlying Windows operating system is essential. This addresses vulnerabilities in Windows services (e.g., DCOM, EFS, Printer Spooler) that attackers exploit to trigger NTLM authentication, as well as fixing vulnerabilities in Exchange itself. The DCOM NTLM Relay vulnerability, for instance, received a patch that was eventually enabled by default in March 2023.
  1. Implement Active Directory Split Permission Model: To mitigate the privilege escalation path from Exchange RCE to Domain Admin, organizations should consider adopting the Active Directory split permission model. This model significantly limits the privileges of Exchange's security groups within Active Directory, thereby breaking the attack chain that leverages Exchange Trusted Subsystem and Exchange Windows Permissions to manipulate OUs, GPOs, and DC objects. While highly effective, implementing this model on an already deployed Exchange environment can be complex and may require manual adjustment of permissions, potentially impacting existing functionalities.
  1. NTLM Hardening and Auditing: While not a complete solution, organizations should continue to harden NTLM where possible. This includes enforcing NTLM signing on all relevant services (e.g., SMB) and auditing for NTLM authentication failures or suspicious activity involving machine accounts. Restricting NTLM usage or disabling it for specific services where Kerberos is a viable alternative can also reduce the attack surface.
  1. Monitor for Suspicious Group Membership Changes: Defenders should actively monitor for any unauthorized additions to highly privileged Exchange groups (e.g., Organization Management, Exchange Trusted Subsystem, Exchange Windows Permissions) or Active Directory groups (e.g., Group Policy Creator Owners). Prompt detection and remediation of such changes are critical.
  1. Network Segmentation: Implementing strict network segmentation between different tiers of Exchange servers and between Exchange and Domain Controllers can limit the lateral movement capabilities of an attacker, even if an initial compromise occurs.

Key Takeaways

  • NTLM Relay remains a critical threat: Despite its age, NTLM Relay continues to be a highly effective attack vector, especially against complex enterprise applications like Microsoft Exchange Server.
  • Exchange machine accounts are high-privilege targets: The Exchange machine account possesses significant power, including Token Serialization rights, local administrator privileges on all Exchange servers, and extensive Active Directory manipulation capabilities, making its compromise extremely dangerous.
  • Patches can introduce new vulnerabilities: The talk demonstrated a clear instance where a security patch inadvertently created a new, more powerful vulnerability by altering core logic related to handling Common Access Tokens.
  • Full compromise is achievable: NTLM Relay against Exchange can lead to arbitrary mailbox takeover, remote code execution on Exchange servers, and ultimately, full Domain Administrator privileges, enabling complete control over the Active Directory forest.
  • Extended Protection for Authentication (EPA) is vital but requires manual action: The primary defense against these NTLM Relay attacks on Exchange is EPA, but it must be manually enabled by administrators, highlighting a critical configuration gap that many organizations may overlook.
  • Layered defense is essential: Mitigating these sophisticated attacks requires a multi-faceted approach, combining manual EPA enablement, diligent patching of all Windows and Exchange components, and strategic Active Directory hardening via the split permission model.

About the Speaker(s)

Tianze Ding is a security researcher from Tencent Security Xuanwu Lab. His research primarily focuses on Active Directory security, cloud security, and web security. As a former CTF player, Tianze has a strong background in competitive cybersecurity, having achieved first runner-up in the HITB CTF Final in 2018 with his team. His work, as presented in this talk, demonstrates a deep understanding of complex authentication protocols and their exploitation in enterprise environments. Tianze also acknowledges Orange Tsai as a co-discoverer of some of the vulnerabilities discussed, highlighting a collaborative spirit in the security research community.

Reviews

Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT

Solid offensive research that chains NTLM relay through Exchange's architecture to Domain Admin. The patch-bypass finding is genuinely good work, and the full kill chain from mailbox takeover to DC compromise is well-demonstrated. Not a novel attack class, but excellent execution on a high-value target.

Heather Calloway (CISO) — STRONG ACCEPT

This is material every CISO running Exchange on-prem needs to know exists. The research demonstrates a complete kill chain from low-privileged domain account to Domain Admin via NTLM relay, and the critical mitigation—EPA—isn't enabled by default. If your team hasn't manually enabled EPA post-August 2022, your Exchange environment is exposed.

→ Top-rated talks at HITBSecConf2023 - Phuket

All talks from HITBSecConf2023 - Phuket