SIP-Fail2banのソースを表示
←
SIP-Fail2ban
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループのいずれかに属する利用者のみが実行できます:
登録利用者
、
管理者
。
このページのソースの閲覧やコピーができます。
==fail2ban== ログファイルとiptablesを利用したファイアウォールの一種。Brute Forceアタックの対策に使いやすい。<br> :http://www.fail2ban.org/ :http://sourceforge.net/projects/fail2ban/ ==動作条件== pythonとiptablesが必要。yum install python iptablesなどで入れておいて下さい。 ==インストール== まずSFからfail2banをダウンロードし、展開します。 tar jxvf fail2ban-0.8.4.tar.bz2 展開したディレクトリでインストールを実行します。 cd fail2ban-0.8.4 python ./setup.py スタートアップ・スクリプトをコピーしておきます(CentOSなどRedHat系の場合の例)。 cp files/redhat-initd /etc/init.d/fail2ban ==設定== ===Asteriskのログフォーマットを変更する=== Fail2banはそのままではAsteriskのログの日付を認識できないため、Asteriskのログフォーマットを変更します。<br> /etc/asterisk/logger.confを編集し、日付のフォーマット変更を行います。<br> [general]セクションにある dateformat=%F %T のコメントを外すか、もしこのエントリがなければ記述します。設定を変更したら、Asteriskを再起動するか、loggerモジュールのリロードを行って、変更を有効にします。これによりAsteriskのログの日付形式が以下のように変わりますので、確認してください。 [2010-12-30 09:25:25] NOTICE[17537] chan_sip.c:..... ===Asterisk用の定義ファイルを作る=== /etc/fail2ban/filter.d ディレクトリに asterisk.conf という名前で以下のようなファイルを作ります。ここで指定したメッセージがBAN基準として使われるメッセージとなります。<br> <br> Asterisk 1.8系の場合 # Fail2Ban configuration file # # # $Revision: 250 $ # [INCLUDES] # Read common prefixes. If any customizations available -- read them from # common.local #before = common.conf [Definition] #_daemon = asterisk # Option: failregex # Notes.: regex to match the password failures messages in the logfile. The # host must be matched by a group named "host". The tag "<HOST>" can # be used for standard IP/hostname matching and is only an alias for # (?:::f{4,6}:)?(?P<host>\S+) # Values: TEXT # failregex = Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Wrong password Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - No matching peer found Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Username/auth name mismatch Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Device does not match ACL Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Peer is not supposed to register Registration from '.*' failed for '<HOST>(:[0-9]{1,5})?' - Not a local domain # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. # Values: TEXT # ignoreregex = Asterisk 1.6とそれ以前の場合 # Fail2Ban configuration file # # # $Revision: 250 $ # [INCLUDES] # Read common prefixes. If any customizations available -- read them from # common.local #before = common.conf [Definition] #_daemon = asterisk # Option: failregex # Notes.: regex to match the password failures messages in the logfile. The # host must be matched by a group named "host". The tag "<HOST>" can # be used for standard IP/hostname matching and is only an alias for # (?:::f{4,6}:)?(?P<host>\S+) # Values: TEXT # failregex = Registration from '.*' failed for '<HOST>' - Wrong password Registration from '.*' failed for '<HOST>' - No matching peer found Registration from '.*' failed for '<HOST>' - Username/auth name mismatch Registration from '.*' failed for '<HOST>' - Device does not match ACL Registration from '.*' failed for '<HOST>' - Peer is not supposed to register Registration from '.*' failed for '<HOST>' - Not a local domain # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. # Values: TEXT # ignoreregex = Asterisk 1.8とそれ以前ではログのホスト部分にポート番号を含む、含まないの違いがあるためfailregexの記述を変える必要がありますので注意してください。この部分に合致するメッセージが、ログファイルに現れたならばBAN基準になりますので注意して記述します。これ意外にも、引っかけたいメッセージがある場合にはそれも記述するとよいでしょう。<br> ===BANのアクションを作成する=== ここではTCP/UDPの5060ポート、つまりSIPだけをBAN対象としたいためアクションをSIP用に作成します。 /etc/fail2ban/action.d で以下のようにしてアクションを作成します。<br> まず cp iptables-allports.conf iptables-sip.conf を行って、全ポート用のアクションをコピーします。次に iptables-sip.conf を編集し、以下のようにBANとUNBANのエントリを修正します。 # Option: actionban # Notes.: command executed when banning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: <ip> IP address # <failures> number of failures # <time> unix timestamp of the ban time # Values: CMD # actionban = iptables -I fail2ban-<name> 1 -s <ip> -p udp --dport 5073 -j DROP # Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: <ip> IP address # <failures> number of failures # <time> unix timestamp of the ban time # Values: CMD # actionunban = iptables -D fail2ban-<name> -s <ip> -p udp --dport 5073 -j DROP -p udp と --dport 5073 を actionban と actionunban に追記します。 ===fail2banの設定ファイルを修正=== /etc/fail2ban にある jail.conf ファイルの最後に以下を追加します。 [asterisk-iptables] enabled = true filter = asterisk action = iptables-sip[name=ASTERISK, protocol=all] sendmail-whois[name=ASTERISK, dest=root, sender=fail2ban@example.net] logpath = /var/log/asterisk/messages maxretry = 5 findtime = 600 bantime = 604800 *action BAN処理のアクションを定義します。この例ではiptables-sipを実行します。その後、sendmail-whois で BANしたIPアドレスのwhois情報を dest= で指定された宛先に送ります。このとき使用されるメールのFrom:はfail2ban@exampleになりますので、適切なものに書き換えます。 *logpath Asteriskのログファイルへのパスを記述します。 *maxretry 何回以上失敗したらBANするかの指定です。 *findtime この時間内にmaxretryで指定した回数以上失敗するとBANします。上の例では600秒(10分)の間に、5回以上の失敗があった場合にはBANされます。 *bantime ここで指定された期間がBAN期間になります。指定は秒数です。上の例では 60x60x24x7=604800、つまり1週間になります。 ==fail2banを起動する== /etc/init.d/fail2ban start 起動したら期待の動作をするかどうかを、よく確認してください。試しに故意に間違えたパスワードで5回以上ログインをしてみるなどです。<br> 起動に問題がなければ、fail2banが自動起動されるように登録しておけば良いでしょう。 chkconfig --add fail2ban
SIP-Fail2ban
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
ソースを閲覧
履歴表示
その他
検索
案内
メインページ
最近の更新
おまかせ表示
ヘルプ
広告
サイトコンテンツ
コミュニティ
Asterisk
Asterisk 18
Asterisk 20
Asterisk 22
IP電話機
購入情報
導入事例
回線接続
ベンダー
ひかり電話
セキュリティ
イベント情報
スペシャル
Asterisk pjsip
ABS
黒電話 ハック
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報