FreeBSD 12.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 /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.

===> 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
 と記述します。  サブネットマスクの計算には、「サブネットマスク計算(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 10 08:47:42 ns portsentry[1165]: attackalert: Connect from host: SHOW202003/192.168.100.134 to TCP port: 1
Dec 10 08:47:42 ns portsentry[1165]: attackalert: Host 192.168.100.134 has been blocked via wrappers with string: "ALL: 192.168.100.134"
Dec 10 08:47:42 ns portsentry[1165]: attackalert: Host 192.168.100.134 has been blocked via dropped route using command: "/bin/echo 'block in log on external_interface from 192.168.100.134/32 to any' | /sbin/ipf -f -"
Dec 10 08:47:44 ns portsentry[1165]: attackalert: Connect from host: SHOW202003/192.168.100.134 to TCP port: 11
Dec 10 08:47:44 ns portsentry[1165]: attackalert: Host: 192.168.100.134 is already blocked. Ignoring
Dec 10 08:47:45 ns portsentry[1165]: attackalert: Connect from host: SHOW202003/192.168.100.134 to TCP port: 15
Dec 10 08:47:45 ns portsentry[1165]: attackalert: Host: 192.168.100.134 is already blocked. Ignoring
Dec 10 08:47:58 ns portsentry[1165]: attackalert: Connect from host: SHOW202003/192.168.100.134 to TCP port: 79
Dec 10 08:47:58 ns portsentry[1165]: attackalert: Host: 192.168.100.134 is already blocked. Ignoring
 おお、出てる出てる。

/usr/local/etc/portsentry.ignore
 を編集して 「192.168.100.104」を遮断しないようにすると、ログが出てこなくなったのでうまく動作しているようです。
スポンサーリンクハイスピードプラン