|
| 1 | +# Entra ID Federated Domain Trust Modification |
| 2 | + |
| 3 | +## Metadata |
| 4 | + |
| 5 | +| Key | Value | |
| 6 | +|--------------|------------------------------------| |
| 7 | +| ID | TRR0000 | |
| 8 | +| External IDs | [T1484.002], [T1556.007] | |
| 9 | +| Tactics | Persistence, Defense Evasion | |
| 10 | +| Platforms | Azure | |
| 11 | +| Contributors | Andrew VanVleet | |
| 12 | + |
| 13 | +### Scope Statement |
| 14 | + |
| 15 | +This TRR covers the modification of Microsoft Entra ID federated domain trust |
| 16 | +configuration to register an attacker-controlled token-signing certificate. The |
| 17 | +modified trust enables the attacker's identity provider (IdP) to issue signed |
| 18 | +identity tokens that Entra accepts as valid for any user in the tenant. |
| 19 | + |
| 20 | +The technique operates entirely against Entra ID's cloud-side configuration. It |
| 21 | +does not require compromise of any on-premises identity infrastructure (such as |
| 22 | +AD FS), and the attacker's IdP is hosted on attacker-controlled infrastructure. |
| 23 | + |
| 24 | +The use of a valid signing certificate to generate a SAML token is referred to |
| 25 | +as a 'Golden SAML' attack ([T1606.002]).[^1] This technique is one of the ways |
| 26 | +an attacker can position themselves for a Golden SAML attack in an Azure tenant. |
| 27 | + |
| 28 | +This technique maps to two MITRE ATT&CK IDs: |
| 29 | + |
| 30 | +- T1484.002 Domain or Tenant Policy Modification: Trust Modification, which |
| 31 | + includes modifications to federated domains. |
| 32 | +- T1556.007 Modify Authenication Process: Hybrid Identity, which includes trust |
| 33 | + relationships between AD FS and Entra ID. |
| 34 | + |
| 35 | +## Technique Overview |
| 36 | + |
| 37 | +An attacker who holds the required privileges in Entra can modify the tenant's |
| 38 | +federated domain configuration to register an attacker-controlled token-signing |
| 39 | +certificate. The modified domain trust authorizes the attacker's IdP to issue |
| 40 | +signed tokens that Entra accepts. Because federation trust in Entra is |
| 41 | +tenant-wide, a single modified domain enables the attacker to authenticate as |
| 42 | +any user in the tenant without knowing those users' credentials. This technique |
| 43 | +was employed for persistence in the SolarWinds (APT29) and Octo Tempest |
| 44 | +intrusion campaigns. |
| 45 | + |
| 46 | +## Technical Background |
| 47 | + |
| 48 | +### Federation in Entra ID |
| 49 | + |
| 50 | +A federated domain delegates authentication to an external identity provider. |
| 51 | +When a user with a User Principal Name (UPN) from the federated domain attempts |
| 52 | +to sign in, Entra redirects them to the IdP's sign-in URL. The IdP authenticates |
| 53 | +the user and returns a signed token (using either the SAML or WS-Federation |
| 54 | +protocols). Entra validates the token's signature against the public certificate |
| 55 | +stored in the domain's federation configuration. If the signature is valid and |
| 56 | +the token corresponds to a user in the tenant the user is signed in. |
| 57 | + |
| 58 | +You can view custom and federated domains in an Entra tenant by using the |
| 59 | +`Get-MgDomain` and `Get-MgDomainFederationConfiguration` PowerShell cmdlets |
| 60 | +(part of the Microsoft.Graph module). |
| 61 | + |
| 62 | +### Per-domain Redirection, Tenant-wide Trust |
| 63 | + |
| 64 | +Federation in Entra has two distinct scopes that operate independently: |
| 65 | + |
| 66 | +#### Per-domain Sign-in Redirection |
| 67 | + |
| 68 | +When a user attempts an interactive sign-in with a UPN in a federated domain |
| 69 | +(e.g., `alice@contoso.com`), Entra redirects that user to the IdP configured for |
| 70 | +`contoso.com`. Users in other domains within the same tenant are not redirected |
| 71 | +to that IdP, they are redirected to whichever IdP their own domain is federated |
| 72 | +with, or if their domain is `Managed` they authenticate against Entra directly. |
| 73 | + |
| 74 | +#### Tenant-wide Token Issuing Trust |
| 75 | + |
| 76 | +Once an IdP is registered as the federation provider for a domain in the tenant, |
| 77 | +Entra will trust signed tokens from that IdP for any user in the tenant. When a |
| 78 | +token is submitted to Entra, the signature is validated against the federation |
| 79 | +configurations registered in the tenant - any registered IdP's certificate is |
| 80 | +acceptable. The user is then identified by matching the token's `NameId` claim |
| 81 | +to an `ImmutableId` in Entra, with no constraint that the user belong to the |
| 82 | +federated domain the token came from. |
| 83 | + |
| 84 | +There is no check that links a token's issuing IdP to the domain of the user |
| 85 | +being authenticated. The domain on the federation configuration controls only |
| 86 | +*redirection during interactive sign-in*; it does not constrain *which users the |
| 87 | +IdP can vouch for* via direct token submission. An attacker who federates a |
| 88 | +domain they own (e.g., `attacker-evil-corp.com`) can forge tokens for any user |
| 89 | +in that tenant even though the attacker's domain has no relationship to those |
| 90 | +users. |
| 91 | + |
| 92 | +This includes: |
| 93 | + |
| 94 | +- Users in other federated domains (whose own domain federates to a different |
| 95 | + IdP) |
| 96 | +- Users in `Managed` (non-federated) domains |
| 97 | +- Cloud-only users (`@<tenant>.onmicrosoft.com`) who have an `ImmutableId` |
| 98 | +- External / guest users who have an `ImmutableId` |
| 99 | + |
| 100 | +>[!NOTE] |
| 101 | +> |
| 102 | +> Not all Entra users have an `ImmutableId` by default. For users synced from |
| 103 | +> on-premises Active Directory, `ImmutableId` is populated automatically and |
| 104 | +> corresponds to the on-prem object's `objectGUID` (or a configured anchor). For |
| 105 | +> cloud-only and guest users, the attribute is `null` by default. Attackers have |
| 106 | +> worked around this limitation by manually adding an `ImmutableId` to a |
| 107 | +> cloud-only user (often a high-privilege one). This requires |
| 108 | +> `User.ReadWrite.All` permissions, typically held by `User Administrator`, |
| 109 | +> `Global Administrator`, etc. It can be done via the MS Graph cmdlet |
| 110 | +> `Update-MgUser -UserId "user@yourdomain.com" -OnPremisesImmutableId |
| 111 | +> "Base64StringValue=="` |
| 112 | +
|
| 113 | +### Federation configuration object |
| 114 | + |
| 115 | +A federated domain's configuration includes the following fields: |
| 116 | + |
| 117 | +- `IssuerUri` - identifier of the IdP. Must match the `Issuer` claim in |
| 118 | + tokens. |
| 119 | +- `PassiveSignInUri` / `ActiveSignInUri` - where Entra redirects |
| 120 | + users for interactive sign-in. |
| 121 | +- `SignOutUri` - where Entra redirects users on sign-out. |
| 122 | +- `SigningCertificate` - base64-encoded X.509 public certificate used to |
| 123 | + verify token signatures. |
| 124 | +- `NextSigningCertificate` - secondary certificate slot supporting |
| 125 | + certificate rollover. Tokens signed by this certificate are also accepted by |
| 126 | + Entra. |
| 127 | +- `PreferredAuthenticationProtocol` - `wsfed` or `saml`. |
| 128 | +- `federatedIdpMfaBehavior` - controls whether Entra accepts MFA claims |
| 129 | + from the federated IdP. |
| 130 | + |
| 131 | +### Domain lifecycle in Entra |
| 132 | + |
| 133 | +A custom domain progresses through a defined lifecycle in Entra: |
| 134 | + |
| 135 | +1. **Add custom domain** - registers the domain string in the tenant. Status |
| 136 | + is set to unverified. |
| 137 | +2. **Verify domain** - the requestor publishes a TXT or MX record at the DNS |
| 138 | + authority for the domain; Entra queries DNS for the record and, on success, |
| 139 | + marks the domain verified. |
| 140 | +3. **Set domain authentication** - changes the authentication type from |
| 141 | + Managed (the default) to Federated. |
| 142 | +4. **Set federation settings on domain** - writes the federation configuration |
| 143 | + (signing certificate, issuer URI, sign-in URIs, etc.) to the domain. |
| 144 | + |
| 145 | +For a domain that is already federated, only step 4 is required to modify the |
| 146 | +configuration. |
| 147 | + |
| 148 | +> [!NOTE] |
| 149 | +> |
| 150 | +> Since spring 2020, Entra has enforced that federation configuration cannot be |
| 151 | +> applied to an unverified domain. Prior to that fix, attackers could federate |
| 152 | +> any unverified domain string - including domains they did not own - via tools |
| 153 | +> like AADInternals' `New-AADIntBackdoor`. Legacy unverified domains may still |
| 154 | +> exist in tenants and warrant review. |
| 155 | +
|
| 156 | +### Required permissions |
| 157 | + |
| 158 | +The Entra role permissions relevant to this technique are: |
| 159 | + |
| 160 | +- `microsoft.directory/domains/allProperties/allTasks` - grants broad domain |
| 161 | + management permissions, including adding and verifying a domain. |
| 162 | +- `microsoft.directory/domains/federation/update` - grants permission to modify |
| 163 | + federation configuration settings |
| 164 | + |
| 165 | +These are held by the following built-in roles: |
| 166 | + |
| 167 | +| Built-in Role | Manage Domains | Update Federation | |
| 168 | +| --- | --- | --- | |
| 169 | +| Global Administrator | X | X | |
| 170 | +| Hybrid Identity Administrator | X | X | |
| 171 | +| Partner Tier 2 Support | X | X | |
| 172 | +| Domain Name Administrator | X | | |
| 173 | +| External Identity Provider Administrator | | X | |
| 174 | + |
| 175 | +### API surfaces |
| 176 | + |
| 177 | +Three API surfaces have historically been usable for this technique, but only |
| 178 | +one remains available. |
| 179 | + |
| 180 | +- **MS Graph** - Used by `Update-MgDomainFederationConfiguration` and |
| 181 | + `New-MgDomainFederationConfiguration`. |
| 182 | +- **Azure AD Graph** - Retired June 2025. Used by AADInternals. |
| 183 | +- **MSOnline V1 Provisioning API** - Retired March 2024. Used by MSOnline's |
| 184 | + `Set-MsolDomainAuthentication`. |
| 185 | + |
| 186 | +### Telemetry |
| 187 | + |
| 188 | +Entra Audit Logs record the following operations relevant to this technique: |
| 189 | + |
| 190 | +- `Add unverified domain` - generated when a new custom domain is added |
| 191 | +- `Verify domain` - generated when a domain is successfully verified |
| 192 | +- `Set domain authentication` - generated when a domain's authentication type is |
| 193 | + changed (options are 'Managed' and 'Federated') |
| 194 | +- `Set federation settings on domain` - generated when a domain's federation |
| 195 | + configuration is created or modified |
| 196 | + |
| 197 | +Each event records the actor, timestamp, target domain, and outcome. Notably, |
| 198 | +the `Set federation settings on domain` event does not include the actual |
| 199 | +federation configuration values (issuer URI, signing certificate, sign-in URIs) |
| 200 | +in the event payload. To recover the configuration that was set, the current |
| 201 | +configuration must be queried from MS Graph after the event fires. |
| 202 | + |
| 203 | +## Procedures |
| 204 | + |
| 205 | +| ID | Title | Tactic | |
| 206 | +| --- | --- | --- | |
| 207 | +| TRR0000.AZR.A | Modify existing federated domain | Persistence, Defense Evasion | |
| 208 | +| TRR0000.AZR.B | Add new federated domain | Persistence, Defense Evasion | |
| 209 | + |
| 210 | +### Procedure A: Modify Existing Federated Domain |
| 211 | + |
| 212 | +This procedure applies when the tenant already has a verified domain configured |
| 213 | +for federation. The attacker modifies the configuration of the existing domain |
| 214 | +to register an attacker-controlled signing certificate. The write can replace |
| 215 | +the primary `SigningCertificate` or populate the `NextSigningCertificate` slot. |
| 216 | +Populating `NextSigningCertificate` leaves the legitimate signing certificate |
| 217 | +intact and operational, so normal user sign-ins continue to succeed while the |
| 218 | +attacker's tokens are also accepted. |
| 219 | + |
| 220 | +#### Detection Data Model |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | +The procedure consists of a single essential operation: modifying the federation |
| 225 | +configuration of a verified, federated target domain. |
| 226 | + |
| 227 | +### Procedure B: Add New Federated Domain |
| 228 | + |
| 229 | +Under this procedure, an attacker adds a new federated domain to Entra. The |
| 230 | +attacker uses a domain they control (or a domain whose DNS they have |
| 231 | +compromised). They publish the verification TXT or MX record at the DNS |
| 232 | +authority for the domain and then invoke verification, which Entra confirms via |
| 233 | +DNS query. With the domain verified, the attacker changes its authentication |
| 234 | +type to 'Federated' and writes the federation configuration with their own |
| 235 | +signing certificate, allowing them to generate tokens for all users in the |
| 236 | +tenant. |
| 237 | + |
| 238 | +This procedure has the same terminal operation as Procedure A but adds three |
| 239 | +preceeding operations - adding the domain, verifying it, and setting the |
| 240 | +authentication type. (Publishing the DNS record needed to verify the domain |
| 241 | +occurs at the attacker's DNS authority and is not observable from within the |
| 242 | +victim's Entra tenant.) |
| 243 | + |
| 244 | +The new domain does not need to resemble or relate to any existing domain in the |
| 245 | +tenant. Because federation trust is tenant-wide, an arbitrarily-named attacker |
| 246 | +domain is sufficient to enable token forgery for any user in the tenant. |
| 247 | + |
| 248 | +#### Detection Data Model |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | +The `Publish DNS Record` prerequisite is shown in gray to indicate that it |
| 253 | +occurs at an external location and is not observable from within the tenant. |
| 254 | + |
| 255 | +## Available Emulation Tests |
| 256 | + |
| 257 | +| ID | Link | |
| 258 | +|---------------|------| |
| 259 | +| TRR0000.AZR.A | | |
| 260 | +| TRR0000.AZR.B | | |
| 261 | + |
| 262 | +## References |
| 263 | + |
| 264 | +- [Add and verify custom domain names - Microsoft Learn] |
| 265 | +- [Add your custom domain - Microsoft Learn] |
| 266 | +- [Microsoft Entra built-in roles - Microsoft Learn] |
| 267 | +- [Monitor changes to federation configuration in Microsoft Entra ID - Microsoft Learn] |
| 268 | +- [Deep-dive to Azure Active Directory Identity Federation - AADInternals] |
| 269 | +- [Security vulnerability in Azure AD & Office 365 identity federation - AADInternals] |
| 270 | +- [How to create a backdoor to Azure AD - part 1: Identity federation - AADInternals] |
| 271 | +- [Roles Allowing To Abuse Entra ID Federation for Persistence and Privilege Escalation - Tenable] |
| 272 | +- [I Spy: Escalating to Entra ID Global Admin - Datadog Security Labs] |
| 273 | +- [Octo Tempest crosses boundaries to facilitate extortion, encryption, and destruction - Microsoft] |
| 274 | +- [Remediation and hardening strategies for Microsoft 365 to defend against APT29 - Mandiant] |
| 275 | +- [Detecting Microsoft 365 and Azure Active Directory backdoors - Mandiant] |
| 276 | +- [AADInternals FederatedIdentityTools - GitHub] |
| 277 | + |
| 278 | +[^1]: [Golden SAML Attack - CyberArk] |
| 279 | + |
| 280 | +[T1484.002]: https://attack.mitre.org/techniques/T1484/002/ |
| 281 | +[T1556.007]: https://attack.mitre.org/techniques/T1556/007/ |
| 282 | +[T1606.002]: https://attack.mitre.org/techniques/T606/002/ |
| 283 | + |
| 284 | +[Add and verify custom domain names - Microsoft Learn]: https://learn.microsoft.com/en-us/entra/identity/users/domains-manage |
| 285 | +[Add your custom domain - Microsoft Learn]: https://learn.microsoft.com/en-us/entra/fundamentals/add-custom-domain |
| 286 | +[Microsoft Entra built-in roles - Microsoft Learn]: https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/permissions-reference |
| 287 | +[Monitor changes to federation configuration in Microsoft Entra ID - Microsoft Learn]: https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-monitor-federation-changes |
| 288 | +[Deep-dive to Azure Active Directory Identity Federation - AADInternals]: https://aadinternals.com/post/aad-deepdive/ |
| 289 | +[Security vulnerability in Azure AD & Office 365 identity federation - AADInternals]: https://aadinternals.com/post/federation-vulnerability/ |
| 290 | +[How to create a backdoor to Azure AD - part 1: Identity federation - AADInternals]: https://aadinternals.com/post/aadbackdoor/ |
| 291 | +[Roles Allowing To Abuse Entra ID Federation for Persistence and Privilege Escalation - Tenable]: https://medium.com/tenable-techblog/roles-allowing-to-abuse-entra-id-federation-for-persistence-and-privilege-escalation-df9ca6e58360 |
| 292 | +[I Spy: Escalating to Entra ID Global Admin - Datadog Security Labs]: https://securitylabs.datadoghq.com/articles/i-spy-escalating-to-entra-id-global-admin/ |
| 293 | +[Octo Tempest crosses boundaries to facilitate extortion, encryption, and destruction - Microsoft]: https://www.microsoft.com/en-us/security/blog/2023/10/25/octo-tempest-crosses-boundaries-to-facilitate-extortion-encryption-and-destruction/ |
| 294 | +[Remediation and hardening strategies for Microsoft 365 to defend against APT29 - Mandiant]: https://www.mandiant.com/resources/remediation-and-hardening-strategies-microsoft-365-defend-against-apt29-v13 |
| 295 | +[Detecting Microsoft 365 and Azure Active Directory backdoors - Mandiant]: https://www.mandiant.com/resources/blog/detecting-microsoft-365-azure-active-directory-backdoors |
| 296 | +[AADInternals FederatedIdentityTools - GitHub]: https://github.com/Gerenios/AADInternals/blob/master/FederatedIdentityTools.ps1 |
| 297 | +[Golden SAML Attack - CyberArk]: https://www.cyberark.com/resources/threat-research-blog/golden-saml-newly-discovered-attack-technique-forges-authentication-to-cloud-apps |
0 commit comments