Perform comprehensive testing to ensure the system works correctly without blocking legitimate traffic.
First, simulate a brute force attack by generating failed logon events (use a test account):
# Generate test failed logon events (run from another machine)
for ($i = 1; $i -le 10; $i++) {
try {
$cred = Get-Credential -UserName "testuser" -Message "Enter wrong password"
Enter-PSSession -ComputerName "YourServerIP" -Credential $cred
} catch {
Write-Host "Failed attempt $i" -ForegroundColor Red
}
Start-Sleep -Seconds 2
}
Monitor the detection in real-time:
# Watch for new Event ID 4625 entries
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625; StartTime=(Get-Date).AddMinutes(-10)} |
Select-Object TimeCreated, @{Name='SourceIP';Expression={([xml]$_.ToXml()).Event.EventData.Data | Where-Object {$_.Name -eq 'IpAddress'} | Select-Object -ExpandProperty '#text'}}
Verify the firewall rule is populated and enabled:
# Check firewall rule status
$Rule = Get-NetFirewallRule -DisplayName "BlockAttackers"
$Addresses = Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $Rule
Write-Host "Rule Enabled: $($Rule.Enabled)" -ForegroundColor $(if($Rule.Enabled){'Green'}else{'Red'})
Write-Host "Blocked Addresses: $($Addresses.RemoteAddress -join ', ')" -ForegroundColor Yellow
Test connectivity from a blocked IP range (if possible):
# From the server, test if the rule is actually blocking
Test-NetConnection -ComputerName "localhost" -Port 3389 -InformationLevel Detailed
Verification: Check the complete system status:
# Complete system health check
Write-Host "=== RDP Brute Force Protection Status ===" -ForegroundColor Cyan
Write-Host "Scheduled Task: $(if((Get-ScheduledTask -TaskName 'RDP_BruteForce_Protection').State -eq 'Ready'){'Running'}else{'Not Running'})" -ForegroundColor Green
Write-Host "Firewall Rule: $(if((Get-NetFirewallRule -DisplayName 'BlockAttackers').Enabled){'Enabled'}else{'Disabled'})" -ForegroundColor Green
Write-Host "Event Logging: $(if((auditpol /get /category:'Logon/Logoff' | Select-String 'Failure.*Success').Count -gt 0){'Enabled'}else{'Disabled'})" -ForegroundColor Green
Write-Host "Recent Blocks: $((Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='RDC Brute Force Prevention Script'} -MaxEvents 5 -ErrorAction SilentlyContinue).Count)" -ForegroundColor Yellow
Warning: Always test from a secondary connection method (console access, VPN, or different IP) before deploying to production. A misconfigured rule could lock you out of your own server.