WAF防火墙用于保护Web应用免受攻击
参考资料
简介
WAF(Web Application Firewall)防火墙用于保护Web应用免受攻击,通过监控、过滤和拦截HTTP/HTTPS流量,防御SQL注入、XSS等攻击。
官网
常见WAF官网:
ModSecurity: https://modsecurity.org/
Naxsi (Nginx插件): https://github.com/nbs-system/naxsi
Cloudflare WAF: https://www.cloudflare.com/waf/
下载
ModSecurity:
通过GitHub下载源码:https://github.com/SpiderLabs/ModSecurity
或使用包管理器安装(如apt install modsecurity
)。Naxsi:
从GitHub获取:https://github.com/nbs-system/naxsi
或通过Nginx模块编译安装。
功能
攻击检测:拦截SQL注入、XSS、CSRF等攻击。
流量监控:记录HTTP/HTTPS请求和响应。
规则自定义:支持自定义安全规则(如OWASP规则集)。
日志分析:生成安全事件日志供审计。
用法
以ModSecurity为例:
安装:
git clone --depth 1 https://github.com/SpiderLabs/ModSecurity cd ModSecurity && ./build.sh && make install
配置:
编辑modsecurity.conf
,启用规则:SecRuleEngine On Include /path/to/owasp-modsecurity-crs/rules/*.conf
集成到Web服务器:
Apache: 加载
mod_security
模块。Nginx: 通过动态模块加载。
防御操作
启用预设规则集:如OWASP CRS(Core Rule Set)。
自定义规则:针对业务需求添加规则,例如:
SecRule ARGS "@contains <script>" "deny,id:1001,msg:'XSS Attack'"
日志监控:定期检查
modsec_audit.log
,分析攻击尝试。误报处理:通过
SecRuleRemoveById
排除误报规则。更新规则:定期同步官方规则库(如GitHub更新)。
抓包示例
使用tcpdump
捕获WAF处理的流量:
tcpdump -i eth0 port 80 -w waf_traffic.pcap
分析工具:Wireshark或ModSecurity日志。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。