Because we care, we're security aware.

I Love Secure

Security step by step

  • Home
  • Security Resources
  • Home
  • /
  • Server
  • /
  • Linux
  • /
  • Protect WordPress Login with Fail2Ban

Protect WordPress Login with Fail2Ban

secureadm September 22, 2015

Brutal force login is one of the common attack to your WordPress.
We want to block people after the 3rd wrong login, to be correct we will block any IP from where we receive 3 failed login attempts in a short time.
Let’s see how to do it:

Prerequisite:

  • your WordPress is installed on a Linux box
  • you are the administrator
  • you have installed Fail2Ban following the guide Protect SSH login with fail2ban

How fail2ban works

Fail2ban is service monitoring log files for specific events, and triggering specific commands when a defined amount of events happen in a defined amount of time.
First of all we need a log file where the events we want to monitor are logged in.
There are 2 possible choices: we can use the apache https log, where there is a line every time the login page is requested, and we can assume if an IP is calling many times the login page is because he is trying to login many times. This assumption is not very precise, it is a sort of proxy of what we want to monitor and can create false positive. The second choice is to use a specific plugin in charge of writing in a log file evry time thee is a failed login attempt. This is more accurate tracking of the even “failed login”.
We chose “WP fail2ban” plugin, you can find a detailed description in theĀ WP Fail2ban page.
1. Install WP Fail2ban plugin from your dashboard
2. Activate your plugin
from this moment all your failed login are logged with the details regarding date, time, ip, etc. In our case (centos 6.7) they are logged in /var/log/messages

Configure fail2ban to intercept failed login

Create in /etc/fail2ban/filters.d a config file called wordpress.conf

vi /etc/fail2ban/filters.d/wordpress.conf

with this content:

# Fail2Ban configuration file
#
# Author: Charles Lecklider
#[INCLUDES]# Read common prefixes. If any customizations available — read them from
# common.local
before = common.conf[Definition]_daemon = wordpress# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named “host”. The tag “” can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P[\w\-.^_]+)
# Values: TEXT
#
failregex = ^%(__prefix_line)sAuthentication failure for .* from $
^%(__prefix_line)sBlocked authentication attempt for .* from $
^%(__prefix_line)sBlocked user enumeration attempt from $
^%(__prefix_line)sPingback requested from $# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =

If you prefer you can find this file in the plugin directory and you can directly move into /etc/fail2ban/filters.d
After you create this filter, edit the fail2ban configuration file

#> vi /etc/fail2ban/jail.conf

and add at the end of the file these lines

[wordpress-ddos]
enabled = true
port = http,https
filter = wordpress
logpath = /var/log/messages

4: restart fail2ban with

#> service fail2ban restart

Your protection is active

How to test it:

– write a wrong password during login in WP. Then check if in /var/log/messages you see a log about the failed login. This is the confirmation the new plugin is working
– try to fail login 3 times in few minute and you should not be able access any page in your WP. Only ports 80 and 443 are blocked. This means you still will be able to ssh to your server.

How to remove an IP from the block

First of all put all your known IP in the in /etc/fail2ban/jail.local in the vaiable knownip.
This will protect your locations with fixed to avoid to be banned. In case it happened, first of all login via ssh into your server.
check the status of your firewall

#>service iptables status
…
Chain FORWARD (policy ACCEPT)
num target prot opt source destinationChain OUTPUT (policy ACCEPT)
num target prot opt source destination

Chain f2b-SSH (1 references)
num target prot opt source destination
1 REJECT all — aa.bb.cc.dd 0.0.0.0/0 reject-with icmp-port-unreachable
2 REJECT all — ee.ff.gg.gg 0.0.0.0/0 reject-with icmp-port-unreachable
3 RETURN all — 0.0.0.0/0 0.0.0.0/0
…

As you can see there is the list of each chain (forward, output, f2b-SSH, …) with the rules implemented one by one. If you want to remove the block for the ip ee.ff.gg.hh, just ask iptables to remove the 2nd rules for the chian f2b-SSH

iptables -D f2b-SSH 2

That’s all!

Tags: brute force attack fail2ban iptables login
Protect SSH login of your linux server with fail2ban (Centos 6) Discover rootkit, trojan, backdoors in your office with Snort

Related posts

  • Securing and Hardening your WordPress
    Securing and Hardening your WordPress
  • Protect SSH login of your linux server with fail2ban (Centos 6)
    Protect SSH login of your linux server with fail2ban (Centos 6)

Get Social

Recent Posts

  • Securing and Hardening your WordPress
  • Protect your site from malvertising and bad tracking codes
  • Taxonomy of cyber attacks
  • For security lovers….
  • WordPress secure or not….

Recent Comments

  • Taxonomy of cyber attacks | I Love Secure on Protect your site from malvertising and bad tracking codes
  • Protect WordPress Login with Fail2Ban | I Love Secure on Protect SSH login of your linux server with fail2ban (Centos 6)
  • Discover rootkit, trojan, backdoors in your office | I Love Secure on Monitor traffic with Snort – intrusion detection
  • Protect SSH login of your linux server with fail2ban (Centos OS) | I Love Secure on Secure Linux ssh login with public key

Archives

  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015

Categories

  • Gadgets
  • Linux
  • Local network
  • Server
  • software
  • Uncategorized
  • web
  • wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
(c) 2015 - I Love Secure
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT