Skip to content

Microsoft Entra and Hybrid Identity Security Incident Response

SOP-SEC-003 Standard Operating Procedure v1.0.0
Last Updated 2026-10-19
Author Security Operations Team
πŸ’» Target OS / Systems:
Microsoft Entra ID (P1 / P2)Microsoft 365 EnterpriseMicrosoft Graph PowerShell SDKMicrosoft Entra Connect Sync / Cloud SyncActive Directory Domain Services (On-Premises)

Before you begin

  • Applies to:Authorized incident response across Microsoft Entra ID, Microsoft 365, and on-premises Active Directory.
  • Where to start:Start with the incident lead and confirm the affected tenant, forest, and identities.
  • What you need:Have authorized access to the relevant logs and admin consoles, an incident record, and approved containment and recovery contacts.
Guide tools
Guide tools
0/0 Steps (0%)

Scope, Threat Vectors & Incident Triggers

This emergency runbook establishes the mandatory triage, containment, forensic preservation, and recovery workflows for compromised cloud and hybrid identities across Microsoft Entra ID (formerly Azure AD), Microsoft 365, and on-premises Active Directory.

Cloud-based identity attacks bypass perimeter firewalls through stolen session cookies, Adversary-in-the-Middle (AiTM) phishing, illicit OAuth app consent grants, and forged service principal credentials. Responders must execute coordinated containment across both cloud and on-premises environments simultaneously.

Microsoft Entra and Hybrid Identity Incident Response Pipeline covering evidence preservation, token revocation, rogue MFA purge, OAuth consent kill, Entra Connect sync isolation, and phishing-resistant FIDO2 re-issue

Microsoft Entra & Hybrid Identity Incident Response Pipeline: Rapid coordinated containment across cloud and on-premises planes: preserve audit/risk telemetry, revoke all active OAuth refresh and Continuous Access Evaluation (CAE) sessions, disable synchronized accounts, purge rogue MFA methods and illicit app consents, freeze sync engines, and enforce phishing-resistant FIDO2 hardware credentials.


Pre-Incident Access & Tooling Baseline

Responders require an administrative workstation equipped with the Microsoft Graph PowerShell SDK and credentials for an emergency break-glass account ([email protected]):

Terminal window
# Install and connect to Microsoft Graph with incident response scopes
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
Connect-MgGraph -Scopes @(
"User.ReadWrite.All",
"AuditLog.Read.All",
"Directory.ReadWrite.All",
"Application.ReadWrite.All",
"IdentityRiskEvent.Read.All",
"Policy.Read.All"
)

Execution: Phase 1 β€” Forensic Evidence Preservation

01

Export Compromised User Sign-In and Risk Logs

Forensic Preservation

Before terminating active sessions, export live sign-in telemetry, IP addresses, user agent strings, and risk detections for forensic preservation and attribution.

Terminal window
$TargetUPN = "[email protected]"
$LogDir = "C:\Forensics\Incidents\$(Get-Date -Format 'yyyyMMdd_HHmmss')_$TargetUPN"
New-Item -ItemType Directory -Path $LogDir -Force
# 1. Export interactive and non-interactive sign-in logs (last 7 days)
Get-MgAuditLogSignIn -Filter "userPrincipalName eq '$TargetUPN'" -All |
Select-Object CreatedDateTime, AppDisplayName, IPAddress, ClientAppUsed, UserAgent, Status, RiskDetail, ConditionalAccessStatus |
Export-Csv -Path "$LogDir\SignIns_$TargetUPN.csv" -NoTypeInformation
# 2. Export real-time risk detections from Entra ID Protection
Get-MgRiskDetection -Filter "userPrincipalName eq '$TargetUPN'" -All |
Export-Csv -Path "$LogDir\RiskDetections_$TargetUPN.csv" -NoTypeInformation
# 3. Export directory audit events (modifications performed by or on the account)
Get-MgAuditLogDirectoryAudit -Filter "targetResources/any(c:c/userPrincipalName eq '$TargetUPN')" -All |
Export-Csv -Path "$LogDir\DirectoryAudit_$TargetUPN.csv" -NoTypeInformation
❯ Illustrative Output (Results Vary)
Confirm CSV files are populated in $LogDir and contain timestamped sign-in and IP attribution data.

Execution: Phase 2 β€” Coordinated Cloud & On-Premises Containment

02

Revoke Active Refresh Tokens & Web Sessions

Token Revocation

Immediately revoke all active OAuth refresh tokens, session cookies, and Continuous Access Evaluation (CAE) tokens to disconnect the attacker from Teams, Outlook Web App, SharePoint, and Azure Portal.

