secure_ssh.sh

#!/bin/bash
#command=$(cat /var/log/secure |awk '/Failed/{print $(NF-3)}' |sort|uniq -c|awk '{print $2"="$1;}')

cat /var/log/secure |awk '/Failed/{print $(NF-3)}' |sort|uniq -c|awk '{print $2"="$1;}' > /root/black.txt
#$command > /root/black.txt

for i in $(cat /root/black.txt); do IP=$(echo $i |awk -F "=" '{print $1}'); NUM=$(echo $i|awk -F "=" '{print $2}'); DEFINE=5; if [ $NUM -gt $DEFINE ];then grep $IP /etc/hosts.deny > /dev/null; if [ $? -gt 0 ];then echo "sshd:$IP:deny" >> /etc/hosts.deny; fi; fi; done

#!/bin/bash
#Usage: ./$0
#      ,      5  ip     /etc/hosts.deny.   ip  linux  sshd  

#         
time=5
cat /var/log/secure |awk '/Failed/{print $(NF-3)}' |sort|uniq -c|awk '{print $2"="$1;}' > /root/SSH_FAILD_IP.txt

for i in $(cat SSH_FAILD_IP.txt); 
do 
  IP=$(echo $i |awk -F "=" '{print $1}'); 
  NUM=$(echo $i|awk -F "=" '{print $2}'); 
  if [ $NUM -gt $time ];then 
    grep $IP /etc/hosts.deny > /dev/null; 
      if [ $? -gt 0 ];then 
        echo "sshd:$IP:deny" >> /etc/hosts.deny; 
      fi; 
  fi; 
done

좋은 웹페이지 즐겨찾기