You do not need Splunk or Sentinel to catch a brute force attack on a Windows server. Windows already writes down every guess. This guide is brute force detection without a SIEM, done by hand: which event IDs carry the signal, a PowerShell script that turns them into alerts, how to schedule it, and the places where a homemade detector quietly falls short.
It is written for the person who looks after a small office’s server, often a part-time IT vendor, who is comfortable in PowerShell. Every command below runs in Windows PowerShell 5.1, the version built into Windows Server 2016 and later, from an elevated prompt.
Before you start: make sure Windows is recording
On Windows Server, auditing of sign-ins (success and failure) is on by default, and so is auditing of user account changes, which is where lockout events come from. Auditing of credential validation, which produces event 4776, is off by default (Microsoft audit policy recommendations). Check and switch on what you need:
auditpol /get /subcategory:"Logon","Credential Validation","User Account Management"
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
auditpol /set /subcategory:"Credential Validation" /success:enable /failure:enable
Group Policy can override these on a domain-joined server, so check again after the next policy refresh. Our audit policy baseline covers the full set.
Then look at the size of the Security log. The default is small, and a server under a steady attack can fill it in hours, after which the oldest events are overwritten. Raising it to 1 GB is reasonable on most servers:
wevtutil gl Security
wevtutil sl Security /ms:1073741824
Indian firms covered by the CERT-In Directions of 28 April 2022 must keep ICT system logs for 180 days, which a local event log alone will not do. Plan to copy logs off the server as well.
The events that carry the signal
| Event ID | Log | What it records | Why it matters |
|---|---|---|---|
| 4625 | Security | An account failed to sign in. Includes account name, source IP, logon type and a status code. | The bulk of the signal. See our Event ID 4625 guide for every field. |
| 4776 | Security | The computer tried to validate NTLM credentials. Has the account name, the client’s workstation name and an error code; no IP. | On a standalone server it mostly repeats what 4625 shows. On a domain controller it records NTLM checks for domain accounts coming from every machine, which is where spraying across the office shows up. |
| 4740 | Security | A user account was locked out. | Shows which account was being hammered. A daily lockout of a real staff account is a classic sign of guessing. |
| 4624 | Security | A successful sign-in. Logon type 10 is Remote Desktop; type 3 is a network sign-in, which is how RDP shows at the network stage when NLA is on. | A success from an address that has been failing is the alert that matters most. |
| 1149 | Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational | A Remote Desktop connection reached the sign-in stage, with user name and source IP. | Its text says “User authentication succeeded”, but on its own it is not proof of a full sign-in. Confirm with 4624. |
One quirk to check before you rely on any of this: on some servers, 4625 events for failed Remote Desktop sign-ins show “-” as the source address. Open a few of your own 4625 events first. The script below skips events without an address, so if yours are blank, the rules that group by IP will see nothing and you will need to lean on the per-account events (4740, 4776) instead.
The Get-WinEvent gotcha: too many IDs looks like “no events”
You may read that Get-WinEvent “silently returns nothing” when you ask for too many event IDs, and elsewhere that it fails loudly. Both are partly true, and the difference matters for your script.
The Windows event query engine accepts only a limited number of ID conditions in one query, a little over 20 (Elastic’s Windows event log documentation describes the same limit). Send it a longer query written in XPath (-FilterXPath) and you get a clear error: “The specified query is invalid”. But with -FilterHashtable, which is what most scripts use, Windows PowerShell 5.1 reports something else. In our test, 23 IDs worked and 24 IDs produced “No events were found that match the specified selection criteria”, the very same error Get-WinEvent gives when there genuinely are no matching events.
So the query does not crash; it misleads. A script that treats “no events found” as “all clear”, which is the sensible thing to do for a normal empty result, will report a quiet server while an attack is in progress. Adding -ErrorAction SilentlyContinue hides the problem completely.
The safe pattern: keep every query to 20 IDs or fewer (split longer lists into several queries), treat “no events found” as an empty result only when the ID list is within that limit, and let every other error through. The function at the top of the script below does exactly this, and refuses a longer list outright. A brute-force detector needs only three or four IDs per query, so this mostly bites when a script grows over time.
The detection script
Save this as C:\Scripts\bf-detect.ps1 (create the folder first). It reads the last 24 hours of the Security log, applies five rules, and writes any new finding to the Application log as event 9001 from the source “BF-Detect”. The numbers at the top are starting points, not recommendations: tune them to your own traffic.
# bf-detect.ps1 - brute-force detection from the Security log (Windows PowerShell 5.1, run elevated or as SYSTEM)
$LookBackHours = 24 # how far back each run reads
$FastMinutes = 10 # window for the fast rule
$FastLimit = 10 # failures from one IP inside $FastMinutes
$SlowLimit = 30 # failures from one IP inside $LookBackHours
$SprayLimit = 5 # different account names tried by one IP
$Ignore = @('-', '::1', '127.0.0.1')
$StateFile = 'C:\Scripts\bf-alerted.txt'
function Get-SecurityEvents([int[]]$Id, [datetime]$Since) {
if ($Id.Count -gt 20) { throw 'Query at most 20 event IDs at a time; split the list.' }
try {
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = $Id; StartTime = $Since } -ErrorAction Stop
} catch {
if ($_.FullyQualifiedErrorId -like 'NoMatchingEventsFound*') { return }
throw
}
}
function Get-EventFields($Record) {
$fields = @{}
foreach ($n in ([xml]$Record.ToXml()).Event.EventData.Data) { $fields[$n.Name] = $n.'#text' }
$fields
}
$since = (Get-Date).AddHours(-$LookBackHours)
$fastSince = (Get-Date).AddMinutes(-$FastMinutes)
$alerts = @()
# 1. Failed sign-ins (4625), minus local noise and machine accounts
$failures = @(foreach ($r in @(Get-SecurityEvents -Id 4625 -Since $since)) {
$f = Get-EventFields $r
if ($f['IpAddress'] -and ($f['IpAddress'] -notin $Ignore) -and ($f['TargetUserName'] -notlike '*$')) {
[pscustomobject]@{ Time = $r.TimeCreated; User = $f['TargetUserName']; Ip = $f['IpAddress']; SubStatus = $f['SubStatus'] }
}
})
foreach ($g in ($failures | Group-Object Ip)) {
$ip = $g.Name
$fast = @($g.Group | Where-Object { $_.Time -ge $fastSince }).Count
$users = @($g.Group.User | Sort-Object -Unique).Count
$nouser = @($g.Group | Where-Object { $_.SubStatus -eq '0xc0000064' }).Count
if ($fast -ge $FastLimit) {
$alerts += [pscustomobject]@{ Rule = 'FAST'; Ip = $ip; Detail = "$fast failures in $FastMinutes minutes" }
} elseif ($g.Count -ge $SlowLimit) {
$alerts += [pscustomobject]@{ Rule = 'SLOW'; Ip = $ip; Detail = "$($g.Count) failures in $LookBackHours hours" }
}
if ($users -ge $SprayLimit) {
$alerts += [pscustomobject]@{ Rule = 'SPRAY'; Ip = $ip; Detail = "$users different account names tried" }
}
if ($nouser -gt 0) {
$alerts += [pscustomobject]@{ Rule = 'NAMES'; Ip = $ip; Detail = "$nouser tries on account names that do not exist" }
}
}
# 2. Success after failure: a 4624 (network or RDP) from an address that has been failing
$failingIps = @($failures | ForEach-Object { $_.Ip } | Sort-Object -Unique)
foreach ($r in @(Get-SecurityEvents -Id 4624 -Since $since)) {
$f = Get-EventFields $r
if (($f['IpAddress'] -in $failingIps) -and ($f['LogonType'] -in @('3', '10'))) {
$alerts += [pscustomobject]@{ Rule = 'SUCCESS'; Ip = $f['IpAddress']; Detail = "$($f['TargetUserName']) signed in at $($r.TimeCreated)" }
}
}
# 3. Lockouts (4740)
foreach ($r in @(Get-SecurityEvents -Id 4740 -Since $since)) {
$f = Get-EventFields $r
$alerts += [pscustomobject]@{ Rule = 'LOCKOUT'; Ip = '-'; Detail = "$($f['TargetUserName']) locked out at $($r.TimeCreated)" }
}
# 4. Report each finding once (rate rules once per IP per day)
$today = Get-Date -Format 'yyyy-MM-dd'
$seen = @(if (Test-Path $StateFile) { Get-Content $StateFile })
$new = @(foreach ($a in $alerts) {
if ($a.Rule -in @('SUCCESS', 'LOCKOUT')) { $key = "$($a.Rule)|$($a.Detail)" } else { $key = "$today|$($a.Rule)|$($a.Ip)" }
if ($key -notin $seen) { Add-Content -Path $StateFile -Value $key; $a }
})
if ($new.Count -gt 0) {
$msg = ($new | ForEach-Object { "$($_.Rule) $($_.Ip) $($_.Detail)" }) -join "`r`n"
if (-not [System.Diagnostics.EventLog]::SourceExists('BF-Detect')) {
New-EventLog -LogName Application -Source 'BF-Detect'
}
Write-EventLog -LogName Application -Source 'BF-Detect' -EventId 9001 -EntryType Warning -Message $msg
$msg
}
Run it once by hand (& 'C:\Scripts\bf-detect.ps1') and read what it prints before you trust it.
What each rule catches
- FAST: a flood from one address. Easy to see, and usually blocked by lockout anyway, but it tells you the server is exposed.
- SLOW: the low-and-slow campaign that never trips lockout because it spreads its guesses over hours.
- SPRAY: one address trying many account names. Even at a low rate, nobody in your office does this by accident.
- NAMES: status 0xC0000064, “user name does not exist”. From an outside address this is guessing, not a typo: staff do not mistype a name they have never used.
- SUCCESS: the one you act on tonight. An address that was failing has now signed in.
Noise the script already filters
Failures with “-“, “::1” or “127.0.0.1” as the source are local: scheduled tasks, services, someone at the console. Account names ending in “$” are computer accounts talking to each other. Two more sources of noise you may need to handle yourself: a service or scheduled task still using an old password will fail every few minutes from a fixed address forever (fix the service rather than allow-listing it), and failures after an account is already locked out are a consequence of the attack, not fresh evidence of a new one.
Status codes help separate the two. 0xC0000064 (no such user) and 0xC000006A (wrong password) from an outside address are guessing. 0xC0000071 (password expired), 0xC0000224 (must change password) and 0xC000015B (not allowed to sign in this way, often a user missing from Remote Desktop Users) are usually a real person who needs help.
Other events worth a look
The script leaves out 4776 and 1149 to stay short. Once credential validation auditing is on, this lists the accounts and client names behind NTLM failures:
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4776; StartTime = (Get-Date).AddDays(-1) } -ErrorAction SilentlyContinue |
ForEach-Object { $x = [xml]$_.ToXml(); $d = @{}; foreach ($n in $x.Event.EventData.Data) { $d[$n.Name] = $n.'#text' }
if ($d['Status'] -ne '0x0') { [pscustomobject]@{ Time = $_.TimeCreated; User = $d['TargetUserName']; Client = $d['Workstation']; Status = $d['Status'] } } } |
Group-Object User | Sort-Object Count -Descending | Select-Object Count, Name -First 10
And this shows who reached the Remote Desktop sign-in stage, and from where:
Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational'; Id = 1149; StartTime = (Get-Date).AddDays(-7) } -ErrorAction SilentlyContinue |
ForEach-Object { $u = ([xml]$_.ToXml()).Event.UserData.EventXML; [pscustomobject]@{ Time = $_.TimeCreated; User = $u.Param1; SourceIp = $u.Param3 } }
In these two quick checks -ErrorAction SilentlyContinue is fine, because you are reading the output yourself. In the scheduled script it is not.
Run it every five minutes
Register a scheduled task that runs the script as SYSTEM:
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\bf-detect.ps1"'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
Register-ScheduledTask -TaskName 'BF-Detect' -Action $action -Trigger $trigger -User 'SYSTEM' -RunLevel Highest
Findings now land in Event Viewer > Windows Logs > Application as event 9001. To be told rather than having to look, attach a second scheduled task to that event (“On an event”, log Application, source BF-Detect, event ID 9001) that sends you a message through whatever your office already uses. Microsoft marks Send-MailMessage as obsolete because it cannot guarantee a secure connection, so prefer your mail provider’s own supported method.
Where homemade detection breaks
This catches most opportunistic attacks on a single server. Be honest with yourself about where it stops:
- It polls. A five-minute schedule means up to five minutes between an event and your alert, about two and a half on average. Plus however long it takes someone to read it.
- It runs on the server being attacked. An intruder with admin rights can stop the task or clear the log (event 1102 records the clearing). Copying events off the server, for example with Windows Event Forwarding, is the durable answer.
- Thresholds drift. Numbers that fit today will be wrong after the next change in staff, VPN or attacker behaviour. Without re-tuning you either alert constantly or miss slow campaigns.
- Someone has to maintain it. Scripts outlive the person who wrote them. A detector that stopped running in March looks exactly like a quiet server.
- Detection is not response. Knowing about a 3 AM attack does not help if nobody acts until 10 AM. You can block an address by hand (below), but bots rotate addresses, so this buys time rather than solving anything. Never block an address without checking it is not your own office or a partner’s home connection.
New-NetFirewallRule -DisplayName 'Block 203.0.113.45' -Direction Inbound -RemoteAddress 203.0.113.45 -Action Block
The best detection of all is having nothing to detect. If the guesses come in over Remote Desktop, take RDP off the internet: Prixl Guard Secure Access, a VPN or an RD Gateway, or at the very least an allow-list of known addresses. Our guide to restricting RDP access covers each route, and account lockout and after-hours sign-in monitoring cover two of the signals above in more depth.
If you would rather not maintain a script
Prixl Warden does this job as a Windows service installed from an MSI. It reads the same Security events, tracks failures per IP address and per account to catch fast floods and slow, low-and-slow campaigns, and emails you with a plain-English explanation. It also watches for sign-ins outside working hours, new accounts, admin-group changes, new services and a cleared audit log, and keeps 30 days of event history in AWS Mumbai, off the server itself. Blocking attacking addresses automatically is opt-in, switched on from the dashboard, and private (LAN) addresses are never auto-blocked.
If your environment is small and you enjoy PowerShell, run the script. If you would rather spend that time elsewhere, let Warden do the watching. Start your 30-day free trial.

