用於非法掃描漏洞的程序,根據用戶返回代碼,靈活設計,有效防護。lua
lua_shared_dict dogs 10m;
init_by_lua_block{
dogs=ngx.shared.dogs
}
設計
rewrite_by_lua_block
{
local function deny_scan()
ngx.ctx.check_ip=ngx.md5(ngx.var.host..ngx.var.binary_remote_addr..ngx.var.http_User_Agent)
if dogs:get(ngx.ctx.check_ip) == nil then
dogs:set(ngx.ctx.check_ip,0,60) --默認60秒能夠加大
elseif dogs:get(ngx.ctx.check_ip) >10 then --容許10次
dogs:flush_expired()
ngx.exit(503)
end
endip
}md5
log_by_lua_block
{
if (dogs:get(ngx.ctx.check_ip) <11) and ngx.status == 403 then
dogs:incr(ngx.ctx.check_ip,1)
end
}
rem