↓ Skip to main content
  1. Articles/

How Device Code Phishing Works, and How to Find It

▶ Present this article as 12 slides you can share, or browse all decks.

⚙ Try it live: Device Code Flow Playground · also SQL Playground Play both roles. Request a device code in one tab as the attacker, open the verification page in a second tab as the victim, enter the code and grant …

Working on something like this? Ask me. Questions about your setup, or anything this article didn't cover. No account needed, private by default.

Only I read it. It isn't published unless you tick the box, and your email is never shown or added to any list. Privacy

Device code phishing is a way to take over an account without stealing a password and without a fake login page. The victim signs in on the real Microsoft page, completes real multifactor authentication, and the tokens go to the attacker. In 2026 it moved from a technique used by a few state-aligned groups to a product anyone could rent. This article explains the legitimate flow, how the abuse works, what happened in 2026, and how to find, block and respond to it in Microsoft Entra ID.

If you want to try this while you read, open the device code flow playground in another tab.

The Legitimate Flow in Brief
#

The OAuth 2.0 device authorization grant (RFC 8628) exists for devices that cannot show a browser or have no keyboard: a smart TV, a meeting room console, a command-line tool on a remote server. The device asks the authorization server for two codes. It keeps the long device_code to itself and shows the short user_code to the person, who types it into a browser on their phone or laptop and signs in there. Meanwhile the device polls the token endpoint until the sign-in is done.

I cover this flow next to the others in How OAuth 2.0 and OpenID Connect Actually Work. The detail that matters here is on the Microsoft identity platform: the device requests the codes from the /devicecode endpoint, and from that moment the user has 15 minutes to sign in.

Notice what the protocol does not check. Nothing ties the device that asked for the code to the person who types it in. The design assumes they are in the same room.

How Attackers Abuse It
#

The attacker simply plays the part of the device.

sequenceDiagram
  autonumber
  participant A as Attacker
  participant E as Microsoft Entra ID
  participant V as Victim
  A->>E: POST /devicecode
  E-->>A: device_code, user_code
  A->>V: Lure: "Enter this code to open the document"
  V->>E: Opens the real page microsoft.com/devicelogin
enters code, signs in, completes MFA A->>E: Poll POST /token E-->>A: access_token, refresh_token A->>A: Read mail and files, register a device, add inbox rules

Three properties make this hard to stop with the usual advice.

The page is real. The victim types the code at Microsoft’s own device login page. The URL is correct, the certificate is valid, and a password manager or a careful look at the address bar finds nothing wrong.

MFA is satisfied, not bypassed. The victim completes whatever the tenant requires: authenticator prompt, number matching, even a passkey. The sign-in is genuine. What the user cannot see is that they are approving a session for somebody else’s device. Phishing-resistant MFA protects against fake login pages by binding the credential to the real site. Here the site is the real one, so that binding does not help.

The attacker gets a refresh token. Access tokens on the Microsoft identity platform last about an hour, but refresh tokens default to 90 days and renew themselves on use. The attacker never learns the password and does not need it.

The sign-in screen does show which application is being authorised. Attackers therefore start the flow with the client ID of a well-known Microsoft application, so the prompt names something the user trusts.

What Happened in 2026
#

All dates below are as reported by the linked sources, as of November 2026.

The technique is not new. In February 2025 Microsoft described Storm-2372, a group it assessed with moderate confidence as aligned with Russian interests, active since August 2024. It built rapport over WhatsApp, Signal or Teams, then sent fake meeting invitations that asked for a device code. Microsoft later added that the group had switched to the client ID of the Microsoft Authentication Broker, which let it register its own device in the tenant and obtain a Primary Refresh Token.

That was targeted and manual, with one weakness: a code pasted into an email expires 15 minutes later, usually before the victim reads it.

