Skip to content
Contact

KQL for sign-in hunting

Building blocks that the code pages and guides reuse.

Start here. It shows which codes appear most, so you know which pages to read first.

Interactive sign-in failures by code, last 7 days
SigninLogs
| where TimeGenerated > ago(7d)
| where ResultType != "0"
| summarize Events = count(), Users = dcount(UserPrincipalName) by ResultType, ResultDescription
| sort by Events desc
Non-interactive sign-in failures by code, last 7 days
AADNonInteractiveUserSignInLogs
| where TimeGenerated > ago(7d)
| where ResultType != "0"
| summarize Events = count(), Users = dcount(UserPrincipalName) by ResultType, ResultDescription
| sort by Events desc

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 datatable of every code with its attack signal, to join onto your own results.
  • ResultType is a string column. Write ResultType == "50126".
  • "0" means success. Everything else is a failure or an interrupt.
  • Conditional Access only runs after the first factor succeeds. Credential failures show ConditionalAccessStatus as notApplied.
  • 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