![]() |
LINUX |
Portsentry-1.2の設定
*iptablesを通過したportscanをキャッチします
*portsentry-1.2をソースからインストールし、設定します
*本家psionicのリンクは切れています
**以降はコメントです
*ソースの取得、削除は省略します
*エディタ、ファイラーの操作は省略します
*ソースを展開したら説明文 (英文) を読みましょう
*Enterキーを省略します
*ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
*設定ファイルで "#" で始まる行はコメントとして解釈されます
関連サイト| :portsentry-1.2.tar.gz (http://sourceforge.net/projects/sentrytools) |
参照ファイル
インストール環境| :OS | CentOS 5.1 |
| :selinux | disabled or permissive |
| :インストール先 | /usr/local/portsentry |
| :作業 | /usr/src |
| :言語 | LANG=en_US.UTF-8 |
| :ユーザー | rootで実行 |
*メンテナンスの場合は一般ユーザから行います
portsentry-1.2
ソースの展開・インストール# cd /usr/src # tar zxvf portsentry-1.2.tar.gz # chown -R root:root portsentry_beta # cd portsentry_beta
*パッチを当てます -下記参照
*1つ上のディレクトリにパッチファイルを置きます
# patch -p1 < ../portsentry_beta.patch
# make linux
# make install
# cd ..
# tar jcvf portsentry-1.2-rt-080106.tar.bz2 portsentry_beta/
*CFLAGS="-march=pentium3" (CPU最適化オプション)
*該当しない場合は指定しない
portsentry.confの修正 (変更追加分)*指定してあるポートを除きすべてチェックします
*必要ならば各自追加します
*iptablesのインストール場所を確認
*"! $TARGET$ -j ACCEPT"でTARGET以外のアドレスを許可する設定
*host.denyに"ALL: ALL"を指定しているのでhost.denyの書き込みをしない
*illegalなScanを1回までは許す?
: /usr/local/portsentry/portsentry.conf (root root 600)
# Advanced Stealth Scan Detection Options # ADVANCED_EXCLUDE_TCP="21,22,25,53,80,110,113,143,443,465,722,953,993" ADVANCED_EXCLUDE_UDP="520,123,67,53"
# Configuration Files # IGNORE_FILE="/usr/local/portsentry/portsentry.ignore" HISTORY_FILE="/usr/local/portsentry/portsentry.history" BLOCKED_FILE="/usr/local/portsentry/portsentry.blocked"
# Dropping Routes # KILL_ROUTE="/usr/local/sbin/iptables -I INPUT -s ! $TARGET$ -j ACCEPT"
# TCP Wrappers # #KILL_HOST_DENY="ALL:$TARGET$"
# Scan trigger value # SCAN_TRIGGER="1"
portsentry.ignoreの修正 (変更追加分): /usr/local/portsentry/portsentry.ignore (root root 600)
127.0.0.0/8 192.168.0.0/24 #0.0.0.0
portsentry.modesファイルの作成: /usr/local/portsentry/portsentry.modes (root root 600)
*portsentry起動スクリプトで読み込みます
*atcp audp (高度な論理モード) で起動します
*README.install、README.stealthを読みましょう
#tcp #udp #stcp #sudp atcp audp
自動起動スクリプトを作成します:/é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がリフレッシュされるまで接続できません
*portcentryで新しくチェックされるごとにチェーンに書き加えられます
Chain INPUT (policy DROP) num target prot opt source destination 1 ACCEPT 0 -- !207.171.191.135 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 5 wan-fwz 0 -- 0.0.0.0/0 219.117.201.3 6 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
定期的に設定をクリアします:/usr/local/sbin/clpschk.sh (root root 700)
*INPUTチェーンの中から!の付いたものを捜して削除します
*INPUTチェーンの先頭に追加されるので、先頭から一行ずつ削除します
*portsentryのblock情報をクリアします
*cronで定期的にスクリプトを実行して下さい
#!/bin/bash
IPTABLES=/usr/local/sbin/iptables
linenum=$($IPTABLES -L INPUT -n --line-numbers) badnum=$($IPTABLES -L INPUT -n --line-numbers | grep "!")
if [ -n "$badnum" ]; then
until [ "$badnum" == "" ]
do
$IPTABLES -D INPUT 1
badnum=$($IPTABLES -L INPUT -n --line-numbers | grep "!")
done
cat /dev/null > /usr/local/portsentry/portsentry.blocked.atcp
cat /dev/null > /usr/local/portsentry/portsentry.blocked.audp
clrnum=$($IPTABLES -L INPUT -n --line-numbers)
echo -e "before\n$linenum\nafter\n$clrnum" | \
mail -s "clear-sentry-check" root@localhost
fi
exit
clearされた記録
before
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT all -- !207.171.191.135 0.0.0.0/0
2 ACCEPT all -- 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 all -- 0.0.0.0/0 219.117.201.3
5 lan-fwz all -- 192.168.0.0/24 0.0.0.0/0
after
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 REJECT tcp -- 0.0.0.0/0 0.0.0.0/0
tcp flags:0x12/0x12 state NEW reject-with tcp-reset
3 wan-fwz all -- 0.0.0.0/0 219.117.201.3
4 lan-fwz all -- 192.168.0.0/24 0.0.0.0/0
![]() |
Copyright(c) 528p.com All Rights Reserved. |