In 2026 the weakness was engineered away. A phishing-as-a-service kit called EvilTokens appeared on Telegram in mid-February 2026. Sekoia’s analysis describes it as a turnkey device code phishing kit. On 20 March 2026 Huntress reported a campaign affecting more than 340 Microsoft 365 organisations in the US, Canada, Australia, New Zealand and Germany, with the first cases on 19 February and a surge from 2 March. The lures were ordinary: bid requests, document signing notices, voicemails. Huntress later linked the campaign to EvilTokens.

On 6 April 2026 Microsoft published Inside an AI-enabled device code phishing campaign. The key change: the device code is generated at the moment the victim clicks the link, so the 15 minutes start then. The landing page copies the code to the clipboard and polls the attacker’s backend every few seconds. Generative AI wrote lures tailored to the recipient’s role, and automation ran everything from code generation to post-compromise activity. Microsoft called it a significant escalation over the Storm-2372 campaign.

On 22 September 2026 Microsoft followed up with Unmasking EvilTokens. It names the developer of the kit as Storm-2992, a different actor from Storm-2372. It puts the damage at more than 12,000 inboxes across over 10,000 organisations, and reports that Microsoft’s Digital Crimes Unit and partners disrupted the infrastructure behind the service. Other kits use the same technique, so the disruption does not close the topic.

Microsoft also changed defaults. According to the security defaults documentation, all new Entra tenants created from 1 July 2026 block device code flow as part of security defaults. For tenants that use Conditional Access there is a Microsoft-managed policy named “Block device code flow”, which Microsoft creates in eligible tenants in report-only mode and later switches on. Neither guarantees that an existing tenant is covered. Check yours.

How to Find It in Your Logs
#

Entra sign-in logs record which protocol a sign-in used. In the SigninLogs table in Log Analytics and Microsoft Sentinel, the column is AuthenticationProtocol and the value for this flow is deviceCode (the others are none, oAuth2, ropc, wsFederation and saml20). In the Entra admin center the same thing is the Authentication Protocol filter with the option Device code.

In most organisations device code sign-ins are rare and come from the same few accounts. So the first query is an inventory, and the second looks for the pattern of an attack: a successful device code sign-in from an address that user has never signed in from before.

let known = SigninLogs
    | where TimeGenerated between (ago(30d) .. ago(1d))
    | where ResultType == "0"
    | distinct UserPrincipalName, IPAddress;
SigninLogs
| where TimeGenerated > ago(1d)
| where AuthenticationProtocol == "deviceCode"
| where ResultType == "0"
| join kind=leftanti known on UserPrincipalName, IPAddress
| project TimeGenerated, UserPrincipalName, IPAddress, Location,
          AppDisplayName, ResourceDisplayName, UserAgent

ResultType is a string in this table, and "0" means success. Microsoft’s own hunting queries also look for error code 50199 followed by a success in the same session, which is the pause while the user confirms the prompt.

The same logic in plain SQL works on any platform that holds an export of the sign-in log. Save this simplified sample as signin_log.csv:

