当前位置:网站首页 / Linux / 正文

linux下防止ssh暴力破解

时间:2018年01月06日 | 作者 : liuhui | 分类 : Linux | 浏览: 6620次 | 评论 0

阿里云限量代金券 | 此广告位出租25元/月

最近在用centos系统搭建网站,但是刚刚搭建好,就出现多次SSH暴力破解的告警,部署linux下防止SSH暴力破解方案就迫在眉睫,下面通过Shell脚本统计访问失败的IP和次数,从而根据这些IP添加到hosts.deny中,从而来限制这些IP再次爆破。

1、编写脚本

vi /usr/local/bin/ssh_black.sh

#! /bin/bash
cat /var/log/securelawk '/Failed/{print $(NF-3)}' 1sortluniq-clawk '{print $2"="$1;}' > /root/black.txt
cat /var/log/securelawk '/Invalid user/{print SNF}' Isortluniq-clawk '{print $2"="$1;}' > /root/black.txt
D E F INE =" 2 e"
for i in'cat /root/black.txt'
IP='echo si lawk-F= '{print $1]'*
NUM='echo silawk-F='fprint $2}'t
if[ SNUM-gt $DEFINE ];
then
grep SIP /etc/hosts.deny > /dev/null
if[s?-gt0];
then
echo "sshd:$IP" >》/etc/hosts.deny
fi
fi
done

2、将/usr/local/bin/ssh_black.sh添加至crontab,一小时执行一次

 0 */1 * * * /usr/local/bin/ssh_black.sh 

3、测试结果

 [root@izj6c9p9mybyg4b5viuufhz ~]# tail-10 /etc/hosts.deny
#
/etc/hosts.allow with a 'deny' option instead.
#
5 hosts_access'
See 'man 5 hosts_options'
and 'man
#
for
information on rule syntax.
#
See
'man tcpd' for
information on tcp_wrappers
sshd:140.205.201.32 

sshd:140.205.201.35 

sshd:140.205.201.47

当hosts.deny文件中出现陌生的IP地址,就说明脚本生效了。

推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信