Naxsi+nginx前端保护

 

官网即下载地址

https://github.com/nbs-system/naxsi/releases

参考网址

https://www.123admin.com/how-to-setup-and-configure-naxsi-for-nginx-on-centos/

解压

tar zxvf  naxsi-0.56rc1.tar.gz

运行

nginx -V

然后可以看到现有的模块,复制保存一下备用。

configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/build/nginx-ph1UVS/nginx-1.14.0/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-ph1UVS/nginx-1.14.0/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-ph1UVS/nginx-1.14.0/debian/modules/http-echo --add-dynamic-module=/build/nginx-ph1UVS/nginx-1.14.0/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-ph1UVS/nginx-1.14.0/debian/modules/http-subs-filterv

Naxsi 不要求任何特定的依赖,它需要的 libpcre libssl zlib gzip 这些 Nginx 已经集成了。

 

从nginx官网下载相应版本

然后编译(记得在 ./configure 后面加上 --add-module=../naxsi-0.55.3/naxsi_src/ 和你之前备份的模块):

 

这里漏掉一些提示,后续再加

 

 

make

 

等待编译完成。Naxsi 安装完成。编译过程中有错误直接贴到google中搜索

替换nginx二进制文件,替换之前记得备份

cp ~/nginx-1.14.0/objs/nginx /usr/sbin/

在conf里配置一个naxsi的文件

vi naxsi.rules

#LearningMode; #Enables learning mode

SecRulesEnabled;

#SecRulesDisabled;

DeniedUrl "/RequestDenied";

## check rules

CheckRule "$SQL >= 8" BLOCK;

CheckRule "$RFI >= 8" BLOCK;

CheckRule "$TRAVERSAL >= 4" BLOCK;

CheckRule "$EVADE >= 4" BLOCK;

CheckRule "$XSS >= 8" BLOCK;

 

在nginx.conf配置文件里

        location / {

            root   html;

            index  index.html index.htm;

            include naxsi.rules;

}

例如 配置文件就放在nginx 的conf 目录里就可以了

技术分享图片

在nginx.conf里配置

 server {

        listen       80;

        server_name  www.hqssjt.cn;

        charset utf-8;

        location =  {

            root   /usr/local/nginx/html;

            index  index.html index.htm;

            expires 30d; # 浏览器缓存

            include naxsi.rules;# WAF防火墙

        }

        location /RequestDenied {

        return 403;

    }

        error_page  403              /403.html;

        location = /403.html {

        root   /usr/local/nginx/html;

 }

        #指定404错误页面

        error_page  404 500 502 503 504  /404.html;

        location = /404.html {

            root   /usr/local/nginx/html/index.html;

        }

    }

检查配置文件

 /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

/usr/local/nginx/sbin/nginx -s reload

模仿攻击,看错误日志

技术分享图片

 

防御测试

浏览器中打开 http://www.test.com/?a=<>‘ ,出现 403 错误,并且在 foo.log 中出现 NAXSI_FMT 开头的日志。恭喜你 Naxsi 启用成功。

白名单规则

Naxsi 社区提供了一些常用的白名单规则,例如 wordpress 。可以在 https://github.com/nbs-system/naxsi-rules 下载白名单规则。

然后将规则 include 到 server 内的 location 中。重启 nginx 即可。不过目前这些白名单最近的修改日期显示是1年前~.~ ,可根据自身需要添加白名单规则。

详细的白名单规则以及 Naxsi 其他支持,可参考 Naxsi WIKI

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值