Terminal window
# 1. Invalidate all active OAuth tokens across Microsoft 365
$User = Get-MgUser -UserId $TargetUPN
Revoke-MgUserAllRefreshToken -UserId $User.Id
# 2. Force session termination in Continuous Access Evaluation (CAE)
Update-MgUser -UserId $User.Id -RevokeSignInSessions $true
Write-Host "[-] All active tokens revoked for $($User.UserPrincipalName)." -ForegroundColor Red
❯ Illustrative Output (Results Vary)
Query user token revocation timestamp:
(Get-MgUser -UserId $User.Id -Property RefreshTokensValidFromDateTime).RefreshTokensValidFromDateTime
Matches current UTC timestamp. Attacker sessions severed.

03

Disable Account in Cloud and On-Premises Active Directory

Account Quarantine

Prevent further authentication attempts while investigations are ongoing across both directory planes.

Terminal window
# 1. Disable cloud account in Entra ID
Update-MgUser -UserId $User.Id -AccountEnabled:$false
# 2. If user is synchronized from on-premises AD, disable immediately in Active Directory:
$SamAccountName = ($TargetUPN -split "@")[0]
if (Get-ADUser -Filter "SamAccountName -eq '$SamAccountName'" -ErrorAction SilentlyContinue) {
Disable-ADAccount -Identity $SamAccountName
Move-ADObject -Identity (Get-ADUser $SamAccountName).DistinguishedName -TargetPath "OU=Quarantine,DC=corp,DC=internal"
Write-Host "[-] Synchronized on-premises AD account disabled and quarantined." -ForegroundColor Yellow
}
❯ Illustrative Output (Results Vary)
(Get-MgUser -UserId $User.Id).AccountEnabled returns False.
(Get-ADUser $SamAccountName).Enabled returns False.

04

Audit and Purge Rogue MFA Authentication Methods

MFA Sanitation

Attackers frequently add rogue FIDO2 keys, phone numbers, or Authenticator apps to maintain persistence. Purge all unapproved MFA methods.

Terminal window
# List all registered authentication methods for the user
Get-MgUserAuthenticationMethod -UserId $User.Id
# 1. Remove rogue Software OATH tokens / Authenticator apps:
Get-MgUserAuthenticationMicrosoftAuthenticatorMethod -UserId $User.Id | ForEach-Object {
Remove-MgUserAuthenticationMicrosoftAuthenticatorMethod -UserId $User.Id -MicrosoftAuthenticatorAuthenticationMethodId $_.Id
}
# 2. Remove rogue FIDO2 security keys:
Get-MgUserAuthenticationFido2Method -UserId $User.Id | ForEach-Object {
Remove-MgUserAuthenticationFido2Method -UserId $User.Id -Fido2AuthenticationMethodId $_.Id
}
# 3. Remove rogue phone numbers:
Get-MgUserAuthenticationPhoneMethod -UserId $User.Id | ForEach-Object {
Remove-MgUserAuthenticationPhoneMethod -UserId $User.Id -PhoneAuthenticationMethodId $_.Id
}
❯ Illustrative Output (Results Vary)
Re-query Get-MgUserAuthenticationMethod:
Confirm only corporate-approved methods remain on target profile.

05

Audit and Revoke Illicit OAuth App Permissions

OAuth Revocation

Attackers frequently abuse user consent to register malicious multi-tenant apps that maintain persistence via Graph API even after the user’s password is changed.

Terminal window
# 1. Audit all OAuth2 permissions consented to by the target user
$Grants = Get-MgOauth2PermissionGrant -Filter "principalId eq '$($User.Id)'" -All
foreach ($Grant in $Grants) {
$App = Get-MgServicePrincipal -ServicePrincipalId $Grant.ClientId
Write-Warning "Consented App Detected: $($App.DisplayName) | Permissions: $($Grant.Scope)"
# 2. Revoke the unauthorized permission grant immediately
Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId $Grant.Id
Write-Host "[-] Revoked OAuth consent: $($Grant.Id)" -ForegroundColor Red
}
❯ Illustrative Output (Results Vary)
Run: Get-MgOauth2PermissionGrant -Filter "principalId eq '$($User.Id)'"
Must return 0 results.

06

Identify & Disable Suspect Service Principals and Credentials

Credential Purge

Check if the attacker created new App Registrations or added credentials (certificates/passwords) to existing Enterprise Applications.

Terminal window
# Query directory audit log for application credential additions (last 72 hours)
Get-MgAuditLogDirectoryAudit -Filter "activityDisplayName eq 'Add service principal credentials'" -All |
Select-Object ActivityDateTime, TargetResources, InitiatedBy | Format-Table
# Disable suspect Service Principal immediately:
$SuspectAppId = "00000000-0000-0000-0000-000000000000" # Replace with target ID
Update-MgServicePrincipal -ServicePrincipalId $SuspectAppId -AccountEnabled:$false
❯ Illustrative Output (Results Vary)
(Get-MgServicePrincipal -ServicePrincipalId $SuspectAppId).AccountEnabled reports False.

