7

我有一个客户,其域似乎受到 DDoS 的严重打击。在日志中,具有随机 IP 的用户代理看起来很正常,但他们翻阅页面的速度太快而无法成为人类。他们似乎也没有要求任何图像。我似乎找不到任何模式,我怀疑它是一群 Windows 僵尸。

客户端过去曾遇到过垃圾邮件攻击问题——甚至不得不将 MX 指向 Postini 以获取 6.7 GB/天的垃圾邮件来阻止服务器端。

我想在 robots.txt 不允许的目录中设置一个 BOT 陷阱……只是以前从未尝试过这样的事情,希望那里有人对陷阱 BOT 有创意!

编辑:我已经有很多想法来捕捉一个..当它落入陷阱时该怎么办。

4

5 回答 5

7

您可以设置一个 PHP 脚本,其 URL 被 robots.txt 明确禁止。在该脚本中,您可以提取可疑机器人的源 IP(通过 $_SERVER['REMOTE_ADDR']),然后将该 IP 添加到数据库黑名单表中。

然后,在您的主应用程序中,您可以检查源 IP,在黑名单表中查找该 IP,如果找到,则改为抛出 403 页面。(可能会显示类似“我们检测到来自您的 IP 的滥用行为,如果您认为这是错误的,请通过 ... 联系我们”之类的消息)

从好的方面来说,你会自动将坏机器人列入黑名单。不利的一面是,它的效率不是很高,而且可能很危险。(一个人出于好奇而无辜地检查该页面可能会导致大量用户被禁止。)

编辑:或者(或另外,我想)您可以相当简单地向您的应用程序添加GeoIP检查,并根据原产国拒绝点击。

于 2010-09-29T20:49:03.010 回答
3

您可以做的是在与您的主要主机不在同一管道上的另一个盒子(一种牺牲的羔羊)然后让该主机重定向到自己的页面(但在 url 中有一个随机的页面名称)。这可能会使机器人陷入无限循环,将 CPU 和带宽捆绑在您的牺牲羔羊上,而不是在您的主盒子上。

于 2010-09-29T20:49:38.853 回答
1

我倾向于认为这是一个比编码更能通过网络安全解决的问题,但我看到了您的方法/问题中的逻辑。

关于服务器故障,有许多问题和讨论可能值得调查。

https://serverfault.com/search?q=block+bots

于 2010-09-29T21:08:03.223 回答
1

好吧,我必须说,有点失望——我希望有一些创造性的想法。我确实在这里找到了理想的解决方案.. http://www.kloth.net/internet/bottrap.php

<html>
    <head><title> </title></head>
    <body>
    <p>There is nothing here to see. So what are you doing here ?</p>
    <p><a href="http://your.domain.tld/">Go home.</a></p>
    <?php
      /* whitelist: end processing end exit */
      if (preg_match("/10\.22\.33\.44/",$_SERVER['REMOTE_ADDR'])) { exit; }
      if (preg_match("Super Tool",$_SERVER['HTTP_USER_AGENT'])) { exit; }
      /* end of whitelist */
      $badbot = 0;
      /* scan the blacklist.dat file for addresses of SPAM robots
         to prevent filling it up with duplicates */
      $filename = "../blacklist.dat";
      $fp = fopen($filename, "r") or die ("Error opening file ... <br>\n");
      while ($line = fgets($fp,255)) {
        $u = explode(" ",$line);
        $u0 = $u[0];
        if (preg_match("/$u0/",$_SERVER['REMOTE_ADDR'])) {$badbot++;}
      }
      fclose($fp);
      if ($badbot == 0) { /* we just see a new bad bot not yet listed ! */
      /* send a mail to hostmaster */
        $tmestamp = time();
        $datum = date("Y-m-d (D) H:i:s",$tmestamp);
        $from = "badbot-watch@domain.tld";
        $to = "hostmaster@domain.tld";
        $subject = "domain-tld alert: bad robot";
        $msg = "A bad robot hit $_SERVER['REQUEST_URI'] $datum \n";
        $msg .= "address is $_SERVER['REMOTE_ADDR'], agent is $_SERVER['HTTP_USER_AGENT']\n";
        mail($to, $subject, $msg, "From: $from");
      /* append bad bot address data to blacklist log file: */
        $fp = fopen($filename,'a+');
        fwrite($fp,"$_SERVER['REMOTE_ADDR'] - - [$datum] \"$_SERVER['REQUEST_METHOD'] $_SERVER['REQUEST_URI'] $_SERVER['SERVER_PROTOCOL']\" $_SERVER['HTTP_REFERER'] $_SERVER['HTTP_USER_AGENT']\n");
        fclose($fp);
      }
    ?>
    </body>
</html>

然后为了保护页面扔<?php include($DOCUMENT_ROOT . "/blacklist.php"); ?>在每一页的第一行..blacklist.php包含:

<?php
    $badbot = 0;
    /* look for the IP address in the blacklist file */
    $filename = "../blacklist.dat";
    $fp = fopen($filename, "r") or die ("Error opening file ... <br>\n");
    while ($line = fgets($fp,255))  {
      $u = explode(" ",$line);
      $u0 = $u[0];
      if (preg_match("/$u0/",$_SERVER['REMOTE_ADDR'])) {$badbot++;}
    }
    fclose($fp);
    if ($badbot > 0) { /* this is a bad bot, reject it */
      sleep(12);
      print ("<html><head>\n");
      print ("<title>Site unavailable, sorry</title>\n");
      print ("</head><body>\n");
      print ("<center><h1>Welcome ...</h1></center>\n");
      print ("<p><center>Unfortunately, due to abuse, this site is temporarily not available ...</center></p>\n");
      print ("<p><center>If you feel this in error, send a mail to the hostmaster at this site,<br>
             if you are an anti-social ill-behaving SPAM-bot, then just go away.</center></p>\n");
      print ("</body></html>\n");
      exit;
    }
?>

我计划接受 Scott Chamberlain 的建议,并且为了安全起见,我计划在脚本上实施 Captcha。如果用户回答正确,那么它将只是die或重定向回站点根目录。只是为了好玩,我将陷阱扔到一个名为/admin/并且当然添加Disallow: /admin/到 robots.txt 的目录中。

编辑:此外,我将忽略规则的机器人重定向到此页面:http ://www.seastory.us/bot_this.htm

于 2010-09-29T23:32:59.520 回答
0

你可以先看看ip来自哪里。我的猜测是他们都来自一个国家,比如中国或尼日利亚,在这种情况下,你可以在 htaccess 中设置一些东西来禁止来自这两个国家的所有 ip,至于为机器人制造陷阱,我没有丝毫想法

于 2010-09-29T20:42:37.457 回答