Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was wondering if there was a simple way to make apache httpd deny (403) any URLs which contain a parent .. in the path.

So far I have tried (ignoring the flase positives for simplicity)

<LocationMatch "\.\.">
Order allow,deny
Deny from all
</LocationMatch>

But that didn't work. The directory has Allow from all in it. Am I on the right track or is there an easier way to do this (like there was in Fasttrack back in the 90s).

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I would do it by using ModSecurity:

SecRule REQUEST_URI "../" "log,deny,msg:'Directory Traversal Attack Detected'"

Testing with some requests:

http://domain.com/../../../../etc/passwd

and examine the audit log, you'll see something like this:

[modsecurity] [client x.x.x.x] [domain domain.com] [302] [/20120816/20120816-1529/20120816-152911-1np2Nn8AAAEAA Aq6EU0AAAAG] [file "/etc/httpd/modsecurity.d/modsecurity_crs_10_config.conf"] [line "305"] [msg "Directory Traversal Attack Detected"] Access denied with code 403 (phase 2). Pattern match "../" at REQUEST_URI.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.