岩本隆史の日記帳(アーカイブ)

はてなダイアリーのサービス終了をうけて移行したものです。更新はしません。

ブルートフォースアタックがひどいのでDenyHostsを入れた

リリースチェッカーを動かしているFreeBSDサーバに対し、ここ数日ブルートフォースアタックが行われていました。どげんかせんといかんので、DenyHostsというツールを入れて様子を見ています。とりあえず作業メモを残しておきます。

なお、作業にあたっては下記のリソースが参考になりました。ありがたいねー。

ports からインストール

# cd /usr/ports
# portinstall security/denyhosts

/etc/rc.conf の編集

インストールすると

To run denyhosts from startup, add denyhosts_enable="YES"
in your /etc/rc.conf.

とか

Warning:

syslogd should ideally be run with the -c option; this will ensure that
denyhosts notices multiple repeated login attempts.

To do this, add syslogd_flags="-c" to /etc/rc.conf

とかいわれたので、/etc/rc.conf を下記のように編集しました。

denyhosts_enable="YES"
#syslogd_flags="-ss"
syslogd_flags="-ss -c"

/usr/local/etc/denyhosts.conf を編集

また

Configiration options can be found in /usr/local/etc/denyhosts.conf

だそうなので、/usr/local/etc/denyhosts.conf を編集しました。必要最小限な感じです。

BLOCK_SERVIE  = sshd
ADMIN_EMAIL = hello@iwamot.com

/etc/hosts.allow を編集、/etc/hosts.deniedssh を作成

おまけに

In order to proper working of denyhosts
1. edit your /etc/hosts.allow file and add:
sshd : /etc/hosts.deniedssh : deny
sshd : ALL : allow
2. issue the following command if /etc/hosts.deniedssh does not exist yet
touch /etc/hosts.deniedssh

といわれたので、そのとおり従いました。

いよいよ起動

/usr/local/etc/rc.d/denyhosts.sh に起動スクリプトができていたので、それを使います。

# /usr/local/etc/rc.d/denyhosts.sh start
Starting denyhosts.

動いた!

ログを見てニヤリ

ログは /var/log/denyhosts にあります。

# cat /var/log/denyhosts | grep 'new denied hosts'
2008-07-03 19:46:20,297 - denyhosts   : INFO     new denied hosts: ['XXX.X.XXX.X
X', 'XXX.XXX.XXX.XXX', 'XXX.XXX.XXX.XX', 'XX.XXX.XXX.XXX']

とかいって引っかかってやんの! しかも4件もwww

/etc/hosts.deniedssh を見る

# cat /etc/hosts.deniedssh
sshd: XXX.X.XXX.XX : deny
sshd: XXX.XXX.XXX.XXX : deny
sshd: XXX.XXX.XXX.XX : deny
sshd: XX.XXX.XXX.XXX : deny

二度と来んなボケー!!

追記(2008-07-04)

syslogd should ideally be run with the -c option」なのでそんなに重要ではないですが(と、自分をなぐさめつつ)、syslogd の再起動を忘れてました><

# /etc/rc.d/syslogd restart

そしてまた1件増えてるwww

# cat /var/log/denyhosts | grep 'new denied hosts'
2008-07-03 19:46:20,297 - denyhosts   : INFO     new denied hosts: ['XXX.X.XXX.X
X', 'XXX.XXX.XXX.XXX', 'XXX.XXX.XXX.XX', 'XX.XXX.XXX.XXX']
2008-07-04 11:44:09,438 - denyhosts   : INFO     new denied hosts: ['XX.XX.XX.XXX']