Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

页面规则本身只能设置三条,一直很鸡肋没怎么用过,因为其他规则更丰富,此次Cloudflare页面规则下线,整理下方便以后忘了。

一、WAF规则

1.1WAF基础防护

WAF就是WEB应用防火墙,基础防护定义了请求方法和威胁分数,这个规则的措施一般采用托管质询即可

Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

1.2WAF表达式如下

(not http.request.method in {"GET" "POST"}) or (cf.threat_score gt 5)

PS:为了避免把服务器的请求屏蔽了,可以另建一个白名单规则让所有的规则跳过服务器IP。

(ip.src in {IP地址}) or (http.request.uri.path contains "/.well-known") or (http.request.uri contains "/wp-includes") or (http.request.uri contains "/wp-content")

1.3更丰富的WAF规则

当然如果有更多的需求可以使用下面这个,根据实际情况修改

(not http.request.method in {"GET" "POST"}) or (cf.threat_score gt 5) or (http.referer eq "" and http.request.uri contains "/?filter_" and http.request.version in {"HTTP/1.0" "HTTP/1.1" "HTTP/1.2"} and not http.user_agent contains "Baiduspider" and not http.user_agent contains "bingbot" and not http.user_agent contains "Googlebot" and not http.user_agent contains "Bytespider") or (http.referer eq "" and http.request.uri contains ".php") or (http.user_agent contains "mj12bot.com") or (http.user_agent contains "mj12bot.com") or (http.referer eq "" and http.request.version in {"HTTP/1.0" "HTTP/1.1" "HTTP/1.2"} and http.request.uri eq "/") or (http.user_agent contains "MSIE 9.0") or (http.referer eq "" and http.request.method eq "POST") or (http.request.uri contains "/plus/") or (http.request.uri contains "base64") or (http.referer contains ".php") or (http.referer eq "" and http.request.version in {"HTTP/1.0" "HTTP/1.1" "HTTP/1.2"} and http.user_agent eq "Go-http-client")

1.4 终极防护规则

过滤常见扫描和uri、uri参数中sql注入、xss等攻击

(http.request.uri.path contains "../..") or (http.request.uri.path contains "/*") or (http.request.uri.path contains "etc/passwd") or (http.request.uri.query contains "gopher:") or (http.request.uri.query contains "doc:") or (http.request.uri.query contains "php:") or (http.request.uri.query contains "glob:") or (http.request.uri.query contains "file:") or (http.request.uri.query contains "phar:") or (http.request.uri.query contains "zlib:") or (http.request.uri.query contains "ftp:") or (http.request.uri.query contains "ldap:") or (http.request.uri.query contains "dict:") or (http.request.uri.query contains "ogg:") or (http.request.uri.query contains "data:") or (http.request.uri.query contains ":$") or (http.request.uri.query contains "${") or (http.request.uri.query contains "invokefunction") or (http.request.uri.query contains "call_user_func_array") or (http.request.uri.query contains "\\think\\") or (http.request.uri.query contains "base64_decode(") or (http.request.uri.query contains "define(") or (http.request.uri.query contains "eval(") or (http.request.uri.query contains "file_get_contents(") or (http.request.uri.query contains "include(") or (http.request.uri.query contains "require(") or (http.request.uri.query contains "require_once(") or (http.request.uri.query contains "shell_exec(") or (http.request.uri.query contains "phpinfo(") or (http.request.uri.query contains "system(") or (http.request.uri.query contains "passthru(") or (http.request.uri.query contains "char(") or (http.request.uri.query contains "chr(") or (http.request.uri.query contains "preg_") or (http.request.uri.query contains "execute(") or (http.request.uri.query contains "echo(") or (http.request.uri.query contains "print(") or (http.request.uri.query contains "print_r(") or (http.request.uri.query contains "var_dump(") or (http.request.uri.query contains "fopen(") or (http.request.uri.query contains "alert(") or (http.request.uri.query contains "showmodaldialog(") or (http.request.uri.query contains "$_GET[") or (http.request.uri.query contains "$_POST[") or (http.request.uri.query contains "$_COOKIE[") or (http.request.uri.query contains "$_FILES[") or (http.request.uri.query contains "$_SESSION[") or (http.request.uri.query contains "$_ENV[") or (http.request.uri.query contains "$_PHPLIB[") or (http.request.uri.query contains "$_GLOBALS[") or (http.request.uri.query contains "$_SERVER[") or (http.user_agent contains "mj12bot.com") or (http.user_agent contains "censys") or (http.user_agent contains "Go-http-client") or (http.request.uri contains ".asp") or (http.request.uri contains ".aspx") or (http.user_agent contains "msray-plus") or (http.request.uri contains ".ashx") or (http.user_agent contains "Skywork") or (http.user_agent contains "GPTBot") or (http.user_agent contains "YisouSpider") or (http.user_agent contains "DataForSeoBot") or (http.user_agent contains "mj12bot.com") or (http.request.uri.query contains " or ") or (http.request.uri.query contains " xor ") or (http.request.uri.query contains " and ") or (http.request.uri.query contains " =") or (http.request.uri.query contains " <") or (http.request.uri.query contains " >") or (http.request.uri.query contains "'") or (http.request.uri.query contains "current_user")

