Link to home
Start Free TrialLog in
Avatar of Brian Pringle
Brian PringleFlag for United States of America

asked on

Block IP After "x" Number of Failed FTP/HTTP Logon Attempts

Environment:

Internet Connection: Bright House Cable Internet, Standard Cable Modem, Dynamic IP
Router/Firewall: D-Link DI-524 (External IP: DHCP on 192.168.0.x Network;  Internal IP: 192.168.1.1)
Web Server: Windows XP Professional running IIS (FTP and HTTP), IP address: 192.168.1.10, Norton Antivirus 2005


Physical Connection Looks Like This:

Internet ------ Motorola Cable Modem ----- D-Link DI-524 w/firewall enabled ----- Windows XP Pro w/IIS


Firewall Rules:

Deny     Block Bad IP        WAN,124.114.97.6 *,* TCP,*  
Deny     Block Bad IP        WAN,203.135.160.34 *,* TCP,*  
Deny     Block Bad IP        WAN,222.62.149.99 *,* TCP,*  
Allow    FTP                    WAN,* LAN,192.168.1.10 TCP,21  
Allow    HTTP                  WAN,* LAN,192.168.1.10 TCP,80  
Allow    Ping WAN port     WAN,* LAN,192.168.1.1 ICMP,8  
Deny     Default                *,* LAN,* *,*  
Allow    Default                LAN,* *,* *,*


The first three rules, I manually created and edit them to block an IP address of anyone that I find is currently trying to gain access using a brute force attack, which seems to be nightly.  The only traffic allowed through the firewall is either on port 80 (HTTP) or port 21 (FTP).  Nothing else is allowed through.


Desired Outcome:

Currently, if I notice that there is an excessive amount of network activity on the workstation (I monitor the activity lights on the router), I look in the IIS logs located in the subfolders under C:\Windows\System32\LogFiles.  I check to see what they are trying to access, which is usually FTP, and copy their IP address.  I then sign on to the DI-524 and go into the firewall rules and change the IP address in the "Block Bad IP" rule so that they are no longer allowed.  I accomplish my desired outcome because they are blocked, but I have to constantly monitor and manually edit the rules.

What I would like is for *Windows* to handle monitoring attempts to sign in and block their *IP Address* if it finds that there are too many failed attempts to authenticate as a specific user within a given amount of time.  In other words, if Windows (or IIS) sees that there are five failed attempts to sign in to FTP using the "Administrator" account from the same IP address within a five minute window, I want it to block the IP address for thirty minutes.  

I would prefer to accomplish this with minimal monetary investment -- preferably freeware.


Please refrain from posting flames about Windows, IIS, Norton, the router, and etc.  
Avatar of giltjr
giltjr
Flag of United States of America image

Not sure if you going to be able to do this.  The DI-524 uses a web interface to manage it.  You would have to capture the data stream while adding an IP address to the block list and see if you might be able to create a script using a telnet client that supports scripting.

You might be able to enable the Windows firewall and script is easier.  This does not stop the traffic to the Windows box, but it does stop the traffic from getting to the application level (IIS and FTP).
Avatar of Brian Pringle

ASKER

I don't want to try to block it on the router.  As far as Windows is concerned, that box does not really exist except for being the default gateway.

I want Windows to look at the incoming request, see that it is someone trying to authenticate from a particular IP address, see that it fails, see that they try it again (say five more times), and then Windows blocks the IP address from that box.  

What I want is something along the lines of Norton AntiVirus where when it detects an incoming request from a known worm, it will block the IP address.  However, I want it based on failed logon attempts.
Actually Norton AntiVirus doesn't do that.  Their firewall may, but not their Antivirus.

In order to do this, you would need stop using Windows authentication programs, write your own and have it do what you want.

You might be able to find a ftp server program that already does that, however I am not sure if it will be free or cheap.
In your above post, you mentioned writing a script for the firewall.  How would I do that?
You would have to caputer the datastream that is sent to the router/firewall when you update it using the web interface and examine it to see if it looks like you could script that.

You also need to caputer the stream when you logon to the firewall.

If the logon and the update appear to be able to be scripted, then you can get a telnet client that supports scripting, write the scritp.  The next step is to figure out how to invoke the script.

