{"id":1564,"date":"2015-07-09T10:53:34","date_gmt":"2015-07-09T08:53:34","guid":{"rendered":"https:\/\/www.hostking.host\/blog\/?p=1564"},"modified":"2015-07-09T10:53:34","modified_gmt":"2015-07-09T08:53:34","slug":"using-fail2ban-to-block-wordpress-login-attacks","status":"publish","type":"post","link":"https:\/\/www.hostking.host\/blog\/using-fail2ban-to-block-wordpress-login-attacks\/","title":{"rendered":"Using fail2ban to block WordPress login attacks"},"content":{"rendered":"<p>Today and in the past few days I&#8217;ve been often flooded with POST requests that look like this:<\/p>\n<pre class=\"code-pre \">103.19.180.119 - - [09\/Jul\/2015:10:50:02 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n103.19.180.119 - - [09\/Jul\/2015:10:50:03 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n103.19.180.119 - - [09\/Jul\/2015:10:50:04 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n103.19.180.119 - - [09\/Jul\/2015:10:50:04 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n103.19.180.119 - - [09\/Jul\/2015:10:50:05 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n103.19.180.119 - - [09\/Jul\/2015:10:50:06 +0200] \"POST \/wp-login.php HTTP\/1.1\" 403 1139\n\nTo stop these attacks we found we had to install fail2ban with CSF.\n\nThe way to perform this is to install fail2ban first using:\n\nrpm -Uvh http:\/\/dl.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm\nyum install fail2ban\n\nOnce installed go to:\n\n\/etc\/fail2ban\n\nThen edit the jail.local file\n\nadd the following:\n\n[wp-auth]\nenabled = true\nfilter = wp-auth\naction = csf-ip-deny[name=wordpress port=\"http,https\"]\nlogpath = \/etc\/httpd\/logs\/access_log\nbantime = 300\nmaxretry = 3\n\nOnce done\n\nGo to \/etc\/fail2ban\/action.d\n\ncreate a file called csf-ip-deny.conf\n\nand add the following within it:\n\n# CSF \/ fail2ban integration\n[Definition]\nactionstart =\nactionstop =\nactioncheck =\nactionban = csf -d &lt;ip&gt; Added by Fail2Ban for &lt;name&gt;\nactionunban = csf -dr &lt;ip&gt;\n\n[Init]\n\nname = default\n\nAfter that go to \/etc\/fail2ban\/filter.d and create a file called wp-auth.conf\n\nadd the following within it:\n\n# WordPress brute force auth filter: \/etc\/fail2ban\/filter.d\/wp-auth.conf:\n#\n# Block IPs trying to auth wp wordpress\n#\n# Matches e.g.\n# 134.255.143.49 - - [24\/Jun\/2015:13:43:31 +0200] \"POST \/wp-login.php HTTP\/1.1\" 200 2930\n#\n[Definition]\nfailregex = ^&lt;HOST&gt; .* \"POST .*wp-login.php HTTP\/1.1 403\"\nignoreregex =\nactionban = csf -d &lt;ip&gt; Added by Fail2Ban for &lt;name&gt;\nactionunban = csf -dr &lt;ip&gt;\n\nOnce done restart fail2ban\n\nservice fail2ban restart\n\nAnd now you should find it being blocked within CSF Deny list. :)\n\n\n\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today and in the past few days I&#8217;ve been often flooded with POST requests that look like this: 103.19.180.119 &#8211; &#8211; [09\/Jul\/2015:10:50:02 +0200] &#8220;POST \/wp-login.php HTTP\/1.1&#8221; 403 1139 103.19.180.119 -&hellip;<\/p>\n","protected":false},"author":2,"featured_media":1565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[86,90,91],"class_list":["post-1564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website-and-web-hosting","tag-bruteforce","tag-fail2ban","tag-wp-login","entry"],"_links":{"self":[{"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/posts\/1564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/comments?post=1564"}],"version-history":[{"count":0,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/posts\/1564\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/media\/1565"}],"wp:attachment":[{"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/media?parent=1564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/categories?post=1564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostking.host\/blog\/wp-json\/wp\/v2\/tags?post=1564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}