两个Cloudflare防火墙策略,能挡住90%以上恶意流量。
域名=>安全性=>WAF=>创建规则=>,如图:
表达式:
(cf.threat_score ge 5 and not cf.client.bot) or (not http.request.version in {"HTTP/1.2" "HTTP/2" "HTTP/3" "SPDY/3.1"}) or (not http.user_agent contains "Mozilla/")
- 上面的意思是威胁分数大于或等于5,且不是已知的合法爬虫,会质询;
- HTTP版本不是 “HTTP/1.2” “HTTP/2” “HTTP/3” “SPDY/3.1” 会质询;
- 请求头不带 Mozilla/ 会质询;
上面可能会误伤爬虫,那么再创建一个合法爬虫规则,如图:
表达式:
(cf.client.bot) or (http.user_agent contains "duckduckgo") or (http.user_agent contains "facebookexternalhit") or (http.user_agent contains "Feedfetcher-Google") or (http.user_agent contains "LinkedInBot") or (http.user_agent contains "Mediapartners-Google") or (http.user_agent contains "msnbot") or (http.user_agent contains "Slackbot") or (http.user_agent contains "TwitterBot") or (http.user_agent contains "ia_archive") or (http.user_agent contains "yahoo")
- 上面的合法爬虫允许访问。
实测,这两条规则能挡住95%以上的CC攻击,然后防火墙设置,安全级别建议设置为低,否则影响浏览体验。
还是那句话,任何攻击都有特征的,分析日志,然后对应屏蔽才是最好的办法。