Detect logon brute force on endpoints (KQL)
This DeviceLogonEvents query finds endpoints hit with a burst of failed logons followed by at least one success — the classic brute-force pattern against local or domain accounts over RDP, SMB or network logon. It counts failed and successful logons per device and source IP in an hour and keeps windows where both a high failure count and a success occur.
Unlike cloud sign-in brute force, this runs on Defender for Endpoint telemetry, so it catches on-host attacks such as RDP password guessing against an internet-exposed server.
The query
DeviceLogonEvents
| where Timestamp > ago(24h)
| summarize
Failed = countif(ActionType == "LogonFailed"),
Success = countif(ActionType == "LogonSuccess"),
FailedAccounts = dcountif(AccountName, ActionType == "LogonFailed"),
Accounts = make_set_if(AccountName, ActionType == "LogonSuccess", 20),
LogonTypes = make_set(LogonType, 10)
by DeviceName, RemoteIP, bin(Timestamp, 1h)
| where Failed >= 20 and Success >= 1
| sort by Failed descLine-by-line explanation
Failed = countif(ActionType == "LogonFailed")Counts failed logons in the window. ActionType distinguishes LogonFailed from LogonSuccess in DeviceLogonEvents.
by DeviceName, RemoteIP, bin(Timestamp, 1h)Groups per target device and source IP each hour, so a guessing run from one source collapses to a single row.
| where Failed >= 20 and Success >= 1Requires both a high failure count and a subsequent success — the signature of a brute force that eventually worked.
Required tables and columns
ActionTypeLogonSuccess or LogonFailed; the basis for counting outcomes.RemoteIPSource address of the logon, when the authentication is remote.AccountNameAccount the logon targeted; distinct failed accounts hint at spraying instead.LogonTypeHow the logon occurred (for example RemoteInteractive, Network).
MITRE ATT&CK mapping
Tuning and false positives
- Exclude vulnerability scanners and monitoring hosts that generate many benign failed logons.
- Split RDP (LogonType RemoteInteractive) into its own stricter rule for internet-exposed servers.
- Lower the Failed threshold for sensitive hosts where even a handful of guesses is suspicious.
Limitations
- Local brute force where RemoteIP is empty groups all sources together; add a filter on isnotempty(RemoteIP) for remote-only hunting.
- A patient attacker spacing attempts beyond the window stays under the count.
Related queries
References
Last reviewed 2026-11-18.