Detect password spray in Entra ID sign-ins (KQL)
Password spray detection in SigninLogs looks for one source IP trying a small number of passwords against many different accounts, instead of many passwords against one account. The query groups failed sign-ins (result code 50126, "invalid username or password") by IP and short time window, then keeps only the windows where a high number of distinct users were targeted.
This is one of the highest-value identity detections for Microsoft Sentinel because password spraying is a common first step against cloud accounts and is hard to spot per-account — the signal only appears when you pivot on the source.
The query
SigninLogs
| where TimeGenerated > ago(1h)
| where ResultType == "50126" // Invalid username or password
| summarize
FailedAttempts = count(),
TargetedAccounts = dcount(UserPrincipalName),
Accounts = make_set(UserPrincipalName, 100),
Apps = make_set(AppDisplayName, 20)
by IPAddress, bin(TimeGenerated, 15m)
| where TargetedAccounts >= 10 and FailedAttempts >= 20
| sort by TargetedAccounts descLine-by-line explanation
| where ResultType == "50126"Keeps only "invalid username or password" failures. ResultType is a string in SigninLogs, so it is compared against a quoted value, not an integer.
by IPAddress, bin(TimeGenerated, 15m)Aggregates per source IP and 15-minute bucket. Spraying is defined by one source hitting many accounts, so the IP is the pivot, not the user.
TargetedAccounts = dcount(UserPrincipalName)Counts the distinct accounts each IP failed against — the core of the heuristic. A high distinct-account count with few attempts per account is the spray signature.
| where TargetedAccounts >= 10 and FailedAttempts >= 20Thresholds that separate a spray from normal retries. Tune both to your tenant size and sign-in volume.
Required tables and columns
ResultTypeSign-in result code as a string; 50126 is an invalid username or password.UserPrincipalNameThe account the sign-in was attempted against; counted distinctly to find spraying.IPAddressSource IP of the sign-in; the pivot for spray detection.AppDisplayNameThe application targeted, useful for spotting legacy-protocol spraying.
MITRE ATT&CK mapping
Tuning and false positives
- Baseline known-good source IPs (corporate egress, VPN concentrators) and exclude them, or raise TargetedAccounts for those ranges.
- Lower the window to 5m for noisier tenants, or widen to 1h for slow, low-and-slow sprays that stay under per-window thresholds.
- Join to successful sign-ins (ResultType "0") from the same IP afterwards to prioritise sprays that ended in a compromise.
Limitations
- Attackers who rotate source IPs (for example through a residential proxy network) spread attempts below the per-IP threshold and can evade it.
- Only covers interactive sign-ins in SigninLogs; spray via non-interactive flows needs AADNonInteractiveUserSignInLogs.
Frequently asked questions
- What ResultType means a failed password in SigninLogs?
- ResultType 50126 means the username or password was invalid. Related codes include 50053 (account locked) and 50055 (expired password); 0 is success.
- How is password spray different from brute force?
- Brute force tries many passwords against one account; password spray tries a few common passwords against many accounts to avoid lockouts, so the detection pivots on the source IP and distinct-account count.
Related queries
References
Last reviewed 2026-11-18.