Skip to content
WETNav

Investigation · Identity

Did a user consent to a malicious OAuth application?

Find an illicit OAuth consent in Entra ID: the grant and its scopes, who owns the app, what it did with its tokens afterwards, and how to remove it cleanly.

When you would ask thisA user approved a permissions prompt for an app they did not recognize, or you found an unfamiliar enterprise application with mail or file permissions. You need to know who consented, what the app can do, whether it has used that access, and how to evict it.

Steps

  1. 1

    Find the consent and grant events in the Entra audit log

    Consent creates a small cluster of AuditLogs records in the ApplicationManagement category. Consent to application records the consent itself, including whether it was admin consent. Add delegated permission grant records the delegated scopes the app may use on behalf of a user (an OAuth2 permission grant). Add app role assignment to service principal records an application permission granted to the app, which only an administrator can consent to. For a multi-tenant app consented for the first time, an Add service principal record usually appears at the same moment. The scopes appear only inside TargetResources modifiedProperties (for example a ConsentAction.Permissions property), so read that field rather than the activity name. For app role assignments the app may not be the first TargetResources entry, so read every entry. In the unified audit log the same activities carry a trailing period (Consent to application.).

    Consent and permission grants with a high-impact scope flag (Sentinel KQL)
    AuditLogs
    | where TimeGenerated > ago(30d)
    | where OperationName in ("Consent to application", "Add delegated permission grant",
        "Add app role assignment to service principal")
    | extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName)),
        ActorIP = tostring(InitiatedBy.user.ipAddress),
        Target = tostring(TargetResources[0].displayName),
        Changes = tostring(TargetResources)
    | extend HighImpactScope = Changes has_any ("Mail.Read", "Mail.ReadWrite", "Mail.Send",
        "Files.Read.All", "Files.ReadWrite.All", "offline_access")
    | project TimeGenerated, OperationName, Actor, ActorIP, Target, HighImpactScope, Changes, Result
    | order by TimeGenerated asc
  2. 2

    Decide whether the scopes matter

    Rank the grant by what it allows. Mail.Read, Mail.ReadWrite and Mail.Send reach the user's mailbox; Files.Read.All and Files.ReadWrite.All reach every file the user can open in OneDrive and SharePoint; offline_access lets the app hold a refresh token and keep working while the user is away; User.Read alone is low impact. Application permissions (app roles such as Mail.Read granted as an application permission) are far broader than delegated ones because they apply across the tenant, not to one user, unless an Exchange application access policy or RBAC for Applications limits them. Also note the consent type on each delegated grant: ConsentType Principal covers one user, while AllPrincipals (admin consent) covers everyone. Delegated mail or file scopes plus offline_access, on an app the user cannot explain, is the typical consent phishing profile.

  3. 3

    Identify the app and its publisher

    Look up the service principal by AppId rather than display name, because malicious apps often use names and logos that imitate Microsoft or a known vendor. Check AppOwnerOrganizationId: a tenant ID that is neither yours nor one of Microsoft's own tenants means the app was registered somewhere else. Check whether the app has a verified publisher; unverified multi-tenant apps are a common vehicle, though a verified publisher is not proof the app is benign. Review the reply URLs (where tokens are sent) and every user who has a grant. If the application object itself is registered in your tenant (created with a compromised account), also review its secrets and certificates in the audit log. Finally, check the tenant's user consent settings to see whether users were allowed to consent to this app at all.

    The app, its publisher and its grants (Microsoft Graph PowerShell)
    # Connect-MgGraph -Scopes 'Application.Read.All','DelegatedPermissionGrant.Read.All'
    $sp = Get-MgServicePrincipal -Filter "appId eq '<malicious-app-id>'"
    $sp | Select-Object DisplayName, AppId, Id, AppOwnerOrganizationId, PublisherName,
      @{n='VerifiedPublisher';e={$_.VerifiedPublisher.DisplayName}}, ReplyUrls
    
    # Delegated grants: who consented and which scopes
    Get-MgOauth2PermissionGrant -Filter "clientId eq '$($sp.Id)'" |
      Select-Object ConsentType, PrincipalId, ResourceId, Scope
    
    # Application permissions granted to the app
    Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id |
      Select-Object ResourceDisplayName, AppRoleId, CreatedDateTime
  4. 4

    See what the app did: sign-ins

    Delegated access shows up as the user: the consent itself is an interactive sign-in to the app, and later token use appears mostly in AADNonInteractiveUserSignInLogs, with AppId set to the malicious app. Application access shows up as the app itself in AADServicePrincipalSignInLogs. Query all three by AppId to get the IPs, the resources (Exchange Online, Microsoft Graph, SharePoint) and the time range of use. The service principal sign-in category must have been exported to your workspace through diagnostic settings; if the table is missing, use the service principal sign-ins view in the Entra admin center within its retention.

    Every sign-in by the malicious app, delegated and app-only (Sentinel KQL)
    let appId = "<malicious-app-id>";
    union isfuzzy=true
        (SigninLogs | extend Kind = "user interactive"),
        (AADNonInteractiveUserSignInLogs | extend Kind = "user non-interactive"),
        (AADServicePrincipalSignInLogs | extend Kind = "app-only")
    | where TimeGenerated > ago(30d)
    | where AppId == appId
    | summarize FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), SignIns = count(),
        IPs = make_set(IPAddress, 20), Resources = make_set(ResourceDisplayName, 10)
        by Kind, UserPrincipalName
    | order by FirstSeen asc
  5. 5

    See what the app did: mail and Graph activity

    For mailbox access, MailItemsAccessed records identify the calling application in their AuditData (an AppId and, in some records, a ClientAppId), so filter on the malicious app's ID to see which mailboxes and folders it read and whether access was Bind or Sync; confirm which field your tenant populates. For everything else through Graph, MicrosoftGraphActivityLogs records each request with AppId, the request URI and method, the response status and the IP. It has to be enabled through diagnostic settings and is not retroactive, so if it was off before the incident you will only see activity from the point it was turned on. Summarize by request path to see whether the app listed messages, downloaded attachments, enumerated drives or read the directory.

    Graph requests made by the app (Sentinel KQL)
    MicrosoftGraphActivityLogs
    | where TimeGenerated > ago(30d)
    | where AppId == "<malicious-app-id>"
    | extend Path = tostring(split(RequestUri, "?")[0])
    | summarize Requests = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated),
        IPs = make_set(IPAddress, 20)
        by UserId, RequestMethod, Path, ResponseStatusCode
    | order by Requests desc
  6. 6

    Remove the access and preserve the evidence

    Export the app's details, grants and app role assignments first so the record survives removal. Then disable the service principal, which stops new tokens being issued to it in your tenant, remove its delegated permission grants and app role assignments, and revoke the sessions of users who consented so refresh tokens already issued to the app stop working. Revoking user sessions does not affect app-only tokens obtained with application permissions; disabling the service principal and removing its app role assignments is what stops those. Delete the service principal once the investigation no longer needs it. If users can still consent, the app can come back, so tighten the user consent settings (for example, allow consent only for apps from verified publishers for low-impact permissions, or require admin approval).

    Disable the app and remove its grants (Microsoft Graph PowerShell)
    # Connect-MgGraph -Scopes 'Application.ReadWrite.All','DelegatedPermissionGrant.ReadWrite.All'
    # Export $sp, its grants and its app role assignments before this step.
    Update-MgServicePrincipal -ServicePrincipalId $sp.Id -AccountEnabled:$false
    
    Get-MgOauth2PermissionGrant -Filter "clientId eq '$($sp.Id)'" |
      ForEach-Object { Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId $_.Id }
    
    Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id |
      ForEach-Object { Remove-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -AppRoleAssignmentId $_.Id }