Execution: Phase 4 β€” Entra Connect Synchronization Isolation

07

Isolate Entra Connect Sync Engine (If On-Premises Breached)

Sync Isolation

If the compromise originated from on-premises Active Directory or involves Domain Controller lateral movement, halt Entra Connect synchronization to prevent on-premises attackers from modifying cloud administrators or pushing malicious attributes.

Terminal window
# On the primary Entra Connect server:
Import-Module ADSync
# 1. Disable the automated synchronization scheduler
Set-ADSyncScheduler -SyncCycleEnabled $false
# 2. Verify current sync scheduler state
Get-ADSyncScheduler | Select-Object SyncCycleEnabled, NextSyncCycleStartTimeInUTC
❯ Illustrative Output (Results Vary)
SyncCycleEnabled : False
NextSyncCycleStartTimeInUTC: Disabled
Cloud identity directory isolated from on-premises directory modifications.

Execution: Phase 5 β€” Privileged Identity & Policy Audit

08

Audit Privileged Identity Management (PIM) and Directory Roles

Privilege Audit

Verify whether the attacker activated or elevated any roles into Global Administrator, Privileged Role Administrator, or Exchange Administrator.

Terminal window
# Query all active Directory Role assignments
Get-MgRoleManagementDirectoryRoleAssignment -All | ForEach-Object {
$RoleDef = Get-MgRoleManagementDirectoryRoleDefinition -UnifiedRoleDefinitionId $_.RoleDefinitionId
$Principal = Get-MgDirectoryObject -DirectoryObjectId $_.PrincipalId
[PSCustomObject]@{
RoleName = $RoleDef.DisplayName
PrincipalUPN = $Principal.AdditionalProperties["userPrincipalName"]
PrincipalType = $Principal.AdditionalProperties["@odata.type"]
}
} | Format-Table -AutoSize
❯ Illustrative Output (Results Vary)
Confirm no unexpected accounts or service principals hold Tier-0 directory roles.

Execution: Phase 6 β€” Remediation, FIDO2 Re-issue & Handover

09

Re-Enable User Account with Phishing-Resistant MFA

Phishing-Resistant MFA

Following full containment, re-enable the user with a temporary password and mandate registration of a FIDO2 hardware security key.

Terminal window
# 1. Reset user password to a cryptographically secure value
$NewTempPass = (-join ((65..90) + (97..122) + (48..57) + 33..38 | Get-Random -Count 24 | ForEach-Object {[char]$_}))
Update-MgUser -UserId $User.Id `
-PasswordProfile @{ ForceChangePasswordNextSignIn = $true; Password = $NewTempPass } `
-AccountEnabled:$true
# 2. Reset risk state in Microsoft Entra ID Protection
Invoke-MgDismissRiskyUser -UserIds @($User.Id)
Write-Host "[+] User account re-enabled. Risk state reset." -ForegroundColor Green
❯ Illustrative Output (Results Vary)
Query risk state:
Get-MgRiskyUser -UserId $User.Id | Select-Object UserPrincipalName, RiskState
RiskState: dismissed

Rollback & Closeout Sign-Off

10

Restore Legitimate Enterprise Application or User Access

Rollback Restoration

If an account or application was disabled mistakenly during containment, safely re-enable the cleared user identity and restore genuine OAuth permissions.

Terminal window
# 1. Re-enable user in Entra ID
Update-MgUser -UserId $User.Id -AccountEnabled:$true
# 2. If synchronized, re-enable on-premises AD account and restore original OU:
Enable-ADAccount -Identity $SamAccountName
Move-ADObject -Identity (Get-ADUser $SamAccountName).DistinguishedName -TargetPath "OU=Users,OU=Staff,DC=corp,DC=internal"
# 3. Resume Entra Connect scheduler if previously paused:
Set-ADSyncScheduler -SyncCycleEnabled $true

SOC Compliance & Incident Sign-off

Incident MilestoneMandatory Verification StandardApproverSign-Off
Evidence PreservationSign-in and audit logs exported to forensic storeSecurity OperationsApproved
Token InvalidationRevoke-MgUserAllRefreshToken executed successfullySecurity OperationsApproved
MFA SanitizationAll unauthorized phone/authenticator methods removedSecurity OperationsApproved
OAuth Consent AuditIllicit permission grants revoked; apps neutralizedLead Systems AdministratorApproved
PIM & CA VerificationZero unauthorized role activations in tenantCISOApproved
Identity Re-issuePhishing-resistant FIDO2 hardware key enforcedCISOApproved

Comments