AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 967794
Accepted
DevOpsSauce
DevOpsSauce
Asked: 2019-05-18 07:07:21 +0800 CST2019-05-18 07:07:21 +0800 CST 2019-05-18 07:07:21 +0800 CST

Fail2ban 禁止 IP,但直到它已经有数百个请求

  • 772

我有一个使用特定用户代理的监狱。它最终禁止了它,但它仍然得到了数百个请求。

以下是相关信息(除非需要其他任何信息):

/etc/fail2ban/jail.conf 中的禁止操作

banaction = iptables-allports

这是 /etc/fail2ban/jail.local 中的条目

[domaincrawler-bot]
enabled = true
filter = domaincrawler-bot
logpath = /var/log/nginx/*access.log
port = 8221,8222,8231,8232
maxretry = 1
findtime = 10
bantime = -1
action = iptables-allports[name=domaincrawler-bot]

我有一个 shell 脚本,它按 IP 地址将最常见的点击组合在一起,它仍然设法在禁止之前获得数百个请求:

Count    IP Address    User Agent String

543 80.248.225.168 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/***************************.com)" "-"
455 80.248.225.79 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/********.com)" "-"
282 80.248.225.4 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/********************.com)" "-"

我可以验证它最终是否会发送到 iptables:

root@****:/var/log/nginx# iptables -L -vn | grep 80.248.225.4
0     0 REJECT     all  --  *      *       80.248.225.4         0.0.0.0/0            reject-with icmp-port-unreachable

这是我在 /etc/fail2ban/filter.d/domaincrawler-bot.conf 中的正则表达式条目

[Definition]
failregex = ^\d{4} <HOST> .*DomainCrawler.*

执行正则表达式测试会产生数千条匹配的行:

root@****:/var/log/nginx# fail2ban-regex --print-all-matched access.log "^\d{4} <HOST> .*DomainCrawler.*"



 Running tests
=============

Use   failregex line : ^\d{4} <HOST> .*DomainCrawler.*
Use         log file : access.log
Use         encoding : UTF-8


Results
=======

Failregex: 2222 total
|-  #) [# of hits] regular expression
|   1) [2222] ^\d{4} <HOST> .*DomainCrawler.*
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [80276] Day(?P<_sep>[-/])MON(?P=_sep)Year[ :]?24hour:Minute:Second(?:\.Microseconds)?(?: Zone offset)?
`-

Lines: 80276 lines, 0 ignored, 2222 matched, 78054 missed [processed in 7.69 sec] 

我还在 regex101.com 上验证了它确实找到了这些字符:

正则表达式101_image

这是检查监狱状态时的输出:

    root@****:/var/log/nginx# fail2ban-client status domaincrawler-bot
Status for the jail: domaincrawler-bot
|- Filter
|  |- Currently failed: 1
|  |- Total failed: 31178
|  `- File list:    /var/log/nginx/access.log
`- Actions
   |- Currently banned: 12
   |- Total banned: 12
   `- Banned IP list:   176.74.192.36 176.74.192.40 176.74.192.42 185.6.8.3 185.6.8.7 185.6.8.9 194.68.17.5 80.248.225.142 80.248.225.168 80.248.225.4 80.248.225.7 80.248.225.79

这个特定的服务器获得了大量的流量,所以在解析访问日志时它可能稍微落后了?我还能做些什么来提高性能吗?正如我所说,它最终确实会禁止 IP,但在收到数百(有时数千)不同监狱的请求之前不会。

谢谢你们。

nginx
  • 1 1 个回答
  • 927 Views

1 个回答

  • Voted
  1. Best Answer
    fiftytwocards
    2019-05-18T13:43:36+08:002019-05-18T13:43:36+08:00

    日志扫描之间有N 秒的间隔。大概是 1-5 秒。Fail2ban 在maxretry 或 N 秒后阻塞,以最后一个为准。

    • 1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve