温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

将ssh失败尝试达到100次以上的IP拒绝掉

发布时间:2020-06-02 12:18:29 来源:网络 阅读:574 作者:winterysea 栏目:安全技术




1、tcpwrapper

#!/bin/bash
Fail_100=`/bin/grep 'Failed' /var/log/secure* | /bin/egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | /bin/sort | /usr/bin/uniq -c | /bin/sort -rn | /bin/awk '$1 > 100 {print $2}'`
for Fip in $Fail_100
do
/bin/grep "$Fip" /etc/hosts.deny &> /dev/null
[[ $? -ne 0 ]] && /bin/echo "sshd:$Fip: spawn (/bin/echo \"login attmpt from %c to %s\" | /bin/mail -s \"information abount sshd login attempt\" root@localhost)&" >> /etc/hosts.deny 2> /dev/null && /bin/echo -e "$Fip" >> /var/log/.Fail_IP_list
done





2、iptables

#!/bin/bash
Fail_100=`/bin/grep 'Failed' /var/log/secure* | /bin/egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | /bin/sort | /usr/bin/uniq -c | /bin/sort -rn | /bin/awk '$1 > 100 {print $2}'`
/etc/init.d/iptables save
for Fip in $Fail_100
do
        /bin/grep "$Fip" /etc/sysconfig/iptables &> /dev/null
        [[ $? -ne 0 ]] && /sbin/iptables -I INPUT 3 -s "$Fip" -j DROP && /bin/echo -e "$Fip" >> /var/log/.Fail_IP_list
done
/etc/init.d/iptables save





向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI