导入 OWASP CRS

Last Updated: 2026-11-30 14:51 Views: 8

运行时只加载 TOML 规则;OWASP CRS 的 ModSecurity .conf 先用 wxserver-convert -from crs 转换。

流程

  1. 准备 CRS 目录:把 crs-setup.conf.example 复制为 crs-setup.conf。
  2. 转换 setup + 全部规则(同一目录下保留 .data 文件,@pmFromFile 相对路径 需要能找到):
wxserver-convert -from crs \
  -in crs-setup.conf \
  -in rules/REQUEST-901-INITIALIZATION.conf \
  -in rules/REQUEST-9xx-....conf \
  ... \
  -in rules/RESPONSE-95x-....conf \
  -out conf/waf/crs.toml

也可以一次传多个 -in;转换器会保留 SecMarker、chain、 SecRuleUpdateTargetById/ActionById、skipAfter 等顺序语义。

  1. 配置:
[waf]
enabled = true
rules_files = ["conf/waf/crs.toml"]
skip_unsupported_rules = false

如评估新规则集时可临时设 skip_unsupported_rules = true。

已验证

  • OWASP CRS 4.31.0-dev 的 crs-setup.conf + rules/*.conf 可完整转换。
  • 转换后的 TOML 可被 WAF 引擎加载,未出现不支持的操作符。
  • 普通请求 200;SQLi、XSS、路径穿越请求被 CRS 规则拦截 (942100/941100/930100,HTTP Host 使用域名而非数字 IP)。
  • SecMarker/skipAfter、TX 变量、multipart FILES、libinjection 检测均已覆盖。

注意

  • SecRuleScript/Lua、少量复杂 ctl 仍不支持;这类自定义规则会报错或被 skip_unsupported_rules 跳过。
  • SecComponentSignature、SecDefaultAction 是规则集元数据/默认动作声明, 不进入 TOML;CRS 默认 pass 行为由引擎默认值匹配。
  • 转换后的文件较大(CRS 4.31 约 8.8k 行 TOML),建议单独放在 conf/waf/ 并纳入 版本管理。
  • .data 文件需与转换后的 TOML 同目录,或把 @pmFromFile 改成绝对路径。
← Previous Article 第 10 章 故障排查 Next Article → Manager 安全配置

Comments

No comments yet