保护 Apache 免受 DOS 攻击

保护 Apache 免受 DOS 攻击

我使用 Apache 的 mod_evasive,这样可以降低 DOS 攻击的可能性。我遇到的问题是反向代理(即我们的服务器 apache)后面的应用程序非常弱,并且开发成一个页面加载 200 个文件(css、js 等)。因此,当我使用类似https://github.com/rohitchormale/hulk/blob/master/hulk.py,我成功终止了该应用程序,因为脚本为攻击生成了许多唯一的 URI,并且因为我必须每秒允许超过 300 个页面(* 10 个可能具有相同 IP 的客户端)。

因此我想到的一个解决方案是,当某个 IP 在一秒钟内收到 ax 数量的 404 错误时,将其列入黑名单。可以这样做吗?

答案1

正如斯文在他的评论中所建议的那样,Fail2ban通过分析 Apache 日志允许此类行为。因此,让我提醒您我的目标:如果用户触发了一定数量的 404 错误或任何其他错误,则阻止用户访问我的服务器。以下是我在设置中执行的操作:

在 /etc/fail2ban/jail.conf 中:

[http-error-dos]  
enabled = true
port = http,https
filter = http-error-dos
logpath = /var/log/httpd/*acces*log #change it to put your path
maxretry = 20
findtime = 100
bantime = 600  #ban for 10 minutes
action = iptables[name=HTTP, port=http, protocol=tcp]

在 /etc/fail2ban/filter.d/http-error-dos.conf 中:

# Fail2Ban configuration file
failregex = <HOST>.* HTTP/.*\" [13456789][1023456789]{2,2}.*

确保根据日志的格式更改 failregex。

相关内容