blacklistd(8)でftpd DoS攻撃を防止する方法 ipfw編
前回までFreeBSD 11.
最初はsshd(8)とファイアウォールにipfw(4)を使う方法を紹介しました。前々回はpf(4)を使う場合、
まず、
# inetd
inetd_enable="YES"
# blacklistd
blacklistd_enable="YES"
blacklistd_flags="-f"
#blacklistd_flags="-r"
# firewall - ipfw
firewall_enable="YES"
firewall_type="OPEN"inetd(8)からftpd(8)を起動するように、
ftp     stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -l -Bftpd(8)のオプションに-Bが追加してある点に注目してください。これが新しく追加されたオプションで、
blacklistd(8)がipfw(4)を使うように/etc/
# touch /etc/ipfw-blacklist.rc
この状態でシステムを再起動すると、
# ps auxww | grep inetd root 687 0.0 0.2 14708 2356 - Is 20:29 0:00.00 /usr/sbin/inetd -wW -C 60 #
ipfw(4)が有効になっているので、
# 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 705 0.0 0.3 14772 2576 - Ss 20:29 0:00.01 /usr/sbin/blacklistd -f #
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:port	type	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	*		=	=	=ほかのホストからftpでログインを試み、
% ftp daichi@192.168.185.50 ← 3回目のトライ Connected to 192.168.185.50. 220 virt.ongs.co.jp FTP server (Version 6.00LS) ready. 331 Password required for daichi. Password: 530 Login incorrect. ftp: Login failed ftp> quit ← 反応がなくなる
この状態でipfw(4)のルールをチェックすると、
# 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
02021 deny tcp from table(port21) to any dst-port 21 ← 追加されたルール
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:21	OK	3/3	2017/09/20 20:39:03
#
blacklistd(8)はデフォルトの設定だと/var/
このようにblacklistd(8)とipfw(4)を使うと自動的にFTPアクセスをブロックするといった設定を実現できます。今回はipfw(4)を取り上げましたけれども、
このあたりも含めてblacklistd(8)の使い方に関して下記勉強会で詳しい内容を取り上げます。ご興味ある方は勉強会の参加を検討してみてください。なかなか面白い仕組みになっています。
勉強会
10月4日(水)19:00~ 第66回 FreeBSD勉強会~vBSD 2017とEuroBSDCon 2017から旬な技術をご報告! - ヴァル研究所 セミナールーム  
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)がどのように動作しているのか紹介するとともに、
参加登録はこちらから。
