Device Code Phishing: Recognising and Preventing Device Code Flow Abuse
Device code phishing is a social engineering technique. Other names for it are device code flow abuse and OAuth device authorisation phishing.
In this attack, the threat actor starts a legitimate OAuth 2.0 device authorisation request to an identity provider, and gets a genuine short code. Then the threat actor tricks the victim, and the victim enters that code on the real sign-in page of the identity provider. The victim authenticates with their own credentials and approves MFA as normal. But the request that waits for this approval belongs to the attacker. Thus the identity provider issues the access and refresh tokens to the infrastructure of the adversary, not to the victim.
This attack relates to the MITRE ATT&CK techniques T1528 (Steal Application Access Token) and T1621 (Multi-Factor Authentication Request Generation). MITRE ATT&CK tracks the rogue device registration that follows as T1098.005 (Account Manipulation: Device Registration).

Why It Matters
Device code phishing does not exploit a vulnerability, and it does not deliver malware. All of the attack occurs in the identity layer, in the cloud. For this reason, endpoint tools alone rarely see it.
The technique defeats the controls that organisations depend on most:
- The victim signs in on a genuine Microsoft page. Thus link rewrite, URL reputation and domain-based email controls have nothing suspicious to flag.
- The victim satisfies MFA legitimately, and the attacker does not intercept it. This includes phishing-resistant methods. Passkeys do a check that the domain is genuine, and the domain is genuine. The attack targets authorisation, which occurs after authentication is successful.
- The stolen access and refresh tokens already have an MFA claim. Thus the access of the adversary can stay valid after a password reset. To contain the attack, you must revoke sessions and refresh tokens. A password change alone is not sufficient.
- After the threat actor gets a valid authentication token, they can do post-compromise activities. Examples are Microsoft Graph reconnaissance, email exfiltration and persistence. Other researchers also saw cases where threat actors registered new devices to generate a Primary Refresh Token (PRT). The PRT gave them longer-term access to the compromised account.
How It Works
The chain is consistent in almost all campaigns, regardless of the lure theme or kit:

- Delivery. The victim receives a lure through email, Teams chat, a QR code, or an attachment (PDF, HTML or SVG). Sometimes the attachment is password-protected specifically to defeat scans. Themes include shared documents, e-signature requests (for example, DocuSign), invoices, RFPs, voicemail notifications and IT or service desk messages.
- The lure page. The landing page pretends to be a portal for shared documents or for verification. It shows a "verification code". In observed campaigns, the page impersonated a shared legal document, a DocuSign or signature request, or a voicemail notification. It told the user to copy the code and verify their identity on the real Microsoft device login page.
- Dynamic code generation. A device code is valid for only 15 minutes. Thus modern kits generate the code on demand, at the moment when the victim opens the page. To do this, the kit relays a request to the device authorisation endpoint of Microsoft. As a result, the countdown starts when the victim arrives, not when the email was sent. Many kits also copy the code directly to the clipboard of the victim to make the attack faster.
- User authentication. The page sends the victim to the genuine microsoft.com/devicelogin. The victim pastes the code, enters their credentials and approves MFA. The victim does not know it, but this completes the sign-in that the attacker started. At the same time, the kit polls its backend every few seconds, and waits for the authentication to succeed.
- Token issuance. Microsoft issues the access and refresh tokens to the party that started the flow, which is the threat actor. Usually, the victim goes to a bland placeholder page and notices nothing.
- Post-compromise. Attackers move quickly to make the access durable and quiet. They register rogue devices, often within a minute of the sign-in and from hosting-provider IPs. They get a PRT through the Authentication Broker. They create hidden inbox rules to hide replies and bounces, and they run Microsoft Graph reconnaissance to map the organisation. They exfiltrate mail, and they send the next wave of phishing from the compromised mailbox.
How to Identify It
The Key Principle: Users should enter a device code only when they started the authentication process themselves. Users should treat a code from another person through email, chat or phone as suspicious.
Key warning signs include:
- A request to enter a device code at a URL such as
https[:]//login.microsoftonline[.]com/common/oauth2/deviceauthormicrosoft.com/devicelogin. The request says that this gives access to a shared document or completes a verification step. - A code shown on one site that must be entered on another.
- Microsoft authentication prompts that refer to an unexpected application.
- Urgency about a code that will expire soon.
- Requests to enter an email address before the device code is generated.
Traditional URL checks can be insufficient, because authentication can occur on a legitimate Microsoft page. Thus awareness should focus on two things. Did the user start the authentication request? Does the user recognise the application that they authorise?
The image that follows shows the attack from the perspective of the victim:

