openresty搭建网站防火墙

本文涉及的产品
Web应用防火墙 3.0,每月20元额度 3个月
简介: openresty搭建网站防火墙

在上一篇文章(diy 你的nginx-OpenResty)中,已经提到了如何安装一个openresty,现在我们可以通过开源项目 https://github.com/loveshell/ngx_lua_waf

实现一个简单的防火墙,例如:

当我提交一个 select * from 疑似 sql注入的参数时,则会直接被拦截

下载waf配置:

wget https://github.com/loveshell/ngx\_lua\_waf/archive/v0.7.2.tar.gz

解压文件并将

./config.lua,

./init.lua,

./waf.lua,

./wafconf/*

文件移动到你的项目目录

例如在上篇文章中的openrestyTest/config 目录:

\[root@tioncico-server openrestyTest\]# tree 
.
├── client\_body\_temp
├── conf
│   ├── nginx.conf
│   └── waf
│       ├── config.lua
│       ├── init.lua
│       ├── wafconf
│       │   ├── args
│       │   ├── cookie
│       │   ├── post
│       │   ├── url
│       │   ├── user-agent
│       │   └── whiteurl
│       └── waf.lua
├── index.php
├── logs
│   ├── access.log
│   ├── error.log
│   └── hack
│       └── xxx.easyswoole.cn\_2020-11-23\_sec.log

新增./log/hack/目录,并且将 ./conf/waf/config.lua里面的RulePath,logdir路径修改为正确路径

image.png

在nginx.conf中的http块中新增代码:

lua\_package\_path "/usr/local/openresty/lualib/?.lua;/www/wwwroot/homeTest/openrestyTest/conf/waf/?.lua";
lua\_shared\_dict limit 10m;
access\_by\_lua_file /www/wwwroot/homeTest/openrestyTest/conf/waf/waf.lua;
init\_by\_lua_file  /www/wwwroot/homeTest/openrestyTest/conf/waf/init.lua;

注意:lua_package_path,必须引入openresty安装目录的lualib,然后增加一个分号,引入当前项目的waf/?.lua,否则将会报错:

nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:

直接启动项目,在项目后面增加:  ?id=select%20*%20from%20information_schema

即可触发waf防护

目录
相关文章
|
缓存 应用服务中间件 网络安全
Nginx + Lua 搭建网站WAF防火墙
Nginx + Lua 搭建网站WAF防火墙目录: 前言1.在线安装1.1.修改yum源地址1.2.在线安装Nginx1.3.端口放行1.4.验证安装2.知识拓展2.1.编译参数2.2.安装目录2.3.
2934 0
|
8月前
|
运维 网络协议 安全
小白带你学习linux的防火墙
小白带你学习linux的防火墙
177 1
|
3月前
|
网络协议 安全 Linux
linux配置防火墙 Centos7下 添加 端口白名单
linux配置防火墙 Centos7下 添加 端口白名单
730 0
|
3月前
|
存储 安全 网络协议
使用 firewall-cmd 管理 Linux 防火墙端口
本文将介绍如何使用 firewall-cmd 工具在 Linux 系统中进行简单端口管理,包括开放、查询、关闭等操作。通过实例展示相关命令的用法,希望能对大家有所帮助。
434 0
|
24天前
|
网络协议 Linux 网络安全
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
在CentOS 7中,新引入了firewalld服务(防火墙),取代了CentOS 6之前的iptables服务(防火墙)。
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
|
2月前
|
网络协议 Java Linux
Linux常用操作命令、端口、防火墙、磁盘与内存
Linux常用操作命令、端口、防火墙、磁盘与内存
48 0
|
3月前
|
XML 安全 Linux
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
|
3月前
|
运维 程序员 Linux
运维最全Linux 基本防火墙设置和开放端口命令,2024年最新程序员如何自我学习和成长
运维最全Linux 基本防火墙设置和开放端口命令,2024年最新程序员如何自我学习和成长
|
3月前
|
XML 安全 Linux
Linux 防火墙开启端口
Linux 防火墙开启端口
64 1
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 如何关闭防火墙(开启管理员权限)
Linux 如何关闭防火墙(开启管理员权限)
40 0