假设我有一个登录名form
:
<form action="index.php" method="post"><input type="password" name="pwd"><input type="submit" />
[我知道应该对iptables
或fail2ban
进行适当的速率限制,但是如果不走太远,我们可以简单地做一些事情,只需要.htaccess
:
可以仅使用.htaccess
(或apache2.conf
)来完成此类操作,而不能使用其他第三方工具(可以使用Apache模块)?
如果您确实需要一种“速率限制”某个特定IP的方法,并且您想要一个Apache模块,那么这可能适合您:https://wiki.debian.org/en/Apache/mod_evasive
mod_evasive是一个类似于IPS(入侵防御系统)的模块,用于检测网络上可能的攻击模式。有关IPS的基本解释right here。
要设置模块运行
sudo apt-get install libapache2-mod-evasive
然后通过以下方式激活模块
sudo a2enmod evasive
通过运行验证安装
sudo apachectl -M | grep evasive
预期输出:evasive20_module(共享)现在,我们为apache模块创建一个新文件夹,以便它可以向其中写入日志。
sudo mkdir /var/log/mod_evasive
sudo chown www-data:root /var/log/mod_evasive
让我们编辑mod_evasive的配置。我在此示例中使用nano
sudo nano /etc/apache2/mods-available/evasive.conf
请注意:切勿在/ apache2 / mods-enabled /中使用/ apache2 / mods-available /来编辑模块配置。上面提供的示例是正确的。这是一个示例配置:
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify [email protected]
DOSSystemCommand "echo +%s > /proc/net/xt_recent/badguys" or block them with iptables "su root -c '/sbin/iptables -A INPUT -s %s -j DROP'" ##command that will be sent to the system - %s = attackers ip
DOSLogDir "/var/log/mod_evasive"
DOSWhitelist 127.0.0.1
</IfModule>
如果您想通过使用sendmail来获取电子邮件通知
sudo ln -s /usr/bin/mail /bin/mail
最后,使用[
重新启动apache sudo systemctl restart apache2
要将模块限制在一个位置,请使用
<Directory /var/www/test/>
<IfModule moduleLimitedToTest>
... do something with module
</IfModule>
</Directory>
有关如何使用容器的更多信息,请参见here。您可以将其放入站点/虚拟主机配置中。对此进行了解释here。尽管我强烈推荐与Olaf Kock相同的事物。
我强烈建议您不要在建议的级别上解决此问题。我宁愿去应用程序层,因为最后最有可能您想要限制的failed登录尝试。
而且,由于我们仍然遭受IPV4和NAT的困扰,您将不知道在一个IP地址后面隐藏着多少种不同的合法浏览器。
[失败后,您的应用程序可以触发fail2ban
或iptables
活动。但是,在分布式攻击和僵尸网络时代,我怀疑这会带来很大的不同。在花费大量时间之前,我建议您检查日志并找出这是否是常见(或更确切地说是最常见)的攻击路径。