apache2 的 fail2ban 似乎不起作用

apache2 的 fail2ban 似乎不起作用

我的 Apache 错误日志中有很多以下错误消息:

[Thu Dec 16 15:13:24 2010] [error] [client 168.144.92.191] File does not exist: /var/www/mydomain/fud
[Thu Dec 16 15:13:24 2010] [error] [client 168.144.92.191] File does not exist: /var/www/mydomain/flag, referer: http://lexington.craigslist.org/fud/2076870022.html
[Thu Dec 16 15:14:28 2010] [error] [client 168.144.92.191] File does not exist: /var/www/mydomain/flag, referer: http://lexington.craigslist.org/fud/2115799176.html
[Thu Dec 16 15:17:51 2010] [error] [client 168.144.92.191] File does not exist: /var/www/mydomain/fud

在我的/etc/fail2ban/jail.local我有:

# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
#  provided now under /usr/share/doc/fail2ban/examples/jail.conf
#  for additional examples.
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
#
# Author: Yaroslav O. Halchenko <[email protected]>
#
# $Revision: 281 $
#

# The DEFAULT allows a global definition of the options. They can be override
# in each jail afterwards.

[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = myip
bantime  = -1
maxretry = 3

# "backend" specifies the backend used to get files modification. Available
# options are "gamin", "polling" and "auto".
# yoh: For some reason Debian shipped python-gamin didn't work as expected
#      This issue left ToDo, so polling is default backend for now
backend = polling

#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = root@localhost

#
# ACTIONS
#

# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define 
# action_* variables. Can be overriden globally or per 
# section within jail.local file
banaction = iptables-allports

# email action. Since 0.8.1 upstream fail2ban uses sendmail
# MTA for the mailing. Change mta configuration parameter to mail
# if you want to revert to conventional 'mail'.
mta = sendmail

# Default protocol
protocol = tcp

#
# Action shortcuts. To be used to define action parameter

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
              %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
               %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s]

# Choose default action.  To change, just override value of 'action' with the
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section 
action = %(action_mw)s

#
# JAILS
#

#
# HTTP servers
#

[apache]

enabled = true
port  = http,https
filter  = apache-auth
logpath = /var/log/apache2/error.log
maxretry = 3

# default action is now multiport, so apache-multiport jail was left
# for compatibility with previous (<0.7.6-2) releases
[apache-multiport]

enabled   = false
port    = http,https
filter    = apache-auth
logpath   = /var/log/apache*/*error.log
maxretry  = 6

[apache-noscript]

enabled = true
port    = http,https
filter  = apache-noscript
logpath = /var/log/apache2/error.log
maxretry = 3

[apache-overflows]

enabled = false
port    = http,https
filter  = apache-overflows
logpath = /var/log/apache*/*error.log
maxretry = 2

在我的/etc/fail2ban/filter.d/apache-noscript.conf我有:

failregex = [[]client <HOST>[]] (File does not exist|script not found or unable to stat): .*
failregex = [[]client <HOST>[]] script '.*' not found or unable to stat

我的 /var/log/fail2ban.log 只包含首次启动时的条目。没有像我的denyhosts.log 那样提及被禁止的 IP。

检查“iptables -L -v -n”显示:

Chain INPUT (policy ACCEPT 834K packets, 145M bytes)
 pkts bytes target     prot opt in     out     source               destination         
  403 71010 fail2ban-apache  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           
  403 71010 fail2ban-apache-noscript  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 574K packets, 976M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain fail2ban-apache (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  403 71010 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain fail2ban-apache-noscript (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  403 71010 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

我遗漏了什么或者我做错了什么?

**** 帖子已更新,显示完整的 jail.local 文件,而不仅仅是 Apache jail 部分和“iptables -L -v -n”的结果。**

答案1

我认为 apache-noscript.conf 中的第二行会删除第一行。

尝试这个:

failregex = [[]client <HOST>[]] (File does not exist|script not found or unable to stat): .*
            [[]client <HOST>[]] script '.*' not found or unable to stat

答案2

除非我遗漏了默认设置action,否则你没有看到任何action行。这是我的(有效):

[apache-noscript]

enabled  = true
filter   = apache-noscript
action   = iptables-multiport[name=NoScript, port="http,https"]
logpath  = /usr/local/www/sites/*/logs/*_error_log
bantime  = 172800
maxretry = 5

我把匹配正则表达式简化为一行:

failregex = [[]client <HOST>[]] (File does not exist|script not found or unable to stat)

至少能iptables -L -v -n表明链条已正确设置吗?

相关内容