首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fail2ban坏机器人apache访问日志regex

fail2ban坏机器人apache访问日志regex
EN

Server Fault用户
提问于 2014-03-20 07:09:17
回答 1查看 3.6K关注 0票数 1

试图使用fail2ban来阻止一些坏的机器人,读取Apache日志,并设置正确的regex。我想在访问日志中匹配的行是:

代码语言:javascript
复制
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/)"

我试图使用的简化正则表达式:

代码语言:javascript
复制
failregex = ^<HOST>*(AhrefsBot)

但不管我怎么试都没用。在这里找到这篇文章就是我想要实现的坏蛋

这里是我最后所做的,以阻止他们所有的伟大的大名单,使用自己的风险,因为它可能会阻碍合法的访问者,如果单词匹配。我用无知来允许好的机器人,并阻止其他的机器人,只要他们自称是机器人:

代码语言:javascript
复制
failregex = ^<HOST> -.*compatible;.*(Bot|bot)
ignoreregex = (Google|Yandex|Mail|bing)

现在这还远远不是理想的,但是阻止99%的不必要的扫描仪机器人释放服务器,快速和肮脏。

EN

回答 1

Server Fault用户

发布于 2014-03-20 07:43:47

你快到了,*没有做你想做的事情,因为它匹配上一个字符的0或更多。

代码语言:javascript
复制
^<HOST> -.*(AhrefsBot)

例如

代码语言:javascript
复制
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 missed
票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/583327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档