Commit 60728c40 by CnChunfeng

修改判断

parent eb61fcc1
Showing with 48 additions and 46 deletions
......@@ -21,6 +21,7 @@ local cjson = require "cjson"
-------去除一些不要验证的请求并获取url
local urlok,temp_uri = reqhandle.Selfwhiteurl()
......@@ -29,7 +30,6 @@ if urlok == "ok" then
end
-------链接redis------------
red = redis:new()
red:set_timeout(1000)
......@@ -57,6 +57,11 @@ if config.redis_auth ~= "" and ok then
end
-------测试的地方start
-------测试的地方end
......@@ -136,71 +141,68 @@ if pageNum ~= nil and tonumber(pageNum) >= 50 then
red:sadd('ichunt_waf_black_ip',user_ip)
end
-------s------------------------20230630新增对m.ichunt.com特殊处理-------s------------------------
--如果在检测的路由中则继续
if temp_uri == '/v3/api/common/data' and tonumber(ngx.var.waf_type) == 2 then
--获取对应的时间和次数
checkuricount = 5
checkuritime = 4
checkuriip = 'waf_urldesc_limit_'..user_ip
--如果不存在则设为1
if red:get(checkuriip) == ngx.null then
red:set(checkuriip,0)
end
--自增1 设置超时时间
red:incr(checkuriip)
red:expire(checkuriip , checkuritime)
-------s------------------------20230707新增正则匹配-------s------------------------
--[[
1 获取对应waf_type的正则集合
2 拿对应站点的正则去一个个尝试,如果成功,则获取对应站点,对应正则,对应匹配的值去获取限制数量和时间
--]]
--查找到当前站点下waf_type所有的正则
platform_pattern_reids_key = 'waf_urldesc_limit_pattern_'..ngx.var.waf_type
allPattern,err = red:smembers(platform_pattern_reids_key)
if err == nil then
--如果存在则循环匹配
for k,pattern in ipairs(allPattern) do
--检测出来的值和已经保存了的当前站点正则值进行对比
checkuri,err = string.match(temp_uri, pattern)
--对比成功之后继续下一步操作
if checkuri ~= nil and red:sismember(platform_pattern_reids_key..'_value_'..pattern, checkuri) ~= 0 then
--获取对应的时间和次数
checkuricount = tonumber(red:get(platform_pattern_reids_key..'_count_'..checkuri))
checkuritime = tonumber(red:get(platform_pattern_reids_key..'_time_'..checkuri))
checkuriip = 'waf_urldesc_limit_'..user_ip
--如果不存在则设为1
if red:get(checkuriip) == ngx.null then
red:set(checkuriip,0)
end
--自增1 设置超时时间
red:incr(checkuriip)
red:expire(checkuriip , checkuritime)
--如果超过次数就跳转至google验证页面,并且带上网址
if tonumber(red:get(checkuriip)) > checkuricount then
redirect.checkgoogle(red)
end
end
--如果超过次数就跳转至google验证页面,并且带上网址
if tonumber(red:get(checkuriip)) > checkuricount then
redirect.checkgoogle(red)
end
end
-------e------------------------20230630新增对m.ichunt.com特殊处理-------e------------------------
-------e------------------------20230737新增正则匹配-------e------------------------
-------s------------------------20200923新增对用户特定URL,IP时间段内的限制-------s------------------------
--[[
1 设置需要的请求网址 redis 集合 waf_urldesc_limit
2 设置url对应的时间和次数控制 redis字符串 次数 waf_urldesc_limit_count_checkuri 时间 waf_urldesc_limit_time_checkuri
3 给每个需要记录的IP进行计数 redis字符串 waf_urldesc_limit_127.0.0.1
--]]
--获取请求的路由
checkuri,err = string.match(temp_uri, "%a+")
--如果在检测的路由中则继续
if tonumber(ngx.var.server_name_id) == 1 and checkuri ~= nil and red:sismember('waf_urldesc_limit', checkuri) ~= 0 then
--获取对应的时间和次数
checkuricount = tonumber(red:get('waf_urldesc_limit_count_'..checkuri))
checkuritime = tonumber(red:get('waf_urldesc_limit_time_'..checkuri))
checkuriip = 'waf_urldesc_limit_'..user_ip
--如果不存在则设为1
if red:get(checkuriip) == ngx.null then
red:set(checkuriip,0)
end
--自增1 设置超时时间
red:incr(checkuriip)
red:expire(checkuriip , checkuritime)
--如果超过次数就跳转至google验证页面,并且带上网址
if tonumber(red:get(checkuriip)) > checkuricount then
redirect.checkgoogle(red)
end
end
-------e------------------------20200923新增对用户特定URL,IP时间段内的限制-------e------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment