试图使用fail2ban来阻止一些坏的机器人,读取Apache日志,并设置正确的regex。我想在访问日志中匹配的行是:
5.10.83.65 - - [18/Mar/2014:09:06:38 +0400] "GET /catalog/product_compare/
,,/form_key/QLZ6ZkIwX3FWqme3/ HTTP/1.1" 302 522 "-" "
Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot/)"我试图使用的简化正则表达式:
failregex = ^<HOST>*(AhrefsBot)但不管我怎么试都没用。在这里找到这篇文章就是我想要实现的坏蛋
这里是我最后所做的,以阻止他们所有的伟大的大名单,使用自己的风险,因为它可能会阻碍合法的访问者,如果单词匹配。我用无知来允许好的机器人,并阻止其他的机器人,只要他们自称是机器人:
failregex = ^<HOST> -.*compatible;.*(Bot|bot)
ignoreregex = (Google|Yandex|Mail|bing)现在这还远远不是理想的,但是阻止99%的不必要的扫描仪机器人释放服务器,快速和肮脏。
发布于 2014-03-20 07:43:47
你快到了,*没有做你想做的事情,因为它匹配上一个字符的0或更多。
^<HOST> -.*(AhrefsBot)例如
fail2ban-regex '5.10.83.65 - - [18/Mar/2014:09:06:38 +0400] "GET /catalog/product_compare/,,/form_key/QLZ6ZkIwX3FWqme3/ HTTP/1.1" 302 522 "-" "Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot/)"' '^<HOST> -.*(AhrefsBot)'
Running tests
=============
Use failregex line : ^<HOST> -.*(AhrefsBot)
Use single line : 5.10.83.65 - - [18/Mar/2014:09:06:38 +0400] "GET /...
Results
=======
Failregex: 1 total
|- #) [# of hits] regular expression
| 1) [1] ^<HOST> -.*(AhrefsBot)
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [1] Day/MONTH/Year:Hour:Minute:Second
`-
Lines: 1 lines, 0 ignored, 1 matched, 0 missedhttps://serverfault.com/questions/583327
复制相似问题