Reply
.htaccess, blacklists & honeypots
Old 12-10-2008, 06:38 PM Question .htaccess, blacklists & honeypots
Skilled Talker

Posts: 61
Name: John
Trades: 0
Looking for a bit of righteous judgement!

I currently use a combination of methods to assuade my bot paranoia, including:
Code:
# --------------------------------------------------------- Bad Agent Blocking
# Blatantly borrowed from various online sources
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Custo
# ... and the list goes on
RewriteRule ^.* - [F,L]

# --------------------------------------------------------- Query String Exploit Blocking
# Also, blatantly borrowed from various online sources
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

# --------------------------------------------------------- Common PHP Exploit Redirect
# I like to think I thought this one up
RewriteCond %{REQUEST_URI} ^.*awstats\.pl [OR]
RewriteCond %{REQUEST_URI} ^.*azenv\.php [OR]
RewriteCond %{REQUEST_URI} ^.*main\.php [OR]
# ... and other apps I don't use
RewriteRule ^(.*)$ /_honeypot/ [L]
Where /_honeypot/ is the location of a logging & blacklisting script.

Questions:

1. Worth the effort?
2. Bad idea?
3. A better way?

Trust me, I can take it.

Last edited by Envision_frodo; 12-10-2008 at 06:58 PM.. Reason: Noob Moment
Envision_frodo is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 12-10-2008, 08:42 PM Re: .htaccess, blacklists & honeypots
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
Your .htaccess file is parsed by the web server for every request. That means all the media on your page, all the scripts, all the style sheets, even every little png file, is going to force Apache to deal with all the .htaccess code. For a 200 KB music file, it won't add much (% wise) overhead, but for a bunch of 300 byte icons, that's going to slow things down.

Also, .htaccess isn't a very expressive medium. I would personally let all traffic be funneled through at this point, and use code at a higher level to keep detailed metrics and ban robot like behavior, instead of simple requests.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 12-11-2008, 05:21 AM Re: .htaccess, blacklists & honeypots
mtishetsky's Avatar
King Spam Talker

Posts: 1,166
Name: Mike
Location: Mataro, Spain
Trades: 0
To avoid parsing .htaccess on small static files it is recommended to install lightweight frontend like nginx or lighttpd to serve all images, css, javascripts and even static html files.
__________________
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-11-2008, 02:07 PM Re: .htaccess, blacklists & honeypots
Skilled Talker

Posts: 61
Name: John
Trades: 0
I hear you on the overhead (every lil' bit helps); how would something like this play out given that scenario:

Code:
<FilesMatch "\.(htm|html|js|php)$">
#... all that jazz above
</FilesMatch>
Would it help? or just add to the total K per access?
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 12-29-2008, 12:53 PM Re: .htaccess, blacklists & honeypots
Novice Talker

Posts: 9
Name: Tom Raef
Trades: 0
It's a great strategy! Honest.

However, the implementation is a bit too resource intensive. Why not use something like Squid as a reverse proxy in front of your webserver? Is that a viable option? That way only good traffic gets through.

That is pure genius however.
__________________
We Watch Your Website - you go do what you do best!
Free Security Report
WeWatch is offline
Reply With Quote
View Public Profile
 
Old 12-30-2008, 02:11 PM Re: .htaccess, blacklists & honeypots
Skilled Talker

Posts: 61
Name: John
Trades: 0
Thanks for the continued assist.

While my host may allow (in this case) the implementation of a proxy (Squid) or similar front end, I'm constantly striving towards simplistic and purist approaches. My experience has always been that (well implemented and understood) less is more, as more tends to have its own baggage in terms of maintenance and security.

The goal is to meet my masochistic and highly retentive desire to enact some form of diluted justice upon the bots and skiddies without taxing everyone else.

Are there any (non-additive) alternatives?
Magical .conf entries?
How about virtual directories?
Does the <FilesMatch> approach do anything for me?
How about <LocationMatch) or <DirectoryMatch> given a tree something like this:

/var/htdocs/ - All php scripts
/var/htdocs/includedir/ - All php/html includes
/var/htdocs/cssdir/ - All external style sheets
/var/htdocs/jscriptdir/ - All javascript
/var/htdocs/imagedir/ - All images

Is the content in a <...MATCH> block skipped on false or parsed regardless?

Last edited by Envision_frodo; 12-30-2008 at 02:22 PM.. Reason: Added a couple more ideas
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 01-08-2009, 12:45 PM Re: .htaccess, blacklists & honeypots
Skilled Talker

Posts: 61
Name: John
Trades: 0
Thanks again for all the great feedback, I modified my ill-advised strategy a bit to hopefully eek out a few extra K.

Code:
# --------------------------------------------------------- Bad Agent Blocking
# Blatantly borrowed from various online sources
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow|^ChinaClaw|^Custo
# ... and the list goes on
RewriteRule ^.* - [F,L]

# --------------------------------------------------------- Common PHP Exploit Redirect
# I like to think I thought this one up
RewriteCond %{REQUEST_URI} ^.*awstats\.pl|^.*azenv\.php|^.*main\.php [OR]
# ... and other apps I don't use
RewriteRule ^(.*)$ /_honeypot/ [L]
For some of my sites that are light on graphics, etc, I may let the extra parsing fly and see how the honeypot grows :P... Thanks

Last edited by Envision_frodo; 01-08-2009 at 12:49 PM.. Reason: nother noob moment
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to .htaccess, blacklists & honeypots
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.17773 seconds with 13 queries