This chueyise.com article provides a solution to monitor the Windows event logs for failed events and dynamically block source IP addresses within the log.
The described solution monitors the Windows event log for failed Remote Desktop Service logons and immediately configures the Windows firewall to block the external source. If desired, the solution can be adapted to monitor any failed network-related events and block it’s source.
As a user with Administrator rights, from the Start menu enter gpedit and select Edit group policy. Traverse to
and enable Audit Logon for Success and Failure.
Create a powershell script and save the file in a location only accessible by users assigned to the Administrators group. For this guide, the file is named FW-Blocker.ps1 and a working example (with comments explaining the code) is provided below.
Add arguments: -File C:\users\adminuser\FW-Blocker.ps1
Run the powershell script as a user with Administrator rights to verify it runs with no errors. The first valid run will create the Windows Firewall rule depicted in Figures 7 thru 11. From the Start menu, enter Firewall, select Windows Defender Firewall with Advanced Security, and Run as administrator. Expand the Inbound Rules and double click on the RDP Block rule.
IMPORTANT: Be sure to refresh the firewall to see any dynamic changes applied to the rules. Right-click on Inbound Rules and select Refresh.
NOTE: At least one IP must exist in the Remote IP address section in order to dynamically add nefarious IP addresses. IP address 1.1.1.1 will always exist by default.