Skip to content

Malicious OAuth App & Consent Risk Matrix

CRITICAL PERSISTENCE GRAPH API & OAUTH 2.0 Vector: Consent Phishing & Application Abuse

Adversaries increasingly favor OAuth Application Abuse over traditional password compromise. By tricking a user into granting permissions to a rogue cloud application, the adversary secures permanent API access to emails, files, and directory objects - completely bypassing MFA, password changes, and Conditional Access policies.


⚠️ High-Risk Microsoft Graph Permissions Matrix

Section titled “⚠️ High-Risk Microsoft Graph Permissions Matrix”
Permission NameTypePotential ImpactAbuse Scenario
Mail.ReadWriteDelegated / AppFull access to user or all tenant mailboxesMass email exfiltration, wire fraud, message tampering
Mail.SendDelegated / AppSend emails as the victim or arbitrary userInternal spear-phishing, spreading malicious links
Files.ReadWrite.AllDelegated / AppRead and write access to all SharePoint and OneDrive filesData extortion, mass file download, ransomware encryption
Directory.ReadWrite.AllAppModify any directory objectCreating backdoor admin users, changing group memberships
RoleManagement.ReadWrite.DirectoryAppGrant arbitrary directory rolesElevating any compromised identity to Global Administrator
User.ReadWrite.AllDelegated / AppModify all user profilesResetting user authentication methods or adding secondary phones
offline_accessDelegatedLong-lived refresh token acquisitionAccessing APIs persistently without user interaction

🔎 KQL Threat Hunting: OAuth Abuse Telemetry

Section titled “🔎 KQL Threat Hunting: OAuth Abuse Telemetry”

Monitor Microsoft Entra ID audit logs (AuditLogs table in Sentinel / Defender XDR) for app registration and consent anomalies:

1. Detect Newly Added Credentials to Service Principals

Section titled “1. Detect Newly Added Credentials to Service Principals”

Adversaries with Application Administrator privileges add certificates or client secrets to existing high-privilege apps:

AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName in ("Add service principal credentials", "Update service principal")
| extend TargetApp = tostring(TargetResources[0].displayName)
| extend Initiator = tostring(InitiatedBy.user.userPrincipalName)
| project TimeGenerated, OperationName, TargetApp, Initiator, Result, AdditionalDetails
| order by TimeGenerated desc
AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName == "Consent to application"
| extend AppName = tostring(TargetResources[0].displayName)
| extend ConsentingUser = tostring(InitiatedBy.user.userPrincipalName)
| extend Permissions = tostring(TargetResources[0].modifiedProperties)
| project TimeGenerated, AppName, ConsentingUser, Permissions, Result
| order by TimeGenerated desc

⚡ PowerShell: Audit & Revoke Illicit OAuth Grants

Section titled “⚡ PowerShell: Audit & Revoke Illicit OAuth Grants”

Run these commands with Application.ReadWrite.All and DelegatedPermissionGrant.ReadWrite.All privileges:

Terminal window
# Connect to Microsoft Graph
# Connect-MgGraph -Scopes "DelegatedPermissionGrant.ReadWrite.All", "Application.ReadWrite.All"
$grants = Get-MgOauth2PermissionGrant
$report = foreach ($g in $grants) {
$sp = Get-MgServicePrincipal -ServicePrincipalId $g.ClientId
[PSCustomObject]@{
GrantId = $g.Id
AppName = $sp.DisplayName
ClientId = $g.ClientId
ConsentType = $g.ConsentType
Scope = $g.Scope
PrincipalId = $g.PrincipalId
}
}
$report | Format-Table -AutoSize
Terminal window
# 1. Revoke the delegated permission grant
$targetGrantId = "ROGuE_GRANT_ID_HERE"
Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId $targetGrantId
Write-Host "[+] OAuth permission grant revoked." -ForegroundColor Green
# 2. Disable the malicious Service Principal completely
$targetClientId = "ROGUE_CLIENT_ID_HERE"
Update-MgServicePrincipal -ServicePrincipalId $targetClientId -AccountEnabled $false
Write-Host "[+] Service Principal disabled." -ForegroundColor Yellow