我们需要在我们网站中防止密码的暴利破解。Fail2Ban 是一个 Python 的应用来查看日志文件,使用的是正则表达式,同时还可以与Shorewall (或者 iptables)直接工作来来启用临时黑名单。当一定的密码破解规则被使用后,就可以使用上面的方法了。我们可以用这个来限制给定的 URL 来访问 Confluence 的登录界面的次数。
本列表是安装的核心部分:
/etc/fail2ban
.conf
文件(fail2ban.conf
和 jail.conf)。请不要对这个进行修改,如果你进行修改的话,将会导致升级的时候困难。
.conf
文件中的配置进行合并。这个文件只会对你需要的修改部分进行修改,能够让你的维护更加容易和简单。filter.d
中进行定义 — 在这里这里,你可以定义正则表达式,每个正则表达式进入自己的文件。action.d
文件中定义 — 你可能不需要添加一个,但是你知道在那里进行定义的能够帮你更好的找到问题。jail.conf
and jail.local
中定义的。不要忘记了为每一个都启动设置 — 这个有可能导致错误的启用,正确的却没有启用。/etc/init.d/fail2ban {start|stop|status
} 来进行进程相关的操作fail2ban-client -d
来导出当前的配置到 STDOUT。在你对问题进行查看的时候,这个就非常有帮助。jail.local
# 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. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
# ignoreip = <space-separated list of IPs>
# "bantime" is the number of seconds that a host is banned.
bantime = 600
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 60
# "maxretry" is the number of failures before a host get banned.
maxretry = 3
[ssh-iptables]
enabled = false
[apache-shorewall]
enabled = true
filter = cac-login
action = shorewall
logpath = /var/log/httpd/confluence-access.log
bantime = 600
maxretry = 3
findtime = 60
backend = polling
下面仅仅被用来作为示例,你需要根据你的站点调整。
filter.d/confluence-login.conf
[Definition]
failregex = <HOST>.*"GET /login.action
ignoreregex =
https://www.cwiki.us/display/CONF6ZH/Using+Fail2Ban+to+limit+login+attempts