如何解决post请求ddos

如何解决post请求ddos

今天我们的 magento 商店受到了攻击,我希望有人可以帮我告诉我如何阻止来自数百个不同 IP 的这些请求:

182.255.44.234 - - [15/May/2017:13:24:14 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
59.61.38.24 - - [15/May/2017:13:24:14 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
120.39.95.47 - - [15/May/2017:13:24:13 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
114.236.17.181 - - [15/May/2017:13:24:14 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
114.236.17.181 - - [15/May/2017:13:23:47 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
58.219.222.251 - - [15/May/2017:13:24:15 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
182.46.161.100 - - [15/May/2017:13:24:16 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
49.83.89.244 - - [15/May/2017:13:24:16 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
117.28.127.48 - - [15/May/2017:13:24:16 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
60.167.222.175 - - [15/May/2017:13:24:16 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
114.236.17.181 - - [15/May/2017:13:24:16 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916
110.84.8.132 - - [15/May/2017:13:24:17 +0100] "POST /calais-shop/customer/account/createpost/ HTTP/1.1" 503 1916

我无法阻止 POST 请求,所以我想知道最好的解决方案是什么?

答案1

这是在 Google 上搜索“magento createPost 攻击”的最佳结果,因此我将继续在此提供我的解决方案。

免责声明你永远不应该修改 Magento Core。由于你可能会在这样的持续攻击中感到恐慌,你可能会暂时地修改 Magento 核心文件并实现适当的解决方案一旦您禁止了违规 IP。

总结 将应用程序代码从该 URL(/route/being/attacked)移动到另一个(/some/new/route),更新前端代码以提交表单(或其他内容)/some/new/route,记录所有访问的 IP 地址/route/being/attacked并使用 IPtables 或您选择的工具禁止它们。

您在这里所做的是创建一个蜜罐来捕获违规 IP,以便您可以通过您喜欢的方式(例如 iptables)永久禁止它们。

  1. 从 Mage_Customer_AccountController::createPostAction 重新定位功能

    只需在 AccountController 中创建一个新方法,例如,createPostNewAction它是以下内容的复制/粘贴createPostAction

  2. 将前端表单 URL 更新为新路线

    到 /customer/account/createPost 的路由是从 Helper 类检索的。Mage_Customer_Helper_Data::getRegisterPostUrl您应该修改此方法,以便它返回到您的新操作的路由,例如,return $this->_getUrl('customer/account/createpostnew');

  3. 记录违规 IPcreatePostAction

    用日志语句替换内容createPostAction。如果愿意,请确保此日志文件不会被覆盖或自动截断。

    public function createPostAction {
       Mage::log($_SERVER['REMOTE_ADDR'], Zend_Log::DEBUG, 'ban_customer_spam_ips', true);
       return false;
    }
    

因此,现在我们所做的就是将处理“新客户注册表单”的功能移至新路由,并用日志语句替换原始路由,该日志语句将记录请求文件 URL 的任何人的 IP 地址ban_customer_spam_ips。合法请求没有理由到达此路由,因此我们可以假设对此路由的任何请求都是恶意的,我们可以禁止它们。

作为 root 用户,tail上述日志文件和禁止 IP 可以使用您喜欢的任何方法。在这里我使用fail2ban利用iptables。您可以选择直接使用 -iptables做任何您喜欢的事情。根据需要调整路径,我的 Magento 安装是,/var/www/magento但您的可能不同!您可以创建一个.sh文件并在后台执行它,或者只需在命令行上运行它:

tail -f /var/www/magento/var/log/ban_customer_spam_ips | awk '
BEGIN {}
{
    print "banning ip: " $4

    block_command = "fail2ban-client set apache banip "$4
    system(block_command)
    close(block_command)
}'

相关内容