星期日, 7月 13, 2008

denyhosts notes

denyhosts notes
OS: FreeBSD 6.3 Release pl2

denyhosts 是一個用來分析 log messages 的 script,主要用來對付 ssh 的暴力破解。
當 ssh 驗證失敗次數過多時,會將 ip 加入 tcp wrapper 的拒絕連線清單 (hosts.allow)。

詳細資訊請參考:
http://denyhosts.sourceforge.net/faq.html
http://www.freebsdsoftware.org/security/denyhosts.html

安裝:
cd /usr/ports/security/denyhosts
make all install clean


把 denyhosts_enable="YES" 加到 /etc/rc.conf 裡如下:
echo 'denyhosts_enable="YES"' >> /etc/rc.conf

把下面兩行加到 /etc/hosts.allow 裡
sshd : /etc/hosts.deniedssh : deny
sshd : ALL : allow


為了讓 denyhosts 能注意到多次嘗試登入的記錄,理論上 syslogd 應該加上 -c 的參數。
在 /etc/rc.conf 裡找到 syslogd_flags 加上 -c 參數如下:
syslogd_flags="-c"

然後編輯 /usr/local/etc/denyhosts.conf
vi /usr/local/etc/denyhosts.conf
要先設定要 block 的 service
BLOCK_SERVICE = sshd

然後開一個空檔給 denyhosts 使用
touch /etc/hosts.deniedssh

執行
/usr/local/etc/rc.d/denyhosts start

沒有留言: