Block RDP brute-force attacks on a Windows VPS in 2026
A Windows VPS with RDP port 3389 open gets thousands of login attempts a day from bots. This guide shows how to stop a brute force attack on Windows Server and block RDP abuse in three steps. First you harden RDP and the accounts, then you ban persistent addresses automatically, and finally you hide RDP behind a VPN. You set up these protections yourself, in Windows Server 2025, the system delivered on OuiHeberg Windows VPS.
Spot a brute force attack in progress
Windows logs every failed logon in the Security log, with event ID 4625. Run the following commands in PowerShell as administrator.
Count failed logons
# Number of failed logons over the last 24 hours
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625; StartTime=(Get-Date).AddDays(-1)} |
Measure-Object | Select-Object -ExpandProperty Count
Beyond a few dozen failures a day, your VPS is being targeted.
See the attacking addresses
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625} -MaxEvents 1000 |
ForEach-Object {
$xml = [xml]$_.ToXml()
$xml.Event.EventData.Data | Where-Object { $_.Name -eq 'IpAddress' } | Select-Object -ExpandProperty '#text'
} |
Where-Object { $_ -and $_ -ne '-' } |
Group-Object | Sort-Object Count -Descending | Select-Object -First 20
You get the 20 most active addresses with their number of attempts. An address with more than 50 attempts is clearly malicious.
See the targeted accounts
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625} -MaxEvents 1000 |
ForEach-Object {
$xml = [xml]$_.ToXml()
$xml.Event.EventData.Data | Where-Object { $_.Name -eq 'TargetUserName' } | Select-Object -ExpandProperty '#text'
} |
Group-Object | Sort-Object Count -Descending | Select-Object -First 20
Names like Administrator, admin or accounts that do not exist point to a blind brute force, the most common case. Bots try lists of known passwords. When one works, they often create a discreet administrator account, turn off Windows Defender and install a crypto miner or ransomware.
Harden RDP and Windows accounts
These basic settings come before any tool. No anti-brute-force software makes up for their absence.
Require NLA
NLA (Network Level Authentication) requires authentication before the RDP session opens. Without NLA, the attacker sees the logon screen and can try much faster.
# Require NLA (registry)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" `
-Name "UserAuthentication" -Value 1
You can also use sysdm.cpl. On the Remote tab, tick the box that only allows connections with Network Level Authentication.
Replace the Administrator account
The Administrator account is the bots' favourite target. First create another administrator account with a name that is hard to guess.
$pw = Read-Host -AsSecureString "Password for the new account"
New-LocalUser -Name "ops-7421" -Password $pw
# S-1-5-32-544 = Administrators group, whatever the Windows language
Add-LocalGroupMember -SID "S-1-5-32-544" -Member "ops-7421"
Log in over RDP with this new account to check that it works. Then rename the Administrator account.
$adminSID = "S-1-5-21-*-500"
$adminAccount = Get-LocalUser | Where-Object { $_.SID -like $adminSID }
Rename-LocalUser -Name $adminAccount.Name -NewName "Admin_$(Get-Random -Maximum 9999)"
Better still, disable it.
Disable-LocalUser -Name "Administrator"
Before disabling Administrator, check that your new account can open an RDP session. Otherwise you lock yourself out of the VPS. The Password tab in the client area shows the password of the Administrator account, so keep the credentials of the new account yourself.
Lock accounts after several failures
After 5 failures, the account is locked for 30 minutes. The setting is in secpol.msc, under Account Policies › Account Lockout Policy.
| Setting | Recommended value |
|---|---|
| Account lockout threshold | 5 attempts |
| Account lockout duration | 30 minutes |
| Reset account lockout counter after | 30 minutes |
The same policy from the command line.
net accounts /lockoutthreshold:5 /lockoutduration:30 /lockoutwindow:30
Enforce long passwords
net accounts /minpwlen:14 /maxpwage:90 /minpwage:1 /uniquepw:5
This command requires at least 14 characters, a change every 90 days and one day between two changes, and it bans reuse of the last 5 passwords. Combined with account lockout, a password this long makes brute force impractical.
Change the RDP port
An RDP port other than 3389 does not stop an attacker who targets your server. It does remove most of the noise from automated scans. The guide Change the RDP port on a Windows Server VPS explains how, firewall rule included.
Restrict RDP to your IP addresses
Do you always connect from the same addresses (office, VPN, fixed IP)? Allow only those on RDP.
# Replace with your allowed addresses
$allowedIPs = "203.0.113.42", "198.51.100.10"
Get-NetFirewallRule -DisplayName "*Remote Desktop*" | ForEach-Object {
Set-NetFirewallRule -Name $_.Name -RemoteAddress $allowedIPs
}
This is the most effective measure. A connection from any other address is dropped before it reaches the RDP service. On Windows installed in another language, the rules carry a translated name, so adjust the filter. For the rest of the firewall, follow How to open a port in Windows Firewall on a VPS. If your address changes often, use a VPN instead, as described below.
Ban addresses automatically with IPBan
Even with these settings, bots keep trying. An auto-ban tool spots the addresses that pile up failures and blocks them in the Windows Firewall.
Choose a tool
| Tool | License | Maintenance | Type | Note |
|---|---|---|---|---|
| IPBan (DigitalRuby) | Free, paid Pro version | Active | Windows service | The most widely used, also watches OpenSSH, SQL Server and MySQL |
| Fail2Ban4Win (Aldaviva) | Free, MIT | Active | Windows service | Lightweight, needs .NET Framework 4.7.2, already in Windows Server 2025 |
| EZWinBan (neil-sabol) | Free | Rare since 2021 | PowerShell script and scheduled task | Simple, for a small server |
| wail2ban (glasnt) | Free | Abandoned | PowerShell script | Archived repository, avoid it |
| EvlWatcher | Free | Active | Windows service | Good, less documented |
| RDPGuard | Paid | Active | Windows service | Also covers FTP, SMTP and SQL |
The free version of IPBan covers most needs. Fail2Ban4Win is the fully open source alternative.
Install IPBan
Open PowerShell as administrator and run the install command given in the official IPBan repository.
$ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/DigitalRuby/IPBan/master/IPBanCore/Windows/Scripts/install_latest.ps1'))
The script downloads the latest version and installs it as a Windows service that starts automatically at boot. Check that the service is running.
Get-Service -Name IPBan
The Status column should show Running.
Configure IPBan
The configuration file is here.
C:\Program Files\IPBan\ipban.config
Here are the key settings. Every option in the file has a comment.
<!-- Failed logons before a ban -->
<add key="FailedLoginAttemptsBeforeBan" value="5"/>
<!-- Ban duration (DD:HH:MM:SS), here 1 day -->
<add key="BanTime" value="01:00:00:00"/>
<!-- Time after the last failure before the counter resets to zero -->
<add key="ExpireTime" value="01:00:00:00"/>
<!-- How often the service does its housekeeping, keep the default -->
<add key="CycleTime" value="00:00:00:15"/>
<!-- Addresses never banned (your management addresses) -->
<add key="Whitelist" value="203.0.113.42,198.51.100.0/24"/>
<!-- Addresses always banned -->
<add key="Blacklist" value=""/>
BanTime sets the ban duration. ExpireTime does not: it sets how long IPBan remembers the failures of an address. Add all your management addresses to Whitelist. Restart the service after each change.
Restart-Service IPBan
Recommended settings by server use.
| Use | Failures before a ban | Ban duration |
|---|---|---|
| Personal or development server | 5 | 1 day |
| Exposed production server | 3 | 7 days |
| Critical server | 2 | 30 days |
| Bastion or single server | 1 | 365 days |
A duration of 30 to 90 days is a good compromise. Bots change addresses often, and a list kept forever becomes heavy.
View and unban addresses
IPBan creates firewall rules whose names start with IPBan_Block. These commands list the banned addresses and follow the log live.
cd "C:\Program Files\IPBan"
.\DigitalRuby.IPBan.exe list
# Addresses listed in the firewall block rules
Get-NetFirewallRule -DisplayName "IPBan_Block*" |
Get-NetFirewallAddressFilter |
Select-Object -ExpandProperty RemoteAddress
# Service log, live
Get-Content "C:\Program Files\IPBan\logfile.txt" -Tail 50 -Wait
To unban an address blocked by mistake, use the unban command. To make sure it is never banned again, also add it to Whitelist, then restart the service.
cd "C:\Program Files\IPBan"
.\DigitalRuby.IPBan.exe unban 203.0.113.42
IPBan stays light. It reads the event log and adds rules to the Windows Firewall, which easily handles tens of thousands of addresses.
Ban without a third-party tool using a PowerShell script
Do not want any third-party service? This standalone script reads 4625 events and blocks any address above a failure threshold over one hour. Save it as C:\Scripts\AutoBanRDP.ps1.
# === RDP auto-ban (no dependency) ===
param(
[int]$Threshold = 10, # Failures before a ban
[int]$WindowHours = 1, # Counting window, in hours
[int]$BanDays = 7 # Duration written to the log, in days
)
$ruleName = "AutoBan_RDP"
$startTime = (Get-Date).AddHours(-$WindowHours)
# Collect the addresses above the threshold
$attackers = Get-WinEvent -FilterHashtable @{
LogName = 'Security'
ID = 4625
StartTime = $startTime
} -ErrorAction SilentlyContinue | ForEach-Object {
$xml = [xml]$_.ToXml()
$ip = ($xml.Event.EventData.Data | Where-Object { $_.Name -eq 'IpAddress' }).'#text'
if ($ip -and $ip -ne '-' -and $ip -ne '::1' -and $ip -ne '127.0.0.1') { $ip }
} | Group-Object | Where-Object { $_.Count -ge $Threshold } | Select-Object -ExpandProperty Name
if (-not $attackers) {
Write-Host "No address to ban (threshold = $Threshold over $WindowHours h)." -ForegroundColor Green
return
}
# Update the existing rule or create it
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
if ($existingRule) {
$currentIPs = ($existingRule | Get-NetFirewallAddressFilter).RemoteAddress
$allIPs = ($currentIPs + $attackers) | Sort-Object -Unique
Set-NetFirewallRule -DisplayName $ruleName -RemoteAddress $allIPs
} else {
New-NetFirewallRule -DisplayName $ruleName `
-Direction Inbound -Action Block `
-RemoteAddress $attackers `
-Description "Auto-ban RDP $(Get-Date -Format 'yyyy-MM-dd HH:mm')"
}
Write-Host "$($attackers.Count) address(es) banned: $($attackers -join ', ')" -ForegroundColor Yellow
# Log each ban and its expiry date
$logPath = "C:\Scripts\AutoBanRDP.log"
$attackers | ForEach-Object {
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`tBAN`t$_`tEXPIRE=$((Get-Date).AddDays($BanDays))" | Out-File -Append $logPath
}
Schedule it every 15 minutes with a task run by the SYSTEM account.
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
-Argument "-NoProfile -ExecutionPolicy Bypass -File C:\Scripts\AutoBanRDP.ps1"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) `
-RepetitionInterval (New-TimeSpan -Minutes 15) `
-RepetitionDuration (New-TimeSpan -Days 365)
Register-ScheduledTask -TaskName "AutoBanRDP" `
-Action $action -Trigger $trigger `
-User "SYSTEM" -RunLevel Highest -Force
Adjust $Threshold, $WindowHours and $BanDays to your tolerance. The script has no dependency, its code is fully readable and it keeps a local log.
It also has limits.
It does not unban on its own.
$BanDaysonly goes into the log, removal has to be scripted separately.It only watches RDP, through event 4625.
Beyond 10,000 addresses, the firewall rule gets heavy. Switch to IPBan then.
Stop exposing RDP to the Internet
The previous steps cut the risk a lot. Real protection means not showing RDP at all. Three architectures do that.
A VPN in front of RDP
Install a WireGuard or OpenVPN server on the VPS or on a machine in front of it. Close RDP to everything except the VPN's internal address. You connect to the VPN first, then over RDP as if on a local network. RDP becomes invisible from the Internet, and the allowed address list no longer has to follow you around. For a VPN on a Linux VPS placed in front, follow How to install a WireGuard VPN server on a Linux VPS.
An RD Gateway
Microsoft's own solution, Remote Desktop Gateway relays your RDP sessions over HTTPS on port 443. The usual RDP client works, traffic is encrypted and the gateway integrates with Active Directory. On the other hand, it needs RDS licenses and more configuration.
A bastion host
A minimal "bastion" server, reachable only over SSH or key-based RDP, carries all your connections. Your other servers only accept RDP from it. Between OuiHeberg VPS in the same location, this traffic can use a private network, as explained in How to connect two VPS over a private network. This setup suits three to five servers or more.
Regain access through the client area console
A firewall rule that is too strict or a locked account can shut you out of RDP. The console in the client area shows the VPS screen without going through RDP, so it does not depend on the Windows Firewall.
In My Services, open the VPS page.
Click the blue Console button at the top right.
The Open the remote console? window appears. Click Open the console.

