我有以下(默认)/etc/fail2ban/filter.d/apache-noscript.conf
配置文件:
[Definition]
script = /\S*(?:php(?:[45]|[.-]cgi)?|\.asp|\.exe|\.pl|\bcgi-bin/)
prefregex = ^%(_apache_error_client)s (?:AH0(?:01(?:28|30)|1(?:264|071)|2811): )?(?:(?:[Ff]ile|script|[Gg]ot) )<F-CONTENT>.+</F-CONTENT>$
failregex = ^(?:does not exist|not found or unable to stat): <script>\b
^'<script>\S*' not found or unable to stat
^error '[Pp]rimary script unknown(?:\\n)?'
我注意到以下错误没有触发监狱:
AH10244: invalid URI path (/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/hosts)
我认为这应该属于监狱apache-noscript
......根据我的理解,我需要调整和prefregex
?failregex
我不认为AH10244
匹配(?:AH0(?:01(?:28|30)|1(?:264|071)|2811): )?
,但prefregex
即使在阅读了官方文件。
任何能帮助我开始的帮助都将不胜感激。
答案1
不是非常优雅,但我能够让它工作......
[Definition]
script = /\S*(?:php(?:[45]|[.-]cgi)?|\.asp|\.exe|\.pl|\bcgi-bin/)
prefregex = ^%(_apache_error_client)s ((?:(?:AH0(?:01(?:28|30)|1(?:264|071)|2811): )?(?:(?:[Ff]ile|script|[Gg]ot) ))|(?:AH10244: ))<F-CONTENT>.+</F-CONTENT>$
failregex = ^(?:does not exist|not found or unable to stat): <script>\b
^'<script>\S*' not found or unable to stat
^error '[Pp]rimary script unknown(?:\\n)?'
^invalid URI path
基本上,我保留了大部分原样prefregex
,但我添加了一个OR
子句来(?:AH10244: )
找到AH10244
我要查找的错误。然后,我failregex
在末尾添加了一个额外的^invalid URI path
。
这是专门针对 Apache 2.4 进行测试的,并不适用于所有设置。此外,要测试它是否有效,我们可以使用fail2ban-regex -v
日志文件和配置文件:
fail2ban-regex -v /var/log/apache2/errors.log /etc/fail2ban/filter.d/apache-noscript.conf