TimeGenerated,UserPrincipalName,IPAddress,Location,AppDisplayName,AuthenticationProtocol,ResultType
2026-11-16 07:02:11,room-berlin@example.com,192.0.2.40,DE,Microsoft Teams Rooms,oAuth2,0
2026-11-16 08:14:52,alice@example.com,192.0.2.10,DE,Office 365 Exchange Online,oAuth2,0
2026-11-16 08:31:07,bob@example.com,192.0.2.22,GB,Microsoft Teams,oAuth2,0
2026-11-16 08:47:30,carol@example.com,192.0.2.31,DE,Office 365 SharePoint Online,oAuth2,0
2026-11-16 09:05:44,dave@example.com,192.0.2.45,DE,Microsoft Azure CLI,oAuth2,0
2026-11-16 09:20:18,erin@example.com,192.0.2.52,FR,Salesforce,saml20,0
2026-11-16 10:12:03,dave@example.com,192.0.2.45,DE,Microsoft Azure CLI,deviceCode,0
2026-11-16 13:40:26,room-berlin@example.com,192.0.2.40,DE,Microsoft Teams Rooms,deviceCode,0
2026-11-17 08:09:15,alice@example.com,192.0.2.10,DE,Office 365 Exchange Online,oAuth2,0
2026-11-17 08:22:41,carol@example.com,192.0.2.31,DE,Office 365 Exchange Online,oAuth2,0
2026-11-17 08:55:02,erin@example.com,192.0.2.52,FR,Microsoft Teams,oAuth2,0
2026-11-17 09:31:47,bob@example.com,192.0.2.22,GB,Office 365 Exchange Online,oAuth2,50126
2026-11-17 09:32:05,bob@example.com,192.0.2.22,GB,Office 365 Exchange Online,oAuth2,0
2026-11-17 10:03:58,dave@example.com,192.0.2.45,DE,Microsoft Azure CLI,deviceCode,0
2026-11-17 11:16:20,carol@example.com,203.0.113.77,US,Microsoft Office,deviceCode,50199
2026-11-17 11:17:02,carol@example.com,203.0.113.77,US,Microsoft Office,deviceCode,0
2026-11-17 11:19:33,carol@example.com,203.0.113.77,US,Office 365 Exchange Online,oAuth2,0
2026-11-17 11:48:10,carol@example.com,192.0.2.31,DE,Microsoft Teams,oAuth2,0
2026-11-17 14:27:39,erin@example.com,198.51.100.23,NL,Microsoft Authentication Broker,deviceCode,50199
2026-11-17 14:28:14,erin@example.com,198.51.100.23,NL,Microsoft Authentication Broker,deviceCode,0
2026-11-17 14:36:51,erin@example.com,198.51.100.23,NL,Microsoft Authentication Broker,oAuth2,0
2026-11-17 15:02:26,alice@example.com,192.0.2.10,DE,Office 365 SharePoint Online,oAuth2,0

The column names match SigninLogs; a real export has many more columns. The addresses come from documentation ranges, with 192.0.2.x standing in for the company’s offices. Drop the file into the SQL playground and it becomes a table called signin_log. In local DuckDB, run CREATE TABLE signin_log AS SELECT * FROM read_csv_auto('signin_log.csv'); first. DuckDB reads ResultType as a number here, so the SQL compares with 0 rather than '0'.

First the inventory:

SELECT UserPrincipalName, AppDisplayName,
       count(*)                  AS sign_ins,
       count(DISTINCT IPAddress) AS ips,
       min(TimeGenerated)        AS first_seen,
       max(TimeGenerated)        AS last_seen
FROM signin_log
WHERE AuthenticationProtocol = 'deviceCode'
  AND ResultType = 0
GROUP BY UserPrincipalName, AppDisplayName
ORDER BY sign_ins DESC;

Four accounts used device code flow. Two look routine: a developer with the Azure CLI and a meeting room account, both from office addresses. Then the detection:

SELECT d.TimeGenerated, d.UserPrincipalName, d.IPAddress,
       d.Location, d.AppDisplayName
FROM signin_log d
WHERE d.AuthenticationProtocol = 'deviceCode'
  AND d.ResultType = 0
  AND NOT EXISTS (
        SELECT 1
        FROM signin_log h
        WHERE h.UserPrincipalName = d.UserPrincipalName
          AND h.IPAddress = d.IPAddress
          AND h.ResultType = 0
          AND h.TimeGenerated < d.TimeGenerated
      )
ORDER BY d.TimeGenerated;

It returns two rows: carol from 203.0.113.77 and erin from 198.51.100.23. Both had only ever signed in from the office, neither had used device code flow before, and in both cases the same foreign address is active on the account minutes later. Erin’s row names the Microsoft Authentication Broker, the application Microsoft described in the Storm-2372 device registration variant. More query patterns of this kind are in SQL for Security: Finding Threats in Logs.

How to Prevent It
#