二、重定向规则

这个还是挺简单的,301重定向,高级用法可见:如何用Cloudflare只重定向子路径

三、缓存规则

3.1静态文件缓存

使用URI包含静态文件后缀即可。

Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

3.2静态缓存表达式

(http.request.uri contains ".exe") or (http.request.uri contains ".deb") or (http.request.uri contains ".ipa") or (http.request.uri contains ".apk") or (http.request.uri contains ".sis") or (http.request.uri contains ".psd") or (http.request.uri contains ".dat") or (http.request.uri contains ".woff") or (http.request.uri contains ".woff2") or (http.request.uri contains ".tof") or (http.request.uri contains ".ttf") or (http.request.uri contains ".js") or (http.request.uri contains ".css") or (http.request.uri contains ".txt") or (http.request.uri contains ".xml") or (http.request.uri contains ".html") or (http.request.uri contains ".csv") or (http.request.uri contains ".bat") or (http.request.uri contains ".jpg") or (http.request.uri contains ".jpeg") or (http.request.uri contains ".png") or (http.request.uri contains ".gif") or (http.request.uri contains ".bmp") or (http.request.uri contains ".svg") or (http.request.uri contains ".webp") or (http.request.uri contains ".ico") or (http.request.uri contains ".mp4") or (http.request.uri contains ".rar") or (http.request.uri contains ".7z") or (http.request.uri contains ".zip") or (http.request.uri contains ".dmg") or (http.request.uri contains ".gz") or (http.request.uri contains ".ios") or (http.request.uri contains ".tar") or (http.request.uri contains ".jar") or (http.request.uri contains ".jsp") or (http.request.uri contains ".asp")

3.3wordpress白名单

为了避免wordpress无法登录等问题,还需要针对wordpress设置缓存白名单,可直接复制规则,也可根据实际情况修改。

Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

(http.request.uri.path contains "/wp-admin") or (http.request.uri.path contains "/wp-login") or (http.request.uri.path contains "/wp-logout.php") or (http.request.uri.path contains "/wp-comments-post.php") or (http.request.uri.path contains "/cart") or (http.request.uri.path contains "/checkout") or (http.request.uri.path contains "/profile.php") or (http.request.uri.path contains "/wp-pass.php") or (http.request.uri.path contains "/dynamic-content") or (http.request.uri.path contains "/wp-json/") or (http.request.uri contains "preview=true") or (http.request.uri contains "/?s=") or (http.request.uri contains "action=rp") or (http.request.uri contains "checkemail=confirm")

四、DDoS规则

对于大多数小站可以不设置,就是新建一个DDOS规则替代默认的,设置将敏感度设置为高即可。

Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

Cloudflare流量序列详解

