Back to Blog
Identity Security10 min read2026-11-30

Microsoft 365 Device Code Phishing and AiTM Attacks: How to Detect and Stop MFA Bypass

Device code phishing, adversary-in-the-middle kits, illicit OAuth consent and token replay all take over Microsoft 365 accounts without breaking MFA. How each one works, what it looks like in Entra and Defender logs, and the controls that stop it.

A

Asfaleia Team

Security Consulting Team

Sections

Attackers now take over Microsoft 365 accounts without defeating MFA at all: they trick users into completing a real sign-in for them (device code phishing), relay the sign-in through a proxy and steal the session cookie (adversary-in-the-middle, or AiTM, phishing), get users to grant a malicious app access (illicit OAuth consent), or steal and replay tokens. The controls that stop them are blocking device code flow with Conditional Access, requiring phishing-resistant MFA such as passkeys or Windows Hello for Business, binding sessions to compliant devices, restricting user consent to applications, and revoking sessions quickly when something looks wrong. A password reset on its own does not end an attacker's session.

These techniques share one idea: the attacker wants the result of a successful sign-in (a token, a session cookie or a consent grant), and once they hold it, MFA plays no further part. This guide explains each technique at defender level, maps it to signals in Microsoft Entra ID, Defender XDR and Microsoft Sentinel, and ends with an incident response checklist.

Why MFA alone no longer stops Microsoft 365 account takeover

Push notifications, SMS codes and one-time passwords prove the user was present, not that they were talking to Microsoft rather than a phishing proxy. That gap is why Microsoft's own guidance now separates "MFA" from "phishing-resistant MFA", and why its built-in Conditional Access authentication strengths include a separate Phishing-resistant MFA strength containing only FIDO2 security keys and passkeys, Windows Hello for Business or platform credential, and multifactor certificate-based authentication.

Phishing-resistant MFA defeats AiTM proxies, but not device code or consent phishing, where the user really is signing in to Microsoft. Those need their own controls.

How the four techniques work

Device code phishing

The OAuth 2.0 device authorisation grant exists for devices without a proper keyboard, such as conference room systems and some command-line tools. The device shows a short code, the user enters it at a Microsoft sign-in page on another device, and the waiting device receives tokens.

In device code phishing, the attacker starts that flow themselves and sends the user the code, dressed up as something else: a meeting ID, a document access code or a verification step. The user enters it on the genuine Microsoft page, completes their normal MFA, and the attacker receives the access and refresh tokens. Nothing about the sign-in page is fake.

Microsoft Threat Intelligence published its analysis of a campaign by a group it tracks as Storm-2372 on 13 February 2025. Microsoft reported activity since August 2024 against government, NGOs, IT services, defence, telecommunications, health, higher education and energy organisations in Europe, North America, Africa and the Middle East. The actor built rapport over WhatsApp, Signal or Microsoft Teams, then sent fake meeting invitations in which the "meeting ID" was a device code, and afterwards searched mailboxes through Microsoft Graph for keywords such as "password" and "admin". In a 14 February 2025 update, Microsoft reported that the actor had moved to using the client ID of the Microsoft Authentication Broker, which let it register an attacker-controlled device in Entra ID and obtain a Primary Refresh Token.

Adversary-in-the-middle phishing kits

An AiTM kit puts a reverse proxy between the user and the real Microsoft sign-in page. The user sees the real login flow, relayed. They type their password and approve the MFA prompt; the proxy passes both to Microsoft and keeps the session cookie that Microsoft returns, which the attacker then loads into their own browser.

This is now sold as a service. Microsoft has published research on Tycoon2FA, one of the most widely used phishing-as-a-service kits of this kind. EvilProxy, first reported by Resecurity in 2022, was used in a 2023 campaign documented by Proofpoint that targeted Microsoft 365 accounts, including senior executives. After a successful AiTM sign-in, attackers typically register a new MFA method, create inbox rules to hide replies, and use the mailbox for invoice fraud or further phishing.

Here the attacker registers an application, often with a convincing name and logo, and sends users a link to the standard Microsoft consent screen. If the user clicks Accept, the app receives delegated permissions such as reading mail or files, often with offline access. No password is captured, and a password reset does not remove the grant; the grant or the app's service principal has to be removed.

Token theft and replay

Tokens can also be stolen from the endpoint, typically by infostealer malware harvesting browser cookies and cached tokens, then replayed from another machine. Microsoft Entra ID Protection's Anomalous token detection looks for this, as does Unfamiliar sign-in properties on non-interactive sign-ins, which Microsoft notes "deserves increased scrutiny due to the risk of token replay attacks".

TechniqueWhat the attacker obtainsDefeated by phishing-resistant MFA?Primary control
Device code phishingAccess and refresh tokensNoBlock device code flow in Conditional Access
AiTM phishing kitSession cookieYesPhishing-resistant MFA, compliant device
Illicit consent grantDelegated app permissionsNoRestrict user consent, admin consent workflow
Token theft from endpointCookies, refresh tokensPartlyToken protection, endpoint security, CAE

How to detect each technique

Device code sign-ins in Entra logs

In the Entra sign-in logs, filter on Authentication protocol = Device code. In Microsoft Sentinel or Log Analytics, the SigninLogs table holds the same information in the AuthenticationProtocol column, with the value deviceCode. A simple starting query:

SigninLogs
| where AuthenticationProtocol == "deviceCode"
| where ResultType == "0"
| project TimeGenerated, UserPrincipalName, AppDisplayName, IPAddress, Location, UserAgent

Most organisations have very few legitimate device code users, so every success outside a known list is worth reviewing. The Original transfer method property in sign-in details shows when a later token refresh descends from a device code sign-in. Also watch for new devices registered shortly after a device code sign-in, as Storm-2372 did.

AiTM and token replay signals

Defender XDR raises session cookie theft alerts, including Stolen session cookie was used and Authentication request from AiTM-related phishing page, and its automatic attack disruption can revoke a stolen session when it has high confidence. Entra ID Protection has a user risk detection called Attacker in the Middle, which Microsoft describes as high precision and which raises the user to high risk; note that Microsoft lists Microsoft 365 E5 with EMS E5 as its licence requirement. Other useful detections are Anomalous token, Unfamiliar sign-in properties, Anonymous IP address and Microsoft Entra threat intelligence. Also look for a sign-in followed quickly by new MFA method registration (Suspicious credential addition) or new inbox rules.

In the Entra audit logs, review Consent to application, Add service principal and Add delegated permission grant events, particularly for unverified apps requesting mail, file or offline access. A periodic review of enterprise applications and their granted permissions catches what real-time detection missed.

How to stop them: controls that work

Block or tightly scope device code flow

Conditional Access has an Authentication flows condition with two options: Device code flow and Authentication transfer. Microsoft recommends getting "as close as possible to a unilateral block" on device code flow. The approach is a policy targeting all users and all resources, with Conditions > Authentication flows > Device code flow and the grant control Block access, first in report-only mode to find legitimate use. Exclude break-glass accounts, and scope any real exceptions narrowly by user group, device platform and network location.

Microsoft also ships a Microsoft-managed Conditional Access policy named Block device code flow, which appears in the tenant in report-only mode before Microsoft enables it. Check its state rather than assuming it is on. If you use device code flow for device registration, Microsoft documents that authentication flows policies targeting all resources also apply to the Device Registration Service, so plan that exclusion deliberately.

Require phishing-resistant MFA

Passkeys (FIDO2), Windows Hello for Business and multifactor certificate-based authentication are bound to the real sign-in origin, so an AiTM proxy cannot relay them. Use the built-in Phishing-resistant MFA strength in Conditional Access, starting with administrators and high-value users, then expanding. Our guide to passkeys and passwordless authentication covers rollout. Restrict who can register security information and devices, so a phished session cannot add a weaker method.

Bind sessions to devices

Requiring a compliant or Entra hybrid joined device stops AiTM proxies and most token replay, because the attacker's machine cannot present a managed device identity. Token protection, a Conditional Access session control, goes further by accepting only device-bound sign-in session tokens. Microsoft currently documents it for native apps accessing Exchange Online, SharePoint Online and Teams, generally available on Windows, with more limited Apple and browser support. Pilot it in report-only mode.

Under Enterprise apps > Consent and permissions > User consent settings, either disable user consent or allow it only for apps from verified publishers and permissions you classify as low impact. Then enable the admin consent workflow (Users can request admin consent to apps they are unable to consent to) so users have a legitimate route to request apps. Existing grants are not affected by changing the setting, so review them separately.

Shorten the attacker's window

