fail2ban-regex 与字符串匹配,但与日志和配置文件不匹配,为什么?

fail2ban-regex 与字符串匹配,但与日志和配置文件不匹配,为什么?

如果我跑

fail2ban-regex '31.22.105.115 - - [11/Apr/2014:18:09:54 +0100] "GET /admin/config.php 
HTTP/1.0" 301 573 "-" "-"' '^<HOST> - - (?:\[[^]]*\] )+\"(GET|POST)/(?i)(PMA|phptest|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|db|pmadb|phpmyadmin1|phpmyadmin2|cgi-bin)'

然后我得到Success, the total number of match is 1。但如果我有一个access.log包含

 .
 .
109.68.191.26 - - [11/Apr/2014:12:47:50 +0100] "GET / HTTP/1.0" 301 541 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
31.22.105.115 - - [11/Apr/2014:18:09:54 +0100] "GET /admin/config.php HTTP/1.0" 301 573 "-" "-"

以及一个filter.d包含以下内容的 .conf 文件

failregex  = '^<HOST> - - (?:\[[^]]*\] )+\"(GET|POST) /(?i)(PMA|phptest|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|db|pmadb|phpmyadmin1|phpmyadmin2|cgi-bin)'

,然后我尝试运行,fail2ban-regex path/to/access.log /etc/fail2ban/filter.d/apache-getphp.conf结果却不行Sorry, no match,为什么?

答案1

啊,只是我不应该在 filter.d 文件中引用正则表达式,即应该是:

failregex  = ^<HOST> - - (?:\[[^]]*\] )+\"(GET|POST) /(?i)(PMA|phptest|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|db|pmadb|phpmyadmin1|phpmyadmin2|cgi-bin)

相关内容