# waf
**Repository Path**: bigberg/waf
## Basic Information
- **Project Name**: waf
- **Description**: 应用和参考https://github.com/unixhot/waf
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2023-08-31
- **Last Updated**: 2024-10-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
OPENRESTY WAF
### 功能列表
- 支持IP白名单和黑名单功能,直接将黑名单的IP访问拒绝。
- 支持URL白名单,将不需要过滤的URL进行定义。
- 支持User-Agent的过滤,匹配自定义规则中的条目,然后进行处理(返回403)。
- 支持CC攻击防护,单个URL指定时间的访问次数,超过设定值,直接返回403。
- 支持Cookie过滤,匹配自定义规则中的条目,然后进行处理(返回403)。
- 支持URL过滤,匹配自定义规则中的条目,如果用户请求的URL包含这些,返回403。
- 支持URL参数过滤,原理同上。
- 支持日志记录,将所有拒绝的操作,记录到日志中去。
- 日志记录为JSON格式,便于日志分析,例如使用ELK进行攻击日志收集、存储、搜索和展示。
### 安装部署
#### 安装依赖组件
```
yum install gcc-c++ libtool gmake make -y
yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel readline readline-devel -y
```
#### 创建nginx用户和组
```
groupadd nginx
usradd -g nginx -s /sbin/nologin -M nginx
```
#### 下载和编译openresty
```
wget https://openresty.org/download/openresty-1.21.4.2.tar.gz
tar -zxvf openresty-1.21.4.2.tar.gz
cd openresty-1.21.4.2
./configure --prefix=/usr/local/openresty \
--sbin-path=/usr/local/openresty/nginx/sbin/nginx \
--conf-path=/usr/local/openresty/nginx/conf/nginx.conf \
--pid-path=/usr/local/openresty/nginx/run/nginx.pid \
--error-log-path=/usr/local/openresty/nginx/logs/error.log \
--http-log-path=/usr/local/openresty/nginx/logs/access.log \
--user=nginx \
--group=nginx \
--with-pcre \
--with-stream \
--with-threads \
--with-file-aio \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
gamke && gmake install
```
#### 为openresty 添加环境变量
```
vim /etc/profile.d/openresty.sh
export PATH=/usr/local/openresty/bin:$PATH
```
#### 测试是否安装成功
vim default.conf
```
location /hello {
default_type text/html;
content_by_lua_block {
ngx.say("hello, world
")
}
}
```
测试访问
```
curl http://127.0.0.1/hello
```
### WAF部署
```
git clone https://gitee.com/bigberg/waf.git
cp -r ./waf/waf /usr/local/openresty/nginx/conf
vim /usr/local/openresty/nginx/conf/nginx.conf
在 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";
```
将core.lua 放到waf目录下
```
ln -s /usr/local/openresty/lualib/resty/ /usr/local/openresty/nginx/conf/waf/resty
openresty -t
openresty -s reload
```