2015-04-07:fail2ban memo
pop3 に対してパスワードアタックかけてくるおバカがいそうなログを qpopper が出していたので、iptables でどけてしまおうと思いつつ、手動の iptables コマンドでしくじるのも怖いので fail2ban でやってもらうように。
手順
- sudo apt-get install fail2ban
- qpopper の出すログから相手ホストを切り出すフィルタを書く
- そのフィルタを使えるようにする
- sudo /etc/init.d/fail2ban restart
フィルタはこんな感じ。
$ cat /etc/fail2ban/filter.d/qpopper.conf [Definition] failregex = qpopper.* \(<HOST>\):.* Password supplied.* is incorrect
フィルタの動作チェックは↓のようなコマンドで。
$ sudo fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/qpopper.conf
大丈夫そうなら jail.conf に今回のフィルタを追加して、fail2ban 再起動。
$ tail /etc/fail2ban/jail.conf ... [qpopper] enabled = true port = pop3 filter = qpopper logpath = /var/log/mail.log maxentry = 10 bantime = 3600
あとは iptables -nL とかして、アタックくんが BAN されてるのを見てニヨニヨしよう。
# iptables -nL ... Chain fail2ban-qpopper (1 references) target prot opt source destination DROP all -- xxx.xxx.xxx.xxx 0.0.0.0/0 RETURN all -- 0.0.0.0/0 0.0.0.0/0 ...