iptablesでブルートフォース攻撃対策

VPSに変なのが来るのでやってみた。

recent モジュールを使って、n秒の間にm回 アクセスしたものをDROPする。--name を指定しないとDEFAULT になる。

# iptables -A INPUT -p tcp --syn --dport 22 -m recent --name badguy --set
# iptables -A INPUT -p tcp --syn --dport 22 -m recent --name badguy --update --seconds 60 --hitcount 5 -j DROP

listされているアドレスは /proc/net/xt_recent/LIST_NAME の中に書かれている。また、このファイルを直接いじっても制御できる。

Each file in /proc/net/xt_recent/ can be read from to see the current list or written two using the
       following commands to modify the list:

echo +addr >/proc/net/xt_recent/DEFAULT
    to add addr to the DEFAULT list

echo -addr >/proc/net/xt_recent/DEFAULT
    to remove addr from the DEFAULT list
	
echo / >/proc/net/xt_recent/DEFAULT
    to flush the DEFAULT list (remove all entries).