![]() |
LINUX |
Portsentry-2.0b1の設定
*iptablesを通過したportscanをキャッチします
*Portsentry-2.0b1をソースからインストールし、設定します
*iptablesでTARGETをDROPします (INPUTチェーンのみ)
*本家psionicのリンクは切れています
*アドレス指定があるので固定IPでないとうまくいかないと思う
*make はメンテナンスマシンで行っています
**以降はコメントです
*ソースの取得、削除は省略します
*エディタ、ファイラーの操作は省略します
*ソースを展開したら説明文(英文)を読みましょう
*Enterキーを省略します
*ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
*設定ファイルで "#" で始まる行はコメントとして解釈されます
関連サイト| :portsentry-2.0b1.tar.gz | (http://www.sfr-fresh.com/unix/privat/) |
参照ファイル
インストール環境| :OS | CentOS 5.5 |
| :selinux | permissive |
| :インストール先 | /usr/local/portsentry2 |
| :作業 | /usr/src |
| :言語 | LANG=en_US.UTF-8 |
| :ユーザー | rootで実行 |
*メンテナンスの場合は一般ユーザから行います
portsentry-2.0b1
ソースの展開・インストール# cd /usr/src # tar zxvf portsentry-2.0b1.tar.gz # chown -R root:root portsentry-2.0b1 # cd portsentry-2.0b1
*パッチを当てます (下記参照)
*1つ上のディレクトリにパッチファイルを置きます
# patch -p1 < ../portsentry.patch
# make linux
# make install
# cd ..
# tar jcvf portsentry-2.0b1-rt-100519.tar.bz2 portsentry-2.0b1/
*CFLAGS="-march=pentium3" (CPU最適化オプション)
*該当しない場合は指定しない
portsentry.confの修正 (変更追加分)*チェックするのはportsentry.confで指定してあるポートのみです
*必要ならば各自追加します
*iptablesのインストール場所を確認します
*host.denyに"ALL: ALL"を指定しているのでhost.denyの書き込みをしない
*KILL_ROUTEを実行後にKILL_RUN_CMDを実行します
*illegalなScanを1回までは許す?
# Interface Configuration # INTERFACE_ADDRESS="219.117.201.3"
# Configuration Files # IGNORE_FILE="/usr/local/portsentry2/portsentry.ignore" HISTORY_FILE="/usr/local/portsentry2/portsentry.history" BLOCKED_FILE="/usr/local/portsentry2/portsentry.blocked"
# Dropping Routes #
#KILL_ROUTE="/usr/local/bin/iptables -I INPUT -s $TARGET$ -j DROP"
KILL_ROUTE="/usr/local/sbin/iptables -I INPUT -s $TARGET$ -j DROP"
# TCP Wrappers # #KILL_HOST_DENY="ALL:$TARGET$"
# External Command # KILL_RUN_CMD_FIRST = "0" KILL_RUN_CMD="/usr/local/sbin/pschk-clear $TARGET$"
# Scan trigger value # SCAN_TRIGGER="1"
*ここでは、"KILL_RUN_CMD"でatを利用し24時間後にiptablesルールを削除します
*"portsentry.blocked"に記録されたアドレスは無視されるので、クリアします
:/usr/local/sbin/pschk-clear (root root 700)
#!/bin/bash
TARGET="$1" PBLOCKED='/usr/local/portsentry2/portsentry.blocked' IPTABLES='/usr/local/sbin/iptables'
/bin/echo "/bin/sed -e "/$TARGET/d" -i $PBLOCKED && \ $IPTABLES -D INPUT -s $TARGET -j DROP > /dev/null 2>&1" \ | /usr/bin/at now+24hour > /dev/null 2>&1
portsentry.ignoreの修正 (変更追加分)127.0.0.0/8 192.168.0.0/24 #0.0.0.0
自動起動スクリプトを作成します:/étc/rc.d/init.d/portsentry (詳細別記)
selinuxヘの対応 (selinuxが有効の場合):新規インストールファイルのselinuxラベルを修正
# restorecon -Rv /etc # restorecon -Rv /usr/local
portsentryを起動します# chkconfig --add portsentry # service portsentry start
iptablesチェーンに追加された例*上手く働くとすれば、iptablesがリフレッシュされるまで接続できません
*portsentryで新しくチェックされるごとにチェーンに書き加えられます
Chain INPUT (policy DROP) num target prot opt source destination 1 DROP 0 -- 58.138.188.154 0.0.0.0/0 2 ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0 3 REJECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:0x12/0x12 state NEW reject-with tcp-reset 4 wan-fwz 0 -- 0.0.0.0/0 219.117.201.3 5 lan-fwz 0 -- 192.168.0.0/24 0.0.0.0/0
iptablesのチェーンの削除*ユーザの誤操作?でチェーンに組み込まれてしまった場合
*--line-numbersオプションをつけてチェーンの順番を調べます
*-Dオプションでチェーンを削除します
*(例)INPUTチェーンの1番目を削除
# iptables -L INPUT -n --line-numbers # iptables -D INPUT 1
atデーモンの起動*予約されたatジョブを表示します (portscanを検知した場合)
# at -l 3 2008-11-12 08:36 a root
*予約されたジョブの詳細(-cオプションで番号を指定)
# at -c 3
*省略
*atジョブをモニターして実行します
# service atd start # chkconfig --level 345 atd on
参考 centos5のnet.ipv4.ip_local_port_range*webクライアントを複数起動すると、portsentryで捕えられる場合があります
*CentOS5を使う場合は、クライアントのlocal_port_rangeを変更しておく
*net.ipv4.ip_local_port_range(デフォルト)
# sysctl -a | grep net.ipv4.ip_local_port_range net.ipv4.ip_local_port_range = 32768 61000
*net.ipv4.ip_local_port_rangeの変更
# cp -a /erc/sysctl.conf /etc/sysctl.conf.orig
# echo "net.ipv4.ip_local_port_range = 16385 65535" >> /etc/sysctl.conf
# sysctl -p
*確認
# sysctl -a | grep net.ipv4.ip_local_port_range net.ipv4.ip_local_port_range = 16385 65535
![]() |
Copyright(c) 528p.com All Rights Reserved. |

