{"id":2494,"date":"2014-09-01T20:09:37","date_gmt":"2014-09-01T19:09:37","guid":{"rendered":"https:\/\/beufa.net\/?p=2494"},"modified":"2014-09-01T20:09:37","modified_gmt":"2014-09-01T19:09:37","slug":"bloquer-le-brute-force-sur-une-authentification-apache","status":"publish","type":"post","link":"https:\/\/beufa.net\/fr\/blog\/bloquer-le-brute-force-sur-une-authentification-apache\/","title":{"rendered":"Bloquer le brute force sur une authentification Apache"},"content":{"rendered":"<p>Toujours et encore du fail2ban !<\/p>\n<p>Pour bloquer des tentatives d&#8217;authentification et donc de l&#8217;\u00e9num\u00e9ration d&#8217;utilisateur type brute force sur des authentifications Apache \/ httpd, il existe d\u00e9j\u00e0 le fichier de filtre suivant :<\/p>\n<pre class=\"brush:shell\">[20:18 user@server ~] &gt; vim \/etc\/fail2ban\/filter.d\/apache-auth.conf\r\n \r\nFail2Ban apache-auth filter\r\n#\r\n\r\n[INCLUDES]\r\n\r\n# Read common prefixes. If any customizations available -- read them from\r\n# apache-common.local\r\nbefore = apache-common.conf\r\n\r\n[Definition]\r\n\r\n\r\nfailregex = ^%(_apache_error_client)s (AH01797: )?client denied by server configuration: (uri )?\\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01617: )?user .*? authentication failure for \"\\S*\": Password Mismatch(, referer: \\S+)?$\r\n            ^%(_apache_error_client)s (AH01618: )?user .*? not found(: )?\\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01614: )?client used wrong authentication scheme: \\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH\\d+: )?Authorization of user \\S+ to access \\S* failed, reason: .*$\r\n            ^%(_apache_error_client)s (AH0179[24]: )?(Digest: )?user .*?: password mismatch: \\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH0179[01]: |Digest: )user `.*?' in realm `.+' (not found|denied by provider): \\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01631: )?user .*?: authorization failure for \"\\S*\":(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01775: )?(Digest: )?invalid nonce .* received - length is not \\S+(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01788: )?(Digest: )?realm mismatch - got `.*?' but expected `.+'(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01789: )?(Digest: )?unknown algorithm `.*?' received: \\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01793: )?invalid qop `.*?' received: \\S*(, referer: \\S+)?\\s*$\r\n            ^%(_apache_error_client)s (AH01777: )?(Digest: )?invalid nonce .*? received - user attempted time travel(, referer: \\S+)?\\s*$\r\n\r\nignoreregex =\r\n<\/pre>\n<p>Il suffit ensuite d&#8217;activer le filtre fans la configuration globale de fail2ban :<\/p>\n<pre class=\"brush:shell\">[20:53 user@serveur ~] &gt; vim \/etc\/fail2ban\/jail.conf\r\n\r\n[apache]\r\nenabled  = true\r\nport     = http,https\r\nfilter   = apache-auth\r\nlogpath  = \/var\/log\/httpd\/*\/*error_log\r\naction = iptables-multiport[name=Apache-auth, port=\"http,https\", protocol=tcp]\r\n         sendmail-whois[name=Apache-auth, dest=user@beufa.net, sender=sender@beufa.net]\r\nmaxretry = 6\r\n<\/pre>\n<p>Ceci permet de bloquer l&#8217;IP source sur le port 80 et 443 dans la cha\u00eene iptables d\u00e9di\u00e9e (ici : fail2ban-Apache-auth), ainsi que d&#8217;envoyer un mail contenant un whois de l&#8217;IP source au bout de 6 authentifications \u00e9chou\u00e9es :<\/p>\n<pre class=\"brush:shell\">[20:56 user@serveur ~] &gt; iptables -L fail2ban-Apache-auth\r\nChain fail2ban-Apache-auth (1 references)\r\ntarget     prot opt source               destination\r\nRETURN     all  --  anywhere             anywhere\r\n<\/pre>\n<p>Malheureusement avec fail2ban, toujours pas de compatibilit\u00e9 IPv6 native (cela est possible, mais via un <a title=\"Fail2ban IPv6 Experimental\" href=\"http:\/\/www.fail2ban.org\/wiki\/index.php\/Fail2ban:Community_Portal#IPv6_Experimental_support\" target=\"_blank\">patch fourni sur le wiki de fail2ban<\/a>).<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Toujours et encore du fail2ban ! Pour bloquer des tentatives d&#8217;authentification et donc de l&#8217;\u00e9num\u00e9ration d&#8217;utilisateur type brute force sur des authentifications Apache \/ httpd,&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/beufa.net\/fr\/blog\/bloquer-le-brute-force-sur-une-authentification-apache\/\">Continue reading<span class=\"screen-reader-text\">Bloquer le brute force sur une authentification Apache<\/span><\/a><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,25],"tags":[33,47,54,79],"class_list":["post-2494","post","type-post","status-publish","format-standard","hentry","category-linux","category-securite-2","tag-apache","tag-fail2ban","tag-iptables","tag-securite","entry"],"_links":{"self":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts\/2494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/comments?post=2494"}],"version-history":[{"count":1,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts\/2494\/revisions"}],"predecessor-version":[{"id":2495,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/posts\/2494\/revisions\/2495"}],"wp:attachment":[{"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/media?parent=2494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/categories?post=2494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beufa.net\/fr\/wp-json\/wp\/v2\/tags?post=2494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}