

I found this tool to be most helpful to nail down who and where these hits were coming from. TANGENT - Once I ran this for a week or so I quickly realized there were a fair amount of patterns in the net ranges of the IP addresses. However it has helped me identify and block over 100 IP addresses in a week or so (mainly China and Hong Kong, but I did block the Department of Homeland Security). I understand that this is not a perfect solution, because it only works with IPv4 IP addresses and only looks at log in attempts made through probably port 1433 depending on your configuration.

WHILE EXISTS(SELECT * FROM TOP(1) FROM FROM WHERE INTO autobanned_ipaddesses (attacked_on,ipaddress,number_login_attempts) = 'netsh advfirewall firewall add rule name="Autobanned IP - SQL Attacked dir=in action=block enable="yes" protocol=any interfacetype=any'ĮXEC master.xp_cmdshell WHERE sp_cycle_errorlog archives the current error log.
GRIFFIN TEAM SL3 BRUTEFORCE SERVER WINDOWS
IF (SELECT COUNT(*) FROM ExitWithoutCycleīEGIN /* Loop through T3 and add each entry to the windows firewall */ GROUP BY CONVERT(varchar(10),LogDate,101),IPAddressīEGIN /* Validate that T3 has records, if not skip the firewall add */ WHERE NOT EXISTS(SELECT * FROM autobanned_ipaddesses ai WHERE ai.ipaddress=T.IPAddress) INSERT INTO CONVERT(varchar(10),LogDate,101) LogDate,IPAddress from T INSERT INTO LogDate,ProcessInfo,REPLACE(REPLACE( SUBSTRING(Text, PATINDEX ('%.%.%.%',Text)-2,50),']',''),':','') FROM /* Get the NEW ip addresses from T2*/ INSERT INTO sp_readerrorlog 0,1,'An error occurred while evaluating the password' INSERT INTO sp_readerrorlog 0,1,'Could not find a login matching the name provided' USE ĭECLARE TABLE(LogDate datetime,ProcessInfo varchar(200),Text varchar(max))ĭECLARE TABLE(LogDate datetime,ProcessInfo varchar(200),IPAddress varchar(max))ĭECLARE TABLE(LogDate datetime,IPAddress varchar(max))īEGIN /* Get error log records with failed login attempt data */ If you don't have it enabled here is a good link to help you. To each their own, but my script won't work without this functionality. I certainly don't want to debate the merits of enabling or disabling this functionality. Also note that this process utilizes xp_cmdshell.

GRIFFIN TEAM SL3 BRUTEFORCE SERVER CODE
Personally I placed this code in an Agent Job running every 10 minutes. ADD CONSTRAINT DEFAULT (getdate()) FOR Ĭreate the process to auto add IP addresses to the firewall. ( ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON ) ON ĪLTER TABLE. Make sure the radio button for either || is selected.Ĭreate the table to store banned IP addresses /* Create table to store banned IP addresses */ĬREATE TABLE. In SQL Server Management Studio (SSMS) right click your instance (above your databases) Properties → Security → Login auditing. Insure you are logging failed attempts.As I run this every 10 minutes the whole process takes about 4-5 seconds. I am running a Windows Server 2008 and SQL Server 2008 R2.īe advised if you have not cycled your SQL Server Error Logs in a while, you may get a great many IP addresses and it may take a little time to process everything. It is based on the SQL Server Error Logs. I wrote this functionality to auto ban an IP address that has made more than X ( log in attempts from the same IP address.
