Forum Moderators: phranque

Message Too Old, No Replies

Root .htaccess precedence over sub-directory .htaccess

Having logical problem with root vs. sub-directory .htaccess

         

yakiv

2:42 am on Aug 1, 2009 (gmt 0)

10+ Year Member



First, I am new to WebMasterWorld.com. Please forgive me if this is too elementary problem.

I have done extensive searching on the web, including with keywords and site:webmasterworld.com . I just cannot come-up with appropriate answer.

Basically, I am trying a technique to protect webmail. But, I have a problem with sub-directory .htaccess seeming to take precedence over the root .htaccess. I contacted hosting company and they said that the "last option" (which I gather is [L] may do the trick, but I cannot confirm).

Here is my set-up:

#1, I have .htaccess in root
#2, This .htaccess has rewrite, like so:


Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^111.111.111.111$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]


ErrorDocument 403 /e403.php
ErrorDocument 404 /e404.php


redirect 301 /webmailprogram http://mydomain.com/crackergoaway

#3, I have a subdomain set-up, pointing to the folder webmailprogram, such as [mywebmail.mydomain.com...]

#4, I have the folder /webmailprogram password protected, through the hosting company's utility and that folder contains the following code in the .htaccess file:


AuthName "Password Protected Area"
AuthType Basic
AuthUserFile /usr/local/webpassword/wp001.dat
Require valid-user

Ideally, what I want to happen is if a cracker, like one of these morfeus idiots is scanning my site, that if they tried to hit the folder, /webmailprogram they would get redirected to /crackergoaway. This allows me to still easily track in the logs and analytics programs what they did and it makes it impossible to get at my mail program.

However, if I access my mail through the subdomain, then I am not affected by the /crackergoaway, I just need to enter the password to get into the area.

The problem is that when the scanner hits the /webmailprogram folder, they are faced with a login for user id and password, rather than getting simply redirected. My host explained that the priority works backwards, which baffled me (I had forgotten about that, on Linux systems). This is why they said it might be solved with "last option" or [L], but did not give me a specific sample code or solution.

I just don't know how to fix that.

Now, someone may say, all of this is not necessary, but, I am just trying to be creative here and it adds a bit of fun for them to get that /crackergoaway page. :-)

Thanks for the help. If I was not clear in something, I will attempt to clarify.

jdMorgan

6:11 pm on Aug 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that there is essentially no difference between your 'entry path' to the mail program's directory, and anyone else's 'entry path' to it. If you can define some difference, then the server can be configured to behave differently based on that difference. But here, there is no difference.

Don't bother trying to redirect the bad guys or serve them cute or gloating 'special' pages. These are almost always automated programs running on compromised PCs in a botnet, and most do not follow redirects.

If a particular malicious request *is* among the tiny minority that has an actual human behind it, then either they won't speak your language and your message will be meaningless to them, or if they do speak your language, they will appreciate the clues you give them about how you've detected them and protected your site. They can then improve their attack based on the info you provide and try again. Most will simply move on to easier victims, though, unless it's "personal." Therefore, any kind of 'special message' is either a waste of your time or *decreases* your security.

Since you've password-protected this directory, why not consider the job done and move on to more important things? And for other access control cases, if you decide to forbid access, then serve a simple 403-Forbidden custom error page with no information whatsoever that would be useful to a malicious agent. Provide a text link to your homepage and 'Help' page if applicable, but little else.

Jim

yakiv

8:04 pm on Aug 1, 2009 (gmt 0)

10+ Year Member



Jim, thanks!

Okay, let's say I want to deliver just a simple 403-Forbidden, which is easy enough, how would I do this based on my set-up?

I essentially agree with what you said, but I am still curious what the principle is, that I would need to do, if I wanted to accomplish this. In other words, it's just a point of curiosity now.

yakiv

8:09 pm on Aug 1, 2009 (gmt 0)

10+ Year Member



by the way, this is the typical bunch of junk I see (I am sure you have seen it all):


121.254.231.13211:06:04/roundcube//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:04/rc//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:05/mss2//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:05/mail//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:06/mail2//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:06/roundcubemail//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:07/rms//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:07/webmail2//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:07/webmail//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:08/wm//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:08/bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:10/round//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:10/cube//bin/msgimport-"Toata dragostea mea pentru diavola"...
121.254.231.13211:06:11-"-"...

jdMorgan

9:24 pm on Aug 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You would need to allow that user-agent to by-pass your login using mod_access "Allow from" and core "Satisfy any" -- not a great idea, by the way -- and then deny that user-agent using either mod_rewrite or mod_setenvif and mod_access "Deny from env=xyz".

Too complicated for the benefit.

Jim

yakiv

10:00 pm on Aug 1, 2009 (gmt 0)

10+ Year Member



Is there not a way to just reverse the order of what happens? Force the redirect to happen before it even needs to request the User ID and password? Or maybe I am missing something.

jdMorgan

10:50 pm on Aug 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, because mod_auth must be the first priority in order to protect your server. Imagine the consequences if otherwise...

Jim

yakiv

2:41 am on Aug 2, 2009 (gmt 0)

10+ Year Member



Aha. I guess that settles that! :-)