Continuous Access Evaluation (CAE) lets Exchange Online, SharePoint Online and Teams act on critical events such as account disablement, password change, refresh token revocation and high user risk in near real time, though Microsoft notes propagation can take up to 15 minutes. Pair CAE with risk-based Conditional Access policies and block legacy authentication.

For email-side controls that stop the lure arriving, see our email security and phishing protection guide.

Incident response checklist for a suspected compromise

Work through these in order, and record what you find as you go:

Scope the sign-ins. Review interactive and non-interactive sign-in logs for the user, checking authentication protocol, IP address, user agent, application and the Original transfer method field. Identify the first suspicious session.
Revoke sessions. Use Revoke sessions on the user in the Entra admin center, or the Microsoft Graph revokeSignInSessions action. Do this alongside the password reset, not instead of it.
Reset the password and review authentication methods. Remove any MFA methods, phone numbers or passkeys the user did not register. Consider marking the user as compromised in Entra ID Protection so risk-based policies apply.
Check registered devices. Delete devices the user does not recognise, especially any registered around the time of a device code sign-in.
Review the mailbox. Look for new inbox rules, forwarding, delegated access and sent messages, including internal phishing. Mailbox audit data such as MailItemsAccessed shows what was read.
Review OAuth grants. Remove unexpected consent grants and investigate the service principals behind them across the tenant, not just for this user.
Hunt for other victims. Search for other users who received or clicked the same lure, signed in from the same infrastructure or completed device code sign-ins in the same period.
Close the gap. Apply the control that would have stopped this attack: block device code flow, enforce phishing-resistant MFA, restrict consent.
Assess notification duties. Decide with legal and compliance teams whether data protection, regulatory or contractual notification obligations apply.

If the attacker used the mailbox for payment fraud, follow our business email compromise prevention guide to contact affected partners and stop pending payments.

Frequently asked questions

Does MFA stop device code phishing?

No. In device code phishing the user signs in on the genuine Microsoft page and completes their own MFA, so even a passkey is satisfied. The effective control is a Conditional Access policy that blocks the device code authentication flow, with narrow, documented exceptions only where it is genuinely needed.

What is the difference between AiTM phishing and ordinary credential phishing?

Ordinary phishing captures a password, which MFA can still stop. An AiTM kit relays the whole sign-in through a proxy, including the MFA step, and captures the session cookie issued afterwards. Phishing-resistant MFA and compliant device requirements defeat it because the proxy cannot complete or replay those checks.

Is resetting the password enough after an account takeover?

No. Microsoft advises revoking sessions as well, because a stolen session cookie or refresh token can outlive the password change, and consent grants to malicious apps are not removed by a reset. Revoke sessions, review MFA methods, devices and app grants, and check the mailbox for persistence such as inbox rules.

How can we find device code sign-ins in our tenant?

In the Entra admin center, filter sign-in logs on Authentication protocol set to Device code. In Microsoft Sentinel, query the SigninLogs table where AuthenticationProtocol equals deviceCode. A report-only Conditional Access policy targeting device code flow also shows who a block would affect.

Which Microsoft licences do these controls need?

Conditional Access, including the authentication flows condition and authentication strengths, needs Microsoft Entra ID P1. Risk-based policies and most Entra ID Protection detections need Entra ID P2, and some detections such as Attacker in the Middle are listed by Microsoft with Microsoft 365 E5 requirements. Check Microsoft's current licensing documentation for your exact plan.

Asfaleia Tech is an NTRA Tier 1 accredited cybersecurity company that works with organisations in Egypt, Saudi Arabia, the wider Middle East and worldwide. We test and harden Microsoft 365 tenants against these techniques through a Microsoft 365 security assessment and an Entra ID security review, build detections in Sentinel and Defender XDR, measure user resilience with a phishing assessment, and support incident response when an account has already been taken over. Book a free 30-minute consultation to discuss your tenant.

Tags

#Microsoft 365#Entra ID#Device Code Phishing#AiTM#Conditional Access#Phishing-Resistant MFA#Incident Response

Downloadable-style takeaway

Use this as a working assessment checklist.

Pull the headings into your next security review, assign owners, and mark each section as ready, partial, or missing.

A

Written by

Asfaleia Team

Security Consulting Team

Written by the Asfaleia Tech Security Team, combining field experience across offensive testing, detection engineering, incident readiness, and compliance evidence.

Ready to Strengthen Your Security?

Let's discuss how Asfaleia-Tech can help protect your organization.