Snort in combination with SnortSAM is an effective tool, SnortSAM can update a windows ISA firewall, you set a threshold, a whitelist of ip's not to block, and even a timeout for the block if you wish: http://www.snortsam.net/ It can also do this on the cisco router or pix firewall. You'd turn off about every rule that snort has, basically commenting them out, and having it sniff the traffic.
You could possibly script this with a WMI script that looked inside the event logs for a certain event, and parsed the IP address out, and have the wmi script update the windows firewall, I'm not sure how you could enable a timeout for the block in this manner however with a simple script.
http://www.microsoft.com/technet/scriptcenter/scripts/logs/eventlog/default.mspx 
http://www.microsoft.com/technet/scriptcenter/scripts/network/firewall/default.mspx
-rich
richrumble,

I was looking at the SnortSAM site and it lists that it works with ISA Server, but does not list that it will work with Windows XP with IIS.  Do you know for sure that this will work?

Thanks
It will not, it only will configure a windows ISA firewall, it will also only receive it's information from snort. I'll look at writing a script that might do this via the netsh command... I'm not sure why no one hasn't done this already, other than this sort of automation can't fully be trusted, as it's easy to DoS yourself without a proper white-list, spoofed packets can make it so that you block your own traffic if your not careful. I don't really trust my scripting is another factor ;) There are tools like Snare or GFI's events manager that can alert you in real-time to these attempts.
http://www.intersectalliance.com/projects/SnareWindows/
http://www.gfi.com/eventsmanager/

-rich
It won't work with IIS it works with firewalls and IIS is not a firewall.

With the WMI script you that richrumble mentioned you write another script to remove the block (an "unblocking script").  In the "blocking" script get the current time and then schedule to run the "unblocking script" with the IP address as a parameter using the AT command.

In fact, can you even block IP addresses within IIS?
Yes, IIS can block via ip/dns name http://www.hostmysite.com/support/dedicated/IIS/blockip/
But a firewall is the best place typically, if the IIS server is the same that has the firewall, it won't make much of a difference in preformance, if you block on a hardware firewall or router ACL your server won't work as hard. Snort can be used in "inline" mode and you don't have to get SnortSam installed, snort can actually send a connection "reset" packet (spoofed) and the connection will be disconnected. http://www.snort.org/docs/snort_htmanuals/htmanual_2.4/node7.html
Again, the method can't be completely trusted, I'd advise you get alerted to the attempts and configure the iss file with an updated ip/dns name to block, and restart IIS.
-rich
Ah, real IIS does.  I have only used the "Personal Web Server" IIS version that comes with XP.   At least on my PC the IP Address stuff is grayed out and I can't change it.  I am making the assumption that btpringle  is running the "personal" version also.

Yes, a firewall is the best place to do this.  I am not 100% sure what he is attempting to accomplish.  Maybe attempting to slow down people that are attempting to guess at userid and passwords?
I didn't even know there was a "mini" IIS, hmmm he/she might not be able to do this... IIS 5.1 as it's called, is intended for development and not production. Apache might be a better web server to use: http://httpd.apache.org/docs/1.3/windows.html you use the .htaccess file (called ht.acl on M$) to block via IP. There are quite a few limitations to 5.1, 10 concurrent connections default, 40 max, no double decode, and only ONE! virtual host (vhost)...
-rich
Yep, not to robust.  I only use IIS, and only the mini version, when I have to.   In fact I only use Windows because that is what my company installs, I use Apache on Linux for my personal stuff and anyplace/everyplacy I can at work.
I am looking into using Snort, but the site is not too user-friendly.  How do I get started?  I am using Windows, so their Linux and Apache guides do not apply.
http://support.microsoft.com/kb/304197

The version of IIS that is installed in Windows XP Pro is IIS v5.1.  The version for Windows 2000 was IIS v5.0.  Microsoft dropped the IP address packet filtering in IIS v5.1, so it is not available for use in Windows XP.  The capability is again enabled in IIS v6.0.

Any workarounds for getting this to work on XP?
ASKER CERTIFIED SOLUTION
Avatar of Rich Rumble
Rich Rumble
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
richrumble,

I am going to continue working on this and would appreciate it if you have any more information, but I think the "netsh firewall" command above might be what I need, so I am accepting that as the answer.  Thanks for all of your help and I will post here again when I have a working solution.

Thanks,
Brian
NP, the netsh commands might help speed things along, and perhaps instead of automatically blocking via snortsam/vbscript, perhaps simply parsing the event logs and giving you a report of the ip's to block, and all you have to do is a quick copy-paste onto the netsh command. You'll want to test, but that command should work fine.
-rich