[fix] Update lib.lua
parent
6115198406
commit
ae2e365496
|
@ -16,7 +16,7 @@ local function waf_main()
|
|||
elseif cookie_attack_check() then
|
||||
elseif url_attack_check() then
|
||||
elseif url_args_attack_check() then
|
||||
elseif post_attack_check() then
|
||||
-- elseif post_attack_check() then
|
||||
else
|
||||
return
|
||||
end
|
||||
|
|
10
init.lua
10
init.lua
|
@ -160,6 +160,8 @@ function url_args_attack_check()
|
|||
for key, val in pairs(REQ_ARGS) do
|
||||
if type(val) == "table" then
|
||||
ARGS_DATA = string.lower(table.concat(val, " "))
|
||||
elseif type(val) == "boolean" then
|
||||
ARGS_DATA = nil
|
||||
else
|
||||
ARGS_DATA = string.lower(val)
|
||||
end
|
||||
|
@ -198,7 +200,7 @@ end
|
|||
|
||||
-- deny post
|
||||
function post_attack_check()
|
||||
if config_post_check == "on" then
|
||||
if config_post_check == "on" and ngx.var.request_method == "POST" then
|
||||
local POST_RULES = get_rule("post")
|
||||
for _,rule in pairs(POST_RULES) do
|
||||
-- local REQ_POST = ngx.req.get_post_args()
|
||||
|
@ -206,17 +208,19 @@ function post_attack_check()
|
|||
if err == "truncated" then
|
||||
log_record("Deny_POST_Many",ngx.var.request_uri,"-",rule)
|
||||
if config_waf_enable == "on" then
|
||||
waf_output()
|
||||
waf_output()
|
||||
return true
|
||||
end
|
||||
end
|
||||
for key, val in pairs(REQ_POST) do
|
||||
if type(val) == "table" then
|
||||
POST_DATA = string.lower(table.concat(val, " "))
|
||||
elseif type(val) == "boolean" then
|
||||
POST_DATA = nil
|
||||
else
|
||||
POST_DATA = string.lower(val)
|
||||
end
|
||||
if POST_DATA and type(POST_DATA) ~= "boolean" and rule ~="" and rulematch(unescape(POST_DATA),string.lower(rule),"jo") then
|
||||
if POST_DATA and rule ~="" and rulematch(unescape(POST_DATA),string.lower(rule),"jo") then
|
||||
log_record("Deny_POST",ngx.var.request_uri,"-",rule)
|
||||
if config_waf_enable == "on" then
|
||||
waf_output()
|
||||
|
|
24
lib.lua
24
lib.lua
|
@ -72,15 +72,25 @@ function log_record(method,url,data,ruletag)
|
|||
end
|
||||
|
||||
-- test log
|
||||
function write(logfile, msg)
|
||||
local fd,err = io.open(logfile,"a+")
|
||||
if fd == nil then
|
||||
ngx.log(ngx.ERR,"writefile msg : "..msg,err)
|
||||
function test_log_record(data)
|
||||
local cjson = require("cjson")
|
||||
local io = require "io"
|
||||
local LOG_PATH = config_log_dir
|
||||
local CLIENT_IP = get_client_ip()
|
||||
local LOCAL_TIME = ngx.localtime()
|
||||
local log_json_obj = {
|
||||
client_ip = CLIENT_IP,
|
||||
req_data = data,
|
||||
}
|
||||
local LOG_LINE = cjson.encode(log_json_obj)
|
||||
local LOG_NAME = LOG_PATH..'/'.."test.log"
|
||||
local file = io.open(LOG_NAME,"a")
|
||||
if file == nil then
|
||||
return
|
||||
end
|
||||
fd:write(msg)
|
||||
fd:flush()
|
||||
fd:close()
|
||||
file:write(LOG_LINE.."\n")
|
||||
file:flush()
|
||||
file:close()
|
||||
end
|
||||
|
||||
-- WAF return
|
||||
|
|
Loading…
Reference in New Issue