Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

Подробная инструкция по настройке Клаудфлэр, которая позволит отсекать от 70 до 99% поведенческих ботов. Многие агентства надувают щёки, типа «мы вам настроим Cloudflare за 100500 денег», я расскажу, как это сделать самому и бесплатно.

Накрутка поведенческих факторов вышла уже куда-то совсем в бесконтрольное пространство. Как только сайт занимает хоть немного топ Яндекса по коммерческим запросам, на него сразу налетают толпы ботов. Как я понимаю, это называется «нагуливать» статистику. Что они там на самом деле нагуливают — скорее всего, никому неизвестно.
У меня в метрике есть на наблюдении несколько сайтов, которые я побоялся бы палкой тыкать, не то что со своего браузера заходить: помойки спамные, сайты под фильтрами и т.д. И на них всегда тусуются вот эти вот ребята, которые в метрике видны как «Переходы из Яндекса». Куда они потом эту статистику утаскивают, а главное, зачем?

Ладно, это эмоциональное вступление, переходим к делу.
Вам понадобится бесплатный аккаунт Cloudflare, как регистрировать и привязывать к хостингу — все знают, не буду останавливаться на этом.

Далее нужно настроить правила фильтрации. В бесплатном тарифе доступно всего 5 правил, но нам больше и не понадобится. Нажимаем вот сюда:

Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

Правила добавляем такие:

  • Сначала пропускаем ботов Яндекс и Гугл
  • Пропускаем запросы со своего хостинга (обязательный пункт! иначе почта, крон и прочие сервисы сломаются)
  • Блокируем ненужные страны
  • Блокируем известных ботов
  • Блокируем зловредных неизвестных ботов
Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

1. Вот как пропустить ботов Гугл, Яндекс:

Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

Нажимаем Edit Expression, вставляем такую команду:

(http.user_agent contains "Google") or (http.user_agent contains "Yandex")

Нажимаем Use expression builder, выбираем действие SKIP и проставляем все галочки, нажимаем Deploy.

Как защитить сайт от ботов: простая инструкция (вам понадобится только Cloudflare)

2. Пропускаем запросы со своего хостинга.

Здесь вам понадобится узнать IP адрес или его ASNUM, если не знаете как - спросите в техподдержке хостинга. И заодно пропускаем все запросы к wp-cron.php, если у вас Вордпресс. Так же через Expression builder вставляем команду.

Пример:

(ip.geoip.asnum eq 22612) or (ip.geoip.asnum eq 62371) or (ip.geoip.asnum eq 47583) or (http.request.uri contains "/wp-cron.php")

Нажимаем Use expression builder, выбираем действие SKIP и проставляем все галочки, нажимаем Deploy.

3. Блокируем ненужные страны и известных ботов.

Поскольку правил всего 5, а ботов много - я раскидал их на 2 правила, чтобы уместиться в лимит. Страны поменяйте соответственно под свой сайт: в моём примере блокируется Болгария, а вам это может быть не нужно.

Часть 1:

(ip.geoip.country eq "CN") or (ip.geoip.country eq "UA") or (ip.geoip.country eq "IR") or (ip.geoip.country eq "IN") or (ip.geoip.continent eq "AF") or (ip.geoip.country eq "SG") or (ip.geoip.country eq "GB") or (ip.geoip.country eq "PL") or (ip.geoip.country eq "ID") or (ip.geoip.country eq "TH") or (ip.geoip.country eq "HK") or (ip.geoip.country eq "CH") or (ip.geoip.country eq "BG") or (ip.geoip.country eq "CZ") or (ip.geoip.country eq "SC") or (ip.geoip.country eq "CA") or (http.user_agent contains "ahrefs.com") or (http.user_agent contains "Abonti") or (http.user_agent contains "AspiegelBot") or (http.user_agent contains "aggregator") or (http.user_agent contains "AhrefsBot") or (http.user_agent contains "Aport") or (http.user_agent contains "asterias") or (http.user_agent contains "Baiduspider") or (http.user_agent contains "BDCbot") or (http.user_agent contains "bidswitchbot") or (http.user_agent contains "Birubot") or (http.user_agent contains "BLEXBot") or (http.user_agent contains "BUbiNG") or (http.user_agent contains "BuiltBotTough") or (http.user_agent contains "Bullseye") or (http.user_agent contains "BunnySlippers") or (http.user_agent contains "Butterfly") or (http.user_agent contains "ca-crawler") or (http.user_agent contains "CamontSpider") or (http.user_agent contains "CCBot") or (http.user_agent contains "Cegbfeieh") or (http.user_agent contains "CheeseBot") or (http.user_agent contains "CherryPicker") or (http.user_agent contains "coccoc") or (http.user_agent contains "CopyRightCheck") or (http.user_agent contains "cosmos") or (http.user_agent contains "crawler")

