# 为什么我会收到大量来自中文网站的搜索？

**URL:** <https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524>\
**Category:** Support\
**Created:** [2020年七月1日 22:04 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524 "2020-07-01T22:04:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)\
**Post date:** [2020年七月1日 22:04 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/1 "2020-07-01T22:04:29Z")

</div>

![Screenshot 2020-07-01 at 23.04.02](https://global.discourse-cdn.com/meta/original/3X/4/4/440a243ff5fb5a9651fa859ea7db4896f8cd108b.png)

列表中的数量远不止这些，有什么想法吗？

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2020年七月1日 22:12 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/2 "2020-07-01T22:12:55Z")

</div>

今天我在其中一个客户的日志中看到了这个，所以这不仅仅是巧合。

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/e/de9558dec7ac9c645868d849069f869a0b0f8ccc.png)

编辑：不，我认为这只是巧合。搜索 ymwears .cn 会发现更多关于引荐垃圾邮件的投诉，例如这些（超过一年前）[Relevanssi shows weird search queries on my page | WordPress.org](https://wordpress.org/support/topic/relevanssi-shows-weird-search-queries-on-my-page/) 和 [Block specific referrer or agent to enter url | WordPress.org](https://wordpress.org/support/topic/block-specific-referrer-or-agent-to-enter-url/)

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2020年七月1日 22:19 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/3 "2020-07-01T22:19:48Z")

</div>

上个月我有一位客户抱怨过这些问题。我封锁了一些 IP 地址，并考虑配置 `fail2ban` 来自动封锁那些搜索了特定 URL 的 IP，但最终并没有实际采取行动。我还研究过按地理区域进行封锁，但似乎需要每月 20 美元的数据库才能实现。

---

<div class="post-metadata">

**Author:** ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)\
**Post date:** [2020年七月3日 03:19 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/4 "2020-07-03T03:19:53Z")

</div>

有意思，你们是否知道有什么解决方案可以在不直接折腾服务器的情况下生效？

@pfaffman @RGJ

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2020年七月3日 05:33 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/5 "2020-07-03T05:33:14Z")

</div>

引荐垃圾邮件是一个相当严重的问题，即使是像 Google Analytics 这样的大公司也无法完全有效地应对。目前我能想到的办法就是手动删除这些条目。

鉴于这些网站显然至少在部分上是跨多个独立的 Discourse 站点重复出现的（从我们的截图可以看出列表几乎相同），也许引入一个（动态）黑名单会是个好主意？@codinghorror 你有什么建议吗？

---

<div class="post-metadata">

**Author:** ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)\
**Post date:** [2020年七月3日 05:42 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/6 "2020-07-03T05:42:07Z")

</div>

> [@Yassine\_Yousfi](#):
>
> 有意思，大家是否知道有什么解决方案可以在不直接折腾服务器本身的情况下生效？

多年来，我们已在大规模范围内发现、解决并缓解了这一问题。在过去几年中，我们发现更可靠的方法是：基于用户代理（User Agent，简称 UA）字符串进行拦截（有时结合 GeoIP 信息）。

多年来，我们已拦截了数亿次来自中国的机器人请求。我们发现，从长期来看，基于 IP 地址的拦截效果远不如基于 UA 字符串的客户端拦截。

以下是我们在一处网站上使用的一段示例代码：

```plaintext
$user_agents = explode('|',$string_of_bad_user_agents,-1);
$hide_content_useragent = $_SERVER['HTTP_USER_AGENT'];
$IS_A_BAD_BOT = FALSE;

foreach($user_agents as $hcag) {
    trim($hcag);
    if (preg_match("/$hcag/i", "$hide_content_useragent")) {
        $IS_A_BAD_BOT = TRUE;
        break;
    }
}

```

绝大多数（并非全部）恶意机器人使用的 UA 字符串都相对容易识别并拦截（在当前时代如此，未来随着技术演变尚不确定）。因此，我们早在几年前就放弃了基于 IP 地址拦截恶意机器人的做法。放弃基于 IP 拦截的原因是：包括中国、俄罗斯、朝鲜在内的许多国家，如今已将机器人农场部署在其他国家的服务器上。IP 地址并不能准确反映真实来源或意图。此外，大规模封锁 IP 地址段可能会导致误封合法用户，使其无法访问。

例如，中国将庞大的机器人服务器农场部署在巴西及其他地理上更接近美国（相对于中国而言）的国家，以此掩盖其真实来源并加快数据获取速度（缩短网络路径）。

有时，WHOIS 数据会反向匹配到中国、朝鲜或俄罗斯（举例）的物理地址，但有时则不会，而是使用所在国的本地物理地址。过去几年中，我们观察到大量恶意中国机器人注册在巴西公司名下；而我们能够确认，其 UA 字符串与来自中国的恶意机器人完全一致。此外，当我们用这些 UA 字符串在 Google 上搜索时，会发现其他人也已识别出许多相同的 UA 字符串属于中国（例如）。

总之，尽管许多人会立即采用基于 IP 地址的拦截方式来应对恶意机器人活动，但大多数成熟的机器人农场非常擅长将机器人部署在其他国家。在大多数国家设置 VPS 非常容易；当然，机器人距离目标国家越近，其可抓取的数据就越多。VPS 可以在几分钟内上线或下线，而机器人软件也可在全球几乎任何 VPS 数据中心快速部署。

过去几年中，基于 UA 字符串的拦截（有时结合 GeoIP 信息，有时不结合）已被证明是更可靠的方法；当然，垃圾邮件发送者、机器人控制者及其代理也开始像隐藏 IP 地址那样，对 UA 字符串进行伪装（这一做法已持续多年）。

希望以上信息对您有所帮助。

祝好，并祝您在“机器人狩猎”中收获满满！

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2020年七月3日 07:02 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/7 "2020-07-03T07:02:54Z")