Microsoft’s recommendation is to get as close as possible to a unilateral block on device code flow. In Conditional Access (which needs Entra ID P1 or higher) the policy is:

  1. Users: include all users, exclude your emergency access accounts.
  2. Target resources: All resources.
  3. Conditions > Authentication Flows: set Configure to Yes and select Device code flow.
  4. Grant: Block access.
  5. Set Enable policy to Report-only, review the impact, then switch to On.

Run the inventory query before step 5, because some things do need the flow. Microsoft’s guidance for Teams devices is to put the room and shared-device resource accounts in a dedicated exclusion group and to exclude the Device Registration Service resource, so those devices can still register. The exception is scoped to the account, not to a scenario: an excluded account can use device code flow for anything. Keep the group small, owned and reviewed.

Developer tools are the other common dependency. Most command-line tools can sign in through a browser instead, and automation should use managed identities or workload identity federation.

One side effect to know about: Entra tracks sessions that began with device code flow, so later token refreshes in such a session are blocked by the policy as well. In the logs, the OriginalTransferMethod column shows this.

When a User Entered a Code
#

Assume the attacker holds a valid refresh token and act on that first.

  1. Disable the account and revoke its sessions. A password reset comes later. The attacker never had the password, and Microsoft’s revocation table shows that a password change does not revoke every kind of refresh token. An explicit revocation does. The order below follows Microsoft’s guide to revoking user access in an emergency:
Connect-MgGraph -Scopes "User.ReadWrite.All","Directory.AccessAsUser.All"
$User = Get-MgUser -Search UserPrincipalName:'carol@example.com' -ConsistencyLevel eventual
Update-MgUser -UserId $User.Id -AccountEnabled:$false
Revoke-MgUserSignInSession -UserId $User.Id
  1. Remember the hour. Revocation stops new tokens. An access token already issued can stay valid for up to an hour unless the application supports continuous access evaluation. That is why Microsoft recommends disabling the account as well.

  2. Check registered devices. List them with Get-MgUserRegisteredDevice -UserId $User.Id -All and disable or remove any the user does not recognise. A device registered by the attacker keeps access alive.

  3. Look for what was done. Inbox rules, mail forwarding, messages sent from the account, new authentication methods, file downloads. Microsoft observed attackers creating inbox rules and reading mail within hours.

  4. Then reset the password and re-enable. Revoke sessions once more afterwards if anything changed in between, and search the sign-in log for other users who received the same lure.

Common Mistakes
#

Believing MFA covers it. The user completes MFA. That is the attack. Only blocking the flow, or requiring a compliant device, removes the path.

Resetting the password and closing the ticket. The refresh token is the stolen credential. Without an explicit session revocation the attacker may keep access.

Training users to check the URL. The URL is correct. Teach one rule instead: never enter a code that someone sent you. A real device code is one you asked for, on a device in front of you.

Blocking without an inventory. Meeting rooms and build scripts stop working on a Monday morning and the policy gets switched off. Report-only first.

Broad exceptions. Excluding “all developers” recreates the problem for the accounts with the most access.

Leaving the policy in report-only. It logs what would have been blocked and blocks nothing.

Only watching for known attacker addresses. Hosting providers change. A first-time device code sign-in from an unfamiliar address is the durable signal.

Try It Yourself
#

A good exercise: run the two queries on the sample log, then write the alert rule in two sentences, as you would hand it to a colleague. The first sentence states the condition (which protocol, which result, compared against what history). The second says what the analyst does first when it fires. If you want more background on what the stolen tokens contain, read How JWT Tokens Actually Work.

Working on something like this? Ask me. Questions about your setup, or anything this article didn't cover. No account needed, private by default.

Only I read it. It isn't published unless you tick the box, and your email is never shown or added to any list. Privacy

Kevin Keller
Author
Kevin Keller
Personal blog: the business case for secure AI and data platforms, and the architecture blueprints to build them. Snowflake-related articles explore the art of the possible and are not official Snowflake solutions or endorsed by Snowflake unless explicitly stated. Opinions are my own. Content is meant as educational inspiration, not production guidance.
Share this article