uuWAF/rules/anti-cc.lua

33 lines
961 B
Lua
Raw Normal View History

--[[
: anti cc
:
:
: 访/api/3605ip访
--]]
2022-09-21 00:32:01 +00:00
if not waf.startWith(waf.toLower(waf.uri), "/api/") then
return false
end
2024-01-05 15:03:08 +00:00
local sh = waf.ipCache
2022-09-22 09:27:05 +00:00
local ccIp = 'cc-' .. waf.ip
local c, f = sh:get(ccIp)
if not c then
2022-10-12 05:05:43 +00:00
sh:set(ccIp, 1, 60, 1) -- 设置1分钟也就是60秒访问计数时间
else
2022-09-22 09:27:05 +00:00
if f == 2 then
2022-10-12 05:05:43 +00:00
return waf.block(true) -- 重置TCP连接不记录日志
2022-09-22 09:17:40 +00:00
end
2022-09-22 09:27:05 +00:00
sh:incr(ccIp, 1)
2022-10-12 05:05:43 +00:00
if c + 1 >= 360 then -- 频率超过360次
2022-09-23 14:08:47 +00:00
sh:set(ccIp, c + 1, 300, 2) -- 设置5分钟也就是300秒拦截时间
2022-10-12 05:06:36 +00:00
return true, ccIp, true -- 返回参数第一个true为是否检测到第二个参数ccIp为日志记录内容第三个参数true表示拦截false表示只记录不拦截
end
end
2022-09-22 09:17:40 +00:00
return false