Skip to content
All posts

Detection & Response

Detecting Stolen-Session Sign-ins in Microsoft Entra ID

A replayed session already carries MFA. We built a lab of Entra sign-in logs, tuned a detection from 15 false positives to none, and show what stops replay.

HHHuzaifa HafeezChief Technology Officer

· 12 min read

On this page

A user passes MFA at nine in the morning. At twenty to two, someone else is reading their mailbox from a server in another country, and Microsoft Entra ID records every one of those requests as "MFA requirement satisfied by claim in the token". Nobody was phished for a password that day. The attacker had the session.

Stolen-session sign-ins are now one of the main ways into Microsoft 365. Infostealer malware copies browser cookies; adversary-in-the-middle (AiTM) phishing kits capture them in transit. Either way, MFA has already happened, so the controls most teams rely on stay quiet. This post explains why replay works, then walks through a lab we built: a week of generated Entra sign-in logs with realistic noise and two stolen-session attacks, the first detection rule we wrote (which failed), the tuned version, and the controls that stop replay rather than just spotting it.

Why MFA does not stop a stolen session

MFA protects the moment of sign-in. After that, Entra ID hands the browser or app artefacts that prove "this user already signed in with MFA": session cookies for login.microsoftonline.com, refresh tokens for apps, and short-lived access tokens for each resource. Each later request presents one of those artefacts instead of the user's factors. The MFA result travels inside them as a claim, which is why the sign-in log says the requirement was "satisfied by claim in the token".

By default most of these artefacts are bearer credentials: whoever holds them can use them. Nothing in a plain session cookie ties it to the laptop it was issued to. That is the one assumption that turns out to be wrong in most tenants: "if the user did MFA, the session belongs to the user".

There are two common ways to get the session:

  • Infostealer on the endpoint. Malware reads the browser's cookie store and uploads it. The user's real sign-in happened on their real, managed device. Only the replay comes from somewhere else.
  • AiTM phishing. The user signs in through a reverse proxy that looks like the Microsoft login page. The proxy relays the password and the MFA approval to Microsoft, then keeps the session cookie that comes back (MITRE T1557). Here even the first sign-in of the session comes from attacker infrastructure.

Microsoft describes both routes and the matching defences in its token protection guidance and its token theft playbook.

Where replay shows up in the logs

Entra ID writes two user sign-in tables when you stream them to Log Analytics or Microsoft Sentinel. SigninLogs holds interactive sign-ins, where the user typed or approved something. AADNonInteractiveUserSignInLogs holds the silent ones, where a client used a token to get another token. A replayed session lives almost entirely in the second table. In our engagements the non-interactive table is the one most often left out of the SIEM, because it is the noisiest and it costs more to ingest.

The fields that matter, from the SigninLogs schema:

