KQL for sign-in hunting
Building blocks that the code pages and guides reuse.
Which failure codes dominate my tenant?
Section titled “Which failure codes dominate my tenant?”Start here. It shows which codes appear most, so you know which pages to read first.
SigninLogs| where TimeGenerated > ago(7d)| where ResultType != "0"| summarize Events = count(), Users = dcount(UserPrincipalName) by ResultType, ResultDescription| sort by Events descThe same for non-interactive sign-ins
Section titled “The same for non-interactive sign-ins”AADNonInteractiveUserSignInLogs| where TimeGenerated > ago(7d)| where ResultType != "0"| summarize Events = count(), Users = dcount(UserPrincipalName) by ResultType, ResultDescription| sort by Events descWhere the rest of the queries are
Section titled “Where the rest of the queries are”This page holds only the starting points. The specific queries live next to what they explain:
- Every AADSTS code page has its own hunting query for that code. Start from the AADSTS code map.
- The hunting guides each build a full query for one attack: password spray, MFA fatigue, token replay, consent phishing, a compromised vendor app and more.
- The KQL lookup table is a copy-paste
datatableof every code with its attack signal, to join onto your own results.
Points to remember
Section titled “Points to remember”ResultTypeis a string column. WriteResultType == "50126"."0"means success. Everything else is a failure or an interrupt.- Conditional Access only runs after the first factor succeeds. Credential failures show
ConditionalAccessStatusasnotApplied. - App and service principal sign-ins are in
AADServicePrincipalSignInLogs, not in the two tables above. Hunting credential reuse after a web-server breach has queries for it.
Theme