終於讓我找到好用的工具 DenyHosts

之前為了阻斷無聊的駭客對我的機器猜密碼. 寫了一隻回報 script. 放在 cron裡面每天回報

[root@samtseng ~]# crontab -e
0 0 * * * /etc/failedssh

[root@samtseng ~]# cat /etc/failedssh
#/bin/bash
grep "Failed password for invalid user" /var/log/secure | awk '{print substr($13,8)}' | awk '{count[$1]++} END  { for( i in count ) { if ( count[i] >= 3 ){print i " Total Failed Attempts: " count[i] ""} }}' > /tmp/failedssh.txt
mail xxxx@samtseng.co.cc -s "Failed Attempts" < /tmp/failedssh.txt
rm -rf /tmp/failedssh.txt

每天半夜12點都可以接收到回報訊息. 也順便提醒自己該睡覺 😛 然後, 就會看到有些主機連續嘗試個2,000 ~ 4,000多次. OOXX的. 大部分都是來自中國.令人有點討厭!

後來今天不小心逛到 Gavin's Home 的 blog. 裡面有篇"最好的阻止SSH暴力破解的方法(DenyHosts)"後, 馬上幫自己的 server 架設起來.

大概寫個幾個重點提醒自己 :
安裝 DenyHosts-2.6-python2.4.noarch.rpm
[root@samtseng ~]# cp /usr/share/denyhosts/daemon-control /etc/rc.d/init.d/denyhosts
[root@samtseng ~]# chkconfig --add denyhosts
[root@samtseng ~]# chkconfig denyhosts on
[root@samtseng ~]# cp /usr/share/denyhosts/denyhosts.cfg-dist /usr/share/denyhosts/denyhosts.cfg
[root@samtseng ~]# vi /usr/share/denyhosts/denyhosts.cfg
ADMIN_EMAIL = xxx@gmail.com
[root@samtseng ~]# /etc/rc.d/init.d/denyhosts start

如果要知道詳細的內容請到 Gavin's Home 看 "最好的阻止SSH暴力破解的方法(DenyHosts)"篇.

參考 :
DenyHosts
DenyHosts - Download
最好的阻止SSH暴力破解的方法(DenyHosts)

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.