---
title: "Secure RDP against brute-force attacks: detect and stop them · CloudSat"
description: "Secure RDP against brute-force attacks: tell spraying from targeted guessing in the logs, tune lockout, block repeat sources and catch the login that matters."
url: https://cloudsat.io/learn/secure-rdp-against-brute-force-attacks
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Remote access](https://cloudsat.io/learn/topic/remote-access)

# Secure RDP against brute-force attacks: detect and stop them

Secure RDP against brute-force attacks: tell spraying from targeted guessing in the logs, tune lockout, block repeat sources and catch the login that matters.

CloudSat team November 18, 2026 9 min read

Any Windows server that answers on port 3389 collects failed sign-ins soon after it gets a public address. Scanners sweep whole address ranges with short lists of account names and leaked passwords, and they never stop. You cannot make the attempts go away while the port is public, but you can make them pointless and catch the rare one that works. This guide reads the attack first, because the response depends on its shape, then tunes what Windows already has, and ends with automatic blocking and a check for real break-ins.

## Three shapes of RDP guessing

"Brute force" rarely means trying every possible password. Three patterns do nearly all of the work:

| Pattern | How it works | What the Security log shows |
| --- | --- | --- |
| Password spraying | One or two common passwords tried against many account names | Many different names, few attempts per name |
| Credential stuffing | User name and password pairs leaked from other services | Plausible real names, each tried once or twice |
| Targeted guessing | Many passwords against one known account, usually Administrator | The same name, over and over |

Spraying stays under any per-account lockout threshold, so lockout alone barely touches it. Targeted guessing is exactly what lockout stops, and stuffing only succeeds where someone reused a password.

## Read the failures before you react

Every failed Remote Desktop sign-in lands in the Security log as event 4625. With Network Level Authentication (NLA) on, Windows checks the password over the network before it builds a session, so these failures carry logon type 3 rather than 10. Two fields tell the story: the source address, and the sub status code that says why the attempt failed.

| Code | Meaning | What it tells you |
| --- | --- | --- |
| 0xC0000064 | The account name does not exist | Blind guessing of names |
| 0xC000006A | The name exists, the password was wrong | The attacker has a real account name |
| 0xC0000234 | The account is locked out | Your lockout policy is firing |
| 0xC0000072 | The account is disabled | Someone is trying an account you retired |
| 0xC000015B | The account may not sign in this way | Your user rights are doing their job |

This profiles the last 24 hours. Run it as administrator, which the Security log requires:

```powershell
function Get-EventFields($Record) {
  $fields = @{}
  foreach ($d in ([xml]$Record.ToXml()).Event.EventData.Data) { $fields[$d.Name] = $d.'#text' }
  $fields
}

$fails = Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddHours(-24) } -ErrorAction SilentlyContinue |
  ForEach-Object {
    $f = Get-EventFields $_
    [pscustomobject]@{
      Source  = $f.IpAddress
      Account = $f.TargetUserName
      Code    = if ($f.SubStatus -and $f.SubStatus -ne '0x0') { $f.SubStatus } else { $f.Status }
    }
  }

# Busiest sources, and how many different account names each one tried
$fails | Group-Object Source | Sort-Object Count -Descending |
  Select-Object -First 15 -Property Count, Name, @{ n = 'Accounts'; e = { ($_.Group.Account | Sort-Object -Unique).Count } }

# Why the attempts failed
$fails | Group-Object Code | Sort-Object Count -Descending | Select-Object Count, Name
```

One address with hundreds of failures across many names is a single spraying tool, which the automatic block below catches. Hundreds of addresses with a few attempts each is a distributed spray that only taking the port off the internet stops. A growing share of 0xC000006A means the attackers hold a real account name: make sure its password is long and used nowhere else. If the source field is empty or shows a dash, match the time against event 131 in the `Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Operational` log, which records the address of each connection the server accepts.

## Take the port off the open internet

A rule that admits only your own addresses ends every pattern in the first table at once. Set it in a firewall in front of the server and mirror it in Windows Defender Firewall, after checking which address the server sees for your own session:

```powershell
Get-NetTCPConnection -LocalPort 3389 -State Established | Select-Object RemoteAddress, RemotePort

Set-NetFirewallRule -Name 'RemoteDesktop-UserMode-In-TCP', 'RemoteDesktop-UserMode-In-UDP' -RemoteAddress 203.0.113.25, 198.51.100.0/24
```

On CloudSat, the **Windows** firewall preset admits 3389 from anywhere, so put your own addresses in the rule's **Sources** field ([Create and apply cloud firewalls](https://cloudsat.io/docs/cloud-firewalls)), and keep **Console access (VNC)** under **Access** > **Recovery tools** as the way back in if a rule shuts you out.

When your address changes too often for an allowlist, put a VPN, an SSH tunnel or an [RD Gateway](https://cloudsat.io/learn/set-up-rd-gateway-on-windows-server) in front and close 3389 to the public. [Moving RDP to another port](https://cloudsat.io/learn/change-rdp-port-without-lockout) trims log noise but stops no one who scans every port.

## Tune lockout for guessing, not for your users

Account lockout caps how many guesses each account gets. According to Microsoft's KB5020282, new installs of Windows 11 version 22H2, and of Windows versions set up with the October 11, 2022 cumulative update already in place, start with this policy: 10 bad passwords within 10 minutes lock the account for 10 minutes, and the built-in Administrator is covered too. Machines set up from older media keep a threshold of 0, which means never, and a provider's image can differ from both. Check rather than assume:

```powershell
net accounts      # threshold, duration and observation window

# Is the built-in Administrator covered as well?
secedit /export /cfg "$env:TEMP\lockout.inf" /areas SECURITYPOLICY | Out-Null
Select-String -Path "$env:TEMP\lockout.inf" -Pattern 'LockoutBadCount|LockoutDuration|ResetLockoutCount|AllowAdministratorLockout'
Remove-Item "$env:TEMP\lockout.inf"

# 10 failures within 10 minutes lock the account for 10 minutes
net accounts /lockoutthreshold:10 /lockoutwindow:10 /lockoutduration:10
```

If `AllowAdministratorLockout` is missing or 0, enable **Allow Administrator account lockout** in `secpol.msc` under **Account Policies** > **Account Lockout Policy**.

Plan for two side effects. Lockout works per account, so a spray that tries each name once never triggers it; the per-address block below covers that gap. And anyone who reaches the sign-in can lock a known account on purpose. The Administrator lockout applies only to network sign-ins such as RDP, so the console still works during it and your provider's console stays the way back in. If your own sign-ins start failing, [Your credentials did not work](https://cloudsat.io/learn/fix-rdp-your-credentials-did-not-work) covers the usual causes. RDP has no second factor of its own; one way to add one is at an [RD Gateway](https://cloudsat.io/learn/set-up-rd-gateway-on-windows-server), through Microsoft's NPS extension for Entra multifactor authentication.

## Block repeat offenders automatically

When the port has to stay public, a scheduled script can add any address that fails too often to one block rule. It reads event 4625 and edits a Windows Defender Firewall rule, and block rules take precedence over the allow rules for RDP. Save it as `C:\Scripts\Block-RdpGuessers.ps1`:

```powershell
$windowMinutes = 30
$threshold     = 15
$neverBlock    = @('203.0.113.25', '127.0.0.1', '::1')   # your own addresses first
$ruleName      = 'Block RDP guessers'

$events = Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddMinutes(-$windowMinutes) } -ErrorAction SilentlyContinue
if (-not $events) { return }

$offenders = $events |
  ForEach-Object { ([xml]$_.ToXml()).Event.EventData.Data | Where-Object { $_.Name -eq 'IpAddress' } | ForEach-Object { $_.'#text' } } |
  Where-Object { $_ -and $_ -ne '-' -and $_ -notin $neverBlock } |
  Group-Object | Where-Object Count -ge $threshold | ForEach-Object Name
if (-not $offenders) { return }

$rule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
if ($rule) {
  $known = ($rule | Get-NetFirewallAddressFilter).RemoteAddress
  Set-NetFirewallRule -DisplayName $ruleName -RemoteAddress (@($known) + $offenders | Sort-Object -Unique)
} else {
  New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Action Block -RemoteAddress $offenders -Profile Any | Out-Null
}
```

Then run it every 10 minutes as SYSTEM:

```powershell
$action  = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Block-RdpGuessers.ps1'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 10)
Register-ScheduledTask -TaskName 'Block RDP guessers' -Action $action -Trigger $trigger -User 'NT AUTHORITY\SYSTEM' -RunLevel Highest
```

Put every address you connect from into `$neverBlock` before the first run, or a few typos become a rule against yourself. Reset the list now and then with `Remove-NetFirewallRule -DisplayName 'Block RDP guessers'`, since addresses change hands. The block and the lockout cover each other: one source spraying many names hits the block, many sources hammering one name hit the lockout. A spray spread thinly enough gets past both, which is why scoping the port comes first.

## Catch the one sign-in that matters

Thousands of failures are noise. One success from an address that was failing a minute earlier is an incident. This compares the last week of failures with successful Remote Desktop sign-ins, event 4624 with logon type 10, using the `Get-EventFields` function from the first snippet:

```powershell
$failed = Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddDays(-7) } -ErrorAction SilentlyContinue |
  ForEach-Object { (Get-EventFields $_).IpAddress } | Sort-Object -Unique

$week  = 7 * 24 * 3600 * 1000
$xpath = "*[System[(EventID=4624) and TimeCreated[timediff(@SystemTime) <= $week]]] and *[EventData[Data[@Name='LogonType']='10']]"
Get-WinEvent -LogName Security -FilterXPath $xpath -ErrorAction SilentlyContinue |
  ForEach-Object { $f = Get-EventFields $_; [pscustomobject]@{ Time = $_.TimeCreated; Account = $f.TargetUserName; From = $f.IpAddress } } |
  Where-Object { $_.From -in $failed }
```

An empty result is the goal. Run it once without the last line too: any type 10 sign-in from an unfamiliar address deserves the same response, in this order:

1. Run `quser` to see who is signed in now, and end any session you do not recognize with `logoff` and its session ID.
2. Change the password of that account and of every administrator, from a computer you trust.
3. Look for accounts created (event 4720) or added to Administrators (event 4732), and for services or scheduled tasks you did not set up.
4. If you find changes you did not make, restore a snapshot from before the first suspicious sign-in, or rebuild, rather than cleaning by hand.

## Keep the listener patched and the certificate honest

Some RDP flaws need no password at all. BlueKeep (CVE-2019-0708) let an attacker run code on unpatched Windows 7, Windows Server 2008 R2 and older systems before any sign-in, and Microsoft listed NLA as a partial mitigation because it forces authentication before the vulnerable code is reached. Install the monthly cumulative updates and keep the server on a Windows version that still receives them.

Remote Desktop also uses a self-signed certificate unless you install one, so clients warn on the first connection. Read the thumbprint on the server once and compare it with the one the warning shows; a warning that appears later, on a network you do not control, is a reason to stop rather than click through:

```powershell
Get-ChildItem 'Cert:\LocalMachine\Remote Desktop' | Select-Object Subject, Thumbprint, NotAfter
```

## FAQ

### Why do failed RDP sign-ins show logon type 3 instead of 10?

Because Network Level Authentication checks the password over the network before Windows creates a session. Logon type 10 appears for successful sign-ins that produce a desktop, and for failures only on servers where NLA is off.

### Will the lockout policy lock me out of my own server?

It can, for the lockout duration, if someone guesses against your account or you mistype too often. Wait it out, sign in through the console, or clear **Account is locked out** in the user's properties in `lusrmgr.msc`.

### How many failed attempts per day are normal?

There is no healthy figure for a public port: the count depends on how long the address has been online and who scanned it last. The number that matters is successful sign-ins from addresses you do not recognize, and that should be zero.

### Does an automatic block replace an allowlist?

No. It removes the loudest sources and shortens the log, but it reacts after the guesses arrive and cannot see a thinly spread spray. An allowlist, VPN or gateway stops the guesses before Windows ever sees them.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Remote access](https://cloudsat.io/learn/topic/remote-access)

- [Set up RD Gateway on Windows Server: RDP over HTTPS](https://cloudsat.io/learn/set-up-rd-gateway-on-windows-server): Windows Server Set up RD Gateway on Windows Server: RDP over HTTPS 8 min read
- [RDP 'Your credentials did not work': what to check, in order](https://cloudsat.io/learn/fix-rdp-your-credentials-did-not-work): Windows Server RDP 'Your credentials did not work': what to check, in order 8 min read
- [How the Remote Desktop Protocol works, step by step](https://cloudsat.io/learn/how-the-remote-desktop-protocol-works): Remote access How the Remote Desktop Protocol works, step by step 7 min read
- [RDP, RDS, VDI and DaaS explained: pick a remote desktop model](https://cloudsat.io/learn/rdp-rds-vdi-and-daas-explained): Remote access RDP, RDS, VDI and DaaS explained: pick a remote desktop model 6 min read
