当前位置: 首页 > news >正文

基于openresty waf二次开发多次匹配到的ip再做拉黑

我们想在openresty waf的基础上做二次开发,比如再精确一些。比如我们先匹配到了select的url我们先打分10分,匹配到cc 1000/s我们再给这个ip打10分…直到100分我们就拉黑这个ip。

[openresty waf][1]

#cat reids_w.lua
require 'lib'
local redis = require "resty.redis"
function redis_hash_ip(white)local red = redis:new()local ok, err = red:connect("192.168.14.66", 6379)if not ok thenngx.log(ngx.ERR, "Failed to connect to Redis: ", err)return false, "Failed to connect to Redis"end-- 认证Redis-- local res, err = red:auth("123456lzx")-- if not res then--   ngx.log(ngx.ERR, "Failed to authenticate Redis: ", err)--   return false, "Failed to authenticate Redis"-- end-- 检查列表中是否已存在要添加的值local exists, err = red:lrange(get_client_ip(), 0, -1)if exists thenfor _, v in ipairs(exists) doif v == white then-- 如果要添加的值已经存在于列表中,则直接返回red:set_keepalive(10000, 100)return true, nilendendend-- 如果要添加的值不存在于列表中,则将其添加到列表头部local res, err = red:lrem(get_client_ip(), 0, white)if res < 0 thenngx.log(ngx.ERR, "Failed to remove value from Redis list: ", err)return false, "Failed to remove value from Redis list"endlocal success, err = red:lpush(get_client_ip(), white)if not success thenngx.log(ngx.ERR, "Failed to set value in Redis lpush: ", err)return false, "Failed to set value in Redis lpush"end-- 关闭Redis连接red:set_keepalive(10000, 100)return true, nil
endfunction redis_select()local red = redis:new()local ok, err = red:connect("192.168.14.66", 6379)if not ok thenngx.log(ngx.ERR, "Failed to connect to Redis: ", err)return ngx.exit(500)endlocal res, err = red:lrange(get_client_ip(), 0, -1)if not res thenreturn nil, "Failed to query Redis list: " .. errelsefor _, v in ipairs(res) dongx.log(ngx.INFO, "List value: ", v)endend-- 关闭 Redis 连接(重用连接池中的连接)red:set_keepalive(10000, 100)return res, nilend

![2023-11-03T08:07:54.png][2]

![2023-11-03T08:08:20.png][3]

![2023-11-03T09:17:30.png][4]

请求url触犯代码

http://192.168.14.66 一分钟多访问一些,触发cc
http://192.168.14.66/.bash_history/ 触发url
...

查看redis里面是否写入数据,这是存得list数据,用ip做的name,然后那些触发得规则放在一个list里面。

![2023-11-03T09:12:30.png][5]

查看日志查出来的结果

![2023-11-03T09:15:45.png][6]

然后我们就可以根据redis里面的客户ip做打分机制,当然这只是一个基础版本

http://www.lryc.cn/news/217190.html

相关文章:

  • 新一代构建工具Vite-xyphf
  • Flink源码解析三之执行计划⽣成
  • Flutter 常见错误记录总结
  • [ASP]校无忧在线报名系统 v2.1
  • 【Hydro】部分基流分割方法及程序代码说明
  • C#Regex正则表达式(Regular Expression)
  • Wi-Fi还可以做什么?柯南解释IOT应用
  • centos部署java程序
  • Sqoop导入到Hive,Hive使用 HA
  • [笔记] %的含义
  • FRI及相关SNARKs的Fiat-Shamir安全
  • TensorFlow案例学习:使用 YAMNet 进行迁移学习,对音频进行识别
  • MySQL CHAR 和 VARCHAR 的区别
  • 虚拟机 ping: www.baidu.com:未知的名称或服务
  • 第二章 Python字符串处理
  • 混合编程 ATPCS规范及案例(汇编调用C、C调用汇编、内联汇编)
  • 使用Gorm进行CRUD操作指南
  • Linux0.11内核源码解析-exec.c
  • 百度竞价排名推广对比自然排名哪一个更具优势-华媒舍
  • python第一课 变量
  • shell之netstat的用法
  • MSQL系列(十二) Mysql实战-为什么索引要建立在被驱动表上
  • C语言,数据结构指针,结构构体操作符 •,->,*的区别,看这篇就够了
  • axios 多个baseURL配置、实现不同前缀代理到不同的服务器的几种方式
  • Diango项目-简易个人博客项目
  • 思维训练3
  • 初识FFmpeg
  • 分布式多主关系数据库的底线业务优势
  • JMM讲解
  • 小程序获取头像和昵称的思路