1 Star 7 Fork 1

克莱里昂/cls_lua_waf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
access.lua 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
cls-company 提交于 2年前 . init
-- g_config 为全局变量,直接用
local ccutil = require 'lib.ccutil'
ccutil.init()
-- CC检测命中返回true, 未开启CC检测功能/CC检测未命中,返回false
function cc_check(ip)
if g_config.cc_check == 'on' then
if ccutil.ip_exist(ip) then
return true
else
-- 请求URI(不含args)
local uri = ngx.var.uri
-- 防止uri过长在存储时出现意外情况,在此md5
local token = g_cctoken_prefix..ip..':'..ngx.md5(uri)
local res = ccutil.get(token)
if res ~= nil then
local token_count = tonumber(res)
if token_count >= g_cc_count then
ccutil.set_ip(ip, g_config.cc_ip_lock_time)
return true
else
ccutil.incr(token)
end
else
ccutil.set(token, 1, g_cc_duration)
end
end
end
return false
end
if g_config.waf_enable == "on" then
local ip = g_util.get_client_ip()
local ua = g_util.get_user_agent()
local uri = ngx.var.uri
-- ngx.log(ngx.ALERT,' ip:::'..ip)
if ip_white_check(ip) then
-- 白名单命中(啥也不做,直接放行)
-- ngx.log(ngx.ALERT,' access 白名单命中:'..ip)
elseif ip_black_check(ip) then
-- 黑名单命中
-- ngx.log(ngx.ALERT,'黑名单命中:'..ip)
g_util.deny_exit(g_config.ip_black_deny_return)
elseif user_agent_white_check(ua) then
-- UA白名单命中(啥也不做,直接放行)
-- ngx.log(ngx.ALERT,' UA白名单命中:'..ua)
elseif ip_foreign_check(ip) then
-- 境外IP命中
-- ngx.log(ngx.ALERT,'境外IP命中:'..ip)
g_util.deny_exit(g_config.ip_foreign_deny_return)
elseif user_agent_check(ua) then
-- user-agent命中
-- ngx.log(ngx.ALERT,'UA命中:'..g_util.get_user_agent())
g_util.deny_exit(g_config.user_agent_deny_return)
elseif cc_check(ip) then
-- CC命中
-- ngx.log(ngx.ALERT,'CC命中:')
g_util.deny_exit(g_config.cc_deny_return)
elseif url_white_check(uri) then
-- URL白名单命中(啥也不做,直接放行)
-- ngx.log(ngx.ALERT,'URL白名单命中:'..uri)
elseif url_check(uri) then
-- URL命中
-- ngx.log(ngx.ALERT,'URL命中:'..uri)
g_util.deny_exit(g_config.url_deny_return)
elseif args_check() then
-- args命中
-- ngx.log(ngx.ALERT,'args命中')
g_util.deny_exit(g_config.args_deny_return)
elseif cookie_check() then
-- cookie命中
-- ngx.log(ngx.ALERT,'cookie命中')
g_util.deny_exit(g_config.cookie_deny_return)
elseif post_check() then
-- post命中
-- ngx.log(ngx.ALERT,'post命中')
g_util.deny_exit(g_config.post_deny_return)
end
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Lua
1
https://gitee.com/chleniang/cls_lua_waf.git
git@gitee.com:chleniang/cls_lua_waf.git
chleniang
cls_lua_waf
cls_lua_waf
master

搜索帮助