Skip to content

Instantly share code, notes, and snippets.

@acosonic
Created March 5, 2019 13:48
Show Gist options
  • Save acosonic/18fcc234a324c858d50d0a96d5748ab4 to your computer and use it in GitHub Desktop.
Save acosonic/18fcc234a324c858d50d0a96d5748ab4 to your computer and use it in GitHub Desktop.
Protecting ubuntu 14.04 server virtualmin websites against wordpress login attack bots
#!/bin/bash
# this script will install fail2ban and enable apache-wp-login rule
# you will notice once it's done that fail2ban-client status shows apache-wp-login rule as active
apt install fail2ban
JAIL=''
JAIL="${JAIL}\n"
JAIL="${JAIL}[apache-wp-login]\n"
JAIL="${JAIL}enabled = true\n"
JAIL="${JAIL}port = http,https\n"
JAIL="${JAIL}filter = apache-wp-login\n"
JAIL="${JAIL}logpath = /var/log/virtualmin/*access_log\n"
JAIL="${JAIL}maxretry = 1\n"
JAIL="${JAIL}findtime = 36000\n"
JAIL="${JAIL}bantime = 36000"
printf "%b" "$JAIL" >> /etc/fail2ban/jail.conf
RULE=''
RULE="${RULE}\n"
RULE="${RULE}[Definition]\n"
RULE="${RULE}failregex = ^<HOST>.*/wp-login.php.*\n"
RULE="${RULE}ignoreregex ="
printf "%b" "$RULE" >> /etc/fail2ban/filter.d/apache-wp-login.conf
fail2ban-client reload
fail2ban-client status
@acosonic
Copy link
Author

acosonic commented Mar 5, 2019

To run this script...
curl -o- https://gist.githubusercontent.com/acosonic/18fcc234a324c858d50d0a96d5748ab4/raw/ae7d0beaa64a33736220128ba92f11772045bee5/fail2ban_wp.sh | bash
or
wget -qO- https://gist.githubusercontent.com/acosonic/18fcc234a324c858d50d0a96d5748ab4/raw/ae7d0beaa64a33736220128ba92f11772045bee5/fail2ban_wp.sh | bash

@acosonic
Copy link
Author

Chain in action, after a while...
Screenshot at Nov 16 00-28-17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment