ModSecurity:一款优秀的开源WAF
一、ModSecurity3.0介绍
ModSecurity是一个开源的跨平台Web应用程序防火墙(WAF)引擎,用于Apache,IIS和Nginx,由Trustwave的SpiderLabs开发。作为WAF产品,ModSecurity专门关注HTTP流量,当发出HTTP请求时,ModSecurity检查请求的所有部分,如果请求是恶意的,它会被阻止和记录。
优势:
完美兼容nginx,是nginx官方推荐的WAF
支持OWASP规则
3.0版本比老版本更新更快,更加稳定,并且得到了nginx、Inc和Trustwave等团队的积极支持
免费
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阻断
劣势:
不支持检查响应体的规则,如果配置中包含这些规则,则会被忽略,nginx的的sub_filter指令可以用来检查状语从句:重写响应数据,OWASP中相关规则是95X。
不支持OWASP核心规则集DDoS规则REQUEST-912-DOS- PROTECTION.conf,nginx本身支持配置DDoS限制
不支持在审计日志中包含请求和响应主体
二、安装部署
测试环境:centOS7.6阿里云镜像
升级软件和内核
yum update
安装nginx: http://nginx.org/en/linux_packages.html#mainline
yum install yum-utils
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
yum install nginx
yum install epel-release
yum install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel doxygen zlib-devel pcre pcre-devel libxml2 libxml2-devel autoconf automake lmdb-devel ssdeep-devel ssdeep-libs lua-devel libmaxminddb-devel git apt-utils autoconf automake build-essential git libcurl4-openssl-dev libgeoip-dev liblmdb-dev ibpcre++-dev libtool libxml2-dev libyajl-dev pkgconf wget zlib1g-dev
报错解决:Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
解决办法:一句话:把/etc/yum.repos.d/epel.repo,文件第3行注释去掉,把第四行注释掉,修改为
1. [epel]
2. name=Extra Packages for Enterprise Linux 6 – $basearch
3. baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
4. #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
克隆GitHub存储库:
git clone --depth 1 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity
编译源代码:
$ cd ModSecurity
$ git submodule init
$ git submodule update
$ ./build.sh
$ ./configure
$ make
$ make install
注意:安装中有报错fatal: No names found, cannot describe anything.是正常现象
下载用于ModSecurity的NGINX连接器:
git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git
确定哪个版本的NGINX是运行在主机上的ModSecurity模块将加载:
[root@guigu ModSecurity]# nginx -v
nginx version: nginx/1.17.3
下载与安装版本对应的源代码:
wget http://nginx.org/download/nginx-1.17.3.tar.gz
tar zxvf nginx-1.17.3.tar.gz
编译动态模块,复制到模块标准目录:
cd nginx-1.17.3
#./configure --with-compat --add-dynamic-module=../ModSecurity-nginx
$ make modules
cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/
将以下load_module指令添加到/etc/nginx/nginx.conf的main中:
load_module modules/ngx_http_modsecurity_module.so;
确定nginx模块加载成功:
nginx -t
三、防护效果测试
ModSecurity 3简单示例
创建Demo web应用vim /etc/nginx/nginx.conf
server {
listen 8085;
location / {
default_type text/plain;
return 200 "Thank you for requesting ${request_uri}\n";
}
}
重新加载nginx:nginx -s reload
确认nginx正常工作:curl -D – http://localhost
保护Demo web应用
创建/etc/nginx/modsec文件夹:mkdir /etc/nginx/modsec
下载推荐的ModSecurity配置文件
wget https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended
mv modsecurity.conf-recommended modsecurity.conf
vim modsecurity.conf #在些文件中编辑以下配置
SecRuleEngine DetectionOnly
SecRuleEngine On
创建ModSecurity的主配置文件
vim /etc/nginx/modsec/main.conf
Include the recommended configuration
Include /etc/nginx/modsec/modsecurity.conf
A test rule
SecRule ARGS:testparam "@contains test" "id:1234,deny,log,status:403"
报错解决:[emerg] “modsecurity_rules_file” directive Rules error.
vim /etc/nginx/modsec/modsecurity.conf
#SecUnicodeMapFile unicode.mapping 20127
配置nginx反向代理,vim /etc/nginx/conf.d/proxy.conf
#include /etc/nginx/conf.d/*.conf; #把这一行注释掉,不然80端口会有冲突
server {
listen 80;
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/main.conf;
location / {
proxy_pass [http://0.0.0.0:8085;](http://0.0.0.0:8085/)
proxy_set_header Host $host;
}
nginx -s reload #重新加载nginx
curl -D - http://localhost/foo?testparam=123 #能正常返回“Thank you for requesting /foo?testparam=123”
curl -D - http://localhost/foo?testparam=test #则返回"403 Forbidden",说明前面配置的那条modsecuriy规则生效了,并阻拦了testparam参数中带test的请求
在/var/log/nginx/error.log中可以看到拦截的详细日志
部署OWASP规则–CRS(Core Rule Set)
安装运行nikto漏洞扫描工具,用于测试CRS的防御效果
git clone https://github.com/sullo/nikto#下载nikto
cd nikto
perl program/nikto.pl -h localhost #用nikto扫描nginx搭建的web系统(反向代理)
扫描结果是+ 7687 requests: 0 error(s) and 308 item(s) reported on remote host #扫描出308个问题
启用OWASP CRS
cd /etc/nginx/modsec/
wget https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/v3.0.2.tar.gz#下载OWASP CRS
cd owasp-modsecurity-crs-3.0.2/
cp crs-setup.conf.example crs-setup.conf
在modsecurity主配置文件中include CRS的配置和规则
vim /etc/nginx/modsec/main.conf
Include the recommended configuration
Include /etc/nginx/modsec/modsecurity.conf
OWASP CRS v3 rules
Include /usr/local/owasp-modsecurity-crs-3.0.2/crs-setup.conf
Include /usr/local/owasp-modsecurity-crs-3.0.2/rules/*.conf
测试CRS
nginx -s reload #重新加载nginx配置
curl http://localhost#返回Thank you for requesting /
curl -H "User-Agent: Nikto" http://localhost#返回403 Forbidden,说明WAF防护已经生效,此处匹配的规则是user-agent中不能包含漏洞扫描器名字
perl nikto/program/nikto.pl -h localhost #再次用nikto扫描nginx搭建的web系统
扫描结果是+ 7687 requests: 0 error(s) and 83 item(s) reported on remote host #扫描出83个问题,比308个少了很多
在安装ModSecurity时,我们将演示应用程序配置为为每个请求返回状态代码200,但实际上并没有返回这些文件,Nikto将这200个状态码解释为它请求的文件确实存在,所以报告出83个问题,为了优化nikto,去除误报,我们做如下配置
cp nikto/program/nikto.conf.default nikto/program/nikto.conf
vim nikto/program/nikto.conf #在第76行最后加上;-sitefiles,如下所示
@@DEFAULT=@@ALL;-@@EXTRAS;tests(report:500);-sitefiles
之后再次用nikto扫描
perl program/nikto.pl -h localhost
扫描结果是+ 7583 requests: 0 error(s) and 7 item(s) reported on remote host
可以看出问题只有7个问题,由于ModSecurity不支持响应(response)的检查,所以涉及此类的漏洞无法防御。但总体还是抵御了绝大部分的nikto的漏洞扫描。
ModSecurity:一款优秀的开源WAF的更多相关文章
- Web 项目可能会用到的20款优秀的开源工具
开源的应用程序和它们的源代码可以免费获得,因为版权是属于任何进行过修改或者提交代码的人.大多数提供开源软件的公司都可以建立行业标准,因此可以获得有利的竞争优势. 很多的开源应用程序和工具都有很强的替代 ...
- 开源WAF工具ModSecurity
0 前言 ModSecurity是一个开源的跨平台Web应用程序防火墙(WAF)引擎,用于Apache,IIS和Nginx,由Trustwave的SpiderLabs开发.作为WAF产品,ModSec ...
- 分享6款优秀的 AR/VR 开源库
今天,为大家推荐几款优秀的 AR/VR 开源库,希望能对大家有所帮助~ 1.AR.js AR.js 是一款应用于 Web 的高效增强现实(AR)库,基于 three.js + jsartoolkit5 ...
- 推荐一款优秀的WPF开源项目
项目介绍 此项目应用了Prism MVVM框架,项目展示数据来源于其他服务程序,使用的WebAPI通信,如果要正常运行此程序,需要您自己做一个WebAPI程序,由API接口提供数据驱动,其实直接查看代 ...
- Windows系统下三十款优秀开源软件
Windows系统下三十款优秀开源软件 1.Firefox 官方网站:http://www.getfirefox.com/ 可替换Internet Explorer 功能特点:如果你还没有使用Fire ...
- 15款优秀移动APP产品原型设计工具
一新来小盆友问:“移动产品原型设计都用啥工具?” 答:“@#¥……&%*” 又问:“能详细说下各个工具吗?我比较一下” “……” 好吧,谁让我那么的爱分享而你又是小美女呢 ———————正文开 ...
- 12款最佳Linux命令行终端工具, 20款优秀的 Linux 终端仿真器
12款最佳Linux命令行终端工具 如果你跟我一样,整天要花大量的时间使用Linux命令行,而且正在寻找一些可替代系统自带的老旧且乏味的终端软件,那你真是找对了文章.我这里搜集了一些非常有趣的 ...
- 最新app源码下载:200款优秀Android项目源码
200款优秀Android项目源码!菜鸟必备!Android开发又将带来新一轮热潮,很多开发者都投入到这个浪潮中去了,创造了许许多多相当优秀的应用.其中也有许许多多的开发者提供了应用开源项目,贡献出他 ...
- 【转】开发者分享如何创造一款优秀的iOS游戏——2013-08-25 17
http://game.dapps.net/gamedev/experience/889.html 创造出<Temple Run>的夫妻团队在高峰时期每天能够获得"好几万&quo ...
随机推荐
- SpringBoot -基础学习笔记 - 01
SpringBoot个人笔记-szs 一.使用thymeleaf模板引擎来指定所需资源的位置 可以做到当项目名进行更改后,模板引擎也会进行更新相关的路径;如下图展示,会自动添加crud根目录! < ...
- DevExpress21:SplashScreenManager控件实现启动闪屏和等待信息窗口
DevExpress中SplashScreenManager这个控件的主要作用就是显示程序集加载之前的进度条显示和进行耗时操作时候的等待界面. 一.SplashScreenManager控件的使用 1 ...
- maven的使用和环境搭建
请在博客分类的未分类中找到这篇文章
- koa2-router中间件来请求数据获取
原理 虽然不使用中间件也能获取请求数据 对于POST请求的处理,koa-bodyparser中间件可以把koa2上下文的formData数据解析到ctx.request.body中. 安装koa2版本 ...
- 深入理解RocketMQ的消费者组、队列、Broker,Topic
1.遇到的问题:上测试环境,上次描述的鸟问题又出现了,就是生产者发3条数据,我这边只能收到1条数据. 2.问题解决: (1)去控制台看我的消费者启动情况,貌似没什么问题 , (2)去测试服务器里看日志 ...
- ssh远程后台运行
ssh hadoop8 "/export/server/storm/bin/storm nimbus >/export/server/storm/nimbus_start.log 2& ...
- PHP命令行常用参数说明和使用
-i 打印phpinfo命令 root@DK:/mnt/hgfs/cpp/php# php -i | grep session -v 输出php版本信息 root@DK:/mnt/hgfs/cpp/p ...
- loj #10131
抽离题意 求删除一条树边和一条非树边后将图分成不连通的两部分的方案数 对于一棵树,再加入一条边就会产生环.若只有一个环,说明只加入了一条非树边 (x, y),记 lca 为 l, 那么 对于任意一条 ...
- Hadoop 机架(集群拓扑)设置
本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/hadoop_rack_awareness Hadoop会通过集群 ...
- YII框架的事件机制
一.什么是事件机制 解释:发生了一件事情,然后某些东西对这件事作出反应. 例子:假设发生了A同学结婚事件,然后B同学给份子钱反应,那么,B是怎么知道(监听)A事件的发生了呢,有两种办法. 扫描式:B不 ...