ngx_lua_wafweb应用防火墙

ngx_lua_wafweb应用防火墙

ngx_lua_waf是一个基于lua-nginx-module(openresty)的web应用防火墙。

waf的作用:

防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击
防止svn/备份之类文件泄漏
防止ApacheBench之类压力测试工具的攻击
屏蔽常见的扫描黑客工具,扫描器
屏蔽异常的网络请求
屏蔽图片附件类目录php执行权限
防止webshell上传

1、安装openresty

见博客:openresty(nginx扩展)实现防cc攻击

2、下载开源项目ngx_lua_waf:

1
2
cd /opt/openresty/nginx/
git clone https://github.com/loveshell/ngx_lua_waf.git

3、修改nginx添加配置,支持lua脚本地址

在http段位置:

1
2
3
4
lua_package_path "/opt/openresty/nginx/ngx_lua_waf/?.lua";  ###相关项目存放地址
lua_shared_dict limit 10m; ###存放limit表的大小
init_by_lua_file /opt/openresty/nginx/ngx_lua_waf/init.lua; ###相应地址
access_by_lua_file /opt/openresty/nginx/ngx_lua_waf/waf.lua; ##相应地址

4、修改ngx_lua_waf相关配置:

vim config.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
RulePath = "/opt/openresty/nginx/ngx_lua_waf/wafconf/"  ##指定相应位置
attacklog = "on" ##开启日志
logdir = "/opt/openresty/nginx/logs/hack/" ##日志存放位置
UrlDeny="on" ##是否开启URL防护
Redirect="on" ##地址重定向
CookieMatch="on" ##cookie拦截
postMatch="on" ##post拦截
whiteModule="on" ##白名单
black_fileExt={"php","jsp"}
ipWhitelist={"127.0.0.1"} ##白名单IP
ipBlocklist={"1.0.0.1"} ##黑名单IP
CCDeny="on" ##开启CC防护
CCrate="100/60" ##60秒内允许同一个IP访问100次

5、创建日志存放目录:

1
2
mkdir /opt/openresty/nginx/logs/hack/
chown -R nobody:nobody /opt/openresty/nginx/logs/hack/

6、启动nginx测试:

1
/opt/openresty/nginx/sbin/nginx

7、网页访问一条测试:

8、压力测试CC攻击:

把congfig.lua的频率改成如下:

1
2
CCDeny="on"
CCrate="50/60"

测试结果:

1
ab -c 100 -n 100 http://192.168.63.242/index.heml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.63.242 (be patient).....done

Server Software: openresty/1.11.2.2
Server Hostname: 192.168.63.242
Server Port: 80
Document Path: /index.heml
Document Length: 2078 bytes
Concurrency Level: 100
Time taken for tests: 0.052 seconds
Complete requests: 100
Failed requests: **49** ##因为做了现在,所以这么多是失败的。

https://www.cnblogs.com/hk315523748/p/6150560.html

-------------本文结束-------------
0%