Investigation · Identity
Was a user tricked into a device code sign-in?
Detect and scope a device code phishing attack in Entra: the device-code sign-in, the client app used, and the tokens the attacker then used non-interactively against Exchange or Graph.
When you would ask thisA user may have been sent a device code and a URL and asked to enter the code, handing an attacker tokens for their account. You need to confirm it and scope what the resulting tokens did.
Steps
- 1
Find the device code sign-in
In Entra sign-in logs, the tell is the authentication protocol. The sign-in detail shows authenticationProtocol = deviceCode (surfaced as AuthenticationProtocol in Sentinel's SigninLogs). Some tenants also expose originalTransferMethod = deviceCodeFlow on the record, which is an even clearer marker; confirm which field your tenant populates. Filter for these across the user base in the incident window, because device code phishing is often sprayed and the victim may not be the only one who entered a code.
Device code flow sign-ins (Sentinel KQL)SigninLogs | where TimeGenerated > ago(14d) | where AuthenticationProtocol =~ "deviceCode" or column_ifexists("OriginalTransferMethod", "") =~ "deviceCodeFlow" | project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName, ResourceDisplayName, AutonomousSystemNumber, ResultType | order by TimeGenerated asc - 2
Flag unusual client apps and resources
Device code flow is designed for input-constrained clients, so in a phishing case the AppDisplayName is usually a first-party public client the attacker abused, such as Microsoft Authentication Broker, Microsoft Azure CLI, Microsoft Azure PowerShell, or Visual Studio Code, requesting a resource like Exchange Online or Microsoft Graph. A normal user signing in interactively to Outlook does not use these. Treat a device-code sign-in whose AppDisplayName is Authentication Broker or Azure CLI, against a mail or Graph resource, as high suspicion and pivot to the token use immediately.
- 3
Follow the tokens in the non-interactive table
The interactive SigninLogs table shows the code redemption, but the attacker then uses the refresh and access tokens silently. Those appear in AADNonInteractiveUserSignInLogs, not SigninLogs, so you must query that table to see what the tokens did afterwards. Filter it to the same user and the attacker IP/ASN in the hours and days after the device-code sign-in. Missing this table is the single most common reason a device-code case looks small when it is not.
Token use after the device code sign-in (Sentinel KQL)AADNonInteractiveUserSignInLogs | where TimeGenerated > ago(14d) | where UserPrincipalName =~ "[email protected]" | project TimeGenerated, IPAddress, AppDisplayName, ResourceDisplayName, AutonomousSystemNumber, UniqueTokenIdentifier, SessionId, ResultType | order by TimeGenerated asc - 4
Correlate the token identifiers
To tie the non-interactive calls back to the phished sign-in, carry the token and session identifiers across tables. UniqueTokenIdentifier identifies the issued token and SessionId the sign-in session; where the same values recur in AADNonInteractiveUserSignInLogs you have the attacker reusing the tokens minted from the device code. The exact linkage and which identifier is most reliable can vary with the auth path, so use these as the primary join but corroborate with IP, ASN and app before asserting a chain, and say so in the report if the correlation is partial.
- 5
Scope what the tokens accessed
With the token use isolated, scope impact against each resource the attacker reached. If the resource was Exchange Online, pivot to the mailbox BEC playbook (MailItemsAccessed, Send, inbox rules). If it was Microsoft Graph, look for directory reads, OneDrive/SharePoint access and any app consent the attacker performed with the token. Record the ResourceDisplayName list from both sign-in tables so the impact statement covers every service the stolen tokens touched, not just mail.
- 6
Contain: revoke sessions and block the flow
Containment has two parts. First, invalidate the stolen tokens by revoking the user's sign-in sessions, which forces re-authentication and kills the refresh token; also reset the password. Second, prevent recurrence with a Conditional Access policy that blocks device code flow for users who do not need it (CA supports an authentication-flows condition for device code flow). Confirm the policy does not break legitimate input-constrained devices in your estate before enforcing broadly. Revoking sessions without blocking the flow leaves the door open to a repeat.
Revoke the user's sessions (Microsoft Graph PowerShell)# Connect-MgGraph -Scopes 'User.RevokeSessions.All' Revoke-MgUserSignInSession -UserId [email protected] # Then reset the password and review/remove any app consents the token performed, # and add a Conditional Access policy blocking device code flow where it is not needed.
Where it goes wrong
- Token use after the phish lands in AADNonInteractiveUserSignInLogs, not SigninLogs; query only the interactive table and you will drastically under-scope the incident.
- The field exposing the flow differs by tenant and over time (authenticationProtocol = deviceCode versus originalTransferMethod = deviceCodeFlow), so check which your tenant populates rather than filtering on one name.
- Device code flow is legitimate for genuinely input-constrained devices (some IoT, conference kit), so baseline expected device-code sign-ins before treating all of them as malicious.
- UniqueTokenIdentifier/SessionId correlation across the interactive and non-interactive tables is not guaranteed complete for every auth path; corroborate the chain with IP, ASN and app, and state in the report where the linkage is only partial.
- Revoke-MgUserSignInSession and a password reset kill current tokens but not a Conditional Access gap; without a policy blocking the flow, the user can be phished again, so treat the CA policy as part of containment.
- Attacker infrastructure often sits behind cloud or VPN ASNs that also serve legitimate traffic, so an ASN match alone is weak; combine it with the device-code protocol marker and the unusual client app.
Beyond event logs
The phishing lure
The user's mailbox / chat: the message that delivered the device code and the microsoft.com/devicelogin style URL
Recovering the lure confirms social engineering, gives the campaign's sender and timing, and lets you find other recipients who may also have entered a code.
Conditional Access and sign-in frequency settings
Entra admin center: Conditional Access policies and session controls
Shows whether a device-code-flow block or short sign-in frequency was in place, which bounds how long a stolen refresh token stayed valid and informs the containment gap to close.