Log in, then fix or disable the faulty rule. The guide How to manage your VPS from the client area covers the console in detail.
Check results and monitor the VPS
Measure the result
A day after the setup, run the diagnostic commands from the start again. 4625 failures should drop below a hundred a day, each address should only try one to three times, and the IPBan list should grow steadily.
Get an alert during a massive attack
This script, to schedule every hour, sends an email beyond 500 failures in one hour.
$count = (Get-WinEvent -FilterHashtable @{
LogName='Security'; ID=4625; StartTime=(Get-Date).AddHours(-1)
} -ErrorAction SilentlyContinue | Measure-Object).Count
if ($count -gt 500) {
Send-MailMessage -From "alerts@yourdomain.com" -To "admin@yourdomain.com" `
-Subject "RDP attack in progress: $count attempts in 1 h" `
-Body "VPS targeted. Check IPBan and the logs." `
-SmtpServer "smtp.yourprovider.com"
}
Microsoft considers Send-MailMessage obsolete, as it does not guarantee an encrypted connection to the SMTP server. Use an SMTP server that accepts TLS, or send the alert to a webhook with Invoke-RestMethod.
Review accounts every week
Get-LocalUser | Where-Object { $_.Enabled -eq $true } | Format-Table Name, LastLogon, Description
Look for recently created accounts that you do not recognise.
Check that the VPS has not been compromised
# Local accounts: any account you did not create is suspicious
Get-LocalUser
# Scheduled tasks: look for unknown scripts
Get-ScheduledTask | Where-Object { $_.TaskPath -notlike '\Microsoft\*' }
# Processes: look for miners (xmrig, ethminer) or unknown names
Get-Process | Sort-Object CPU -Descending | Select-Object -First 15
Also look at the Application and System logs for unexpected installations. If in serious doubt, reinstall the VPS. A compromised server is not cleaned, it is replaced. The guide How to manage your VPS from the client area explains reinstalling from the client area.
Need help?
Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. In the Related Service field, pick the VPS so the team saves time. You can also ask your question on the OuiHeberg Discord.
Windows Server 2025 with the license included, Remote Desktop access and management from the client area.
View plans →