</div>

是的，我完全同意 IP 封禁效果不佳。

封禁用户代理通常效果不错，除非垃圾信息发送者不断更改它。

因此，我的想法是直接列入黑名单，封禁那些被用于引荐垃圾信息的实际 URL。

这样做“感觉更好”，因为我们不是基于某种假设进行封禁（例如“该用户代理提供了不良引荐来源，所以我们不信任它”），而是直接封禁我们真正想要封禁的内容（“我们发现该网站在多个 Discourse 站点上被用于引荐垃圾信息，那就不要将其加入我们的数据库”）。至少，这种方式更难被绕过。

---

<div class="post-metadata">

**Author:** ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)\
**Post date:** [2020年七月3日 07:24 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/8 "2020-07-03T07:24:59Z")

</div>

> [@RGJ](#):
>
> 屏蔽用户代理通常效果不错，除非垃圾信息发送者不断更改它。
> 
> 这就是为什么我的想法转向直接列入黑名单，阻止被引荐垃圾信息攻击的实际 URL。

想法很好。

没有任何一种“一刀切”的方法能阻止所有恶意和流氓机器人；每个网站都必须评估哪些控制措施最适合自己。

> 类似地……

主要依赖黑名单和垃圾信息或流氓机器人数据库的网站也可能遇到问题。比如说，如果有人不喜欢网站 `www.our-arch-rival.com`，因为该网站是竞争对手（或者仅仅让我们感到愤怒或冒犯），那么有些人就会将该网站提交到黑名单或数据库中。结果，其他网站会因为这种黑名单数据库方法的“不良后果”而过滤掉这个合法网站。

当然，黑名单的支持者会说：“你可以去黑名单网站提交报告并要求移除”，但对于许多忙碌且历史悠久的网站来说，这可能非常耗时。

一般来说，重要的是分析问题，并根据具体场景制定缓解策略，因为每个“对手”都不同。这正是《孙子兵法》中“知己知彼，百战不殆”的古老智慧。现实世界中的每种情况都略有不同，不幸的是，系统管理员需要具备分析能力，才能制定出针对恶意或不受欢迎的网络活动的最佳缓解策略。

> 这也是在反向代理后面运行 Discourse 的一个很好的理由，因为反向代理是分析、分类和控制恶意活动的理想位置，可以在这些流量到达 Discourse 应用之前进行拦截。

在 2020 年，控制和缓解流氓机器人及其他恶意网络活动可能成为一份 `全职工作`。一旦管理员想出一个有效的检测和缓解策略，垃圾信息发送者和爬虫就会调整并找到绕过的方法。我通常建议人们扩大服务器规模，以确保有足够的余量，因为这类网络空间问题只会随时间恶化，而不会好转。

**准备好迎接挑战吧！**

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2020年七月3日 11:52 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/9 "2020-07-03T11:52:48Z")

</div>

> [@neounix](#):
>
> 一旦管理员提出一种有效的检测和缓解策略，垃圾邮件发送者和爬虫就会调整并找到绕过的方法。

这也是 **另一个** 远离 IP 封禁的理由：垃圾邮件发送者会 **知道** 你正在采取措施。

---

<div class="post-metadata">

**Author:** ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)\
**Post date:** [2020年七月3日 16:13 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/10 "2020-07-03T16:13:25Z")

