parent
fd566bd0e2
commit
3ce453ab98
96
init.lua
96
init.lua
|
@ -199,32 +199,90 @@ end
|
||||||
|
|
||||||
-- deny post
|
-- deny post
|
||||||
function post_attack_check()
|
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")
|
local POST_RULES = get_rule("post")
|
||||||
ngx.req.read_body()
|
local receive_headers = ngx.req.get_headers()
|
||||||
for _,rule in pairs(POST_RULES) do
|
for _,rule in pairs(POST_RULES) do
|
||||||
-- local REQ_POST = ngx.req.get_post_args()
|
ngx.req.read_body()
|
||||||
local REQ_POST, err = ngx.req.get_post_args()
|
if string.sub(receive_headers["content-type"],1,20) == "multipart/form-data;" then
|
||||||
if err == "truncated" then
|
local body_data = ngx.req.get_body_data()
|
||||||
log_record("DENY_POST_MANY",ngx.var.request_uri,"-",rule)
|
content_type = receive_headers["content-type"]
|
||||||
if config_waf_enable == "on" then
|
if not body_data then
|
||||||
waf_output()
|
local body_data_file = ngx.req.get_body_file()
|
||||||
return true
|
if body_data_file then
|
||||||
end
|
local fh, err = io.open(body_data_file,"r")
|
||||||
end
|
if fh then
|
||||||
for key, val in pairs(REQ_POST) do
|
fh:seek("set")
|
||||||
if type(val) == "table" then
|
body_data = fh:read("*a")
|
||||||
POST_DATA = string.lower(table.concat(val, " "))
|
fh:close()
|
||||||
else
|
end
|
||||||
POST_DATA = string.lower(val)
|
end
|
||||||
end
|
end
|
||||||
if POST_DATA and type(POST_DATA) ~= "boolean" and rule ~="" and rulematch(unescape(POST_DATA),string.lower(rule),"jo") then
|
bi, bj = string.find(content_type, 'boundary=')
|
||||||
log_record("Deny_POST",ngx.var.request_uri,"-",rule)
|
boundary = string.sub(content_type, bj+1)
|
||||||
|
if body_data ~= "" and boundary ~= "" then
|
||||||
|
boundary = '--'..boundary
|
||||||
|
body_data = string.gsub(body_data, "\r", "")
|
||||||
|
body_data = string.gsub(body_data, "\n", "")
|
||||||
|
body_data = string.gsub(body_data, "\t", "")
|
||||||
|
local table_body_data = {}
|
||||||
|
local i = 0
|
||||||
|
local b = string.len(boundary)
|
||||||
|
while true do
|
||||||
|
x = i + b + 1;
|
||||||
|
i,j = string.find(body_data, boundary, i + b + 1)
|
||||||
|
if i == nil then break end
|
||||||
|
body = string.sub(body_data, x, i-1)
|
||||||
|
table.insert(table_body_data, body)
|
||||||
|
end
|
||||||
|
for key, val in pairs(table_body_data) 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 rule ~="" and rulematch(unescape(POST_DATA),string.lower(rule),"jo") then
|
||||||
|
log_record("Deny__MULTIPART_POST",ngx.var.request_uri,"-",rule)
|
||||||
|
if config_waf_enable == "on" then
|
||||||
|
waf_output()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
log_record("Deny__MULTIPART_POST",ngx.var.request_uri,"Empty",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
|
||||||
|
else
|
||||||
|
local REQ_POST, err = ngx.req.get_post_args()
|
||||||
|
if err == "truncated" then
|
||||||
|
log_record("DENY_POST_MANY",ngx.var.request_uri,"-",rule)
|
||||||
|
if config_waf_enable == "on" then
|
||||||
|
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 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()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue