概述
针对HTTP/HTTPS的安全策略为web应用提供保护的产品,承担了sql注入,xss,远程命令执行,目录遍历等攻击的抵抗,是守护安全的第一道防线
优点
- 使用,配置简单方便
- 能够抵抗常见的扫描和常见的漏洞测探
缺点
- 防护能力不足以对抗黑产,依赖规则,针对未知攻击无应对方法,容易绕过
- 无法承担基础业务安全能力,比如褥羊毛行为,刷短信接口等
- 审计能力不足,出现事故无法提取较为详细的事件log记录等等
配置一个简单的WAF
以unixhot的WAF为例,进行分析,其代码的架构如下

其中access.lua有一堆的check函数,分别来自init.lua文件。
1 2 3 4 5
| init.lua文件分别从config.lua和lib.lua文件中取得: 规则开关 +解析用户请求数据 +自己定义的正则规则 =决定该请求是否为合法请求
|
OpenResty
基于nginx与lua的高性能web平台,内部集成了大量精良的nginx模块,用于方便的搭建超高并发和拓展性极高的web应用,web服务和动态网管
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| # 安装
Debian 和 Ubuntu 用户 推荐您使用 apt-get安装以下的开发库:
apt-get install libpcre3-dev \ libssl-dev perl make build-essential curl Fedora 和 RedHat 用户 推荐您使用yum安装以下的开发库:
yum install pcre-devel openssl-devel gcc curl
./configure 然后在进入 openresty-VERSION/ 目录, 然后输入以下命令配置:
./configure 默认, --prefix=/usr/local/openresty 程序会被安装到/usr/local/openresty目录。
您可以指定各种选项,比如
./configure --prefix=/opt/openresty \ --with-luajit \ --without-http_redis2_module \ --with-http_iconv_module \ --with-http_postgres_module make 或者make -j2 (双核编译)
sudo make install
|
waf
https://github.com/unixhot/waf.git
配置反向代理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| # openresty http{ ... lua_shared_dict limit 50m; lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua"; init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua"; access_by_lua_file "/usr/local/openresty/nginx/conf/waf/access.lua"; } include "/usr/local/openresty/nginx/conf/www.testwaf.com.conf";
./nginx -s reload
# www.testwaf.com.conf upstream testwaf{ server 192.168.1.12:80; } server { listen 80; server_name www.testwaf.com; location / { proxy_pass: http://testwaf; index index.html index.htm; } }
# 最好使用root权限安装
|
一切安装好以后,效果如下:

Reference
https://openresty.org/cn/
https://openresty.org/cn/installation.html