• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress

By Abhishek Ghosh September 15, 2016 6:25 pm Updated on May 31, 2017

iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress

Advertisement

We have talked with the needed basics though iptables Basics : Chapter 1, Creating root user with sudo privilege on Fail2Ban iptables Basics : Chapter 2. We talked about OSI model and of course easy article on how and what steps, works to perform on a blank new server. Chapter 3 Describes Configuring Fail2Ban With WordPress to Give Ultimate Protection. Thus We Secured OSI Model’s All Layers Which are Within Our Reach.

 

iptables Basics Chapter 3 : Prerequisites

 

You should read the above three iptables related articles and configure your server. You should not mix up following tutorials from this and that website on your server. We are describing method for Ubuntu server 16.04 LTS running Nginx latest version with PHP7.0-FPM. A running WordPress website is obviously needed for this guide. Other PHP-MySQL web application will work in the same way. We are assuming that /usr/share/nginx/html/ is the path of WordPress installation.

iptables-basics-chapter-3-configuring-fail2ban-with-wordpress

Above image is best seen on full size by clicking here.

Advertisement

---

 

iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress

 

First install a WordPress Plugin from WordPress admin named WP Fail2Ban Redux, details of which can seen here :

Vim
1
https://wordpress.org/plugins/wp-fail2ban-redux/

it is a fork of popular plugin WP Fail2Ban. It controls Failed XML-RPC authentication attempts, successful authentication attempts, failed wp-login.php authentication attempts, pingback requests, blocked user enumeration attempts, authentication attempts for blocked usernames and spammed comments. It is for PHP7.0. Install and activate the plugin first.

From SSH screen, cd to where your WordPress installation’s plugins directory is located, like :

Vim
1
/usr/share/nginx/html/wp-content/plugins

cd to wp-fail2ban-redux directory. If you do a ls, you will see these directories :

Vim
1
classes  config  languages  README.md  readme.txt  wp-fail2ban-redux.php

If you cd to config/filters of that wp-fail2ban-redux directory and do a ls, you’ll see 2 files :

Vim
1
wordpress-hard.conf  wordpress-soft.conf

Now, cd to /etc/fail2ban/filter.d directory and do a ls. There will be lot of files for SSH, PAM, Nginx etc. Copy both files to that directory from wp-fail2ban-redux directory :

Vim
1
2
cp /usr/share/nginx/html/wp-content/plugins/wp-fail2ban-redux/config/filters/wordpress-hard.conf /etc/fail2ban/filter.d
cp /usr/share/nginx/html/wp-content/plugins/wp-fail2ban-redux/config/filters/wordpress-soft.conf /etc/fail2ban/filter.d

In that WordPress installation’s plugins wp-fail2ban-redux directory’s wp-fail2ban-redux/config/jail location, there is another file named wordpress.conf file :

Vim
1
2
3
cd /usr/share/nginx/html/wp-content/plugins/wp-fail2ban-redux/config/jail
ls
cat wordpress.conf

highlight and copy only this part from the SSH output :

Vim
1
2
3
4
5
6
[wordpress-hard]
enabled = true
filter = wordpress-hard
logpath = /var/log/auth.log
maxretry = 2
port = http,https

Now open jail.local from /etc/fail2ban/jail.local location and add that stanza at the bottom :

Vim
1
2
3
4
5
6
7
8
nano /etc/fail2ban/jail.local
# paste and save
# restart fail2bain
sudo service fail2ban restart
# check fail2ban service
sudo service fail2ban status
# check whether we did correct or not
sudo fail2ban-client status wordpress-hard

You will get output like :

Vim
1
2
3
4
5
6
7
8
9
Status for the jail: wordpress-hard
|- Filter
|  |- Currently failed: 0
|  |- Total failed:     40
|  `- File list:       /var/log/auth.log
`- Actions
   |- Currently banned: 1
   |- Total banned:     1
   `- Banned IP list:   91.200.12.155

It is an optional step. Open logrotate.conf :

Vim
1
sudo nano /etc/logrotate.conf

Add this stanza :

Vim
1
2
3
4
5
/var/log/auth.log {
    size 30k
    create 0600 root root
    rotate 4
}

It is to set the maximum size of the file, permissions of the file, and the number of weeks (4 in above example) that file will not become /var/log/auth.log.1. It is auto cleaning system in GNU/Linux preserving the record in different file. You can cat on these files :

Vim
1
cat /var/log/auth.log

I got something like this :

Vim
1
2
3
4
5
6
7
8
9
Sep 15 00:06:03 thecustomizewindows wp(thecustomizewindows.com)[3431]: Authentication failure for abhishek from 91.200.12.155
Sep 15 00:06:05 thecustomizewindows wp(thecustomizewindows.com)[3411]: Authentication failure for abhishek from 91.200.12.155
Sep 15 00:06:06 thecustomizewindows wp(thecustomizewindows.com)[3411]: Authentication failure for abhishek from 91.200.12.155
Sep 15 00:06:07 thecustomizewindows wp(thecustomizewindows.com)[3431]: Authentication failure for abhishek from 91.200.12.155
Sep 15 00:06:09 thecustomizewindows wp(thecustomizewindows.com)[3411]: Authentication failure for abhishek from 91.200.12.155
Sep 15 00:06:10 thecustomizewindows wp(thecustomizewindows.com)[3411]: Authentication attempt for unknown user Articles from 91.200.12.155
Sep 15 00:06:13 thecustomizewindows wp(thecustomizewindows.com)[3431]: Authentication attempt for unknown user Articles from 91.200.12.155
Sep 15 00:06:14 thecustomizewindows wp(thecustomizewindows.com)[3411]: Authentication attempt for unknown user Articles from 91.200.12.155
Sep 15 00:06:16 thecustomizewindows wp(thecustomizewindows.com)[3431]: Authentication attempt for unknown user Articles from 91.200.12.155

Like we say not to allow root user to do SSH but a custom username with sudo privilege, for WordPress you should not use the publicly available name as username to login. I can drop that IP :

Vim
1
iptables -D INPUT -s 91.200.12.155 -j DROP

If I run a cat on cat /var/log/fail2ban.log file :

Vim
1
cat /var/log/fail2ban.log

I will find :

Vim
1
2
3
4
5
6
7
2016-09-15 00:08:49,614 fail2ban.jail           [3667]: INFO    Creating new jail 'wordpress-hard'
2016-09-15 00:08:49,614 fail2ban.jail           [3667]: INFO    Jail 'wordpress-hard' uses poller
...
2016-09-15 00:08:49,727 fail2ban.actions        [3667]: NOTICE  [sshd] Ban 109.61.246.109
2016-09-15 00:08:49,811 fail2ban.jail           [3667]: INFO    Jail 'wordpress-hard' started
2016-09-15 00:38:06,690 fail2ban.filter         [3980]: INFO    [wordpress-hard] Found 91.200.12.155
2016-09-15 00:38:07,484 fail2ban.actions        [3980]: NOTICE  [wordpress-hard] 91.200.12.155 already banned

There is nothing to explain. If you add this to Nginx server block :

Vim
1
2
3
4
5
  location ~ ^/(wp-admin|wp-login\.php) {
                allow 127.0.0.1;
                allow your.server.IP.address;
                deny all;
  }

You can make it a file named wp-login-ban.conf. Then call the file by including on Nginx server block :

Vim
1
include /path/to/wp-login-ban.conf

Perform nginx -t and do service nginx restart.

These problems with attack on wp-login.php will get reduced. We never use WordPress backend 24*7 unlike official WordPress website. Before writing posts and doing other works i.e. logging to WordPress, you can comment out that :

Vim
1
# include /path/to/wp-login-ban.conf

Perform nginx -t and do service nginx restart. Previously we talked about how Nginx, PHP5-FPM behaves on WordPress XML-RPC attack fakes PHP-FPM errors and how to fix. You can ban those IP from iptables too.

Tagged With iptables-Basics-Chapte , iptables , iptables Basics

This Article Has Been Shared 496 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress

Actually a list should normally appear here. Automated calculation failed.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023
  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023

About This Article

Cite this article as: Abhishek Ghosh, "iptables Basics : Chapter 3, Configuring Fail2Ban With WordPress," in The Customize Windows, September 15, 2016, February 5, 2023, https://thecustomizewindows.com/2016/09/iptables-basics-chapter-3-configuring-fail2ban-wordpress/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, 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 affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT