ngx_lua_waf是一個基于lua-nginx-module(openresty)的web應用防火墻
下載資源
1.下載 luajit
2.下載 ngx_devel_kit
3.下載 ngx_lua
4.下載 nginx
5.下載 ngx_lua_waf-
編譯安裝 luajit 官網地址
make PREFIX=/usr/local/luajit make install PREFIX=/usr/local/luajit
-
編譯不安裝nginx
wget 'http://nginx.org/download/nginx-1.13.6.tar.gz' tar -xzvf nginx-1.13.6.tar.gz cd nginx-1.13.6/ # tell nginx's build system where to find LuaJIT 2.0: export LUAJIT_LIB=/path/to/luajit/lib export LUAJIT_INC=/path/to/luajit/include/luajit-2.0 # tell nginx's build system where to find LuaJIT 2.1: export LUAJIT_LIB=/path/to/luajit/lib export LUAJIT_INC=/path/to/luajit/include/luajit-2.1 # or tell where to find Lua if using Lua instead: #export LUA_LIB=/path/to/lua/lib #export LUA_INC=/path/to/lua/include # Here we assume Nginx is to be installed under /opt/nginx/. ./configure --prefix=/opt/nginx \ --with-ld-opt="-Wl,-rpath,/path/to/luajit-or-lua/lib" \ --add-module=/path/to/ngx_devel_kit \ --add-module=/path/to/lua-nginx-module # Note that you may also want to add `./configure` options which are used in your # current nginx build. # You can get usually those options using command nginx -V # you can change the parallism number 2 below to fit the number of spare CPU cores in your # machine. make -j2 copy objs/nginx /usr/sbin/nginx
-
使用ngx_lua_waf
- 把ngx_lua_waf下載到nginx/conf目錄下,解壓命名為waf
- 在nginx.conf的http段添加
lua_package_path "/etc/nginx/conf/waf/?.lua"; lua_shared_dict limit 10m; init_by_lua_file /etc/nginx/conf/waf/init.lua; access_by_lua_file /etc/nginx/conf/waf/waf.lua;
- 配置config.lua里的waf規(guī)則目錄(一般在waf/conf/目錄下)
RulePath = "/etc/nginx/conf/waf/wafconf/"
-
配置文件說明:
RulePath = "/usr/local/nginx/conf/waf/wafconf/" --規(guī)則存放目錄 attacklog = "off" --是否開啟攻擊信息記錄蜘渣,需要配置logdir logdir = "/usr/local/nginx/logs/hack/" --log存儲目錄,該目錄需要用戶自己新建倔监,切需要nginx用戶的可寫權限 UrlDeny="on" --是否攔截url訪問 Redirect="on" --是否攔截后重定向 CookieMatch = "on" --是否攔截cookie攻擊 postMatch = "on" --是否攔截post攻擊 whiteModule = "on" --是否開啟URL白名單 black_fileExt={"php","jsp"} --填寫不允許上傳文件后綴類型 ipWhitelist={"127.0.0.1"} --ip白名單,多個ip用逗號分隔 ipBlocklist={"1.0.0.1"} --ip黑名單现诀,多個ip用逗號分隔 CCDeny="on" --是否開啟攔截cc攻擊(需要nginx.conf的http段增加lua_shared_dict limit 10m;) CCrate = "100/60" --設置cc攻擊頻率,單位為秒. --默認1分鐘同一個IP只能請求同一個地址100次 html=[[Please go away~~]] --警告內容,可在中括號內自定義 備注:不要亂動雙引號,區(qū)分大小寫
-
重啟nginx之后毛萌,可以嘗試如下命令:
curl http://xxxx/test.php?id=../etc/passwd
返回"Please go away~~"字樣航闺,說明規(guī)則生效褪测。