Bjorn
Basic Pleskian
Hi,
I want to add a custom action to all jails, this action calls a script that writes the ban info to mysql.
When i run my script directly from the console, it works fine. But it does not get called with the actionban...
First some info:
Plesk 17.5.3 CentOS 7
Fail2Ban v0.9.6
MariaDB 5.5.52
This is what i have done so far:
1) created the script in /usr/local/bin/fail2ban-mysql.sh
2) created a fail2ban-mysql action in /etc/fail2ban/action.d/fail2ban-mysql.conf
3) added (inside plesk) the new action to the plesk-wordpress jail for testing.
Files
Fail2ban-mysql.sh
fail2ban-mysql.conf
---------------------------
Testing:
- I saw some script 'if' errors in the fail2ban log ( /var/log/fail2ban.log ) after restart, so i know my banaction is called.
- After fixing the errors, the fail2ban log stays clear of errors, but nothing is added to mysql.
- output of 'fail2ban-client get plesk-wordpress action fail2ban-mysql actionban' =
/usr/local/bin/fail2ban-mysql.sh qdsrv1 test_jail ssh 22 123.123.123.132
It seems all F2B configuration settings are correct, does anyone know why my script doens't work?
Thanks
Best regards,
Bjorn
I want to add a custom action to all jails, this action calls a script that writes the ban info to mysql.
When i run my script directly from the console, it works fine. But it does not get called with the actionban...
First some info:
Plesk 17.5.3 CentOS 7
Fail2Ban v0.9.6
MariaDB 5.5.52
This is what i have done so far:
1) created the script in /usr/local/bin/fail2ban-mysql.sh
2) created a fail2ban-mysql action in /etc/fail2ban/action.d/fail2ban-mysql.conf
3) added (inside plesk) the new action to the plesk-wordpress jail for testing.
Files
Fail2ban-mysql.sh
#!/usr/bin/bash
#Script to run automated sql queries
#Declaring mysql DB connection
MASTER_DB_USER='fail2ban_user'
MASTER_DB_PASSWD='********'
MASTER_DB_PORT=3306
MASTER_DB_HOST='localhost'
MASTER_DB_NAME='fail2ban_db00'
#Check if all arguments are passed
if [ $# -eq 5 ]
then
#Prepare sql query
Q_HOSTNAME=$1
Q_NAME=$2
Q_PROTOCOL=$3
Q_PORT=$4
Q_IP=$5
SQL_Query="INSERT INTO bans set hostname='$Q_HOSTNAME', name='$Q_NAME', protocol='$Q_PROTOCOL', port='$Q_PORT', ip='$Q_IP', created=NOW()"
#mysql command to connect to database
mysql -u$MASTER_DB_USER -p$MASTER_DB_PASSWD -P$MASTER_DB_PORT -h$MASTER_DB_HOST -D$MASTER_DB_NAME <<EOF
$SQL_Query
EOF
echo "Success"
else
echo "Missing required arguments"
fi
-----------------------------#Script to run automated sql queries
#Declaring mysql DB connection
MASTER_DB_USER='fail2ban_user'
MASTER_DB_PASSWD='********'
MASTER_DB_PORT=3306
MASTER_DB_HOST='localhost'
MASTER_DB_NAME='fail2ban_db00'
#Check if all arguments are passed
if [ $# -eq 5 ]
then
#Prepare sql query
Q_HOSTNAME=$1
Q_NAME=$2
Q_PROTOCOL=$3
Q_PORT=$4
Q_IP=$5
SQL_Query="INSERT INTO bans set hostname='$Q_HOSTNAME', name='$Q_NAME', protocol='$Q_PROTOCOL', port='$Q_PORT', ip='$Q_IP', created=NOW()"
#mysql command to connect to database
mysql -u$MASTER_DB_USER -p$MASTER_DB_PASSWD -P$MASTER_DB_PORT -h$MASTER_DB_HOST -D$MASTER_DB_NAME <<EOF
$SQL_Query
EOF
echo "Success"
else
echo "Missing required arguments"
fi
fail2ban-mysql.conf
[INCLUDES]
before = iptables-common.conf
[Definition]
# custom actionban
_mysqlscript = /usr/local/bin/fail2ban-mysql.sh
actionban = %(_mysqlscript)s qdsrv1 test_jail ssh 22 123.123.123.132
[Init]
before = iptables-common.conf
[Definition]
# custom actionban
_mysqlscript = /usr/local/bin/fail2ban-mysql.sh
actionban = %(_mysqlscript)s qdsrv1 test_jail ssh 22 123.123.123.132
[Init]
---------------------------
Testing:
- I saw some script 'if' errors in the fail2ban log ( /var/log/fail2ban.log ) after restart, so i know my banaction is called.
- After fixing the errors, the fail2ban log stays clear of errors, but nothing is added to mysql.
- output of 'fail2ban-client get plesk-wordpress action fail2ban-mysql actionban' =
/usr/local/bin/fail2ban-mysql.sh qdsrv1 test_jail ssh 22 123.123.123.132
It seems all F2B configuration settings are correct, does anyone know why my script doens't work?
Thanks
Best regards,
Bjorn