防止SSH暴力破解


 

# 今天發現有人“搞事情”, 隨手lastb 一看估計在爆破用戶名呢。。。

 

 

# 把出現“Invalid User”大於30次的就直接丟進"/etc/hosts.deny"

#!/bin/bash
# Author: Loki
# Date: 2020-01-13
# Readme: autocheck "Invalid user" and write down "/etc/hosts.deny"

# Brute force "username"
grep "Invalid user" /var/log/secure|awk '{print $10}'|sort|uniq -c|awk '{print $2"="$1;}' > /tmp/black_ip.txt
max_count="30"

for item in `cat /tmp/black_ip.txt`;do
    ip_addr=`echo $item |awk -F=  '{print $1}'`
    ip_num=`echo $item |awk -F= '{print $2}'`
    if [ $ip_num -gt $max_count ];
    then
        grep $ip_addr /etc/hosts.deny > /dev/null
        if [ $? -gt 0 ];
            then
            echo "sshd:$ip_addr" >> /etc/hosts.deny
        fi
    fi
done

 

# 最后加入到計划任務 5分鍾執行一次

*/5 * * * * <執行用戶名> /bin/bash /xxx/xxx/BP_user_protect.sh


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM