-1

IPTablesを使用して、Fedora 21でAsterisk 11を使用してfail2ban 0.9.1を使用しています。

サーバーを攻撃する IP アドレスが IP テーブルに自動的に書き込まれません (手動で banip を実行した場合の動作については、以下を参照してください)。これを引き起こすエラーはありますか?

/var/log/asterisk/messages ログに、悪意のある人が誤った拡張機能を試みているというメッセージが表示されます。

私の正規表現は、私が実行したときに機能します

 fail2ban-regex /var/log/asterisk/messages /etc/fail2ban/filter.d/asterisk.conf

私は得る

 Lines: 2985 lines, 0 ignored, 597 matched, 2388 missed [processed in 0.66 sec]

これは、597 行が正規表現に一致したことを意味します。右?どの行が一致したかを表示する方法はありますか? 変数は何でしたか?

私もできる:

 fail2ban-client set asterisk banip 107.150.44.222

IPTables が適切に更新され、IP が禁止されます。(はい、私は実際の IP アドレスを使用したことを知っています -- そして私に関する限り、誰もが ba$%*$#rd を禁止することを歓迎します)

 jail.local 

 [asterisk]
 enabled=yes
 filter=asterisk
 protocol=all
 logpath = /var/log/asterisk/messages
 banaction=iptables-multiport
 port     = 5060,5061
 action   = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
       %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
       %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s"]
 maxretry = 3
 bantime=432000
 findtime =86400

競合を避けるために、jail.conf のアスタリスクへの参照を削除しました

 filter.d/asterisk.conf 

 [INCLUDES]

 # Read common prefixes. If any customizations available -- read them from
 # common.local
 before = common.conf

 [Definition]

 # Option:  failregex
 # Notes.:  regex to match the password failures messages in the logfile.
 # Values:  TEXT
 #
 log_prefix= \[\]\s*(?:NOTICE|SECURITY)%(__pid_re)s:?(?:\[\S+\d*\])? \S+:\d*

 failregex = ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - Wrong password$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - No matching peer found$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - Username/auth name mismatch$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - Device does not match ACL$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - Peer is not supposed to register$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - ACL error \(permit/deny\)$
        ^%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - Not a local domain$
        ^%(log_prefix)s Call from '[^']*' \(<HOST>:\d+\) to extension '\d+' rejected because extension not found in context 'default'\.$
        ^%(log_prefix)s Host <HOST> failed to authenticate as '[^']*'$
        ^%(log_prefix)s No registration for peer '[^']*' \(from <HOST>\)$
        ^%(log_prefix)s Host <HOST> failed MD5 authentication for '[^']*' \([^)]+\)$
        ^%(log_prefix)s Failed to authenticate (user|device) [^@]+@<HOST>\S*$
        ^%(log_prefix)s (?:handle_request_subscribe: )?Sending fake auth rejection for (device|user) \d*<sip:[^@]+@<HOST>>;tag=\w+\S*$
        ^%(log_prefix)s SecurityEvent="(FailedACL|InvalidAccountID|ChallengeResponseFailed|InvalidPassword)",EventTV="[\d-]+",Severity="[\w]+",Service="[\w]+",EventVersion="\d+",AccountID="\d+",SessionID="0x[\da-f]+",LocalAddress="IPV[46]/(UD|TC)P/[\da-fA-F:.]+/\d+",RemoteAddress="IPV[46]/(UD|TC)P/(<HOST>)/[0-9]{4}"(,Challenge="\w+",ReceivedChallenge="\w+")?(,ReceivedHash="[\da-f]+")?$

 # Option:  ignoreregex
 # Notes.:  regex to ignore. If this regex matches, the line is ignored.
 # Values:  TEXT
 #
 ignoreregex =
4

1 に答える 1

0

あなたの asterisk.conf と jail.local エントリは問題ないように見えますが、私は通常、banaction の後に刑務所名を追加します。例えば:banaction=iptables-multiport[name=asterisk]

fail2ban サービスを再起動し、fail2ban ログにエラーがないか確認します。v0.9.2 まで修正されなかった一般的なものは次のとおりです。

Error in FilterPyinotify callback: 'module' object has no attribute '_strptime_time'

これを修正するには、fail2ban を v0.9.2 に更新するか、ファイルを編集します。/usr/share/fail2ban/common/__init__.py

ファイルの末尾に次のテキストを追加します。

from time import strptime
# strptime thread safety hack-around - http://bugs.python.org/issue7980
strptime("2012", "%Y")

どの行が一致したかを表示する方法はありますか? 変数は何でしたか?

-vオプションを fail2ban-regex で使用することをお勧めします。一致した変数は表示されませんが、一致した行に関連付けられた各 IP アドレスが一覧表示されます。その後、アスタリスク ログでその IP の詳細を調べることができます。

fail2ban-regex -v /var/log/asterisk/messages /etc/fail2ban/filter.d/asterisk.conf

于 2015-08-28T19:28:45.433 に答える