</div>

我认为可以通过 Cloudflare 屏蔽大部分垃圾邮件发送者，但不确定在规则中该如何设置浏览器 User-Agent。

@neounix 你说的“UA 字符串”是什么意思？它们如何在 Cloudflare 防火墙规则中使用？

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2020年七月3日 18:45 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/11 "2020-07-03T18:45:52Z")

</div>

> [@RGJ](#):
>
> 引荐垃圾信息是一个相当严重的问题，甚至连大公司也深受其害

但这甚至算不上引荐垃圾信息，对吧？他们只是在搜索那个 URL，所以实际上并没有造成任何影响，对吗？我是不是完全误解了那份报告？那份报告应该只有管理员才能查看，没错吧？

---

<div class="post-metadata">

**Author:** ![markersocial](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markersocial/32/170136_2.png) [@markersocial](https://meta.discourse.org/u/markersocial)\
**Post date:** [2020年七月3日 20:59 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/12 "2020-07-03T20:59:03Z")

</div>

你说得对，@pfaffman，这份报告似乎仅针对在论坛上进行的搜索。它还包含了点击率（CTR），如果这是一份引荐报告，那就不合逻辑了。

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2020年七月3日 21:55 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/13 "2020-07-03T21:55:39Z")

</div>

> [@pfaffman](#):
>
> 但这甚至不算引荐垃圾信息，对吧？他们只是在搜索该 URL，所以实际上并没有做任何事情，对吗？

不，从技术上讲，这不算引荐垃圾信息，但我不确定是否有专门术语来描述这种确切类型的滥用。我认为这非常接近引荐垃圾信息，只不过针对的是搜索查询报告？

引荐垃圾信息从来不会执行任何操作，它唯一的目的就是出现在报告中。

---

<div class="post-metadata">

**Author:** ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)\
**Post date:** [2020年七月3日 22:22 UTC](https://meta.discourse.org/t/why-im-getting-lots-of-searches-from-chinese-websites/156524/14 "2020-07-03T22:22:48Z")

</div>

> [@Yassine\_Yousfi](#):
>
> @neounix 你说的“UA 字符串”是什么意思？它们如何在 Cloudflare 防火墙规则中使用？

@Yassine_Yousfi

这就来了……

> 在 HTTP 中， **User-Agent 字符串** 常用于 [内容协商](https://en.m.wikipedia.org/wiki/Content_negotiation)，即源服务器根据响应选择合适的内容或操作参数。例如，Web 服务器可能会利用 User-Agent 字符串，根据特定版本客户端软件的已知能力来选择变体。内容定制的概念已内置于 HTTP 标准中，见 [RFC 1945](https://tools.ietf.org/html/rfc1945#page-46)，“以便定制响应，避免特定用户代理的局限性”。

> User-Agent 字符串是 Web 爬虫使用 [Robots 排除标准](https://en.m.wikipedia.org/wiki/Robots_Exclusion_Standard)（_robots.txt_ 文件）被禁止访问网站某些部分的依据之一。

> 与许多其他 HTTP 请求头一样，“User-Agent”字符串中的信息构成了客户端发送给服务器的信息的一部分，因为该字符串在不同用户之间可能有很大差异。[[5]](https://en.m.wikipedia.org/wiki/User_agent#cite_note-5)

参考：

> **[User agent](https://en.wikipedia.org/wiki/User_agent)**
>
> On the Web, a user agent is a software agent responsible for retrieving and facilitating end-user interaction with Web content. This includes all web browsers, such as Google Chrome and Safari, some email clients, standalone download managers like youtube-dl, and other command-line utilities like cURL.
> The user agent is the client in a client–server system. The HTTP User-Agent header is intended to clearly identify the agent to the server. However, this header can be omitted or spoofed, so some ...

@Yassine_Yousfi，互联网上有大量关于 HTTP User-Agent（UA）字符串及其各种用法的参考资料，包括将其作为检测机器人和其他恶意网络活动的传感器。

祝你在机器人狩猎中好运！

注意：

1. 你可以在这里查看 Discourse 视图中的机器人用户代理（某些 UA 字符串被截断）：

```plaintext
https://discourse.your-great-domain.com/admin/reports/web_crawlers

```

1. 没有任何检测算法能以 100% 的准确率检测所有机器人。

2. 你也可以从 Web 服务器日志文件和其他方法中获取 UA 字符串。

另见：

> <https://serverfault.com/questions/89773/get-list-of-user-agents-from-nginx-log>
