欢迎光临
我们一直在努力

nginx_lua_waf安装测试

ngx_lua_waf是一个基于lua-nginx-module(openresty)的web应用防火墙,对于中小企业或不愿购置硬件防火墙的企业的首选,能有效保证网站的安全性。

源码:https://github.com/loveshell/ngx_lua_waf


0x1  安装部署

系统版本:Centos7 x86_64

安装依赖包

yum install -y readline-devel pcre-devel openssl-devel

1、openresty的安装配置

cd /usr/local/src

wget https://openresty.org/download/openresty-1.9.15.1.tar.gz

tar -zxvf openresty-1.9.15.1.tar.gz

cd openresty-1.9.15.1

./configure –prefix=/usr/local/openresty-1.9.15.1 –with-luajit –with-http_stub_status_module –with-pcre –with-pcre-jit

gmake && gmake install

ln -s /usr/local/openresty-1.9.15.1/ /usr/local/openresty

测试启动nginx

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

成功启动nginx显示如下

nginx: the configuration file /usr/local/openresty-1.9.15.1/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/openresty-1.9.15.1/nginx/conf/nginx.conf test is successful

启动nginx

/usr/local/openresty/nginx/sbin/nginx

2、配置nginx_lua_waf

git clone https://github.com/loveshell/ngx_lua_waf.git

将git获取的文件放到nginx的conf目录下

在nginx.conf的http段添加

lua_package_path “/usr/local/openresty/nginx/conf/ngx_lua_waf/?.lua”;

lua_shared_dict limit 10m;

init_by_lua_file /usr/local/openresty/nginx/conf/ngx_lua_waf/init.lua;

access_by_lua_file /usr/local/openresty/nginx/conf/ngx_lua_waf/waf.lua;

配置config.lua里的waf规则目录(一般在ngx_lua_waf/wafconf/目录下)

RulePath = “/usr/local/openresty/nginx/conf/ngx_lua_waf/wafconf”

attacklog = “on”

logdir = “/usr/local/nginx/logs/waf”

 

3、waf日志配置

#将nginx.conf首行的”# user nobody;”的”#”注释去掉,重新启动nginx服务
user nobody
#将防护日志目录所属user和group修改为nobody,目录权限可设为700也可以写入,当然也可以默认

cd /usr/local/nginx/conf

//chown -R nobay.nobady waf

//chmod 700 waf

因为nginx、php模块等是单独安装的,所以每次重启服务器都需要重启相应的服务

启动nginx

cd  /usr/local/openresty/nginx/sbin

./nginx   (不关闭nginx而重新加载配置文件   ./nginx  -t)

0x2  nginx_lua_waf测试

启动php

直接执行/usr/sbin/php-fpm

测试SQL注入漏洞

测试结果

测试任意文件读取

进行CC***测试

通过查看waf_logs可以看到waf拦截的所有的***操作

通过waf_logs可以看到无论是sql注入、任意文件读取还是CC***都被成功的拦截,waf的部署是成功可靠的!

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。