Research

Device code phishing in Entra ID: what the sign-in logs actually show

ByInvictus CERT

PublishedUpdated

  • T1566 Phishing
  • T1078 Valid Accounts
  • T1528 Steal Application Access Token
LinkedInXSend to your team
On this page

Device code flow exists so a device without a browser — a TV, a CLI, a conference-room display — can sign a user in. The device shows a short code, the user types it on a phone, and the device receives tokens. Nothing about that requires the two to be near each other, which is exactly what makes it useful to an attacker.

What the sign-in logs record

Two rows matter, and they are not adjacent. The first is the authentication itself, logged against the client application the attacker chose. The second is the token redemption. In a legitimate flow both come from the same network within a couple of minutes. In a phished one the redemption arrives from the attacker.

KQLDevice code sign-ins where the redemption came from a different address
SigninLogs
| where AuthenticationProtocol == "deviceCode"
| extend Redeemed = todatetime(CreatedDateTime)
| project UserPrincipalName, AppDisplayName, IPAddress, Redeemed, ResultType
| summarize Addresses = make_set(IPAddress), Attempts = count()
    by UserPrincipalName, bin(Redeemed, 1h)
| where array_length(Addresses) > 1

The query is deliberately loose. Tightening it on AppDisplayName is tempting and wrong — the application is the attacker’s choice, not a constant, and pinning it is how a hunt stops finding the next campaign.

Why MFA did not help

Conditional Access policies are commonly scoped to interactive sign-ins. The device code flow is not one. An account with MFA enforced everywhere a user would notice can still be taken over here, and the sign-in log will show the policy as not applied rather than as failed — which reads, at a glance, like nothing happened.

The policy did not fail. It was never evaluated. That distinction is the whole finding.

What to do about it

Block the device code flow for everyone who does not demonstrably need it, then allow it back by exception. In most estates the genuine need is a handful of shared devices and a few engineers, which is a small enough list to maintain by hand.

Cited by