Add test write function
parent
1f65c765cc
commit
1b4dc7cbd3
4
init.lua
4
init.lua
|
@ -60,13 +60,15 @@ end
|
||||||
function cc_attack_check()
|
function cc_attack_check()
|
||||||
if config_cc_check == "on" then
|
if config_cc_check == "on" then
|
||||||
local USER_AGENT = get_user_agent()
|
local USER_AGENT = get_user_agent()
|
||||||
local ATTACK_URL = ngx.var.host .. ngx.var.request_uri
|
--local ATTACK_URL = ngx.var.host .. ngx.var.request_uri
|
||||||
|
local ATTACK_URL = ngx.var.host .. ngx.var.uri
|
||||||
local CC_TOKEN = get_client_ip() .. "." .. ngx.md5(ATTACK_URL .. USER_AGENT)
|
local CC_TOKEN = get_client_ip() .. "." .. ngx.md5(ATTACK_URL .. USER_AGENT)
|
||||||
local limit = ngx.shared.limit
|
local limit = ngx.shared.limit
|
||||||
local CCcount=tonumber(string.match(config_cc_rate,'(.*)/'))
|
local CCcount=tonumber(string.match(config_cc_rate,'(.*)/'))
|
||||||
local CCseconds=tonumber(string.match(config_cc_rate,'/(.*)'))
|
local CCseconds=tonumber(string.match(config_cc_rate,'/(.*)'))
|
||||||
local req,_ = limit:get(CC_TOKEN)
|
local req,_ = limit:get(CC_TOKEN)
|
||||||
if req then
|
if req then
|
||||||
|
--write('/data/wwwlogs/info.log',CC_TOKEN ..'\t'.. ATTACK_URL .. '\t'.. 'req: ' .. req .. "\n")
|
||||||
if req > CCcount then
|
if req > CCcount then
|
||||||
log_record('CC_Attack',ngx.var.request_uri,"-","-")
|
log_record('CC_Attack',ngx.var.request_uri,"-","-")
|
||||||
if config_waf_enable == "on" then
|
if config_waf_enable == "on" then
|
||||||
|
|
14
lib.lua
14
lib.lua
|
@ -48,7 +48,7 @@ function log_record(method,url,data,ruletag)
|
||||||
local LOG_PATH = config_log_dir
|
local LOG_PATH = config_log_dir
|
||||||
local CLIENT_IP = get_client_ip()
|
local CLIENT_IP = get_client_ip()
|
||||||
local USER_AGENT = get_user_agent()
|
local USER_AGENT = get_user_agent()
|
||||||
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,
|
||||||
|
@ -71,6 +71,18 @@ function log_record(method,url,data,ruletag)
|
||||||
file:close()
|
file:close()
|
||||||
end
|
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)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
fd:write(msg)
|
||||||
|
fd:flush()
|
||||||
|
fd:close()
|
||||||
|
end
|
||||||
|
|
||||||
--WAF return
|
--WAF return
|
||||||
function waf_output()
|
function waf_output()
|
||||||
if config_waf_output == "redirect" then
|
if config_waf_output == "redirect" then
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
\.(htaccess|bash_history)
|
\.(htaccess|bash_history)
|
||||||
\.(bak|inc|old|mdb|sql|backup|java|class|tgz|gz|tar|zip)$
|
\.(bak|inc|old|mdb|sql|backup|java|class|tgz|gz|tar|zip)$
|
||||||
(phpmyadmin|jmx-console|admin-console|jmxinvokerservlet)
|
(jmx-console|admin-console|jmxinvokerservlet)
|
||||||
java\.lang
|
java\.lang
|
||||||
\.svn\/
|
\.svn\/
|
||||||
/(attachments|upimg|images|css|uploadfiles|html|uploads|templets|static|template|data|inc|forumdata|upload|includes|cache|avatar)/(\\w+).(php|jsp)
|
/(attachments|upimg|images|css|uploadfiles|html|uploads|templets|static|template|data|inc|forumdata|upload|includes|cache|avatar)/(\\w+).(php|jsp)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
\.(js|css)$
|
\.(js|css)
|
||||||
\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$
|
\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)
|
||||||
|
403\.html
|
||||||
|
|
Loading…
Reference in New Issue