#! /bin/bash
cat /var/log/secure |awk '/fail/{print $(NF)}'|sort|uniq -c|awk '{print $2"="$1;}' |grep 'rhost' > /root/black.txt
DEFINE="50"
for i in `cat /root/black.txt`
do
IP=`echo $i |awk -F= '{print $2}'`
NUM=`echo $i|awk -F= '{print $3}'`
if [ $NUM -gt $DEFINE ];
then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ];
then
echo "sshd: $IP" >> /etc/hosts.deny
echo "vsftpd: $IP" >> /etc/hosts.deny
fi
fi
done
设置定势执行任务
* */1 * * * /root/check-secure.sh
一段时间/etc/hosts.deny如下:
sshd: 64.31.21.150
vsftpd: 64.31.21.150
sshd: 46.16.247.163
vsftpd: 46.16.247.163
sshd: 208.106.56.228
vsftpd: 208.106.56.228
sshd: 94.109.183.86
vsftpd: 94.109.183.86
sshd: 85.172.55.226
vsftpd: 85.172.55.226
sshd: 80.59.136.252
vsftpd: 80.59.136.252
sshd: 75.99.187.4
vsftpd: 75.99.187.4
sshd: 12.132.106.30
vsftpd: 12.132.106.30
阅读(1480) | 评论(0) | 转发(0) |