防暴力破解sshd腳本


注意: 此腳本並不會定期清理之前添加到/etc/hosts.deny中的ip地址

     爲了以防萬一,先在/etc/hosts.allow中添加自己本地的ip地址,萬一哪天忘記了root密碼,還有試一試的機會,不然就呵呵了。。。


此腳本運行在centos6的系統之上,如centos7需要的話,需要修改腳本聲明(#!/usr/bin/bash);


第一步:   


mkdir /date/script/ -p


vim /date/script/cron.sh


#!/bin/bash

for ((i=1;i<=12;i++))

do

       source /date/script/sshd_fblpj.sh

       sleep 5

done



第二步:

vim /date/script/sshd_fblpj.sh


#!/bin/bash

#

awk '/Failed password/{print $(NF-3)}' /var/log/secure | sort | uniq -c | awk '{if($1>=4) print $2}' > /tmp/reject.txt

for i in `cat /tmp/reject.txt`

do

ip=$i

grep -w "$ip" /etc/hosts.deny

if [ $? -gt 0 ]

then

echo "sshd:$ip" >> /etc/hosts.deny

fi

done



第三步:

crontab -e


*/1     *       *       *       *        sh /date/script/cron.sh




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章