本篇介绍在CentOS7.6上安装、测试使用ngx_lua_waf + openresty。

Preface

# yum install epel-release -y
# yum group install "Development Tools" -y    # 安装基本编译工具

安装Luagit

# cd /opt/
# wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
# tar -xvf LuaJIT-2.1.-beta3.tar.gz
# cd LuaJIT-2.1.-beta3/
# make && make install
# ln -sf luajit-2.1.-beta3 /usr/local/bin/luajit

安装OpenResty

安装依赖

# yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

下载安装

# cd /opt/
# wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
# tar -xvf openresty-1.13.6.1.tar.gz
# cd openresty-1.13.6.1/
# ./configure --prefix=/usr/local/openresty --with-luajit --with-http_stub_status_module --with-pcre --with-pcre-jit
# gmake && gmake install
# ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty
# /usr/local/openresty/bin/openresty   # 启动openresty
# netstat -lntp | grep 80 # 服务运行正常
tcp 0.0.0.0: 0.0.0.0:* LISTEN

配置ngx_lua_waf

下载

# cd /usr/local/openresty/nginx/conf                  # 到openresty配置文件目录
# git clone https://github.com/loveshell/ngx_lua_waf.git      # 下载
Cloning into 'ngx_lua_waf'...
# mv ngx_lua_waf/ waf/                           # 改个简单的名字

添加配置

修改openresty配置文件。

