天天看點

linux web應用防火牆,基于ngx_lua_waf子產品配置web應用防火牆

前言

ngx_lua_waf是一個基于lua-nginx-module(openresty)的web應用防火牆

1,用途:

防止sql注入,本地包含,部分溢出,fuzzing測試,xss,×××F等web***

防止svn/備份之類檔案洩漏

防止ApacheBench之類壓力測試工具的***

屏蔽常見的掃描***工具,掃描器

屏蔽異常的網絡請求

屏蔽圖檔附件類目錄php執行權限

防止webshell上傳

2,安裝配置

2.1下載下傳安裝 luajit

Luajit是一個C語言寫的lua解釋器。

#git clone http://luajit.org/git/luajit-2.0.git

#make  install PREFIX=/usr/local/luajit

# export LUAJIT_LIB=/usr/local/luajit/lib

# export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0 導出環境變量

# vim /etc/profile.d/luajit  添加全局環境變量export PATH=/usr/local/luajit/bin:$PATH

2.2下載下傳安裝ngx_devel_kit

Ngx_devel_kit是nginx的一個子產品,用來擴充nginx伺服器的核心功能,其他子產品可以在這個架構下更好的開發。

#/usr/local/soft/ngx_devel_kit 找到位置即可。

2.3下載下傳安裝下載下傳lua-nginx-module

#tar -zxvf v0.9.15.tar.gz

#/usr/local/soft/lua-nginx-module-0.9.15  解壓後找到位置即可

2.4重新編譯nginx,需要注意編譯順序--with-ld-opt="-Wl,-rpath, /usr/local/luajit/lib " \

--add-module=/usr/local/soft/ngx_devel_kit \

--add-module=/usr/local/soft/lua-nginx-module-0.9.15

以上luajit的lib,ngx_devel_kit,lua-nginx子產品隻主要添加的子產品。最後得到如下配置。#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

--error-log-path=/var/log/nginx/error.log

--http-log-path=/var/log/nginx/access.log

--pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock

--with-http_ssl_module --with-http_stub_status_module

--with-http_gzip_static_module --with-http_flv_module

--with-http_mp4_module

--http-client-body-temp-path=/var/tmp/nginx/client

--http-proxy-temp-path=/var/tmp/nginx/proxy

--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi

--with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib"

--add-module=/usr/local/soft/ngx_devel_kit

--add-module=/usr/local/soft/lua-nginx-module-0.9.15  && make

&&make install

安裝完成之後檢視版本:

[[email protected] nginx-1.7.10]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.7.10

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --user=nginx

--group=nginx --error-log-path=/var/log/nginx/error.log

--http-log-path=/var/log/nginx/access.log

--pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock

--with-http_ssl_module --with-http_stub_status_module

--with-http_gzip_static_module --with-http_flv_module

--with-http_mp4_module

--http-client-body-temp-path=/var/tmp/nginx/client

--http-proxy-temp-path=/var/tmp/nginx/proxy

--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi

--with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib

--add-module=/usr/local/soft/ngx_devel_kit

--add-module=/usr/local/soft/lua-nginx-module-0.9.15

2.3平滑重新開機nginx

#kill -HUP `cat /var/run/nginx/nginx.pid`

#/usr/local/nginx/sbin/nginx -s reload

2.4下載下傳之後後解壓,把ngx_lua_waf移動到nginx安裝目錄的conf目錄下,改名為waf

# mv ngx_lua_waf-master/  waf

在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;

2.5在conf.lua裡的waf規則目錄(/usr/local/nginx/conf/waf)

RulePath = "/usr/local/nginx/conf/waf/wafconf/"  注意規則配置檔案的路徑

重新開機nginx即可。

3.測試

測試waf防火牆配置 /?a=union select,證明攔截成功~ok.

linux web應用防火牆,基于ngx_lua_waf子產品配置web應用防火牆

[以上内容腳本一鍵安裝:

4.總結

Ngx_lua_waf安裝還算順利,在此需要注意的就是luajit(解釋器)->ngx_devel_kit(快速開的模

塊)->lua-nginx-module(子產品),luajit的需要編譯和指定安裝目錄,在後續nginx編譯子產品時候需要該參數。還有下載下傳好

的ngx_devel_kit和lua-nginx-module子產品,無需編譯隻需要下載下傳之後,找到路徑,然後編譯nginx的時候編譯進去即可。同時

建議使用nginx1.7版本。