本站教程收集整理的这篇文章主要介绍了基于Nginx的Waf开源模块Naxsi:安装及验证,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。
目录
1.查看当前的Nginx版本及相关文件目录
2.下载Naxsi、Nginx源便宜香港vps代码、编译Nginx并替换Nginx可执行文件
3.新增Naxsi策略配置文件
4.修改Nginx配置及其http站点配置
5.验证配置是否生效
1.查看当前的Nginx版本及相关文件目录
? PS:本文登陆Ubantu是以非超管权限的账号登录的,所以命令前要加上sudo,然后输入超管密码即可以管理员权限操作(下同)。
sudo Nginx -v
- 确认当前Nginx版本为:
,即,1.17.10
- 确认当前Nginx的配置(Nginx.conf)位置,一般在Ubantu根目录下的etc/Nginx,即,/etc/niginx
- 确认当前Nginx可执行文件的位置(在第2步要被新编译完的Nginx替换),一般在Ubantu根目录下的usr/sbin(该目录下还包括各种其他程序的可执行文件),即,/usr/sbin
- 可以在Ubantu系统中,用以下命令查找Nginx文件和文件夹。
find / -name Nginx
?
2.下载Naxsi、Nginx源代码、编译Nginx并替换Nginx可执行文件
-
在宿主机win10下载Nginx-1.17.10版本的源代码(http://nginx.org/download/nginx-1.17.10.tar.gz),注意,必须与当前已经安装的Nginx版本一致。
-
在宿主机win10下载naxsi最新发布的版本的源代码(https://github.com/nbs-system/naxsi),在页面右侧找到
-
把源代码文件包从宿主机win10移动到虚拟机Ubantu系统中(移动文件的方法见:https://blog.csdn.net/u010046615/article/details/110135930),放在系统根目录的tmp文件夹下(即,/tmp/),并用tar命令进行解压缩,
tar zxvf Nginx-1.17.10.tar.gz tar zxvf naxsi-1.3.tar.gz
?
-
查看当前Nginx版本的详细配置参数(注意是大写的V):
sudo Nginx -V
打印:
Nginx version: Nginx/1.17.10 (Ubuntu) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/Nginx-Pmk9_C/Nginx-1.17.10=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_sourcE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -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-compat --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_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-mail=dynamic --with-mail_ssl_module
把打印的参数(configure arguments:)后面的全部内容拷贝存起来,PS:在编译时,在参数前面加上addmodule重新编译。
-
进入到Nginx-1.17.10源代码目录里
,使用以下命令重新配置Nginx:
./configure --add-module=/tmp/naxsi-1.3/naxsi_src/ --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/Nginx-Pmk9_C/Nginx-1.17.10=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_sourcE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -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-compat --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_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-mail=dynamic --with-mail_ssl_module
重点在于,在configure后(configure是一个系统脚本,用来配置源代码),加上以下语句,表示把naxsi的源代码也配进来。
--add-module=/tmp/naxsi-1.3/naxsi_src/
?
-
接着系统会开始Run脚本,可能run到一半会有问题,报错,例如:
,这说明当前系统找不到对应的依赖库.
? ? (图中的例子是Opensll lib库,其他库可以百度一下,大同小异),需要先安装。因此先执行安装语句:
sudo apt-get install libssl-dev
? ? ? ?然后重新执行上一步的./configure语句。如果还有其他库未安装,再继续执行sudo apt-get 进行安装。(如果有库找不到,可以考虑换软件源为清华大学或阿里云。)
-
配置成功后系统返回各种配置路径:
Configuration sumMary + using threads + using system PCRE library + using system OpenSSL library + using system zlib library Nginx path prefix: "/usr/share/Nginx" Nginx binary file: "/usr/share/Nginx/sbin/Nginx" Nginx modules path: "/usr/lib/Nginx/modules" Nginx configuration prefix: "/etc/Nginx" Nginx configuration file: "/etc/Nginx/Nginx.conf" Nginx pid file: "/run/Nginx.pid" Nginx error log file: "/var/log/Nginx/error.log" Nginx http access log file: "/var/log/Nginx/access.log" Nginx http client request body temporary files: "/var/lib/Nginx/body" Nginx http proxy temporary files: "/var/lib/Nginx/proxy" Nginx http fastcgi temporary files: "/var/lib/Nginx/fastcgi" Nginx http uwsgi temporary files: "/var/lib/Nginx/uwsgi" Nginx http scgi temporary files: "/var/lib/Nginx/scgi"
?
-
接着执行编译语句,
@H_682_37@make
?编译完成后最后返回,其中包括了Nginx配置和Nginx错误日志的文件的路径:
sed -e "s|%%PREFIX%%|/usr/share/Nginx|" \ -e "s|%%PID_PATH%%|/run/Nginx.pid|" \ -e "s|%%CONF_PATH%%|/etc/Nginx/Nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/var/log/Nginx/error.log|" \ < man/Nginx.8 > objs/Nginx.8 make[1]: Leaving directory '/tmp/Nginx-1.17.10'
?
-
将Naxsi的核心规则模块拷贝到Nginx配置目录中:
sudo cp naxsi_core.rules /etc/Nginx/naxsi_core.rules
?
-
在/tmp/Nginx-1.17.10/objs目录下,把刚编译好的Nginx可执行文件替换掉原有的Nginx可执行文件(保险起见,可以先把原有的可执行程序Nginx备份后,再替换):
sudo cp Nginx /usr/sbin/
?
-
完成以上步骤,再次执行Nginx -V,会发现新的配置已生效:
?
3.新增Naxsi策略配置文件
- 进入/etc/Nginx/目录,新建防护策略文件:mysite.rules? , 其内容为:
#LearningMode; #Enables learning mode SecrulesEnabled; ##Secrulesdisabled; DeniedUrl "/403.html"; ### check rules checkRule "$sql >= 8" BLOCK; checkRule "$RFI >= 8" BLOCK; checkRule "$TRAVERSAL >= 4" BLOCK; checkRule "$EVADE >= 4" BLOCK; checkRule "$XSS >= 8" BLOCK;
其中,SecrulesEnabled,表示开启WAF防护;DeniedUrl,表示策略生效后,指向的Url的位置,相对位置,相对当前目录(/etc/Nginx/)。
-
其他规则可查询:https://github.com/nbs-system/naxsi/wiki
4.修改Nginx配置及其http站点配置
?
5.验证防护策略的配置是否生效
本站总结
以上是本站教程为你收集整理的基于Nginx的Waf开源模块Naxsi:安装及验证全部内容,希望文章能够帮你解决基于Nginx的Waf开源模块Naxsi:安装及验证所遇到的程序开发问题。
如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。