Write a script to parse your web server logs and ban IPs with CSF of attackers. That's it.
#!/bin/bash
IP_LIST=`(cat /var/log/httpd/access_log | grep "w00tw00t" | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | sort | uniq)`
IP_LIST2=`(cat /var/log/httpd/error_log | grep "w00tw00t" | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | sort | uniq)`
IP_LIST3=`(cat /var/log/httpd/domains/*.log | grep "w00tw00t" | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | sort | uniq)`
for OUTPUT in $IP_LIST
do
/etc/csf/csf.pl -d $OUTPUT Blocked for w00tw00t scanning main apache log
echo "Blocking IP $OUTPUT"
done
for OUTPUT2 in $IP_LIST2
do
/etc/csf/csf.pl -d $OUTPUT2 Blocked for w00tw00t scanning error log
echo "Blocking IP $OUTPUT2"
done
for OUTPUT3 in $IP_LIST3
do
/etc/csf/csf.pl -d $OUTPUT3 Blocked for w00tw00t scanning domain log
echo "Blocking IP $OUTPUT3"
done
192.168.0.1 Blocked for w00tw00t scanning main apache log
192.168.0.1 is already present in csf.deny
csf -g $OUTPUT
if [ `csf -g $OUTPUT | grep 'No matches found' -c` -eq 0 ]; then
# Here we block IP, as it was not found in IPTABLES
fi;
1.) It won't block it again, correct. But I like to know when something is blocked and the way it's now (without check), I get an email from CSF every 10 minutes with a statement that the ip is trying to be blocked but is already present in csf.deny. If the check is done, you don't have that result and no mail is send because no old ip is trying to be blocked again.1) CSF won't block same IP again, so there's no need to double check if IP has been previously blocked. CSF also chceck IP syntax before blocking IP.