CloudFlare 的各种操作

开启防护1

自定义防御规则

Security -> WAF 中:

  1. 点击 Custom rules -> Create rule 创建自定义规则, 名字随意;
  2. 可以使用 Expression builderExpression editor 来编辑匹配规则;
  3. 匹配动作自行选择 Block (封禁) 或 Managed Challenge (质询, 5 秒盾);
  4. 选择放置位置 (可选), 然后保存。
规则总结

常见的蜘蛛爬虫的 User-Agent 有:

1
2
3
4
5
6
7
8
9
Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys.io/)
Mozilla/5.0 (compatible; InternetMeasurement/1.0; +https://internet-measurement.com/)
Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0; +info@netcraft.com)
python-httpx/0.28.1
python-requests/2.28.1
Python-urllib/3.12
Go-http-client/1.1
# 截至 2025-03-01
# 待补充

常见扫描路径有:

  1. 环境变量文件, 如 .env, .env.bak 等;
  2. WordPress 路径, 如 wp-admin, wp-content, wp-includes;
  3. 各种 .php 文件。

根据以上特征可以编写出 CloudFlare 的规则表达式2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
(
  (http.user_agent contains "censys") or
  (http.user_agent contains "Dataprovider") or
  (http.user_agent contains "facebook") or
  (http.user_agent contains "InternetMeasurement") or
  (http.user_agent contains "Go-http-client") or
  (http.user_agent contains "scan") or
  (http.user_agent contains "Survey") or
  (http.user_agent contains "python") or
  (http.user_agent contains "Python") or
  (http.request.uri.path contains ".env") or
  (http.request.uri.path contains ".php") or
  (http.request.uri.path contains "wp-admin") or
  (http.request.uri.path contains "wp-content") or
  (http.request.uri.path contains "wp-includes")
)

直接粘贴到 Expression editor 中保存即可。

如果站点使用了 PHP, 可以添加额外的条件, 将 http.request.uri.path contains ".php" 替换为 (http.request.uri.path contains ".php") and (http.host ne "php.example.com")
如果用于特殊用途, 建议移除关于 Go-http-client 的规则。

封禁 Bots

Security -> Bots 中:

  1. 打开 Bot Fight Mode, 但如果域名用于特殊用途, 建议关闭, 不然会影响;
  2. 打开 Block AI Bots
DDoS

Security -> DDoS 中:

  1. 点击 Deploy a DDoS override, 名称随意;
  2. Ruleset actionRuleset sensitivity 可以自行选择;
  3. 点击 Save 保存。
其他可以做的

Security -> Settings 中:

  1. 调整 Security Level (安全级别);
  2. 更改 Challenge Passage (质询过期时间);
  3. 打开 Browser Integrity Check (浏览器完整性检查)。

Network 中, 关闭 Onion Routing

开启缓存3

Cache Rules 中:

  1. 点击 Create rule 创建规则, 名称随意;
  2. 根据网站是否有动态内容来选择 Custom filter expression 还是 All incoming requests
    一般来说, 网站的静态资源只会存放在某一文件夹, 选择 Custom filter expression 更好。
  3. Cache eligibility 选择 Bypass cache 将不会缓存,适用于开发模式。
    所以选择 Eligible for cache
  4. 其他设置可自行配置。
    最常见的配置有 Edge TTL (边缘服务器缓存时间), Browser TTL (用户浏览器缓存时间), 打开 Cache deception armorIgnore query string;
  5. 保存部署。

隧道 SaaS 回源

待补充


  1. 部分内容来源 cloudflare防CC、DDOs攻击保姆级教程, 附带防御规则 ↩︎

  2. 受限于 Free Plan, 不能使用正则表达式匹配, 所以规则表达式比较繁冗 ↩︎

  3. Cloudflare进阶技巧:缓存利用最大化 ↩︎

使用 Hugo 构建
主题 StackJimmy 设计