[style] Update format

pull/13/head
oneinstack 2020-03-14 16:57:59 +08:00
parent ae2e365496
commit 7b238357ae
2 changed files with 32 additions and 32 deletions

View File

@ -119,8 +119,8 @@ function cookie_attack_check()
return true return true
end end
end end
end end
end end
end end
return false return false
end end
@ -149,14 +149,14 @@ function url_args_attack_check()
local ARGS_RULES = get_rule('args') local ARGS_RULES = get_rule('args')
for _,rule in pairs(ARGS_RULES) do for _,rule in pairs(ARGS_RULES) do
--local REQ_ARGS = ngx.req.get_uri_args() --local REQ_ARGS = ngx.req.get_uri_args()
local REQ_ARGS, err = ngx.req.get_uri_args() local REQ_ARGS, err = ngx.req.get_uri_args()
if err == "truncated" then if err == "truncated" then
log_record("Deny_URL_Args_Many",ngx.var.request_uri,"-",rule) log_record("Deny_URL_Args_Many",ngx.var.request_uri,"-",rule)
if config_waf_enable == "on" then if config_waf_enable == "on" then
waf_output() waf_output()
return true return true
end end
end end
for key, val in pairs(REQ_ARGS) do for key, val in pairs(REQ_ARGS) do
if type(val) == "table" then if type(val) == "table" then
ARGS_DATA = string.lower(table.concat(val, " ")) ARGS_DATA = string.lower(table.concat(val, " "))
@ -204,14 +204,14 @@ function post_attack_check()
local POST_RULES = get_rule("post") local POST_RULES = get_rule("post")
for _,rule in pairs(POST_RULES) do for _,rule in pairs(POST_RULES) do
-- local REQ_POST = ngx.req.get_post_args() -- local REQ_POST = ngx.req.get_post_args()
local REQ_POST, err = ngx.req.get_post_args() local REQ_POST, err = ngx.req.get_post_args()
if err == "truncated" then if err == "truncated" then
log_record("Deny_POST_Many",ngx.var.request_uri,"-",rule) log_record("Deny_POST_Many",ngx.var.request_uri,"-",rule)
if config_waf_enable == "on" then if config_waf_enable == "on" then
waf_output() waf_output()
return true return true
end end
end end
for key, val in pairs(REQ_POST) do for key, val in pairs(REQ_POST) do
if type(val) == "table" then if type(val) == "table" then
POST_DATA = string.lower(table.concat(val, " ")) POST_DATA = string.lower(table.concat(val, " "))
@ -232,4 +232,4 @@ function post_attack_check()
return true return true
end end
return false return false
end end

26
lib.lua
View File

@ -51,15 +51,15 @@ function log_record(method,url,data,ruletag)
local SERVER_NAME = ngx.var.host local SERVER_NAME = ngx.var.host
local LOCAL_TIME = ngx.localtime() local LOCAL_TIME = ngx.localtime()
local log_json_obj = { local log_json_obj = {
client_ip = CLIENT_IP, client_ip = CLIENT_IP,
local_time = LOCAL_TIME, local_time = LOCAL_TIME,
server_name = SERVER_NAME, server_name = SERVER_NAME,
req_url = url, req_url = url,
attack_method = method, attack_method = method,
req_data = data, req_data = data,
rule_tag = ruletag, rule_tag = ruletag,
user_agent = USER_AGENT, user_agent = USER_AGENT,
} }
local LOG_LINE = cjson.encode(log_json_obj) local LOG_LINE = cjson.encode(log_json_obj)
local LOG_NAME = LOG_PATH..'/'..ngx.today().."_sec.log" local LOG_NAME = LOG_PATH..'/'..ngx.today().."_sec.log"
local file = io.open(LOG_NAME,"a") local file = io.open(LOG_NAME,"a")
@ -79,9 +79,9 @@ function test_log_record(data)
local CLIENT_IP = get_client_ip() local CLIENT_IP = get_client_ip()
local LOCAL_TIME = ngx.localtime() local LOCAL_TIME = ngx.localtime()
local log_json_obj = { local log_json_obj = {
client_ip = CLIENT_IP, client_ip = CLIENT_IP,
req_data = data, req_data = data,
} }
local LOG_LINE = cjson.encode(log_json_obj) local LOG_LINE = cjson.encode(log_json_obj)
local LOG_NAME = LOG_PATH..'/'.."test.log" local LOG_NAME = LOG_PATH..'/'.."test.log"
local file = io.open(LOG_NAME,"a") local file = io.open(LOG_NAME,"a")
@ -103,4 +103,4 @@ function waf_output()
ngx.say(config_output_html) ngx.say(config_output_html)
ngx.exit(ngx.status) ngx.exit(ngx.status)
end end
end end