Нажимаем Use expression builder, выбираем действие BLOCK, нажимаем Deploy.

Используем следующее правило, вставляем часть 2:

(http.user_agent contains "Crescent") or (http.user_agent contains "CyotekWebCopy/1.7") or (http.user_agent contains "CyotekHTTP/2.0") or (http.user_agent contains "DataForSeoBot") or (http.user_agent contains "DeuSu") or (http.user_agent contains "discobot") or (http.user_agent contains "DittoSpyder") or (http.user_agent contains "DnyzBot") or (http.user_agent contains "DomainCrawler") or (http.user_agent contains "DotBot") or (http.user_agent contains "Download Ninja") or (http.user_agent contains "EasouSpider") or (http.user_agent contains "EmailCollector") or (http.user_agent contains "EmailSiphon") or (http.user_agent contains "EmailWolf") or (http.user_agent contains "EroCrawler") or (http.user_agent contains "Exabot") or (http.user_agent contains "ExtractorPro") or (http.user_agent contains "Ezooms") or (http.user_agent contains "FairShare") or (http.user_agent contains "Fasterfox") or (http.user_agent contains "FeedBooster") or (http.user_agent contains "Foobot") or (http.user_agent contains "Genieo") or (http.user_agent contains "GetIntent Crawler") or (http.user_agent contains "Gigabot") or (http.user_agent contains "gold crawler") or (http.user_agent contains "GrapeshotCrawler") or (http.user_agent contains "grub-client") or (http.user_agent contains "Harvest") or (http.user_agent contains "hloader") or (http.user_agent contains "httplib") or (http.user_agent contains "HTTrack") or (http.user_agent contains "humanlinks") or (http.user_agent contains "HybridBot") or (http.user_agent contains "ia_archiver") or (http.user_agent contains "ieautodiscovery") or (http.user_agent contains "Incutio") or (http.user_agent contains "InfoNaviRobot") or (http.user_agent contains "InternetSeer") or (http.user_agent contains "IstellaBot") or (http.user_agent contains "Java") or (http.user_agent contains "Java/1.") or (http.user_agent contains "JamesBOT") or (http.user_agent contains "JennyBot") or (http.user_agent contains "JS-Kit") or (http.user_agent contains "k2spider") or (http.user_agent contains "Kenjin Spider") or (http.user_agent contains "Keyword Density/0.9") or (http.user_agent contains "kmSearchBot") or (http.user_agent contains "larbin") or (http.user_agent contains "LexiBot") or (http.user_agent contains "libWeb") or (http.user_agent contains "libwww") or (http.user_agent contains "Linguee") or (http.user_agent contains "LinkExchanger") or (http.user_agent contains "LinkextractorPro") or (http.user_agent contains "linko") or (http.user_agent contains "LinkScan/8.1a Unix") or (http.user_agent contains "LinkWalker") or (http.user_agent contains "LinkpadBot") or (http.user_agent contains "lmspider") or (http.user_agent contains "LNSpiderguy") or (http.user_agent contains "ltx71") or (http.user_agent contains "lwp-trivial") or (http.user_agent contains "lwp-trivial") or (http.user_agent contains "magpie") or (http.user_agent contains "Mata Hari") or (http.user_agent contains "MaxPointCrawler") or (http.user_agent contains "MegaIndex")

Нажимаем Use expression builder, выбираем действие BLOCK, нажимаем Deploy.

4. Самая мякотка: блокируем зловредных ботов.

Большинство из них не использует ssl или заходит со странных ip адресов. Инструкцию подсмотрел на сайте partnerkin.com и честно стырил оттуда. Вот команда:

(ip.src in {::/0}) or (not ssl) or (not http.request.version in {"HTTP/2" "HTTP/3" "SPDY/3.1"})

Если очень много ботов попадает через прямые заходы, тогда добавляем ещё такую команду:

or (http.referer eq "")

Всем посетителям без реферера, т. е. обычным пользователям, которые заходят на сайт напрямую, будет выдаваться капча. Смотрите сами по ситуации, стоит это применять или нет.

Выбираем действие Choose action: Managed Challenge, нажимаем Deploy.

Всё, вы круче, чем кулхацкер! Эти настройки позволяют отсекать до 99% ботов, но, к сожалению, некоторые всё равно могут пролезть.

Всем хорошего сео, подпишись, поставь лайк, колокольчик, комментарий, донат, патреон, ссылка в описании!

15
20 комментариев