Where it goes wrong

  • A consent grant survives password resets and MFA changes; until the grant is removed and sessions are revoked, an app holding offline_access can keep reading data.
  • The scopes live only in TargetResources modifiedProperties; the activity name Consent to application says nothing about whether the app got User.Read or Mail.ReadWrite.
  • Operation names differ by source: AuditLogs uses Consent to application, while the unified audit log uses Consent to application. with a trailing period, so exact-match filters can silently miss records.
  • Delegated activity is logged under the user's identity, so filter by the app's AppId; otherwise an app's automated reads look like the user's own actions.
  • An app role assignment (application permission) requires admin consent; if one exists for the malicious app, an administrator account or a privileged app was involved and the investigation widens to it.
  • Display names and logos are easy to spoof and a verified publisher is not a guarantee; identify the app by AppId and AppOwnerOrganizationId.

Beyond event logs

Enterprise application record

Entra admin center: Enterprise applications > the app > Permissions, Users and groups, Sign-in logs

Shows current delegated and application permissions, who consented and when. Export it before removal so the evidence survives.

The consent lure

The phishing message in the user's mailbox or chat, containing a login.microsoftonline.com authorize link with the app's client_id

Confirms consent phishing rather than a deliberate choice by the user, gives you the client_id, and finds other recipients who may also have consented.

Defender for Cloud Apps app governance

Microsoft Defender portal: App governance and OAuth apps pages (license dependent)

Where licensed, summarizes an app's permissions, data usage and alerts across users, which helps size the impact quickly.

References