FieldWhy it matters for replay
SessionIdTies every sign-in in one Entra session together, interactive and non-interactive. The anchor for the whole detection.
IPAddress, AutonomousSystemNumberWhere each request came from. The ASN (the network operator's number) is steadier than the IP for mobile users.
DeviceDetail.deviceId, isCompliantPresent when a registered or joined device authenticated. A copied cookie replayed elsewhere does not bring the device with it.
DeviceDetail.operatingSystem, browserA coarse client fingerprint. Less reliable than the device ID, because attackers can copy a user agent.
AuthenticationDetailsShows whether MFA was performed in this request or carried in from the token.
IsInteractiveSeparates the user's own sign-ins from silent token use.

Entra ID Protection already has detections for this, such as Anomalous token, Unfamiliar sign-in properties and Attacker in the Middle. Microsoft's own risk detection reference lists them as Premium: they need Entra ID P2, and Attacker in the Middle needs Microsoft 365 E5 with EMS E5. Without P2 you see only "Additional risk detected" with no detail. The same page warns that Anomalous token still produces some false positives at low and medium risk. A rule you own, on logs you collect, is worth having either way.

Building the lab

We could not attack a real tenant, and we would not use real users' logs, so we generated them. A short Python script (gen_logs.py) writes one working week of sign-ins for six invented users at example.com, using the same field names and nesting as the Entra tables. Public IPs come from the 192.0.2.0/24 documentation range and ASNs from the private-use range (64512 to 65534), so nothing points at a real network.

Normal traffic follows a pattern we see in most Microsoft 365 tenants: one interactive MFA sign-in each morning, then silent token refreshes every 45 to 90 minutes until evening. On top of that we added the noise that breaks naive rules:

  • Omar takes his laptop home at four. Same device, same session, new ISP.
  • Hina uses Outlook on her phone. The carrier IP changes all day, and she moves between mobile data, office Wi-Fi and home.
  • Bilal switches to the corporate VPN every afternoon.
  • Zain's browser auto-updates at lunchtime, so his user-agent string changes mid-session.

Then two attacks, written to match the two routes above:

  • Scenario A, infostealer. Amina signs in normally from the office on Thursday. At 13:41 her session is replayed from a hosting provider (AS64600). The attacker copies her exact user-agent string, so the browser and operating system look identical. Her real laptop keeps using the same session in parallel.
  • Scenario B, AiTM. On Friday Sara signs in through a phishing proxy (AS64610). The proxy forwards her real browser's user agent, and she completes MFA. Three minutes later the attacker uses the session from a different host (AS64620) with a different browser.
lab@futaqsec: ~/entra-replay
$ python3 gen_logs.py
wrote 256 sign-in events, 31 sessions, 6 users
Generating the lab data set.

Here is Amina's Thursday session, one line per sign-in. The replay is easy to see once you sort by SessionId. It is invisible if you only look at interactive sign-ins, because there is only one.

lab@futaqsec: ~/entra-replay
$ python3 extra.py
2026-11-05T09:18:00Z SigninLogs 192.0.2.10 AS64520 dev=d-amina-01 compliant=true Office 365 Exchange Online MFA successfully completed
2026-11-05T12:36:00Z AADNonInteractiveU 192.0.2.10 AS64520 dev=d-amina-01 compliant=true Office 365 SharePoint Online MFA requirement satisfied by claim in the token
[!] 2026-11-05T13:41:00Z AADNonInteractiveU 192.0.2.200 AS64600 dev=- compliant=false OfficeHome MFA requirement satisfied by claim in the token
[!] 2026-11-05T13:48:00Z AADNonInteractiveU 192.0.2.200 AS64600 dev=- compliant=false Office 365 Exchange Online MFA requirement satisfied by claim in the token
2026-11-05T13:49:00Z AADNonInteractiveU 192.0.2.10 AS64520 dev=d-amina-01 compliant=true Microsoft Teams MFA requirement satisfied by claim in the token
[!] 2026-11-05T13:55:00Z AADNonInteractiveU 192.0.2.200 AS64600 dev=- compliant=false Office 365 Exchange Online MFA requirement satisfied by claim in the token
[!] 2026-11-05T14:02:00Z AADNonInteractiveU 192.0.2.200 AS64600 dev=- compliant=false Office 365 SharePoint Online MFA requirement satisfied by claim in the token
2026-11-05T14:53:00Z AADNonInteractiveU 192.0.2.10 AS64520 dev=d-amina-01 compliant=true Office 365 SharePoint Online MFA requirement satisfied by claim in the token
Amina's session on 5 November, from generated lab data. Output trimmed to the replay window.

Three things stand out. The session ID is the same throughout. The replayed requests carry the MFA claim but no device ID and no compliance. And the real user and the attacker take turns in the same session, which is what "replay" looks like in practice: nobody kicks anybody out.

The first rule we wrote, and why it failed

The obvious idea: a session should not change networks. For each SessionId, take the first sign-in as the origin and flag any later sign-in from a different ASN.

lab@futaqsec: ~/entra-replay
$ python3 detect.py
== rule 1, first version (any ASN change in a session): 17 session(s) flagged, 43 sign-in(s), 2/2 attacks found, 15 false positive(s)
[+] [email protected] session 40c905e4 origin AS64520 -> AS64600 192.0.2.200 device='-' Windows 10/Edge 142 first 2026-11-05T13:41:00Z (+3 more)
[-] [email protected] session 141db6b7 origin AS64520 -> AS64521 192.0.2.20 device='d-bilal-01' Windows 10/Edge 142 first 2026-11-05T14:08:00Z (+2 more)
# ... four more Bilal sessions: corporate VPN every afternoon
[-] [email protected] session 059f4850 origin AS64540 -> AS64520 192.0.2.10 device='d-hina-ios' Ios 18/Outlook Mobile first 2026-11-02T12:40:00Z (+1 more)
# ... four more Hina sessions: phone joins office Wi-Fi
[-] [email protected] session 46c561e7 origin AS64520 -> AS64530 192.0.2.60 device='d-omar-01' Windows 10/Edge 142 first 2026-11-05T16:51:00Z (+0 more)
# ... four more Omar sessions: laptop goes home
[+] [email protected] session 85b9889c origin AS64610 -> AS64620 192.0.2.220 device='-' MacOs/Chrome 141 first 2026-11-06T10:15:00Z (+4 more)
Rule 1, first version, against the full week. [+] is a known attack session, [-] a false positive. Repeated lines trimmed.

It caught both attacks. It also raised 15 false positives in a week from six users, which in a real tenant of a few hundred people becomes a queue nobody reads. Every false positive had something in common: the network changed, but the device did not. Same device ID, same operating system, same browser.

We also tried comparing the full user-agent string within a session (extra.py prints full UserAgent string change in a session flags users: ['[email protected]', '[email protected]']). That flagged Sara (correct) and Zain (his browser updated), and it missed Amina completely, because the attacker had copied her user agent. User-agent strings are the attacker's to choose. A device ID from a registered device is not.

The tuned rule

The tuned rule asks two questions about each later sign-in in a session. Did the network change to something that is not our own office or VPN? And did the client change: either the device ID disappeared or changed, or the operating system or browser family is different? Both must be true.

CORP_ASNS = {"64520", "64521"}       # office and corporate VPN egress

def rule_v2(first, r):
    a, b = fp(first), fp(r)
    # Same network, or our own egress: not interesting
    if b["asn"] == a["asn"] or b["asn"] in CORP_ASNS:
        return False
    # The session started on a known device and that device is no longer present
    device_lost = bool(a["device"]) and b["device"] != a["device"]
    # Or the coarse client fingerprint changed (browser family, not full version)
    client_changed = (a["os"], a["browser"]) != (b["os"], b["browser"])
    return device_lost or client_changed

Comparing the browser family ("Edge", not "Edge 142.0.3595.80") is deliberate. It keeps Zain's auto-update quiet.

AiTM needs one more rule, because the origin of Sara's session is already the attacker's proxy. Rule 2 looks at interactive sign-ins only: a successful MFA from a network this user has never used before, with no device ID, for a user whose sign-ins normally come from a managed device.

lab@futaqsec: ~/entra-replay
$ python3 detect.py
== rule 1, tuned (ASN change + client/device change, corporate egress excluded): 2 session(s) flagged, 9 sign-in(s), 2/2 attacks found, 0 false positive(s)
[+] [email protected] session 40c905e4 origin AS64520 -> AS64600 192.0.2.200 device='-' Windows 10/Edge 142 first 2026-11-05T13:41:00Z (+3 more)
[+] [email protected] session 85b9889c origin AS64610 -> AS64620 192.0.2.220 device='-' MacOs/Chrome 141 first 2026-11-06T10:15:00Z (+4 more)
== rule 2 (new network + unmanaged interactive MFA): 1 sign-in(s)
[+] [email protected] 2026-11-06T10:12:00Z AS64610 192.0.2.210 device='-' app=OfficeHome step='MFA successfully completed'
Tuned rule 1 and rule 2 on the same week of data. Output trimmed to these two rules.

Both attacks found, every replayed sign-in flagged, and no false positives on this data. Rule 2 fires three minutes before the attacker's first replay, on the phishing sign-in itself. That is the window in which revoking the session stops the attack before it starts.

The same logic in KQL

We did not have a live Sentinel workspace for this lab, so we tested the logic in Python on the generated logs (above) and translated it to KQL. Treat the KQL as a starting point and run it in report-only form for a week before you alert on it.

// Rule 1: a session that moves to a new network AND loses its device or changes client
let corpAsns = dynamic(["64520", "64521"]);   // replace with your office and VPN egress ASNs
let lookback = 1d;
let signins = union
    (SigninLogs | where TimeGenerated > ago(lookback)),
    (AADNonInteractiveUserSignInLogs | where TimeGenerated > ago(lookback))
| where ResultType == "0" and isnotempty(SessionId)
| extend DD = parse_json(tostring(DeviceDetail))   // the two tables can type this column differently
| project TimeGenerated, UserPrincipalName, SessionId, IPAddress, AppDisplayName,
          ASN = tostring(AutonomousSystemNumber), DeviceId = tostring(DD.deviceId),
          OS = tostring(DD.operatingSystem), Browser = tostring(split(tostring(DD.browser), " ")[0]);
let origins = signins
| summarize arg_min(TimeGenerated, ASN, DeviceId, OS, Browser, IPAddress) by SessionId
| project SessionId, OriginTime = TimeGenerated, OriginASN = ASN, OriginDevice = DeviceId,
          OriginOS = OS, OriginBrowser = Browser, OriginIP = IPAddress;
signins
| join kind=inner origins on SessionId
| where TimeGenerated > OriginTime
| where ASN != OriginASN and not(ASN in (corpAsns))
| where (isnotempty(OriginDevice) and DeviceId != OriginDevice)
     or OS != OriginOS or Browser != OriginBrowser
| summarize FirstSeen = min(TimeGenerated), SignIns = count(), Apps = make_set(AppDisplayName),
            IPs = make_set(IPAddress)
    by UserPrincipalName, SessionId, OriginIP, OriginASN, OriginDevice, ReplayASN = ASN
// Rule 2: interactive MFA from a never-seen network, without a device, for a normally managed user
let baseline = SigninLogs
| where TimeGenerated between (ago(14d) .. ago(1h)) and ResultType == "0"
| extend DeviceId = tostring(parse_json(tostring(DeviceDetail)).deviceId)
| summarize KnownASNs = make_set(tostring(AutonomousSystemNumber)),
            ManagedSignIns = countif(isnotempty(DeviceId)) by UserPrincipalName;
SigninLogs
| where TimeGenerated > ago(1h) and ResultType == "0"
| extend DeviceId = tostring(parse_json(tostring(DeviceDetail)).deviceId),
         ASN = tostring(AutonomousSystemNumber)
| where isempty(DeviceId)
| join kind=inner baseline on UserPrincipalName
| where ManagedSignIns >= 3 and not(set_has_element(KnownASNs, ASN))
| project TimeGenerated, UserPrincipalName, IPAddress, ASN, AppDisplayName, SessionId, UserAgent

Where the rules are blind

Be honest with yourself about the gaps. Rule 1 depends on the device ID, so sessions that start on unmanaged personal devices have no anchor, and an attacker who copies the user agent will not change the browser or operating system either. An attacker who replays through a residential proxy in the user's own city may share an ASN with the victim. Rule 2 will fire for a real user signing in on a new personal laptop at a hotel. These are reasons to close the gaps with policy (next section), not reasons to skip detection.

Responding when it fires

When we work an alert like this, the order matters more than speed on any single step:

  1. Revoke sessions first. In the Entra admin centre use Revoke sessions on the user, or call Microsoft Graph: POST /users/{id}/revokeSignInSessions. This revokes the user's Entra refresh tokens, so the stolen session can no longer get new tokens. If the attacker is active, disable the account as well while you work. Microsoft's guide to revoking user access is clear about the gap: access tokens already issued (one hour by default) and sessions an application issued itself last until they expire, unless the app supports Continuous Access Evaluation.
  2. Then reset the password and review MFA methods. Attackers who reach a session often register their own authenticator or phone. Remove anything the user does not recognise, and check the audit log for "User registered security info".
  3. Look for persistence in the mailbox and apps. New inbox rules, forwarding, OAuth consents and app registrations made from the replay IPs. The token theft playbook lists the queries.
  4. Find the source. Scenario A means an infected endpoint: isolate and rebuild it, or the attacker will simply steal the next session. Scenario B means a phishing email: find who else received it.

If incident response is not something your team runs every week, this is the point where a practised incident response process saves hours.

Stopping replay, not just spotting it

Detection buys time. These controls remove the value of a stolen session, in rough order of effort:

ControlWhat it does against replayLimits
Collect AADNonInteractiveUserSignInLogsMakes rule 1 possible at allIngestion cost
Conditional Access: require a compliant or joined deviceA replayed session from an attacker's machine fails the device checkNeeds Intune or hybrid join; plan for BYOD
Phishing-resistant MFA (passkeys, FIDO2, Windows Hello)Stops AiTM: the credential is bound to the real site, so a proxy cannot complete itDoes not help if an infostealer copies a session afterwards
Token Protection (Conditional Access session control)Accepts only device-bound sign-in tokens, so a copied token fails on another devicePer Microsoft's documentation, native apps for Exchange, SharePoint and Teams are generally available; browser support is in preview for selected apps
Continuous Access EvaluationSupported apps act on revocation and risk changes in near real time instead of at token expiryOnly CAE-capable apps
Risk-based Conditional Access (Entra ID P2)Forces re-authentication or blocks on medium or high sign-in riskLicence; still detection-driven
Sign-in frequency on sensitive apps and admin rolesShortens how long any stolen session stays usefulUser friction if overused

For a small or mid-sized tenant, the first three rows close most of the gap. Requiring compliant devices on Microsoft 365 turns Scenario A from "attacker reads mail" into a failed sign-in, and phishing-resistant MFA for administrators and finance staff turns Scenario B into a dead proxy page.

For a broader view of when to run this kind of monitoring in-house and when to hand it to a provider, see In-House SOC or MSSP?. The same lesson, that the alert has to be on behaviour rather than on a tool's banner, ran through our rebuild of the fake coding assignment attack. When we build identity detections as part of managed detection and response, session drift is one of the first rules we tune against a tenant's own noise, because every organisation's VPNs, mobile users and travel look different.

Checklist

  • Both SigninLogs and AADNonInteractiveUserSignInLogs are streamed to your SIEM.
  • Your office and VPN egress ASNs are recorded, so they can be excluded from drift rules.
  • A rule alerts when a session changes network and loses its device ID or changes client.
  • A rule alerts on interactive MFA from a never-seen network with no device for managed users.
  • Your runbook revokes sessions before resetting the password.
  • Conditional Access requires a compliant or joined device for Microsoft 365.
  • Administrators and finance staff use phishing-resistant MFA.
  • Token Protection is piloted in report-only mode for Windows users.

Tooling and references

  • Entra ID
  • Detection Engineering
  • KQL
  • Identity
HH

Written by

Huzaifa Hafeez

Chief Technology Officer, FutaqSec

Keep reading

Detection & Response12 min read

Inside the Binance Heist: Malware in a Coding Assignment

A fake job interview ends in a coding task that runs attacker code on install. We rebuild the technique in our lab and show the detection that catches it.

Huzaifa Hafeez

Not sure where to start?

A 30-minute scoping call is enough to understand your environment and recommend the right first step. No obligation.

Book a free consultation