F5社区-F5技术交流中心

内生安全-NGINX WAF(modsecurity)测试

2020-02-01 13:10:42

闫海波

参考:

1、UDF实验环境

2、https://www.freebuf.com/sectool/211354.html

ModSecurity是一个开源的跨平台Web应用程序防火墙(WAF)引擎,用于Apache,IIS和Nginx,由Trustwave的SpiderLabs开发。作为WAF产品,ModSecurity专门关注HTTP流量,当发出HTTP请求时,ModSecurity检查请求的所有部分,如果请求是恶意的,它会被阻止和记录。


优势:

1、完美兼容nginx,是nginx官方推荐的WAF

2、支持OWASP规则

3、3.0版本比老版本更新更快,更加稳定,并且得到了nginx、Inc和Trustwave等团队的积极支持

4、免费

ModSecurity的功能:

SQL Injection (SQLi):阻止SQL注入

Cross Site Scripting (XSS):阻止跨站脚本攻击

Local File Inclusion (LFI):阻止利用本地文件包含漏洞进行攻击

Remote File Inclusione(RFI):阻止利用远程文件包含漏洞进行攻击

Remote Code Execution (RCE):阻止利用远程命令执行漏洞进行攻击

PHP Code Injectiod:阻止PHP代码注入

HTTP Protocol Violations:阻止违反HTTP协议的恶意访问

HTTPoxy:阻止利用远程代理感染漏洞进行攻击

Shellshock:阻止利用Shellshock漏洞进行攻击

Session Fixation:阻止利用Session会话ID不变的漏洞进行攻击

Scanner Detection:阻止黑客扫描网站

Metadata/Error Leakages:阻止源代码/错误信息泄露

Project Honey Pot Blacklist:蜜罐项目黑名单

GeoIP Country Blocking:根据判断IP地址归属地来进行IP阻断

劣势:

1、不支持检查响应体的规则,如果配置中包含这些规则,则会被忽略,nginx的的sub_filter指令可以用来检查状语从句:重写响应数据,OWASP中相关规则是95X。

2、不支持OWASP核心规则集DDoS规则REQUEST-912-DOS- PROTECTION.conf,nginx本身支持配置DDoS限制

3、不支持在审计日志中包含请求和响应主体


基础环境:

ModSecurity 3.1

DVWA

一、DVWA漏洞测试

1、Command Injection

输入:www.google.com; cat /etc/passwd



成功执行



2、SQL Injection

输入:%' or 1='1



成功执行


 

3、XSS Injection

输入:<script>alert(“test”)</script>



成功执行



二、下载并启用modsecurity

下载解压core ruleset:

cd /etc/nginx/modsec/


sudo wget https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/v3.1.0.tar.gz


sudo tar zxvf v3.1.0.tar.gz


启用modsecurity

sudo vi /etc/nginx/modsec/modsecurity.conf


将“off”改为“on”



sudo vim /etc/nginx/conf.d/default.conf



设置modsecurity使用OWASP CRS

cd /etc/nginx/modsec/owasp-modsecurity-crs-3.1.0


sudo cp crs-setup.conf.example crs-setup.conf


sudo vim /etc/nginx/modsec/main.conf



一定要重新加载nginx:

sudo nginx -s reload


三、验证防护效果






四、查看防护日志

tail -1 /var/log/nginx/error.log




cat /var/log/modsec_audit.log




The audit log steps through each phase of modsecurity’s evaluation

  • A Audit log header (mandatory)
  • B Request headers
  • C Request body
  • D Reserved
  • E Response body
  • F Response headers
  • G Reserved
  • H Audit log trailer, which contains additional data
  • I Compact request body alternative (to part C), which excludes files
  • J Information on uploaded files
  • K Contains a list of all rules that matched for the transaction
  • Z Final boundary (mandatory)












发布评论 加入社群

发布评论

2020-02-06 11:45:33 0

评论一下

念 回复 念 : 回复一下

相关文章

博文精选 | 三高(高并发,高可用,高性能)解决方案

F5小安

2022-01-10 10:04:22 503

博文精选 | 合谋欺诈:合谋操纵系统的艺术

F5小安

2021-09-22 11:43:52 615

对抗型应用层安全服务

朱杰

2020-12-03 19:03:41 1021

Login

手机号
验证码
© 2019 F5 Networks, Inc. 版权所有。京ICP备16013763号-1