Cloudflare WAF 实战:5 条自定义规则稳住扫描器/爬虫/CC

前言

最近网站频繁遭遇扫描器探测、恶意爬虫与 CC 压力。我基于“先放行可信、再阻断恶意、灰度挑战补位、按地区加门槛”的思路,落地了 5 条 Cloudflare WAF 自定义规则,过去一段时间运行稳定,分享给有相同困扰的你。

整体策略

  • 先放行可信流量(白名单)
  • 再拦截明确恶意行为与恶意 ASN(扫描器/UA)
  • 对不确定流量进行 Challenge 验证
  • 对高风险地区进行托管质询

规则清单(5 条)

1) 白名单|管理员 IP 放行

目的:避免后台/运维被误伤

(ip.src in {1.2.3.4 5.6.7.8})

动作:Skip(跳过 WAF 检查)
建议跳过的组件:自定义规则、速率限制规则、托管规则、超级自动程序攻击模式
备注:把示例 IP 换成你的实际管理出口 IP;如需动态办公网络,建议用 Zero Trust + 短期 IP 列表。

2) 白名单|SEO 与静态资源放行

目的:确保搜索引擎抓取正常,常见静态文件不被挑战

(cf.client.bot)
or (http.request.uri.path in {
  "/rss.xml" "/sitemap.xml" "/robots.txt"
  "/favicon.ico" "/favicon.svg" "/favicon-96x96.png"
  "/apple-touch-icon.png" "/site.webmanifest"
  "/web-app-manifest-192x192.png" "/web-app-manifest-512x512.png"
})

动作:Skip
备注:路径按你站点实际文件调整;如使用 SEO 插件生成的 sitemap 索引,请额外加入对应路径。

3) 拦截|ASN 与已知恶意扫描器 UA

目的:直接阻断明显攻击工具与恶名 ASN

(http.user_agent eq "" or http.user_agent eq "undefined")
or (http.user_agent contains "masscan")
or (http.user_agent contains "nmap")
or (http.user_agent contains "zmap")
or (http.user_agent contains "zgrab")
or (http.user_agent contains "WPScan")
or (http.user_agent contains "sqlmap")
or (http.user_agent contains "fimap")
or (http.user_agent contains "Acunetix")
or (http.user_agent contains "FHscan")
or (http.user_agent contains "Gscan")
or (http.user_agent contains "Researchscan")
or (http.user_agent contains "Wprecon")
or (http.user_agent contains "BackDoorBot")
or (http.user_agent contains "Zeus")
or (ip.src.asnum in {
  210644 216246 211522 214351 213194 214196 44477 215789 214943 48589 202685 57523 136897 45104 45103 45102 37963 59055 59054 59053 59052 59051 59028 269939 206798 45090 132203 132591 133478 131444 63727 63655 61348 134963 34947 55990 141180 139144 139124 137876 140723 136907 211914 149167 206204 200756 398324 14618 10912 24940 14061 16276 36352 53667 60781 5065 6207 35624 43444 198571 33993 209847 35478 58854 138915 140666 265443
})

动作:Block
重要提示:上述 ASN 列表包含多家云厂商网段,可能影响部分国内搜索引擎抓取与第三方服务回源。如需收录,请剔除对应 ASN 或对 Bot 验证放行。UA 关键字基于常见安全测试/漏洞扫描工具,建议定期滚动更新。

4) 验证|灰色 UA 与自动化行为

目的:对疑似自动化访问先做 JS 质询,降低误杀

(http.user_agent contains "java")
or (http.user_agent contains "python")
or (http.user_agent contains "libwww")
or (http.user_agent contains "libweb")
or (http.user_agent contains "PyCurl")
or (http.user_agent contains "PHPCrawl")
or (http.user_agent contains "wrk")
or (http.user_agent contains "hey/")
or (http.user_agent contains "apache")
or (http.user_agent contains "scanbot")

动作:JS Challenge
备注:比 Block 更温和,适合“存疑但非确认恶意”的流量。

5) 验证|高风险国家访问

目的:按地区风险增加一道门槛

(ip.src.country in {"RU" "UA" "T1"})

动作:Managed Challenge
备注:国家/地区名单按你站点读者分布与业务需求定制。T1 为保留/特殊网络代号,按需调整。

运行效果(24h 示例)

  • 管理员白名单放行:1.34k
  • SEO 静态资源放行:192
  • 扫描器拦截:22
  • 灰度验证:未触发
  • 高风险国家验证:未触发

说明:当前主要为扫描器探测阶段;灰度与地区挑战作为“第二道门”。

调优建议

  • 规则顺序:白名单(Skip)置顶,其次 Block,再 Challenge,最后地区策略。
  • 观察期:新规则上线后 48–72 小时重点观察 WAF 命中与访问日志,避免误伤。
  • 细化 Skip:仅跳过必要组件,避免把所有防护一次性绕空。
  • 结合速率限制:对 /wp-login.php、/xmlrpc.php 等路径叠加 Rate Limit 更稳。
  • 维护清单:UA/ASN 列表每月滚动更新;为常用第三方监控/健康检查 IP 增加例外。

附:常见敏感路径(可选拦截/Challenge)

  • /wp-json/(按需;若对外提供 API 则放行)
  • /wp-admin/、/wp-login.php、/xmlrpc.php(建议高优先级保护)
  • /?author=、/?s=(枚举与搜索探测,按需 Challenge)

发布前请替换管理员 IP 白名单以及站点静态文件路径;如需国内收录,评估是否保留/剔除部分 ASN。

暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
加载中...