Detection
The attack occurs in the identity layer, so the signals are in that layer. The signals that follow apply across campaigns.
Sign-In Log Signals (Entra ID)
- Error code 50199 ("user confirmation is required for this request"). Within minutes, a successful sign-in follows, with "MFA requirement satisfied by claim in the token". This pattern, a failure and then a success, is the signature of a victim who stops to enter the code.
- Sign-ins from IP addresses that are associated with VPN or proxy services. Sign-ins from an IP with no other tenant users are especially significant, because this removes the benign remote-worker explanation.
- Device code sign-ins that target the Device Registration Service resource. This is the sign of Authentication Broker and PRT escalation.
Audit Log Signals (Entra ID and Microsoft 365)
- The Device Registration Service adds new devices. This is especially suspicious for several devices in a short time. The same applies to devices from unfamiliar IPs, or devices with generic default hostnames. A typical pattern is one or more generic DESKTOP-* devices registered within one minute.
- Changes to the MFA method or the Authenticator app, close in time to unusual sign-ins.
- New inbox rules, particularly rules with empty or special-character names. Look for rules that hide relevant emails from the user. For example, a rule can move mail to obscure folders, mark it as read or delete it. Rule names can look unusual, or they can look completely legitimate. Also review rules that were created or changed through Exchange PowerShell. This is particularly important when parameters such as
AlwaysDeleteOutlookRulesBlobsuppress the warning that usually shows when Inbox rules change. - MailItemsAccessed and Send operations that do not match the normal client, location or volume of the user. These operations can show mail exfiltration. They can also show that the attacker uses the mailbox to send the next wave of phishing.
Correlation, Not Any Single Alert: At the identity provider layer, a device code grant that a phishing attack started looks identical to a legitimate grant. Thus these signals do not give a single deterministic rule. They set a baseline and show outliers. Correlation across several signals turns weak signals into a confident case.
Secured with SenseOn
Here, the SenseOn Platform made three things possible. Strong correlation of signals detected the compromise. An effective response through integrations revoked user sessions with the Entra ID integration. A detailed, high-confidence follow-up used the data from the SenseOn Universal Sensor and the ingested telemetry from integrations to fully investigate the Incident. Together, these different steps make a fast and decisive response possible where it matters.
How to Block Device Code Flow with Conditional Access Policy
The most effective way to prevent device code phishing attacks is with Conditional Access. You can create a policy that blocks device code authentication completely. This policy stops the full authentication flow.
Audit Before You Block: Evaluate the use of device code authentication before you implement such a policy. In some environments, device code authentication can be legitimate. SenseOn recommends a policy that audits the current use of device code flow, to find out if device code flow is still necessary. Before you block device code authentication across most devices, add exclusions only where necessary. Permit device code flow only in well-documented and appropriately secured use cases, such as legacy tools that you cannot update.
To block device code flow, use the Conditional Access policy that follows:
- Sign in to the Microsoft Entra admin center as at least a Conditional Access Administrator.
- Go to Entra ID > Conditional Access > Policies.
- Select New policy.
- Under Assignments, select Users or workload identities.
- Under Include, select the users that you want in scope for the policy (All users is recommended).
- Under Exclude, select Users and groups. Then select the emergency access or break-glass accounts of your organisation, and any other necessary users. Audit this exclusion list regularly.
- Under Target resources > Resources (formerly cloud apps) > Include, select the apps that you want in scope for the policy (All resources (formerly 'All cloud apps') is recommended).
- Under Conditions > Authentication Flows, set Configure to Yes.
- Select Device code flow.
- Select Done.
- Under Access controls > Grant, select Block access.
- Choose Select.
- Make sure that your settings are correct. Then set Enable policy to Report-only.
- Select Create to enable your policy.
Use policy impact or report-only mode to make sure that the settings are correct (refer to External Resources). Then move the Enable policy toggle from Report-only to On.
Remediation Steps
If your company was involved in the same attack, the SenseOn SOC team recommends the steps that follow:
- Reset the password of the user. Revoke the sessions of the user in Microsoft 365.
- Disable the user account as a precaution until the investigation is complete.
- Disable or remove the registered devices.
- Force the user to register for MFA again.
- Block Indicators of Compromise (IOCs) with firewall rules. This prevents more interaction with known-bad infrastructure.
- Educate users on device code phishing threats.
External Resources
- Microsoft blog post about device code phishing
- Microsoft documentation about Conditional Access and authentication flows
- Microsoft documentation about how to block authentication flows with a Conditional Access policy
- Microsoft documentation about how to analyse the impact of a Conditional Access policy