The WAF detection plugin for BFE 在 BFE(基于百度的 7 层负载均衡)上使用的对接 Chaitin Safeline WAF 的插件,用于检测和拦截恶意请求。
触发拦截时,会直接返回 HTTP 403 状态码(默认配置),响应内容为 safeline-event-id: f3a3406c8fa04818ab96c2f2aaaf364e
, 该字段可以用于WAF 上「攻击检测日志」的日志分析。
当前不支持响应检测以及日志中展示目的 IP 与目的端口。
- BFE v1.2.0 及以上版本
[basic]
# 127.0.0.1:8000
SafelineAddress=""
# detect time out limit Default: 3
# ReqTimeout=""
# Block Response Status Code Default: 403
# SafelineDetectBlockCode=403
[log]
# Default: safeline_waf
# LogPrefix=safeline_waf
# Default: ../log
# LogDir=..log
# Default: NEXTHOUR
# RotateWhen=NEXTHOUR
# Default: 24
# BackUpCount=24
需要先准备好 BFE 项目源码,并按照如下步骤将代码与配置文件放入 BFE 源码的指定目录。
- 移动 mod_safeline_waf_detection 目录至 bfe/bfe_modules
- 在 bfe/conf 下创建 mod_safeline_waf_detection 目录,并移动 mod_safeline_waf_detection.conf 文件至 bfe/conf/mod_safeline_waf_detection 目录中,修改配置文件中的 SafelineAddress 为 WAF 检测服务地址
- 向 bfe/bfe_modules/bfe_modules.go 中的 moduleList 添加 ModuleSafelineWaf 初始化
- mod_safeline_waf_detection.NewModuleSafelineWaf()
- 向 bfe/conf/bfe.conf 中 [Server] 添加 ModuleSafelineWaf 配置
- Modules = mod_safeline_waf_detection
- 构建/启动bfe