编辑 fail2ban apache-noscript 配置以添加“AH10244:无效 URI 路径”

编辑 fail2ban apache-noscript 配置以添加“AH10244:无效 URI 路径”

我有以下(默认)/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......根据我的理解,我需要调整和prefregexfailregex我不认为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

相关内容