blacklistd(8)でsshd DoS攻撃を防止する方法
FreeBSD 11.
FreeBSD 11.
まず、
# sshd
sshd_enable="YES"
sshd_flags="-o UseBlacklist=yes"
# blacklistd
blacklistd_enable="YES"
# firewall
firewall_enable="YES"
firewall_type="OPEN"
sshdはデフォルトの設定ではblacklistd(8)に対応していませんので、
このままではblacklistd(8)がipfw(8)を使わないので、
# touch /etc/ipfw-blacklist.rc
この状態でシステムを再起動すると、
# ps auxww | grep sshd root 661 0.0 0.7 57812 6940 - Is 17:19 0:00.00 /usr/sbin/sshd -o UseBlacklist=yes #
ipfw(8)が有効になっているので、
# ipfw list 00100 allow ip from any to any via lo0 00200 deny ip from any to 127.0.0.0/8 00300 deny ip from 127.0.0.0/8 to any 00400 deny ip from any to ::1 00500 deny ip from ::1 to any 00600 allow ipv6-icmp from :: to ff02::/16 00700 allow ipv6-icmp from fe80::/10 to fe80::/10 00800 allow ipv6-icmp from fe80::/10 to ff02::/16 00900 allow ipv6-icmp from any to any ip6 icmp6types 1 01000 allow ipv6-icmp from any to any ip6 icmp6types 2,135,136 65000 allow ip from any to any 65535 deny ip from any to any #
blacklistd(8)も次のように動作していることを確認できます。
# ps auxww | grep blacklistd root 712 0.0 0.3 14772 2572 - Ss 17:19 0:00.01 /usr/sbin/blacklistd #
blacklistd(8)の保持しているルールはblacklistclt(8)コマンドで次のように確認できます。システムを再起動した段階では次のようになんのルールも入っているはずです。
# blacklistctl dump -a address/ma:port id nfail last access #
blacklistd(8)の設定は/etc/
# $FreeBSD: releng/11.1/etc/blacklistd.conf 301226 2016-06-02 19:06:04Z lidl $
#
# Blacklist rule
# adr/mask:porttype proto owner name nfail disable
[local]
ssh stream * * * 3 24h
ftp stream * * * 3 24h
smtp stream * * * 3 24h
submission stream * * * 3 24h
#6161 stream tcp6 christos * 2 10m
* * * * * 3 60
# adr/mask:port type proto owner name nfail disable
[remote]
#129.168.0.0/16 * * * = * *
#6161 = = = =/24 = =
#* stream tcp * = = =
ほかのホストからsshでログインを試み、
$ ssh 192.168.185.50 Password for [email protected]: Password for [email protected]: Password for [email protected]: Permission denied (publickey,keyboard-interactive). $ ssh 192.168.185.50
この状態でipfw(8)のルールをチェックすると、
# ipfw list 00100 allow ip from any to any via lo0 00200 deny ip from any to 127.0.0.0/8 00300 deny ip from 127.0.0.0/8 to any 00400 deny ip from any to ::1 00500 deny ip from ::1 to any 00600 allow ipv6-icmp from :: to ff02::/16 00700 allow ipv6-icmp from fe80::/10 to fe80::/10 00800 allow ipv6-icmp from fe80::/10 to ff02::/16 00900 allow ipv6-icmp from any to any ip6 icmp6types 1 01000 allow ipv6-icmp from any to any ip6 icmp6types 2,135,136 02022 deny tcp from table(port22) to any dst-port 22 ← ここに追加されている 65000 allow ip from any to any 65535 deny ip from any to any #
blacklistctl(8)コマンドでブロック情報を確認すると、
# blacklistctl dump -a address/ma:port id nfail last access 192.168.185.1/32:22 OK 3/3 2017/08/23 18:27:01 #
blacklistctl(8)コマンドは-rを指定するとルールが適用される残り時間を表示させることもできます。次のような感じです。
# blacklistctl dump -ar address/ma:port id nfail remaining time 192.168.185.1/32:22 OK 3/3 23h58m22s #
blacklistd(8)はデフォルトの設定だと/var/
blacklistd_flags="-f"
blacklistd_flags="-r"
blacklistd.
ここまでの設定でだいたい一通り基本的な操作はできるようになります。blacklistd(8)はlibblacklist APIを使うことで汎用的に利用できますので、
blacklistd(8)の使い方に関しては下記勉強会でより詳しい内容を取り上げようと思います。ご興味ある方は勉強会の方もご検討いただければと思います。
勉強会
10月4日(水)19:00~ 第66回 FreeBSD勉強会~vBSD 2017とEuroBSDCon 2017から旬な技術をご報告! - ヴァル研究所 セミナールーム
9月に米国バージニア州で開催されるvBSDcon 2017とフランスで開催されるEuroBSDCon 2017から、
本勉強会への参加者には抽選か勝ち抜きかデーモンTシャツなどのグッズをお渡しします。ふるってご参加ください。
参加登録はこちらから。
10月26日(木)19:00~第67回 FreeBSD勉強会~blacklistd(8)でsshd DoS攻撃を防止する方法 基礎から応用まで - ドワンゴ セミナールーム
FreeBSD 11.
FreeBSD 11.
blacklistd(8)と類似した機能を提供するソフトウェアにはsshguard、
blacklistd(8)はライブラリとしてlibblacklistを提供しているため、
今回の勉強会ではblacklistd(8)がどのように動作しているのか紹介するとともに、
参加登録はこちらから
FreeBSD勉強会 発表者募集
FreeBSD勉強会では発表者を募集しています。FreeBSDに関して発表を行いたい場合、