Solved

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

Posted on 2006-11-29
18
4,471 Views
Last Modified: 2008-01-09
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.  
0
Comment
Question by:Brian Pringle
  • 6
  • 6
  • 6
18 Comments
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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).
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
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.
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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.
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
In your above post, you mentioned writing a script for the firewall.  How would I do that?
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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.

0
 
LVL 38

Expert Comment

by:Rich Rumble
Comment Utility
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
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
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
0
 
LVL 38

Expert Comment

by:Rich Rumble
Comment Utility
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
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 38

Expert Comment

by:Rich Rumble
Comment Utility
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
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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?
0
 
LVL 38

Expert Comment

by:Rich Rumble
Comment Utility
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
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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.
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
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.
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
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?
0
 
LVL 38

Accepted Solution

by:
Rich Rumble earned 500 total points
Comment Utility
I can't find any workaround for IIS 5.1, Apache can do this, and it's more secure by default and also the most used web server on the net as well. Snort can be tough to get going for a lot of folks, here is a site dedicated to win32 snort http://www.winsnort.com/ and it will work with snortsam as he has ported ss to win32.
If you wanted a script that might do this, I'd open another question in the VBScripting TA here on EE for that. A script that parses the event logs, looking for X number of failed events from a single ip address, in X amount of time. If that condition is meet, issue the netsh commands to block that ip indefinitely. See if a whitelist can be used to allow certain ip's to never be firewalled. The script should back up the firewall's settings so that you can easily roll-back if you need to.
C:\>netsh firewall show config >c:\FW_back-up.txt      (to write a backup file with the current firewall settings before the block is set)
C:\>netsh firewall set portopening ALL 21 DISABLE CUSTOM x.x.x.x    (x.x.x.x is the ip of the offending "attacker")

Look at the netsh /? help commands for further examples, netsh firewall /?      netsh firewall set /? etc...
-rich
0
 
LVL 16

Author Comment

by:Brian Pringle
Comment Utility
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
0
 
LVL 38

Expert Comment

by:Rich Rumble
Comment Utility
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Logparser is the smartest tool I have ever used in parsing IIS log files and there are many interesting things I wanted to share with everyone one of the  real-world  scenario from my current project. Let's get started with  scenario - How do w…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now