首页 > 其他 > 详细

通过脚本加hosts.deny文件阻止防攻击

时间:2016-05-31 14:16:32      阅读:201      评论:0      收藏:0      [点我收藏+]
  1. 用vim打开编辑文集

    vi sshdeny.sh

#!/bin/bash
awk ‘{for(i=1;i<=NF;i++){if($i ~ /rhost/)print substr($i,7)}}‘ /var/log/secure | sort | uniq    -c>/root/black.txt
DEFINE="10"
cat     /root/black.txt |    while read LINE
do
               NUM=`echo $LINE |awk ‘{print $1}‘`
               host=`echo $LINE    |awk ‘{print $2}‘`
               if [ $NUM -gt $DEFINE ];
               then
                grep $host    /etc/hosts.deny > /dev/null
                   if [ $? -gt 0 ];
                   then
                   echo "sshd:$host"     >> /etc/hosts.deny
                   echo "vsftpd:$host" >> /etc/hosts.deny
                   fi
               fi
done

2. 添加定时任务


每5分钟执行以下该脚本

*/5 * * * * /data/script/sshdeny.sh >/dev/null 2>&1


通过脚本加hosts.deny文件阻止防攻击

原文:http://lizhuan.blog.51cto.com/8099531/1784727

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!