Cloudflare 是一个提供网站性能优化和网络安全服务的平台,它通过一系列工具和技术帮助网站所有者保护其在线资产、加速内容分发并改善用户体验。下面我将根据您列出的项目,简要解释每个功能如何在Cloudflare的流量处理序列中发挥作用,以及它们如何影响请求通过Cloudflare时的处理流程。

DDoS防护(DDoS)

当网络流量异常增加,可能是由于分布式拒绝服务攻击(DDoS)时,Cloudflare会自动检测并缓解这类攻击。它通过分析流量模式,识别并过滤恶意流量,确保合法用户请求能够顺利到达服务器,保护网站免受服务中断的影响。

URL重写

URL重写功能允许用户在请求到达源服务器之前,根据预设规则改变请求中的URL路径。这有助于实现网站迁移时的路径调整、SEO优化或实现特定的路由逻辑,而无需更改源代码。

页面规则(Page Rules)

页面规则为特定URL路径或文件类型提供定制化的缓存、安全、性能设置。例如,可以设置特定页面不被缓存,或者对某些文件类型应用更严格的访问控制。

Origin Rules

Origin Rules 允许用户针对回源请求(从Cloudflare到您的原始服务器的请求)设置更细致的控制策略,比如基于请求的属性(如HTTP方法、路径等)来调整回源行为,提高安全性或优化资源加载。

缓存规则(Cache Rules)

这些规则定义了哪些内容应该被缓存,以及缓存的条件和时间。合理设置缓存规则可以显著加快页面加载速度,减轻源服务器负担。

配置规则(Configuration Rules)

虽然这个术语可能不是Cloudflare官方直接使用的,但它可能指的是通过Cloudflare的控制面板或API自定义的一系列高级配置,用于调整安全、性能设置等,以满足特定站点的需求。

重定向规则

重定向规则允许用户基于各种条件(如请求的URL、设备类型、地理位置等)自动将用户重定向到另一个URL。这对于网站结构调整、移动优化或区域化内容分发非常有用。

IP访问规则

通过设置IP访问控制规则,可以允许或阻止特定IP地址或IP段访问网站,增强安全性,防止恶意访问。

自动程序(Bots)

Cloudflare提供了自动程序管理工具,可以识别并管理爬虫、搜索引擎机器人等自动程序的行为,通过设置访问频率限制、验证码验证等措施来保护网站资源和性能。

WAF(Web应用程序防火墙)

Web应用程序防火墙监控和过滤进入网站的HTTP请求,根据预定义的安全规则阻止恶意攻击,如SQL注入、跨站脚本攻击等,增强应用层安全。

标头修改

此功能允许用户在请求或响应的HTTP标头中添加、删除或修改信息,以实现安全增强、遵守CORS策略或传递额外的元数据。

Access

Cloudflare Access是一种身份验证服务,它要求用户在访问指定的内部应用或资源前进行身份验证。通过集成SSO(单点登录)和其他身份提供商,提高企业应用的安全性。

Workers

Cloudflare Workers是一个边缘计算平台,允许开发者在Cloudflare的全球网络边缘运行JavaScript代码,实现对请求的实时处理,比如内容修改、API调用、A/B测试等,无需更改源服务器配置,大大提高了灵活性和响应速度。

综上所述,Cloudflare通过这一系列功能,为网站流量提供了一个全面的管理和优化框架,从安全防御、性能加速到定制化处理,每一步都旨在提升最终用户的体验和网站的整体健壮性。

本文作者:ZKCOI

文章名称:Cloudflare页面规则弃用后,如何配置WAF、缓存规则?

文章链接:https://www.zkcoi.com/365up/program/3585.html

本站资源仅供个人学习和交流,如若转载,请注明出处,详见《免责声明》

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
ZKCOIZKCOI
看来除了自然码还得掌握微软双拼
上一篇 2024年5月27日 上午9:52
下一篇 2024年6月7日 下午7:53

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

评论列表(2条)

联系博主

立即联系
一般有空就回复

qrcode_web

微信扫码联系我

insert_link 友情链接
分享本页
返回顶部