目次
之前不停在用 modsecurity ,结果还不错,但是它对 nginx 支持真的不太好~.~ 。经常会产生大量错误日记,不过这个并不影响它的正常功能,只是看着揪心。让我想更换它的主要原因是 Modsecurity 经常在处理某个哀求(正常或不正常)时,会突然导致 CPU 99.9% 以上,这是最不能忍受的。 1、Naxsi 和 Modsecurity对比
在一样寻常使用中,可以发现 Modsecurity 具有非常严格的防御规则(误报挺多的),并且规则支持较好(有强盛的后台?)。如果你使用 Apache 服务器,保举使用 Modsecurity WAF。如果你使用的是 Nginx 服务器,建议先尝试使用 Naxsi 。 下面就来在 Centos 下编译安装 Nginx + Naxsi WAF 。 【占位:Modsecurity 的编译安装】 2、编译 Nginx + Naxsi首先先运行: [code]# nginx -V[/code]然后可以看到现有的模块,复制保存一下备用。 [code]configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2l --with-pcre=../pcre-8.40 --with-pcre-jit --with-ld-opt=-ljemalloc[/code]3、下载 Nginx 和 NaxsiNaxsi 应该使用全部高于 0.8.X 的 Nginx 版本。 Naxsi 版本可以在 https://github.com/nbs-system/naxsi 这里,选择 Branch –> Tags 检察版本号。 下载 Nginx 和 Naxsi ,并解压,然后进入解压后的 Nginx 目次: [code]# wget http://nginx.org/download/nginx-1.12.1.tar.gz # wget https://github.com/nbs-system/naxsi/archive/0.55.3.tar.gz # tar xvzf nginx-1.12.1.tar.gz # tar xvzf naxsi-0.55.3.tar.gz # cd nginx-1.12.1/[/code]Naxsi 不要求任何特定的依靠,它必要的 libpcre ,libssl ,zlib ,gzip 这些 Nginx 已经集成了。 然后编译(记得在 ./configure 背面加上 --add-module=../naxsi-0.55.3/naxsi_src/ 和你之前备份的模块): [code]./configure --prefix=/usr/local/nginx --user=www --group=www --add-module=../naxsi-0.55.3/naxsi_src/ --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2l --with-pcre=../pcre-8.40 --with-pcre-jit --with-ld-opt=-ljemalloc make //不要 make install,否则就真的覆盖了[/code]期待编译完成。Naxsi 安装完成。 4、替换nginx二进制文件[code]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak # cp ./objs/nginx /usr/local/nginx/sbin/[/code]注:如果提示 cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy ,请先 service nginx stop 5、检查 nginx 模块[code]# nginx -V[/code]看到有 –add-module=../naxsi-0.55.3/naxsi_src/ 就成功了。 6、nginx/naxsi 基本配置6.1、http 部分配置打开 nginx.conf 在 http 部分配置: [code]http { include naxsi_core.rules; #导入 naxsi 核心规则 ... } server 部分配置 在 nginx.conf 的 server 部分配置: location / { #开启 naxsi SecRulesEnabled; #开启学习模式 LearningMode; #界说阻止哀求的位置 DeniedUrl "/50x.html"; #CheckRules, 确定 naxsi 何时采取行动 CheckRule "$SQL >= 8" BLOCK; CheckRule "$RFI >= 8" BLOCK; CheckRule "$TRAVERSAL >= 4" BLOCK; CheckRule "$EVADE >= 4" BLOCK; CheckRule "$XSS >= 8" BLOCK; #naxsi 日记文件 error_log /.../foo.log; ... } error_page 500 502 503 504 /50x.html; #This is where the blocked requests are going location = /50x.html { return 418; #I'm a teapot \o/ }[/code]6.2、测试测试 nginx 配置 [code]/nginx/sbin/nginx -t nginx: the configuration file /nginx/conf/nginx.conf syntax is ok nginx: configuration file /nginx/conf/nginx.conf test is successful [/code]重启 nginx [code]service nginx reload[/code]6.3、防御测试欣赏器中打开 http://www.test.com/?a=<>‘ ,出现 403 错误,并且在 foo.log 中出现 NAXSI_FMT 开头的日记。恭喜你 Naxsi 启用成功。 6.4、白名单规则Naxsi 社区提供了一些常用的白名单规则,例如 wordpress 。可以在 https://github.com/nbs-system/naxsi-rules下载白名单规则。 然后将规则 include 到 server 内的 location 中。重启 nginx 即可。不过目前这些白名单最近的修改日期有点久了~.~ ,可根据自身必要添加白名单规则。 详细的白名单规则以及 Naxsi 其他支持,可参考 Naxsi WIKI。 到此这篇关于Nginx安装配置naxsi waf防火墙的方法实现的文章就先容到这了,更多相干Nginx安装配置naxsi waf防火墙内容请搜索脚本之家以前的文章或继续欣赏下面的相干文章渴望各人以后多多支持脚本之家! 来源:https://www.jb51.net/server/326341053.htm 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
|手机版|小黑屋|梦想之都-俊月星空
( 粤ICP备18056059号 )|网站地图
GMT+8, 2025-7-1 18:09 , Processed in 0.031275 second(s), 18 queries .
Powered by Mxzdjyxk! X3.5
© 2001-2025 Discuz! Team.