mod_rewrite Rules To Stop Worms & Web Attacks

 
 
By Larry Seltzer  |  Posted 2003-05-28 Print this article Print
 
 
 
 
 
 
 

A reader submits rules to have Apache stop most attacks against web servers.

Thanks to Jonas Eckerman (http://www.truls.org/) for answering my request in a recent column for input rules for the Apache mod_rewrite module to make it work roughly like Microsofts UrlScan. Eckerman isnt familiar with UrlScan, but says these rules "stop a majority of worms and attacks against web servers."

These rules cause Apache to return an HTTP 403 ("forbidden") response for URLs which match (for example "http://www.truls.org/testing/cmd.exe?whatever"). Its not perfect or complete, but it does stop a lot.

    RewriteEngine On
    RewriteOptions inherit
    RewriteLog logs/rewrite_log

    RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/winnt/system32/(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/winnt/system/(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/windows/system32/(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/windows/system/(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/cmd\.exe[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/scripts/root.exe[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/msadc/root\.exe[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)\\\.\.(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/admin\.dll[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/msadcs\.dll[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/ext\.dll[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI} (.*)/\.(.*) [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)/php\.exe[$|\?(.*)] [NC,OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)\<(.*) [OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)\>(.*) [OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)\|(.*) [OR] RewriteCond %{REQUEST_URI} (.{255,}) [OR] RewriteCond %{QUERY_STRING} (.{127,}) [OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} [\x00-\x1f]+ [OR] RewriteCond %{REQUEST_URI}?%{QUERY_STRING} [\x7f|\xff]+ RewriteRule (.*) http://monty.frukt.org/error/filtered.html [NC,F]
 
 
 
 
Larry Seltzer has been writing software for and English about computers ever since—,much to his own amazement—,he graduated from the University of Pennsylvania in 1983.

He was one of the authors of NPL and NPL-R, fourth-generation languages for microcomputers by the now-defunct DeskTop Software Corporation. (Larry is sad to find absolutely no hits on any of these +products on Google.) His work at Desktop Software included programming the UCSD p-System, a virtual machine-based operating system with portable binaries that pre-dated Java by more than 10 years.

For several years, he wrote corporate software for Mathematica Policy Research (they're still in business!) and Chase Econometrics (not so lucky) before being forcibly thrown into the consulting market. He bummed around the Philadelphia consulting and contract-programming scenes for a year or two before taking a job at NSTL (National Software Testing Labs) developing product tests and managing contract testing for the computer industry, governments and publication.

In 1991 Larry moved to Massachusetts to become Technical Director of PC Week Labs (now eWeek Labs). He moved within Ziff Davis to New York in 1994 to run testing at Windows Sources. In 1995, he became Technical Director for Internet product testing at PC Magazine and stayed there till 1998.

Since then, he has been writing for numerous other publications, including Fortune Small Business, Windows 2000 Magazine (now Windows and .NET Magazine), ZDNet and Sam Whitmore's Media Survey.
 
 
 
 
 
 
 

Submit a Comment

Loading Comments...
 
Manage your Newsletters: Login   Register My Newsletters























 
 
 
 
 
 
 
 
 
 
 
Rocket Fuel