ngx_lua_waf改版,增加網段、UA、主機白名單等功能,修復了一些bug,項目地址:https://github.com/whsir/ngx_lua_waf
ngx_lua_waf改版基於ngx_lua_waf二次修改,增加了一些必要的功能,使用起來簡單,高性能和輕量級。
主要功能如下:
防止sql注入,本地包含,部分溢出,fuzzing測試,xss,SSRF等web攻擊
防止svn/備份之類文件泄漏
防止ApacheBench之類壓力測試工具的攻擊
屏蔽常見的掃描黑客工具,掃描器
屏蔽異常的網絡請求
屏蔽圖片附件類目錄php執行權限
防止webshell上傳
可以根據ip、網段、server_name、User-Agent做白名單
本文基於Centos7.x系統,關閉selinux,關閉防火牆(或自行設置規則)
想要使用ngx_lua_waf改版,首先要編譯Nginx增加lua模塊。
配置方法如下
1、安裝所需依賴
|
yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
|
2、下載ngx_devel_kit
|
cd /usr/local/src
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1rc1.tar.gz
tar xf v0.3.1rc1.tar.gz
|
3、下載lua-nginx-module
|
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz
tar xf v0.10.14.tar.gz
|
4、安裝luajit
|
wget https://github.com/openresty/luajit2/archive/v2.1-20190329.tar.gz
cd luajit2-2.1-20190329
make
make install
|
5、導入環境變量
|
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
|
6、編譯nginx模塊
|
useradd -s /bin/false -M www
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar xf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --add-module=/usr/local/src/ngx_devel_kit-0.3.1rc1 --add-module=/usr/local/src/lua-nginx-module-0.10.14 --with-ld-opt=-Wl,-rpath,$LUAJIT_LIB
make
make install
|
7、設置Nginx啓動服務
|
ln -sv /usr/local/nginx/sbin/nginx /usr/local/sbin/
wget -P /etc/init.d/ http://down.whsir.com/downloads/nginx
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
/etc/init.d/nginx start
|
8、下載ngx_lua_waf改版
|
cd /usr/local/nginx/conf
wget https://github.com/whsir/ngx_lua_waf/archive/v1.0.3.tar.gz
tar xf v1.0.3.tar.gz
mv ngx_lua_waf-1.0.3/ waf
|
9、在nginx.conf的http字段內添加以下內容
|
lua_package_path "/usr/local/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;
|
10、最後重啓nginx(reload也可以的)
|
/etc/init.d/nginx restart
|
11、驗證
訪問http://域名或IP地址/index.php?id=../etc/passwd
例如:http://192.168.157.132/index.php?id=../etc/passwd
看到503 Service Temporarily Unavailable則表示配置成功