找回密码
 注册
查看: 2025|回复: 2

[问题解决] SSH暴力破解解决方法

[复制链接]
lieren 发表于 2020-4-19 17:23:29 | 显示全部楼层 |阅读模式
碰到了ssh暴力破解,然后安装挖矿病毒,导致cpu满了,远程都链接不上,只能重装系统。

查看/var/log/secure 文件可以看到很多认证失败的Failure的ip登录信息。所以想到根据secure文件查看失败的ip如果超过五次,那么就把此ip写入/etc/hosts.deny文件,禁止此ip登录。我用了第一种方法,设置了定时任务,每分钟执行一次。执行之后,查看secure文件就没有那么多失败的信息日志输出了。

收集 /var/log/secure 里面的信息,若是某个IP 链接次数超过一定次数 ,则把此ip记录到/etc/hosts.deny里面。
通过crontab来执行,每分钟执行一次。


*/1 * * * * /bin/bash /root/Denyhosts/Denyhosts.sh



#!/bin/bash
#Denyhosts SHELL SCRIPT


cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"=" $1;}' >/root/Denyhosts/Denyhosts.txt
DEFINE="5"
for i in `cat /root/Denyhosts/Denyhosts.txt`
do
        IP=`echo $i|awk -F= '{print $1}'`
        NUM=`echo $i|awk -F= '{print $2}'`
        if [ $NUM -gt $DEFINE ]
        then
                ipExists=`grep $IP /etc/hosts.deny |grep -v grep |wc -l`
                if [ $ipExists -lt 1 ]
                then
                echo "sshdIP" >> /etc/hosts.deny
                fi
        fi
done


fch101227 发表于 2021-12-15 10:06:19 | 显示全部楼层
     ????
回复

使用道具 举报

fch101227 发表于 2021-12-15 10:13:03 | 显示全部楼层
你这个最后添加进   /etc/hosts.deny   之后,     /etc/hosts.deny    里面的内容能看下么?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|Linux公社论坛

GMT+8, 2023-6-10 23:34 , Processed in 0.062500 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表