modsecurity3.0安装部署

Centos7.4 modsecurity with nginx 安装

1.安装依赖

yum install -y pcre pcre-devel openssl openssl-devel libtool libtool-ltdl-devel gcc gcc-c++ gcc-g77 autoconf automake

geoip geip-devel libcurl libcurl-devel yajl yajl-devel lmdb-devel ssdeep-devel lua-devel

2. openresty与modsecurity安装编译相关依赖  

注:安装包放在/opt  目录 否则 openresty make  失败

wget http://www.over-yonder.net/~fullermd/projects/libcidr/libcidr-1.2.3.tar.xz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
wget https://openresty.org/download/openresty-1.15.8.2.tar.gz
tar -xvf libcidr-1.2.3.tar.xz
tar -zxvf pcre-8.43.tar.gz
tar -zxvf openssl-1.1.1d.tar.gz
tar -zxvf openresty-1.15.8.2.tar.gz
rm -rf pcre-8.43.tar.gz \
           openssl-1.1.1d.tar.gz \
           openresty-1.15.8.2.tar.gz
cd /opt/libcidr-1.2.3
make && make install

#libmodsecurity编译安装
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


#modsecurity nginx dynamicmodule编译
git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git


#openresty 编译

cd /opt/openresty-1.15.8.2/
./configure --with-pcre-jit --with-ipv6 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_geoip_module \
--with-openssl=/opt/openssl-1.1.1d \
--with-pcre=/opt/pcre-8.43
--add-dynamic-module=../ModSecurity-nginx
gmake && gmake install

 3.owasp规则库下载

git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
cd owasp-modsecurity-crs/
cp crs-setup.conf.example crs-setup.conf
cd rules
cp REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
cp RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf

4.nginx.conf 内容 

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#modsecurity动态库加载
load_module /usr/local/openresty/nginx/modules/ngx_http_modsecurity_module.so;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info; 

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /opt/openresty/bundle/nginx-1.15.8/conf/mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    server {

        listen       80;
        server_name  _;
        #access_log  logs/host.access.log  main;
        #modsecurity 支持
        modsecurity on;
        location / {
            #modsecurity配置文件路径
            modsecurity_rules_file /opt/ModSecurity/modsecurity.conf;
            root   html;
            index  index.html index.htm;
        }

        location = /50x.html {
            root   html;
        }
    }
}

 5.owasp规则库配置

cp /opt/ModSecurity/modsecurity.conf-recommended modsecurity.conf
vi modsecurity.conf
#最后添加
Include /opt/owasp-modsecurity-crs/crs-setup.conf
Include /opt/owasp-modsecurity-crs/rules/*.conf
#保存

 

6.访问攻击url查看日志

cat /var/log/modsec_audit.log

默认只是检测,不拦截,可以修改配置,将

vi /usr/local/nginx/modsecurity.conf 

# Enable ModSecurity, attaching it to every transaction. Use detection
# only to start with, because that minimises the chances of post-installation
# disruption.
#
#SecRuleEngine DetectionOnly
SecRuleEngine On
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值