本文共 950 字,大约阅读时间需要 3 分钟。
#/bin/bash
#auto drop ssh failed ip address#author by efoni 2018.7SEC_FILE=/var/log/secure#如下为截取secure文件恶意ip远程登录22端口,大于等于4次就写入防火墙deny,禁止以后在登录22端口,egrep -o "[0-9]{1,3}.){3}[0-9]{1,3}"是匹配ip的正则表达式IP_ADDR=tail -n 1000 $SEC_FILE|grep "Failed password"|egrep -o "[0-9]{1,3}.){3}[0-9]{1,3}"|sort -nr |uniq -c|awk '$1>=4 {print $2}'IPTABLE_CONF=/etc/sysconfig/iptablesechocat <<EOF++++++++++++++++++++++++++++++++welcome to use ssh login drop failed ip+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++EOFfor i in echo $IP_ADDR
转载于:https://blog.51cto.com/efoni/2146447