nginx + lua 防止扫描攻击

用于非法扫描漏洞的程序,根据用户返回代码,灵活设计,有效防护。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

相关文章
相关标签/搜索