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注入漏洞

f090a0947a33c0f226e924b861a481f9.png-wh_


測試結果

6abdacb3269720682b3e47d77a6398db.png-wh_


測試任意文件讀取

4fa86ef73f1a6993a4045bdabf39aea1.png-wh_


進行CC***測試

41cdfdb1dbcf7eedda1f53a595589ee8.png-wh_


通過查看waf_logs可以看到waf攔截的所有的***操作

909f018bed3c69a02e515cd117ae2aa0.jpg-wh_


通過waf_logs可以看到無論是sql注入、任意文件讀取還是CC***都被成功的攔截,waf的部署是成功可靠的!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章