uuWAF/rules/anti-cc.lua

33 lines
759 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
2022-09-22 09:17:40 +00:00
local sh = ngx.shared.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-09-23 14:07:33 +00:00
sh:set(ccIp, 1, 60, 1) -- 设置1分钟也就是60秒访问计数时间
else
2022-09-22 09:27:05 +00:00
if f == 2 then
2022-09-23 14:13:35 +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-09-23 14:07:33 +00:00
if c + 1 >= 360 then
2022-09-23 14:08:47 +00:00
sh:set(ccIp, c + 1, 300, 2) -- 设置5分钟也就是300秒拦截时间
2022-09-23 14:13:35 +00:00
return true, ccIp, true
end
end
2022-09-22 09:17:40 +00:00
return false