Click to return to home page
Richard Lowe Jr Home

Redirect Worms Away

Until recently, my site was hosted on an Apache web server. Why was that? Because eariler versions of Microsoft's IIS web server were in no way qualified to service internet web sites. This was largely corrected in Version 6 of IIS.

But what about those of us who are already hosting their sites on Apache servers? I've seen lots of articles about how to protect, detect, cleanse and prevent the Worms from attacking IIS servers. While the Worms do not penetrate Apache security, they do cause damage.

Some of the damage includes:

Server logs get filled with junk - The Nimda Worm alone created over 20,000 entries in a 2 day period in my log files. 

The server is made very busy This is especially true if you've got a custom 404 error page, as I do. This means that every time the Worm attempts a penetration, then entire 404 page is returned (in my case, that's about 40k). That adds up to a lot of wasted bandwidth.

I thought about this issue for a while after examining my logs and seeing thousands of 404 errors from attempted Worm penetrations. Surely there was a way to at least reduce the impact of these things? As I saw the 404 error count increase, I realized that a significant portion of the bandwidth that I was paying for was being thrown away.

An examination of the log files produced several thousand attempts at each of the following URLs. Obviously each of these is the address of a possible weakness in an IIS server.

/_mem_bin/..%5c../..%5c../..%5c../winnt/system32/cmd.exe
/c/winnt/system32/cmd.exe
/d/winnt/system32/cmd.exe
/scripts/..%2f../winnt/system32/cmd.exe
/scripts/..%c1%9c../winnt/system32/cmd.exe
/scripts/..%%35%63../winnt/system32/cmd.exe
/scripts/ .%%35c../winnt/system32/cmd.exe
/scripts/..%c0%2f../winnt/system32/cmd.exe
/scripts/..%c0%af../winnt/system32/cmd.exe 
/MSADC/root.exe

The Apache web server provides a feature called .htaccess, which provides commands to control a web site. This file is very obscure and extremely useful when used properly. You have to be careful when editing .htaccess files, as a small mistake can make your web site stop working. What I like to do is immediately test the site to be sure it works. 

Be sure not to make the mistake that I made once - I browsed to my site, saw that the home page came up, and went to work. Later, I found it was not working but appeared to work because the home page was stored in my browser cache. Thus I learned a simple lesson the hard way: always hit the refresh key of the browser when testing .htaccess changes.

I did a little research and testing, and added the following lines to my .htaccess file.

redirect /scripts http://www.stoptheviruscold.invalid
redirect /MSADC http://www.stoptheviruscold.invalid
redirect /c http://www.stoptheviruscold.invalid
redirect /d  http://www.stoptheviruscold.invalid
redirect /_mem_bin http://stoptheviruscold.invalid
redirect /msadc http://stoptheviruscold.invalid
RedirectMatch (.*)\cmd.exe$ http://stoptheviruscold.invalid$1

These lines did exactly what I wanted them to do - they stopped the virus from creating 404 errors in my log file, and they prevented my 404 error page from being triggered, thus creating lots of useless bandwidth utilization. There is still some bandwidth used, obviously, but it is far less than it would have been. The load on the server is also considerably reduced, which should make my web hosting company happy.

Note that log file entries are still made by the various Worms as they attempt to penetrate the server. These entries do now show as errors, which makes it easier to pick out real errors from the logs.

Additional Reading

  • Htaccess file If you have direct access to the .htaccess file, then you are in luck. You can do some very cool things.
  • Htaccess file - Protecting directories The most common usages of .htaccess is to restrict access to all of the files within a directory.
  • Htaccess file - MIME types You can use .htaccess to define your own MIME types. What this means is you can associated file types with actions to be performed.
  • Htaccess file - Custom error pages You can use htaccess to define custom error pages to trap 404 and other error conditions.
  • Htaccess file - Redirect You can redirect visitors to other pages using the redirect function of htaccess.
  • Htaccess file - Deny Deny is especially useful to block out unwanted spiders and malicious visitors.
  • Htaccess file - Rewrite Rewrite is a complex, but useful feature which can help you stop spam harvesters.
  • Htaccess file - Redirect Worms Away Is your site running on an Apache server and is your log file being filled with useless errors from the recent worm penetrations? Is your bandwidth being used to no good cause? Here's a solution which might help.

Unless otherwise noted, all photos and text is Copyright © Richard G Lowe, Jr.