大网数据广告活动
服务器运维问答

Fail2Ban regex is wrong?

· 52CE 我爱测

I'm currently setting up a filter to filter POST attacks on a file named xmlrpc.php . Requests that should be monitored in the log access look like: 1.99.437.201 - - [01/Feb/2016:01:57:14 +0000] "POST /xmlrpc.php HTTP/1.1" 200 63…

问题原文

原帖链接 · Tom · CC BY-SA 3.0

I'm currently setting up a filter to filter POST attacks on a file named xmlrpc.php. Requests that should be monitored in the log access look like:

1.99.437.201 - - [01/Feb/2016:01:57:14 +0000] "POST /xmlrpc.php HTTP/1.1" 200 631 "-" "curl/7.30.0"

The jail looks like:

[xmlrpc]
enabled = true
filter = xmlrpc
action = iptables[name=xmlrpc, port=http, protocol=tcp]
logpath = /srv/www/logs/access.log
bantime = 43600
maxretry = 5

And my filter is:

[Definition]
failregex = ^<HOST> .*POST .*xmlrpc\.php.*
ignoreregex =

I'm trying to figure way the regex isn't catching the log attempts. Any insight on what <HOST> actually represent?

已采纳解答

原帖链接 · user9517 · CC BY-SA 3.0

The <HOST> regex is quite smart. Amongst other things it knows that an IP address consists of 4 octets and each octet can have a value between 0 and 255. The IP address in your question 1.99.437.201 does not meet this specification and will not match a <HOST> regex. If you change the second octet to meet the specification then your regex works as expected

$ cat log
1.99.237.201 - - [01/Feb/2016:01:57:14 +0000] "POST /xmlrpc.php HTTP/1.1" 200 631 "-" "curl/7.30.0"

$ fail2ban-regex  log "^<HOST> .*POST .*xmlrpc\.php.*"

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

Use   failregex line : ^<HOST> .*POST .*xmlrpc\.php.*
Use         log file : log
Use         encoding : UTF-8


Results
=======

Failregex: 1 total
|-  #) [# of hits] regular expression
|   1) [1] ^<HOST> .*POST .*xmlrpc\.php.*
`-

Ignoreregex: 0 total

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

Lines: 1 lines, 0 ignored, 1 matched, 0 missed [processed in 0.00 sec]

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。