Regex Fail2Ban无法禁止星号错误

Regex Fail2Ban无法禁止星号错误,regex,asterisk,fail2ban,Regex,Asterisk,Fail2ban,我在Fedora 21上使用IPTables失败了一个带有星号11的0.9.1 攻击我的服务器的IP地址不会自动写入IP表(请参阅下文,了解手动运行banip时它们的工作情况)。您是否看到导致此问题的任何错误 在我的/var/log/asterisk/messages日志中,我收到了一些关于歹徒尝试错误扩展的消息 我的正则表达式有效,因为当我跑步时 fail2ban-regex /var/log/asterisk/messages /etc/fail2ban/filter.d/asterisk

我在Fedora 21上使用IPTables失败了一个带有星号11的0.9.1

攻击我的服务器的IP地址不会自动写入IP表(请参阅下文,了解手动运行banip时它们的工作情况)。您是否看到导致此问题的任何错误

在我的/var/log/asterisk/messages日志中,我收到了一些关于歹徒尝试错误扩展的消息

我的正则表达式有效,因为当我跑步时

 fail2ban-regex /var/log/asterisk/messages /etc/fail2ban/filter.d/asterisk.conf
我明白了

这意味着597行与正则表达式匹配。对吗?有没有办法显示哪些线是匹配的?变量是什么

我还可以做:

 fail2ban-client set asterisk banip 107.150.44.222
IPTables被正确更新,IP被禁止。(是的,我知道我使用了真实的IP地址——就我而言,欢迎所有人禁止ba$%*$#rd)

为了避免冲突,我删除了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 =
filter.d/asterisk.conf
[包括]
#读取常用前缀。如果有任何可用的自定义设置,请从
#普通的,本地的
before=common.conf
[定义]
#选项:failregex
#注意:regex与日志文件中的密码失败消息相匹配。
#值:文本
#
日志前缀=\[\]\s*(?:注意安全性)%(\uu-pid\u-re)s:?(?:\[\s+\d*])\S+:\d*
failregex=^%(日志前缀)从“[^”]*”注册失败,原因是“(:\d+)”-密码错误$
^%(日志前缀)从“[^”]*”注册“(:\d+”)失败-找不到匹配的对等方$
^%(日志前缀)从“[^”]*”注册失败,原因是“(:\d+)”-用户名/身份验证名称不匹配$
^%(日志前缀)从“[^”]*”注册“(:\d+”)失败-设备与ACL不匹配$
^%“(:\d+”(日志前缀)从“[^”]*”注册失败-对等方不应注册$
^%(:\d+)-ACL错误\(允许/拒绝\)的(日志前缀)从“[^”]*”注册失败$
^%(日志前缀)从“[^”]*”注册“(:\d+”)失败-不是本地域$
^%(日志前缀)从“[^”]*'\(:\d+\)到扩展名“\d+”的调用被拒绝,因为在上下文“default”中找不到扩展名$
^%(日志前缀)的主机未能作为“[^”]*”进行身份验证$
^%(日志前缀)没有对等方“[^”]*'\(从\)的注册$
^%(日志前缀)的主机对“[^']*'\([^]+\)的MD5身份验证失败$
^%(日志前缀)s无法验证(用户设备)[^@]+@\s*$
^%(日志前缀)s(?:处理请求\订阅:)?为(设备|用户)\d*发送假身份验证拒绝;标记=\w+\S*$
^%(原木前缀)两个城市的安保层(原木前缀)的安保层的安全事件(如:(原木前缀)的安全事件(如:(原木前缀)的安全事件(如:(原木前缀)的安全事件(如:(原木前缀)的安全事件(若)的安全事件(若)的安全事件(若)日据据据据据据据据据据据据信失败的无效人士(若上述上述上述上述两名人士)上述上述上述上述上述两词),),事件,日ttttttv(若若若?????、日据据据据据据据据据据据据据据据据据???????、日,若若,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”日日日据据据据你呢?(,ReceivedHash=“[\da-f]+”)$
#选项:ignoreregex
#注意:要忽略的正则表达式。如果此正则表达式匹配,则忽略该行。
#值:文本
#
ignoreregex=

您的asterisk.conf和jail.local条目看起来不错,不过我通常会在banaction之后添加jail名称。例如:
banaction=iptables multiport[name=asterisk]

重新启动fail2ban服务,并检查fail2ban日志中是否存在任何错误。在v0.9.2之前无法修复的常见错误是:

FilterPyNotify回调中出现错误:“模块”对象没有属性“\u strTime\u 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

 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 =
from time import strptime
# strptime thread safety hack-around - http://bugs.python.org/issue7980
strptime("2012", "%Y")