nginx增加modsecurity模块

  modsecurity原本是Apache上的一款开源waf,可以有效的增强web安全性,目前已经支持nginx和IIS,配合nginx的灵活和高效,可以打造成生产级的WAF,是保护和审核web安全的利器。

git clone https://github.com/SpiderLabs/ModSecurity.git
cd ModSecurity/
./autogen.sh
./configure--enable-standalone-module --disable-mlogc
make
cd tengine/
./configure--prefix=/usr/local/nginx
 --conf-path=/etc/nginx/nginx.conf--pid-path=/var/run/nginx/nginx.pid 
--error-log-path=/var/log/nginx/nginx.log--http-log-path=/var/log/nginx/nginx-http.log--add-module=/root/ngx_devel_kit-0.2.19/--add-module=/root/lua-nginx-module-0.9.13/--add-module=/root/ModSecurity/nginx/modsecurity/
 --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
make

  modsecurity倾向于过滤和阻止web危险,之所以强大就在于规则,OWASP提供的规则是于社区志愿者维护的,被称为核心规则CRS(corerules),规则可靠强大,当然也可以自定义规则来满足各种需求。

git clone https://github.com/SpiderLabs/owasp-modsecurity-crs
cp -R owasp-modsecurity-crs /etc/nginx/
cp
 /etc/nginx/owasp-modsecurity-crs/modsecurity_crs_10_setup.conf.example 
/etc/nginx/owasp-modsecurity-crs/modsecurity_crs_10_setup.conf
cd ModSecurity/
cp modsecurity.conf-recommended /etc/nginx/modsecurity.conf
cp unicode.mapping /etc/nginx
vim modsecurity.conf
SecRuleEngine on
nclude owasp-modsecurity-crs/modsecurity_crs_10_setup.conf
Includeowasp-modsecurity-crs/base_rules/modsecurity_crs_41_sql_injection_attacks.conf
Include owasp-modsecurity-crs/base_rules/modsecurity_crs_41_xss_attacks.conf
Includeowasp-modsecurity-crs/base_rules/modsecurity_crs_40_generic_attacks.conf
Includeowasp-modsecurity-crs/experimental_rules/modsecurity_crs_11_dos_protection.conf
Include owasp-modsecurity-crs/experimental_rules/modsecurity_crs_11_brute_force.conf
Includeowasp-modsecurity-crs/optional_rules/modsecurity_crs_16_session_hijacking.conf

  在需要启用modsecurity的主机的location下面加入下面两行即可:

ModSecurityEnabled on;  
ModSecurityConfig modsecurity.conf;




参考文章

http://www.52os.net/articles/nginx-use-modsecurity-module-as-waf.html

https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#Installation_for_NGINX

http://drops.wooyun.org/tips/2614

http://drops.wooyun.org/tips/3804

http://drops.wooyun.org/tips/734

http://www.freebuf.com/articles/web/18084.html

http://www.freebuf.com/articles/web/16806.html

时间: 2024-08-29 07:23:53

nginx增加modsecurity模块的相关文章

为nginx增加nginx_http_concat模块

为nginx增加nginx_http_concat模块 时间 2013-06-05 22:14:56  我行我思 原文  http://www.fanjun.me/?p=562 主题 Nginx 缘由 最近在做的一个项目引入的js库文件比较多,所以导致的问题就是感觉速度会比较慢,而很多库文件都是拿的开源的库,基本上不会改动,所以想是否合并一下来下载. 合并JS方式很多,一般要么是服务器端合并要么是客户端合并,如果是以前我可能会选择客户端合并,但是现在nginx上面有比较成熟的模块 nginx-h

nginx增加新模块

以gzip这个模块为例,讲述一下,在nginx中如何安装新的模块1.首先查看nginx已经安装了哪些模块.nginx –V2.发现没有gzip模块,安装进入nginx的安装目录中,不是nginx的软件目录.在已有模块种写上要安装的模块,执行下边的命令./configure \--prefix=/usr/local/ywgh/nginx \--http-client-body-temp-path=/tmp/clientbody \--http-proxy-temp-path=/tmp/proxy

nginx增加第三方模块

增加第三方模块 ============================================================ 一.概述nginx文件非常小但是性能非常的高效,这方面完胜apache.nginx文件小的一个原因之一是nginx自带的功能相对较少,好在nginx允许第三方模块,第三方模块使得nginx越发的强大. nginx已支持动态加载模块 二.安装第三方模块./configure --prefix=源安装目录 --add-module=/第三方模块解压目录 以安装ng

nginx配合modsecurity实现WAF功能

一.准备工作 系统:centos 7.2 64位.nginx1.10.2, modsecurity2.9.1 owasp3.0 1.nginx:http://nginx.org/download/nginx-1.10.2.tar.gz 2.modsecurity for Nginx: https://www.modsecurity.org/tarball/2.9.1/modsecurity-2.9.1.tar.gz 3.OWASP规则集:https://github.com/SpiderLabs

nginx添加WAF模块

WAF全称叫Web Application Firewall,web应用防火墙 最近公司网页发现有人天天在刷单,ELk真心不错,能多维度的发现这些问题.所以现在考虑给nginx增加个WAF模块,找了个老外的ModSecurity,下面讲下如何安装 1.安装依赖rpm包 yum -y install gcc gcc-c++ ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel autoconf

nginx上传模块nginx_upload_module和nginx_uploadprogress_module模块进度显示,如何传递GET参数等。

ownload:http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gzconfigure and make : ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module   --add-module=/data/software/lnmp1.

Mac系统安装nginx+rtmp模块

1.安装命令 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 如果安装后, 想要卸载 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" 2.安装nginx 先clone nginx项目到本地 brew t

Nginx的GeoIp模块的应用与使用

使用GeoIP模块的原因(Why):由于项目的需要,需要对不同城市访问的客户进行请求转发,eg: 当天津用户A访问www.XXXX.com的时候,Nginx把这个请求转发到天津的服务器以及天津的域名上去,浏览器自动跳转tj.XXXX.com 当广州用户B访问www.XXXX.com的时候,Nginx把这个请求转发到广州的服务器以及广州的域名上去,浏览器自动跳转gz.XXXX.com 使用GeoIP模块的目的(What):博主理解为两个层面,第一技术层级的,可以减轻某个服务器的负载,做到负载均衡的

【Nginx】核心模块ngx_events_module

核心模块ngx_events_module是一个专门用于管理事件模块的模块.它的实现很简单,下面是该模块的定义: ngx_module_t ngx_events_module = { NGX_MODULE_V1, &ngx_events_module_ctx, /* module context */ ngx_events_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init mast