FreeBSD 11.3 RELEASE - ポート遮断プログラム portsentry

クラウディア 
1. 概要
2. インストール
3. 構成ファイルの編集
4. 起動
5. 試験

1. 概要

 portsentry は、ポートスキャンを行ってくる IP アドレスに対して、一見ポートが開いているように見せかけて遮断するという、セキュリティ上、有効なプログラムです。  ポートスキャンについては「ウィキペディア - ポートスキャン」をご参照ください。

2. インストール


cd /usr/ports/security/portsentry
make
make install
 インストール時のオプションは、デフォルトのままにします。  インストール時のメッセージを掲載しておきます。

Installing portsentry-1.2_1...


       Edit ${PREFIX}/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.                                  *
       ***************************************************


===> 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. 構成ファイルの編集


/usr/local/etc/portsentry.conf
/usr/local/etc/portsentry.ignore
 この2つを編集します。  /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」というコメントのある行があるのが気になりますわなぁ。  /usr/local/etc/portsentry.ignore は

0.0.0.0
 の行を削除して、遮断しないアドレス(つまり自分のローカルやワールドのアドレス)を記述します。  /(スラッシュ)を使うことによってサブネットマスクを使ってネットワークアドレスでの記述ができます。  例えば、192.168.0.0 ~ 192.168.0.255 のアドレスを許可するには

192.168.0.0/24
 と記述します。

4. 起動

 起動スクリプトが作成されています。

/usr/local/etc/rc.d/portsentry.sh
 操作コマンドは、以下になります。

service portsentry.sh start	←	起動
service portsentry.sh stop	←	停止
 ステータスを見るオプションがないので、起動しているか見るのはとりあえず

> pgrep -lf portsentry
17304 /usr/local/bin/portsentry -udp
17302 /usr/local/bin/portsentry -tcp
 で良しとしましょう。

5. 試験

 portsentry を実行している状態でポートスキャンをかけて /var/log/message を見てみます。

Jul 17 01:10:39 vm portsentry[26801]: attackalert: Connect from host: SHOW201601/192.168.100.104 to TCP port: 15
Jul 17 01:10:39 vm portsentry[26801]: attackalert: Host: 192.168.100.104 is already blocked. Ignoring
Jul 17 01:10:52 vm portsentry[26801]: attackalert: Connect from host: SHOW201601/192.168.100.104 to TCP port: 79
Jul 17 01:10:52 vm portsentry[26801]: attackalert: Host: 192.168.100.104 is already blocked. Ignoring
Jul 17 01:10:59 vm portsentry[26801]: attackalert: Connect from host: SHOW201601/192.168.100.104 to TCP port: 111
Jul 17 01:10:59 vm portsentry[26801]: attackalert: Host: 192.168.100.104 is already blocked. Ignoring
Jul 17 01:11:01 vm portsentry[26801]: attackalert: Connect from host: SHOW201601/192.168.100.104 to TCP port: 119
Jul 17 01:11:01 vm portsentry[26801]: attackalert: Host: 192.168.100.104 is already blocked. Ignoring
Jul 17 01:11:05 vm portsentry[26801]: attackalert: Connect from host: SHOW201601/192.168.100.104 to TCP port: 143
Jul 17 01:11:05 vm portsentry[26801]: attackalert: Host: 192.168.100.104 is already blocked. Ignoring
 おお、出てる出てる。

/usr/local/etc/portsentry.ignore
 を編集して 192.168.100.104 を遮断しないようにすると、ログが出てこなくなったのでうまく動作しているようです。
ハイスピードプラン世界最大級のオンライン英会話EF English Live