Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 05:31:49 PM

Pages: [1]   Go Down
  Print  
Author Topic: Example of an htaccess file  (Read 5137 times)
etech97
Space Explorer
***
Offline Offline

Posts: 7



WWW
« on: August 25, 2009, 09:35:13 AM »

After my Website was hacked, I researched on the Internet all I could about the .htaccess file. Here is a portion of my file. The "deny from can contain multiple ip addresses and you can block whole subnets by entering as an example 194.874. makeing sure you have the trailing period. As far as the bad user agents, they are available on the Internet, all you have to do is search for them and add them into the correct section. Since I implemented my .htaccess file I have not had any problems at all!

# Lets deny some users
# deny from xx.xxx.xxx.xxx

# Use Options
Options +FollowSymLinks

#  mod_rewrite in use
RewriteEngine On

#  Uncomment following line if your webserver’s URL
#  is not directly related to physical file paths.
#RewriteBase /

#RewriteCond %{HTTP_HOST} ^corephp\.com
#RewriteRule ^(.*)$ http://www.corephp.com/$1 [R=permanent,L]

#Redirect moved pages
#Redirect 301 /old-link.html http://www.corephp.com/new-link.html

#Rewrites
#RedirectMatch    ^/somedir(/)?$   http://www.corephp.com/index.php?option=com_somecomponent

ServerSignature Off
RewriteCond %{REQUEST_METHOD}  ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]
RewriteCond %{THE_REQUEST}     ^.*(\\r|\\n|%0A|%0D).* [NC,OR]

RewriteCond %{HTTP_REFERER}    ^(.*)(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{HTTP_COOKIE}     ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
#RewriteCond %{REQUEST_URI}     ^/(,|;|:|<|>|'>|'<|/|\\\.\.\\).{0,9999}.* [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(libwww-perl|curl|wget|python|nikto|scan).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]

RewriteCond %{QUERY_STRING}    ^.*(;|<|>|’|”|\)|%0A|%0D|%22|%27|%3C|%3E|%00).*(/\*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*\.[A-Za-z0-9].* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC]

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
## Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
########### End - Rewrite rules to block out some common exploits

########## Begin - Joomla! core SEF Section#
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^/index.php
#RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
#RewriteRule (.*) index.php
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########### End - Joomla! core SEF Section

########## Block bad user agents
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_user_AGENT} (copier¦collect¦download¦express¦extract¦grab¦mail¦mass¦offline|attach¦copy¦entry¦extract¦Ninja¦Stripper¦Sucker¦Whacker) [NC]


Maybe the Moderator will be kind enough to sticky this post  Yep

Cheers!
etech97:)
« Last Edit: August 29, 2009, 10:16:32 AM by etech97 » Logged
Paulo
Newbie
*
Offline Offline

Posts: 5


« Reply #1 on: September 22, 2009, 09:20:45 PM »

My server got hacked and I searched for htaccess and this is one of the replies that came up and I want to copy what you used. 

I know it is an overseas site that is hacking my site and I want to know how to add there IP into the htaccess in the above post.

I know what the IP is and normally a allow-all-but-deny htaccess file would look like this:

Code:
# Allow all and deny IP.
order allow,deny
deny from 91.121.24.139
allow from all

How would I add 91.121.24.139 to the htaccess file in the first post?

This site helped me a bit more than some of the Whois sites: http://www.malwareurl.com/listing.php?domain=tiqt.ru
 
Logged
Paulo
Newbie
*
Offline Offline

Posts: 5


« Reply #2 on: September 22, 2009, 10:07:14 PM »

Duh, it was on the second line, just had to un-comment it:
Code:
# Lets deny some users
 deny from 91.121.24.139
Logged
DEddleman
Spacescooter Operator
*****
Offline Offline

Posts: 34


Elite!


« Reply #3 on: January 07, 2010, 07:01:19 AM »

Semi-necropost, but I just saw this and I am impressed...

Code:
RewriteCond %{HTTP_USER_AGENT} ^.*(libwww-perl|curl|wget|python|nikto|scan).* [NC,OR]
Blocking nikto? That's outright genious.
(For those of you who don't know what nikto is, go here.)


Code:
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
Also genious, given how many modern exploits are done in base64 for obfuscation purposes!
Logged

jimlongo
Intergalactic Superstar
*****
Offline Offline

Posts: 125



WWW
« Reply #4 on: January 12, 2010, 07:06:18 AM »

All of those QUERY_STRING directives stop my websites from functioning.  I get a 500 error with any of them.  Sad

EDIT

Maybe it's the formatting of this post, when I found these in an earlier forum at - http://www.corephp.com/blog/htaccess-security/ - they worked

Code:
RewriteCond %{QUERY_STRING}    ^.*(;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|%00).*(/\*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*\.[A-Za-z0-9].* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|%00).* [NC]
« Last Edit: January 12, 2010, 07:27:26 AM by jimlongo » Logged

Pages: [1]   Go Up
  Print  
 
Jump to: