admin_hub

sysop@hub:~/explainers/device-code-phishing-explained$

device-code-phishing-explained

How device code phishing gets tokens past MFA

The attacker starts a sign-in for a device without a keyboard and lets the victim finish it on the real Microsoft page. No fake website is involved.

Read the steps as text
  1. Requests a device code. The attacker's script asks Entra ID to start a device sign-in for a well-known Microsoft app. Entra ID answers with a short user code and a hidden device code. Both are valid for about 15 minutes.
  2. Sends the lure. The victim gets a message by mail, Teams or a messenger: a meeting invitation or a document, with the instruction to open microsoft.com/devicelogin and enter the code.
  3. Enters the code on the real page. The victim opens the genuine Microsoft address and types the code. The address bar is correct, the certificate is correct, there is nothing to spot.
  4. Sign-in and MFA. Entra ID asks the victim to sign in. Password, authenticator prompt, even a passkey: everything is real and everything succeeds. The page names the app, not the person who started the request.
  5. Asks whether the code was used. Meanwhile the attacker's script asks the token endpoint every few seconds, using the hidden device code.
  6. Tokens issued. As soon as the victim has finished, Entra ID hands an access token and a refresh token for the victim's account to whoever holds the device code. This is the moment the attacker wins. The sign-in happened on the real site, so phishing-resistant MFA did not help. The refresh token keeps working for weeks.
  7. Reads mail and files. The attacker uses the tokens against Exchange, SharePoint and Graph, and trades the refresh token for tokens to other services. A password reset alone does not end this.

How to defend

  • Block the device code flow with Conditional Access: under Conditions, Authentication flows, select Device code flow and block it for all users. Most organisations never use it.
  • If something needs it, such as meeting room devices or a command-line tool on a server, allow it only for those accounts and from your own locations.
  • A policy that requires a compliant or hybrid joined device also stops the attack, because this flow carries no device identity.
  • Teach one rule: never enter a code that someone else sent you. A real device code is shown on a device you are holding.
  • Hunt for it: in the sign-in logs the authentication protocol is "deviceCode". Any hit for a normal office user deserves a look.
  • If it happened: revoke the user's sessions, then reset the password, then review what the mailbox did. Revoking is the step that kills the refresh token.

Find it in the sign-in logs (KQL)

SigninLogs
| where TimeGenerated > ago(30d)
| where AuthenticationProtocol == "deviceCode"
| project TimeGenerated, UserPrincipalName, AppDisplayName, IPAddress, Location, ResultType
| order by TimeGenerated desc

Why this works when AiTM phishing does not

AiTM phishingDevice code phishing
Where the victim signs inOn a look-alike site that relays to MicrosoftOn the real Microsoft page
What the attacker getsThe session cookieAccess and refresh tokens
Stopped by passkeys and FIDO2Yes, the key refuses the wrong domainNo, the domain is right
Stopped by requiring a compliant deviceYesYes
Most direct defencePhishing-resistant MFABlock the device code flow

Related: Glossary: Device code phishingAiTM phishing explainedCA analyzerAttack mapCompromised account checklist