- 论坛徽章:
- 0
|
本帖最后由 wsleichao3 于 2013-03-25 17:32 编辑
还有一个脚本是根据抚琴煮酒大侠写的脚本稍微改动了下
这个脚本使用的sudo,没有直接使用root,是为了使用权限较大的命令时能够在日志中记录,sudo配置的时无密码的sudo。- #!/bin/bash
- #脚本模仿“抚琴煮酒”的http://andrewyu.blog.51cto.com/1604432/1074650
- #脚本描述:
- # 对SSH和FTP的恶意连接的IP尝试次数大于10次以上进行屏蔽。
- #时间:2013-03-23
- #awk展开是
- #for(i=1;i<NF;i++){
- # if($i~/rhost/&&$i!~/\//){
- # ip=substr($i,7);
- # if(ip~/^:/){
- # print substr(ip,8)
- # }else{
- # print print ip
- # }
- # }
- #}
- sudo awk '{for(i=1;i<NF;i++){if($i~/rhost/&&$i!~/\//){ip=substr($i,7);if(ip~/^:/){print substr(ip,8)}else print ip}}}' /var/log/secure|sort|uniq -c >drop.ip
- cat drop.ip|while read A
- do
- num=$(echo $A|awk '{print $1}');
- ip=$(echo $A|awk '{print $2}');
- if [ "$num" -ge "10" ];then
- sudo iptables -L -n|grep "$ip" >/dev/null
- if [ "$?" -ne "0" ];then
- echo "sudo iptables -I INPUT -s $ip -j DROP"
- fi
- fi
- done
复制代码 |
|