如何使用fail2ban添加非永久性禁用ip apache

时间:2014-11-28 11:49:32

标签: apache ip fail2ban

我可以在我的错误日志中看到apache尝试定期访问非现有文件的IP。 Fail2ban不会自动禁用此IP,因为请求的频率太慢。

1)那么如何手动将此ip添加到fail2ban的非永久禁止列表中呢?也许还有其他工具/方法在X小时内禁用IP(使用X参数化)?

2)我在哪里可以看到fail2ban实际禁止的完整IP列表?

THX。

1 个答案:

答案 0 :(得分:0)

我建议您使用apache-nohome过滤器,默认情况下我认为该过滤器应包含在您的filter.d目录中 - 如果没有,请创建文件apache-nohome.conf in您的filter.d子目录包含以下内容:



# Fail2Ban filter to web requests for home directories on Apache servers
#
# Regex to match failures to find a home directory on a server, which
# became popular last days. Most often attacker just uses IP instead of
# domain name -- so expect to see them in generic error.log if you have
# per-domain log files.

[INCLUDES]

# overwrite with apache-common.local if _apache_error_client is incorrect.
before = apache-common.conf

[Definition]


failregex = ^%(_apache_error_client)s (AH00128: )?File does not exist: .*/~.*

ignoreregex =

# Author: Yaroslav O. Halchenko <debian@onerussian.com>
&#13;
&#13;
&#13;

如果您需要修改正则表达式,则可以在同一目录中创建apache-nohome.local来修改此问题,这将覆盖.conf版本(根据fail2ban documentation )。

创建此文件后,您需要在jail配置中包含相应的相应段 - 如果尚未这样做,请将jail.conf文件复制到jail.local进行编辑,然后插入类似的段以下是一个例子:

&#13;
&#13;
[apache-nohome]

enabled  = true
filter   = apache-nohome
action   = iptables-allports[name=apache-nohome]
           sendmail-whois[name=apache-nohome, dest=you@yourdomain.tld, sender=yourbox@yourdomain.tld]
logpath  = /var/log/httpd/error.log*
maxretry = 5
findtime = 86400 ; 1 day (specified in seconds)
bantime = 2592000 ; 1 month (specified in seconds)
&#13;
&#13;
&#13;

简要说明上述监狱 - 这将禁止在apache-nohome过滤器中匹配失败正则表达式的主机的所有IP流量,在24小时内发生5次实例,并禁止IP一个月。然后,它会向您发送一封电子邮件,其中包含有关违规IP的WHOIS详细信息。您当然可以将maxretry值或findtimebantime值修改为您想要的任何值,如果您不想接收,甚至可以从操作中删除sendmail-whois行每个禁令的电子邮件。 您可能还希望修改logpath值以适合您希望扫描的日志 - 我仅提供了CentOS 6.5下httpd的默认错误日志路径作为示例。

希望这有帮助!