Apache DDOS 预防

Apache DDOS 预防

从 Stackoverflow 移出。

我有一台运行 Ubuntu 的 LAMP 服务器,其中安装了 Denyhosts、Fail2ban 等安全程序和 Mod_security,但似乎经常成为 DDOS 攻击的目标。以下是 access.log 的一部分:

    83.57.208.254 - - [07/Oct/2013:12:44:32 +0100] "POST / HTTP/1.1" 200 14225 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    71.234.72.17 - - [07/Oct/2013:12:44:33 +0100] "POST / HTTP/1.1" 200 14225 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    77.242.132.166 - - [07/Oct/2013:12:44:36 +0100] "POST / HTTP/1.1" 200 14227 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    41.215.148.226 - - [07/Oct/2013:12:44:37 +0100] "POST / HTTP/1.1" 200 14227 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    193.95.115.254 - - [07/Oct/2013:12:44:37 +0100] "POST / HTTP/1.1" 200 4621 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    77.252.113.238 - - [07/Oct/2013:12:44:37 +0100] "POST / HTTP/1.1" 200 14225 "-"         "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    203.125.241.10 - - [07/Oct/2013:12:44:40 +0100] "POST / HTTP/1.1" 200 14259 "-"         "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    202.3.84.79 - - [07/Oct/2013:12:44:40 +0100] "POST / HTTP/1.1" 200 14248 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    125.60.156.222 - - [07/Oct/2013:12:44:42 +0100] "POST / HTTP/1.1" 200 14233 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    41.194.49.44 - - [07/Oct/2013:12:44:44 +0100] "POST / HTTP/1.1" 200 14258 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    79.211.175.35 - - [07/Oct/2013:12:44:45 +0100] "POST / HTTP/1.1" 200 14258 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    109.86.12.76 - - [07/Oct/2013:12:44:46 +0100] "POST / HTTP/1.1" 200 14258 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    84.121.39.44 - - [07/Oct/2013:12:44:47 +0100] "POST / HTTP/1.1" 200 14259 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
    86.148.77.223 - - [07/Oct/2013:12:44:49 +0100] "POST / HTTP/1.1" 200 14259 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"

基于http://systembash.com/content/how-to-stop-an-apache-ddos-attack-with-mod_evasive/这似乎是“Sloworis”攻击,而且一直在发生。我已经安装了 Mod_evasive,但由于它似乎每秒只从唯一 IP 地址发出 1 个请求,所以没有任何区别。

当其他合法用户同时访问其他网站时,Apache 似乎会产生太多子进程并挂起,需要重新启动,尽管我不确定它们是否相关。

有没有什么方法可以调整 Apache 来帮助防止这种情况发生?

谢谢你的帮助。

答案1

不,POST 绝不是 slowloris 攻击;如果是的话,那就是 RUDY 攻击(你死了吗?;如果你不知道,请谷歌搜索)。分布式 1 线程 slowloris/rudy 毫无意义,如果我没记错的话,你不会在日志中看到 slowloris / rudy,因为请求从未完成(这就是这类攻击的目的);这看起来更像是暴力攻击;有什么可以登录的吗?

每秒接收 1 个请求时,您的 Apache 会崩溃吗?似乎您应该稍微调整一下您的设置。

有没有什么方法可以调整 Apache 来帮助防止这种情况发生?

apache >= 2.2.16 不再受到 slowloris 的攻击(不知道 rudy 的情况),但是如果你想要处理这类问题:apache 有 mod_antiloris,

如果您想创建一个可靠的缓解措施:在 apache 前面放置一个像 nginx 或 varnish 这样的反向代理。

如果 / 上没有要发布的内容,请为自己制定一个 mod_security - 规则,或者使用重写规则触发 403

答案2

警告:可能仅适用于“单服务器安装”,如果您有更复杂的东西,您将需要更复杂的解决方案。


我使用 iptables LIMIT 功能.. 不关心他们试图强行破解什么,减慢他们的速度,但让其他人运行良好。;-)

IE:数百次 ssh 登录失败

这是我的 bash 防火墙脚本的一部分(它在最后保存到 iptables-save,其中 $IPT 先前定义为 /sbin/iptables)

echo "HTTP/S hash-based-limiting"
$IPT -N LIMIT
$IPT -A LIMIT -j LOG --log-prefix "IPTABLES LIMIT: "
$IPT -A LIMIT -m recent --set --name attacks -j DROP
$IPT -A INPUT -m recent --update --seconds 180 --name attacks -j DROP
$IPT -A INPUT -p tcp --dport 80  -m state --state NEW -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
$IPT -A INPUT -m state --state RELATED,ESTABLISHED -m limit --limit 50/second --limit-burst 50 -j ACCEPT
$IPT -A INPUT -m hashlimit --hashlimit-srcmask 32 --hashlimit-mode srcip -p tcp -m state --state NEW --hashlimit-above 10/minute --hashlimit-burst 15 --hashlimit-name webflood --dport 80  -j LIMIT
$IPT -A INPUT -m hashlimit --hashlimit-srcmask 32 --hashlimit-mode srcip -p tcp -m state --state NEW --hashlimit-above 10/minute --hashlimit-burst 15 --hashlimit-name webflood --dport 443 -j LIMIT

基本上,没有人会发出比这更多的请求,所以它只会阻止机器人,而不会阻止它们,它只是塑造它们,当然你可以简单地将端点链更改为 DROP 而不是 LIMIT。调整值以适合您的服务器。

不要忘记:

/sbin/modprobe ip_conntrack
echo "Enabling syncookies protection"
echo "1" > /proc/sys/net/ipv4/tcp_syncookies

我显然已经针对服务端口、20:22 和这些 Web 端口实施了各种洪水保护措施。我的拒绝主机系统上的任何人都会被添加到基于 iptables 的完整黑名单和其他内容中。到目前为止,效果很好。

如果用户“停止”淹没服务器,他们会在 180 秒后自动释放,因此不需要大量维护,并且 LIMIT 的连接会显示在日志监视报告中。

在此之前,我会允许您的本地服务器或用户进行备份,但有时这会导致它们受到限制...尤其是大量使用 SOAP!

相关内容