美文网首页
CentOS7.7下源码安装naxsi及配置策略

CentOS7.7下源码安装naxsi及配置策略

作者: 小浪崇礼 | 来源:发表于2020-04-28 18:57 被阅读0次

CentOS7.7下源码安装naxsi及配置策略

服务器操作系统:CentOS7.7 64位 需要安装依赖环境如下:

1.环境可以实现通过lnmp一件安装脚本进行部署,测试的话可以不用部署,如果一起安装过nginx,可以关闭nginx,然后备份配置文件,再重新编译加载naxsi模块

关闭已经启动nginx,这里如果没有nginx那么可以跳过此步骤,直接进行安装nginx

netstat -tulnp | grep "80"

pkill nginx

cp /usr/local/nginx/conf/nginx.conf /tmp/nginx.conf

cp /usr/local/nginx/conf/extra/app.conf  /tmp/cntf.conf

rm -rf /usr/local/nginx*

2.下载naxsi,重新将此模块编译到nginx中

git clone https://github.com/nbs-system/naxsi.git

wget http://nginx.org/download/nginx-1.16.1.tar.gz

tar -zxvf nginx-1.16.1.tar.gz

cd /usr/local/nginx-1.16.1

./configure --prefix=/usr/local/nginx-1.16.1 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-file-aio --with-http_dav_module --add-module=../naxsi/naxsi_src/

make && make install # 这里使用的版本编译安装会显示一个same file错误,这个不影响

ln -s /usr/local/nginx-1.16.1 /usr/local/nginx 添加nginx版本目录为软连接

cd /usr/local/nginx/conf/

mv nginx.conf nginx.conf.bak && egrep -v "^$|#" nginx.conf.bak >> nginx.conf # 这里是拿出非注释掉的配置

3.在nginx主配置文件中引入naxsi核心规则文件,这里要放在http里面

cp /usr/local/naxsi/naxsi_config/naxsi_core.rules /usr/local/nginx/conf/

vim /usr/local/nginx/conf/nginx.conf

添加如下内容:

user                nginx;

worker_processes    1;

worker_rlimit_core  500M;

working_directory  /tmp/;

error_log          /var/log/nginx/naxsi.log;

events {

    worker_connections 1024;

    use epoll;

    # multi_accept on;

}

http {

    include                        /usr/local/nginx/conf/naxsi_core.rules; #引用核心规则

    include                        /usr/local/nginx/conf/mime.types;

    include                        /usr/local/nginx/conf/cntf.conf;

    server_names_hash_bucket_size  128;

    access_log                    /var/log/nginx/access.log;

    sendfile                      on;

    keepalive_timeout              65;

    tcp_nodelay                    on;

    gzip                          on;

    gzip_disable                  "MSIE [1-6]\.(?!.*SV1)";

}

复制好的naxsi_core.rules 不用更改

vim /usr/local/nginx/conf/naxsi.rules

添加如下内容:

SecRulesEnabled;        # 启用naxsi

LearningMode;          # 是否启用学习模式,只记录,不拦截,方便自己设置白名单

DeniedUrl "/50x.html";

# check rules

CheckRule "$SQL >= 8" BLOCK;

CheckRule "$RFI >= 8" BLOCK;

CheckRule "$TRAVERSAL >= 4" BLOCK;

CheckRule "$EVADE >= 4" BLOCK;

CheckRule "$XSS >= 8" BLOCK;

然后开始新建子配置文件,就是server的文件

vim /usr/local/nginx/conf/cntf.conf

添加如下配置信息:

server {

    proxy_set_header  Proxy-Connection "";

    listen            *:80;

    access_log        /tmp/nginx_access.log;

    error_log        /tmp/nginx_error.log debug;

    location / {

        include          /usr/local/nginx/conf/naxsi.rules; #引用子规则

        try_files $uri $uri/ =404;

    }

    location /RequestDenied { #配置拦截后拒绝访问时展示的页面

        return 418;

        error_page  500 502 503 504  /50x.html;

            root  html;

    }

}

这里配置生成日志的位置也可以在naxsi.rules里面添加

上述如果没有什么问题,那么就可以将nginx添加到系统环境变量,方便使用

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx 添加nginx为软连接

4.测试nginx配置并启动

nginx -t

nginx

如果更改了配置,需要重启执行如下:

nginx -s reload

5.测试访问

http://42.159.83.201/?id=2%27or%201-3

推荐:https://klionsec.github.io/2017/09/18/naxsiwaf/

推荐:https://blog.micblo.com/2015/07/19/NGINX%E7%9A%84WAF%E6%A8%A1%E5%9D%97-Naxsi%E7%9A%84%E7%AE%80%E4%BB%8B%E4%B8%8E%E5%AE%89%E8%A3%85-1/

相关文章

网友评论

      本文标题:CentOS7.7下源码安装naxsi及配置策略

      本文链接:https://www.haomeiwen.com/subject/fdvbwhtx.html