1. 概要
「portsentry」は、ポートスキャンを行ってくる「IP」アドレスに対して、一見ポートが開いているように見せかけて遮断するという、セキュリティ上、有効なプログラムです。
ポートスキャンについては「ウィキペディア - ポートスキャン」をご参照ください。
2. インストール
「root」ユーザ権限で。
cd /usr/ports/security/portsentry
make
make install
インストール時のオプションは、デフォルトのままにします。
インストール時のメッセージを掲載しておきます。
Installing portsentry-1.2_1...
Edit /usr/local/etc/portsentry.conf and change
your settings if you haven't already. (route, etc)
IGNORE stealth mode. It is for Linux only.
The author hopes to have a platform independent
version at some time. So don't even bother
trying it now.
===> NOTICE:
The portsentry port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:
https://bugs.freebsd.org/bugzilla
More information about port maintainership is available at:
https://docs.freebsd.org/en/articles/contributing/#ports-contributing
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/portsentry
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/portsentry.sh
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.
バージョンは、変わっていません。
3. 構成ファイルの編集
「root」ユーザ権限で。
vi /usr/local/etc/portsentry.conf
#KILL_ROUTE="/bin/echo 'block in log on external_interface from $TARGET$/32 to any' | /sbin/ipf -f -"
の先頭の「#」を削除して生かします。
これで、攻撃してきた IP を遮断します。
ただこの行のコメントが「For those running ipfilt (OpenBSD, etc.)」となっていて上の方に「FreeBSD」というコメントのある行があるのが気になりますわなぁ。
vi /usr/local/etc/portsentry.ignore
0.0.0.0
の行を削除して、遮断しないアドレス(つまり自分のローカルやワールドのアドレス)を記述します。
/(スラッシュ)を使うことによってサブネットマスクを使ってネットワークアドレスでの記述ができます。
例えば、「192.168.0.0」~「192.168.0.255」のアドレスを許可するには
192.168.0.0/24
と記述します。
サブネットマスクの計算には、「サブネットマスク計算(IPv4)/サブネット一覧(早見表)」がとても便利です。
4. 起動
起動スクリプトが作成されています。
/usr/local/etc/rc.d/portsentry.sh
操作コマンドは、以下になります(上が起動、下が停止)。
service portsentry.sh start
service portsentry.sh stop
ステータスを見るオプションがないので、起動しているか見るのはとりあえず
$ pgrep -lfa portsentry
20832 /usr/local/bin/portsentry -udp
20830 /usr/local/bin/portsentry -tcp
で良しとしましょう。
5. 試験
「portsentry」を実行している状態でポートスキャンをかけて /var/log/message を見てみます。
Dec 8 17:09:15 ns portsentry[1669]: attackalert: Connect from host: SHOW202003/192.168.100.113 to TCP port: 1
Dec 8 17:09:15 ns portsentry[1669]: attackalert: Host 192.168.100.113 has been blocked via wrappers with string: "ALL: 192.168.100.113"
Dec 8 17:09:15 ns portsentry[1669]: attackalert: Host 192.168.100.113 has been blocked via dropped route using command: "/bin/echo 'block in log on external_interface from 192.168.100.113/32 to any' | /sbin/ipf -f -"
Dec 8 17:09:16 ns portsentry[1669]: attackalert: Connect from host: SHOW202003/192.168.100.113 to TCP port: 11
Dec 8 17:09:16 ns portsentry[1669]: attackalert: Host: 192.168.100.113 is already blocked. Ignoring
Dec 8 17:09:18 ns sshd[1678]: error: Fssh_kex_exchange_identification: Connection closed by remote host
Dec 8 17:09:38 ns portsentry[1669]: attackalert: Connect from host: SHOW202003/192.168.100.113 to TCP port: 111
Dec 8 17:09:38 ns portsentry[1669]: attackalert: Host: 192.168.100.113 is already blocked. Ignoring
Dec 8 17:09:43 ns portsentry[1669]: attackalert: Connect from host: SHOW202003/192.168.100.113 to TCP port: 119
Dec 8 17:09:43 ns portsentry[1669]: attackalert: Host: 192.168.100.113 is already blocked. Ignoring
といった感じで、スキャンに対するログが補油辞されます。
/usr/local/etc/portsentry.ignore
を編集して、スキャンをしかけてくるアドレスをを遮断しないようにすると、ログが出てこなくなったのでうまく動作しているようです。