Securiza tu web con este .htaccess

Bueno bueno bueno, feliz año 2012 y tal y cual…. aquí os copypasteo un .htaccess para que podais evitar a los pequeños lamers que intentan joder y escanear vuestras webs o aplicaciones webs. Ponerlo bajo vuestra responsabilidad y siempre guardar el .htaccess original antes de agregar lineas

#Evitar escaneos, manipulación e inyeccion SQL (SQL, XSS, etc)
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(-|\.|’) [OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)(<|>|%3C|%3E)(.*) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget)(.*) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)(libwww-perl|libwwwperl|snoopy|curl|wget|winhttp|python|nikto|scan|clshttp|archiver|loader|email|harvest|fetch|extract|grab|miner|suck|reaper|leach|havij)(.*) [NC,OR]
RewriteCond %{REQUEST_URI} ^(/,|/;|/<|/>|/’|/`|/%2C|/%3C|/%3E|/%27|/////) [NC,OR]
RewriteCond %{HTTP_REFERER} ^(.*)(%00|%08|%09|%0A|%0B|%0C|%0D|%0E|%0F|%2C|<|>|’|%3C|%3E|%26%23|%27|%60)(.*) [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)(%00|%08|%09|%0A|%0B|%0C|%0D|%0E|%0F|%2C|%3C|%3E|%27|%26%23|%60)(.*) [NC,OR]
RewriteCond %{HTTP_COOKIE} ^(.*)(<|>|’|%3C|%3E|%27)(.*) [NC]
RewriteRule ^(.*)$ index.php [NC]

#Evita manipulacion en la URL
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|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} ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC]
RewriteRule ^(.*)$ index.php [NC]
#Complica los ataques Remote File include y Local File include

RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC]
RewriteRule .* – [F]


Be Sociable, Share!

Articulos relacionados:

7 Comments

  1. Información Bitacoras.com…

    Valora en Bitacoras.com: Bueno bueno bueno, feliz año 2012 y tal y cual…. aquí os copypasteo un .htaccess para que podais evitar a los pequeños lamers que intentan joder y escanear vuestras webs o aplicaciones webs. Ponerlo bajo vuestra responsa……

  2. Sergio dice:

    Chapó. Metiendo “havij” como opción añadida en la linea 6 ya sería de Oscar.

    ¡¡¡ Muy buen aporte !!!

    • GhOsTi dice:

      ajam cierto Sergio, voy a meter havij en la linea 6 :D gracias por tu aporte

      se te ocurre alguna modificación más?

      • UnaPregunta dice:

        Una pregunta, ¿de que sirve la lista tan detallada por aplicaciones? de la linea 6

        Si la conexión es por wget y se ejecuta como modificando el agente, (por ejemplo “MSIE 6.0; Windows NT 5.1″), creo que será un poco igual ¿no?

        La pregunta es desde el desconocimiento, nada de “pocahuevos”

        • GhOsTi dice:

          No es nada tocahuevos…. porque es muy evidente la respuesta.

          Muchos lamercillos se bajan software/scriptsphp, etc… con la finalidad de tocar los huevos y defacear webs, sacar bases de datos, etc. estos programas ya están compilados y muchos de esos usan esos agentes para hacer sus POST/GET y demás con la finalidad de joder webs, bases de datos, etc

          Cabe decir que los verdaderos conocedores de seguridad web, saben, conocen y se saltan, la pequeña “seguridad” que aplica el anterior .htaccess en un plisplas

  3. Sergio dice:

    Así en principio me parece genial. ;)

  4. cm.labs dice:

    Muy bueno, gracias por compartirlo.

Leave a Comment