# vim /usr/local/openresty/nginx/conf/nginx.conf
...
user nobody; # 取消注释
...
http{ # 在http块下添加如下内
...
lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/openresty/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/openresty/nginx/conf/waf/waf.lua;

...

修改ngx_lua_waf配置

# cd /usr/local/openresty/nginx/conf/waf/     # ngx_lua_waf目录
# vim config.lua
...
RulePath = "/usr/local/openresty/nginx/conf/waf/wafconf/" # 规则文件路径
attacklog = "on" # 启用日志
logdir = "/usr/local/openresty/nginx/logs/hack/" # 日志目录
...

创建日志目录

# mkdir -p /usr/local/openresty/nginx/logs/hack/
# chown -R nobody:nobody /usr/local/openresty/nginx/logs/hack/

测试openresty配置是否正常:

# /usr/local/openresty/bin/openresty               # 如果没有启动服务,则启动
# /usr/local/openresty/bin/openresty -s reload # 如果已经启动,则重载配置
# /usr/local/openresty/bin/openresty -t # 测试配置是否正常
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

WAF测试

直接访问站点(此处为虚拟机的ip地址),应该能看到Openresty的欢迎页。

攻击测试

尝试目录遍历攻击,即使用../,跳转目录读取文件。

访问:http://192.168.139.139//test.php?id=../etc/passwd

提示,检测到攻击行为,请求被拦截,说明可以正常工作。

ngx_lua_waf配置文件说明

配置文件路径:/usr/local/openresty/nginx/conf/waf/config.lua

RulePath = "/usr/local/openresty/nginx/ngx_lua_waf/wafconf/"   ##指定相应位置
attacklog = "on" ##开启日志
logdir = "/usr/local/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次

参考

  centos下安装openresty+ngx_lua_waf防火墙部署

  https://github.com/loveshell/ngx_lua_waf

  https://blog.51cto.com/tar0cissp/1980249

注:参考链接中都有几个小问题,写的不够清晰。

OpenResty + ngx_lua_waf使用的更多相关文章

  1. openresty+lua劫持请求,有点意思

    0x01 起因 几天前学弟给我介绍他用nginx搭建的反代,代理了谷歌和维基百科. 由此我想到了一些邪恶的东西:反代既然是所有流量走我的服务器,那我是不是能够在中途做些手脚,达到一些有趣的目的. op ...

  2. OpenResty安装使用教程(CentOS 6)

    一.安装OpenResty Linux官方建议直接通过官方提供的预编译包安装:http://openresty.org/cn/linux-packages.html # 确保yum周边工具已经安装 y ...

  3. nginx安装ngx_lua_waf防护

    ngx_lua_waf基于ngx_lua的web应用防火墙,使用起来简单,高性能和轻量级. ♦防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击♦防止svn/备份之类 ...

  4. ngx_lua_waf

    Web应用防护系统Web Application Firewall,简称WAF.针对HTTP/HTTPS的安全策略专门为Web应用提供保护的产品. OpenResty是一个基于 Nginx 与 Lua ...

  5. Bypass ngx_lua_waf SQL注入防御(多姿势)

    0x00 前言 ​ ngx_lua_waf是一款基于ngx_lua的web应用防火墙,使用简单,高性能.轻量级.默认防御规则在wafconf目录中,摘录几条核心的SQL注入防御规则: select.+ ...

  6. 打破基于OpenResty的WEB安全防护(CVE-2018-9230)

    原文首发于安全客,原文链接:https://www.anquanke.com/post/id/103771 0x00 前言 ​ OpenResty® 是一个基于 Nginx 与 Lua 的高性能 We ...

  7. Openresty增加waf配置

    Openresty增加waf配置 1. Ngx lua waf 说明 防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击 防止svn/备份之类文件泄漏 防止Apach ...

  8. openresty+lua在反向代理服务中的玩法

    openresty+lua在反向代理服务中的玩法 phith0n · 2015/06/02 10:35 0x01 起因 几天前学弟给我介绍他用nginx搭建的反代,代理了谷歌和维基百科. 由此我想到了 ...

  9. 23. Bypass ngx_lua_waf SQL注入防御(多姿势)

    0x00 前言 ngx_lua_waf是一款基于ngx_lua的web应用防火墙,使用简单,高性能.轻量级.默认防御规则在wafconf目录中,摘录几条核心的SQL注入防御规则: select.+(f ...

随机推荐

  1. ContractPattern 面向面向契约模式

  2. FluentData -Micro ORM with a fluent API that makes it simple to query a database

    Code samples Create and initialize a DbContextThe connection string on the DbContext class can be in ...

  3. 西柚考勤系统——alpha2

    这个作业属于哪个课程 http://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业的要求在哪里 https://www.cn ...

  4. pku-3321 Apple Tree(dfs序+树状数组)

    Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow ...

  5. Jutil 单元测试

    eclipse 自身集成了jtuil,右击项目,点击bulidpath,addjar,如下所示添加jutil 新建一个Junit的测试类用来测试上面的测试方法,新增Junit的测试类方法如下: // ...

  6. iOS 利用UICollectionView做一个无限循环广告栏

    一.效果图 左右丝滑滑动,并且有缩放动画. 二.分析和思路 1. 为什么选择用UICollectionView去做上面的效果? 首先无限效果永远是表现出来的,而不是程序里面创建了无数个view,如何做 ...

  7. Druid入门(1)—— 快速入门实时分析利器-Druid_0.17

    一.安装准备 本次安装的版本是截止2020.1.30最新的版本0.17.0 软件要求 需要Java 8(8u92 +)以上的版本,否则会有问题 Linux,Mac OS X或其他类似Unix的操作系统 ...

  8. Linux文件和目录的属性及权限总结

    本文讲述的是文件或目录的属性及权限,比如索引节点inode.文件类型.文件权限及属主:还对setuid.setgid及粘贴位进行了相关的讲解.其中,对ln.chmod.chown.chgrp.umas ...

  9. 14、 NAT

    私有IP地址段:10.0.0.0-10.255.255.255/8172.16.0.0-172.31.255.255/12192.168.0.0-192.168.255.255/16 NAT的必要性: ...

  10. C++输出中文字符

    注:本文转载自互联网,感谢作者整理!   1. cout 场景1: 在源文件中定义 const char* str = "中文" 在 VC++ 编译器上,由于Windows环境用 ...