On this page
Review update: The Quick Start now previews the deployment with
-WhatIf; cleanup previews with-Destroy -WhatIffirst. Commit1f4c3e7, from November 14, creates all five rules disabled unless-EnableRules(alias-EnableSentinelRules) is supplied, so the Quick Start adds that step before the simulation. Rules deployed from commits through6992806were created enabled with incident creation and stay enabled until a run of1f4c3e7or a later commit without the switch, a portal change, or-Destroy. The helper’s scenario count is corrected to five, and the resource table notes that the deployed rules carry parent ATT&CK techniques. Checked offline: that commit’s 34 offline tests pass, and the five rule queries are unchanged; nothing was deployed. Commit31b24f4, from later on November 14, gives each Quick Start step in the README its own code block, as this page does, and a new README test fails if one block holds a preview and its real command, or a deployment and the-EnableRulesrerun. The scripts inscripts/, the rule queries and the workbook are unchanged; its 38 offline tests pass, and nothing was deployed. The pinned commit is now072781b, from November 15: it changes only the README and its test, and the Quick Start here now uses the README’s words on where to tune the queries and what a rerun does. The scripts, rule queries and workbook are unchanged, its 41 offline tests and CI’s KQL analysis passed, and nothing was deployed.
Earlier notes
Earlier notes from reviews of this lab, newest first. What the dates on a lab mean.
Review update
The merged source passed 25 offline tests and semantic analysis of all five deployed queries. Rules preserve nonempty immutable
UserId, map account entities, and gate fresh evidence after correlation without shortening the 14-day/7-day baselines. The travel rule labels distant equal-time eventsSimultaneousrather than inventing infinite speed. No fresh Azure deployment or detection evidence is claimed.
Source maintenance reviewed
This updated source passed its offline and CI checks. Historical tenant evidence in the companion article retains its original dates; no fresh tenant deployment or detection result is asserted here.
Overview
This lab deploys a five-rule detection stack for infostealer session hijacking to an existing Microsoft Sentinel workspace. Infostealers can steal browser cookies and session tokens that carry claims from an earlier MFA-protected sign-in, allowing an attacker to replay the session without repeating the victim’s interactive password and MFA ceremony while the session remains valid. The detection rules focus on the behavioral anomalies that stolen-token replay leaves in Entra ID non-interactive sign-in logs.
Blog post: Detecting Infostealer Session Hijacking with Microsoft Sentinel
Reviewed source: j-dahl7/session-hijack-detection-sentinel at 072781b8
Prerequisites
| Requirement | Details |
|---|---|
| Azure subscription | With Microsoft Sentinel enabled on a Log Analytics workspace |
| Entra ID P2 | For Identity Protection risk scoring and sign-in risk signals |
| Diagnostic settings | SignInLogs and NonInteractiveUserSignInLogs categories routed to the workspace |
| Azure CLI and RBAC | az CLI authenticated with Microsoft Sentinel Contributor for the workspace, Workbook Contributor for shared-workbook creation, and read access to inspect the workspace and diagnostic settings |
| PowerShell 7.4+ | For running deployment and simulation scripts |
Azure CLI log-analytics extension | Required by Deploy-Lab.ps1 before any resource write: az extension add --name log-analytics |
Quick Start
# Clone the companion repo
git clone https://github.com/j-dahl7/session-hijack-detection-sentinel.git
cd session-hijack-detection-sentinel
git checkout 072781b85463dcde8b719f5d7c5e7e46a44659cf
# Install the query extension; the deployer stops without it, including during a preview
az extension add --name log-analytics
Preview the deployment:
# Preview: read-only checks and workspace queries run, rule and workbook writes are skipped
./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab" -WhatIf
Read the preview output, then deploy:
# Deploy to your Sentinel workspace: the workbook and the five rules, disabled
./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab"
The next run writes each rule again from scripts/Deploy-Lab.ps1, so it replaces any query you changed in the portal. Review the queries, tune them in that file if needed, then enable the rules:
# After reviewing the queries, enable the rules explicitly
./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab" -EnableRules
Every later deployment without -SkipSentinel writes the five rules again from the script, with their stored queries. It also writes the workbook again from workbook/session-hijack-workbook.json. If you enabled the rules, add -EnableRules to each rerun, or they return to disabled. Add -SkipSentinel instead to leave the rules and the workbook as they are, including changes made in the portal. That run stops after its read-only checks.
With the rules enabled, generate seed activity:
# Run the simulation
./scripts/Test-SessionHijack.ps1
Deploy-Lab.ps1 creates all five rules disabled, and a disabled rule never runs, so it raises no alerts or incidents. Review the queries and thresholds against your own sign-in data and run each query manually first, then rerun with -EnableRules (alias -EnableSentinelRules) or enable individual rules on the Active rules tab. Each rule keeps incident creation on, which applies once it is enabled. The switch is declarative: a later run without it returns all five lab rules to disabled, including rules you enabled in the portal, and warns about each one first. -EnableRules cannot be combined with -Destroy or -SkipSentinel. Rules deployed from commits through 6992806 were created enabled and stay enabled until you rerun this commit without -EnableRules, disable them in the portal, or remove them with -Destroy. The companion article records an earlier revision of Rule 1, deployed enabled, that accumulated 632 alerts and 48 High incidents in 30-day retention. The -WhatIf preview shows the planned rule state but does not validate live rule output.
What Gets Deployed
| Resource | Type | MITRE |
|---|---|---|
| LAB - Token Replay from New Device or IP | Analytics Rule (High) | Unfamiliar user/IP/device-ID tuple; a new combination does not prove either value is globally new. T1539, T1550.001 |
| LAB - Impossible Travel on Token Refresh | Analytics Rule (High) | 500 km/h triage threshold; legitimate flights, VPN egress, and GeoIP error require context and tenant tuning. T1539 |
| LAB - Anomalous Non-Interactive Sign-in Surge | Analytics Rule (Medium) | T1539, T1550.001 |
| LAB - Browser or OS Mismatch in Same Session | Analytics Rule (Medium) | T1539, T1550.001 |
| LAB - Revoked Grant Followed by New-IP Authentication | Analytics Rule (High) | Entra error 50173, then a same-UserId success from a different IP; triage lead, not proof of theft or CAE. T1539, T1550.001 |
| Session Hijack Threat Dashboard | Workbook | โ |
The deployer sends parent technique IDs only: T1539 on all five rules and T1550 on Rules 1, 3, 4 and 5. The T1550.001 sub-technique in the table is documentation; it is not set on the deployed rules.
Test Scenarios
Test-SessionHijack.ps1 is a safe connectivity and seed-activity helper, not a deterministic incident generator. Besides Microsoft Graph, it queries api.ipify.org to display the current public IP address, so review that external call for your environment. It walks through five scenarios; the last two are manual:
- Varied Graph request headers โ validates five low-privilege
/merequests; those headers are not guaranteed to become EntraDeviceDetailfingerprints. - Graph request burst โ validates a controlled request path; cached-token requests do not create one new Entra refresh row per request.
- Current-IP token use โ provides context when the actual token activity produces a new source IP.
- Impossible travel โ still requires controlled token issuance or refresh from a VPN or Azure Cloud Shell region.
- Revoked grant followed by new-IP authentication โ requires an authorized manual sequence: produce a real 50173 row for a dedicated lab user, then authenticate the same immutable
UserIdfrom a different IP within 30 minutes.
Earlier revisions of all five rule families have historical live-incident evidence in the companion article. That evidence does not validate every condition in the current pinned queries: Rule 4 now requires one recorded SessionId; Rule 5 now requires documented error 50173 and correlates both sign-in tables on a nonempty immutable UserId; and Rule 1’s tuple/baseline behavior has changed. It also does not prove the helper caused Rules 3 and 4. Validate the surge rule with real non-interactive token issuance or refresh volume, and validate the fingerprint rule with controlled sign-ins that populate both SessionId and genuinely different DeviceDetail fingerprints for that same recorded session. Impossible travel and the revoked-grant sequence still require the documented manual steps. Error 50173 can also follow password changes, token expiry, or administrator revocation, so a match is a triage lead rather than proof of token theft or CAE enforcement.
Cost Estimate
This lab creates no new workspace or ingestion pipeline; it deploys analytics rules and a shared workbook into an existing Sentinel workspace. Existing Microsoft Sentinel and Log Analytics ingestion, retention, query, and related workspace charges still apply. AADNonInteractiveUserSignInLogs can be high-volume, so review the tenant’s data volume and retention settings before enabling or extending collection.
Cleanup
# Preview: lists and validates the owned rule IDs and ownership markers without deleting
./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab" -Destroy -WhatIf
Run the preview first and check the subscription, resource group, workspace, rule IDs, and ownership markers it lists. Then run the cleanup:
# Remove the five owned rules and the workbook
./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab" -Destroy
This command removes all 5 analytics rules, enabled or disabled, and the workbook. Diagnostic settings are not modified.
