Level 3 · Did they get in? · Mission 4 of 5 · by Kaushik Saha
The detection
Alert Failures, then a success · Idea let · min · max · join
Commands here project · where · == · != · and / or · ago · count · summarize · min / max · let · join · kind=inner · all commands
Briefing
You found this incident by hand. A detection should find the next one by itself: several failures, and then a success, for the same user from the same address.
One idea: find each half with let, then join them and check the order
"Then" matters. Counting failures and successes in the same window isn't enough: a success at 08:01 followed by five failures is not an attack that got in. So the rule finds the first failure and the last success separately, joins them on the user and the address, and keeps the pair only when the success came after the failures began:
let Lookback = 6h;
let Threshold = 5;
let Failed = SigninLogs
| where TimeGenerated > ago(Lookback) and ResultType != "0"
| summarize Failures = count(), FirstFailure = min(TimeGenerated) by UserPrincipalName, IPAddress;
let Succeeded = SigninLogs
| where TimeGenerated > ago(Lookback) and ResultType == "0"
| summarize LastSuccess = max(TimeGenerated) by UserPrincipalName, IPAddress;
Failed
| where Failures >= Threshold
| join kind=inner Succeeded on UserPrincipalName, IPAddress
| where LastSuccess > FirstFailure
| project UserPrincipalName, IPAddress, Failures, FirstFailure, LastSuccess
Result on the sample · 1 row
| UserPrincipalName | IPAddress | Failures | FirstFailure | LastSuccess |
|---|---|---|---|---|
| alex.morgan@contoso.com | 203.0.113.45 | 8 | 2026-06-10 08:14:02 | 2026-06-10 09:02:41 |
One row: Alex, from 203.0.113.45, failing from 08:14 and succeeding after it. Nothing else on the sample crosses
the line: the spray never succeeded, and the office mistypes were single failures.
let puts the numbers at the top, so whoever tunes the rule changes them in one place.
Your turn
Change the detection to need at least three failures and to look back two hours only. Does it still find Alex? (The attack began at 08:14; the shift's clock reads 12:00.)
Write it in the box below and check it. Then compare with one answer; others can be right too.
Show one answer
let Lookback = 2h;
let Threshold = 3;
let Failed = SigninLogs
| where TimeGenerated > ago(Lookback) and ResultType != "0"
| summarize Failures = count(), FirstFailure = min(TimeGenerated) by UserPrincipalName, IPAddress;
let Succeeded = SigninLogs
| where TimeGenerated > ago(Lookback) and ResultType == "0"
| summarize LastSuccess = max(TimeGenerated) by UserPrincipalName, IPAddress;
Failed
| where Failures >= Threshold
| join kind=inner Succeeded on UserPrincipalName, IPAddress
| where LastSuccess > FirstFailure
| project UserPrincipalName, IPAddress, Failures, FirstFailure, LastSuccess
Result on the sample · 0 rows
| UserPrincipalName | IPAddress | Failures | FirstFailure | LastSuccess |
|---|
Check your own query
Write your query for the task above and check it against the real schema.
Debrief
This is the shape of a real "successful sign-in after failures" analytics rule. In Sentinel it would run every hour over the last hour or two. One bug hunt left.
All data on this page is sample data, made up for this course. The IP addresses come from ranges reserved for documentation, and the people and the company are fictional.
Mission by Kaushik Saha. Every query checked with Microsoft.Azure.Kusto.Language 12.4.1 against schema bundle 2026.10.29; every result computed on the course's sample with Kusto-Loco 1.4.9, an open-source KQL engine (credits). The story's clock reads 12:00 UTC on 10 June 2026.