- Joined
- Apr 24, 2018
- Messages
- 160
- Reaction score
- 16
A few of our customers are getting excessive blacklisted IPs due to failed authentications. I would would like to implement an automated method of permanently blocking those IPs. The best way to do this I believe would be to use syslog to send the logs elsewhere on the network and then do the blacklist in real time. From what I understand though 3CX still has not yet implemented a syslog function (correct me if I'm wrong). If that is the case and they haven't, does anyone know of a way to view the list or logs of blacklisted IP's from CLI? My plan would be to just have a script run every 5 minutes or so check if an IP is already in the list, and add it to iptables if it isn't.
I'm using a script from a user that posted about this a few years back but I'm guessing some things may have changed since then because it doesn't seem to be working. I haven't changed much about it except for line 20 where it checks if the IP is already in iptables. The original command didn't work. Left all comments intact so the original creator of the script is credited.
Hoping that since this script was posted 3CX has made some of this stuff easier.
EDIT: Forgot to put version and system info.
Version: 18.0 Update 8
OS: Debian
I'm using a script from a user that posted about this a few years back but I'm guessing some things may have changed since then because it doesn't seem to be working. I haven't changed much about it except for line 20 where it checks if the IP is already in iptables. The original command didn't work. Left all comments intact so the original creator of the script is credited.
Hoping that since this script was posted 3CX has made some of this stuff easier.
EDIT: Forgot to put version and system info.
Version: 18.0 Update 8
OS: Debian
Bash:
#!/bin/bash
# Script to check eventlog in postgres db for 3cx for IP's that were banned
# this script then add the IP to iptables
# This script is ment to be added to crontab
# Written by Chris Wianecki
# contact me via email [email protected]
while read line
do
first_var=`echo "$line" | awk 'BEGIN { FS="|" } { print $1 }'`
sixth_var=`echo "$line" | awk 'BEGIN { FS="|" } { print $6 }'`
if expr $first_var + 0 > /dev/null 2>&1
then
if [[ ! -z $first_var ]]; then
if [[ $sixth_var = *"Too many failed authentications"* ]]; then
IPAddressToBan=`echo $sixth_var | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
if nft list table ip filter | grep -q "$IPAddressToBan"
then
echo "IP already found in IPTables"
else
echo "Adding $IPAddressToBan to IPTables to DROP any connections for that IP to 3CX server."
/sbin/iptables -A INPUT -s "$IPAddressToBan" -j DROP
/sbin/iptables -L -n | grep "$IPAddressToBan"
fi
fi
fi
fi
done < <(cd /tmp; sudo -u phonesystem -H -- psql -d database_single -c "SELECT * FROM eventlog")
Last edited: