Compare commits

..

17 Commits
0.4 ... master

Author SHA1 Message Date
loveshell 314a2f62ec filter some post data
thanks for bajief
2016-04-06 12:17:47 +08:00
loveshell 6606edda34 fix concat table bool and string 2016-01-30 10:20:28 +08:00
loveshell 3492d0601c fix ip 2016-01-10 22:45:34 +08:00
loveshell fa5bf74cbe fix table concat bug 2015-10-28 13:51:45 +08:00
loveshell f609d3296d Update README.md 2015-10-21 12:38:43 +08:00
loveshell 2b1079ee50 fix readme 2015-10-21 12:37:02 +08:00
loveshell 6a38f4fe2d fix symbols 2015-08-24 15:22:41 +08:00
loveshell c0b121a64c fix data is ni 2015-06-23 22:52:33 +08:00
loveshell 14a78d0155 add local var 2015-05-19 20:21:52 +08:00
loveshell 2897e494ea low ngxlua support ngxmatch 2015-05-14 12:09:54 +08:00
loveshell 834c937a83 统一下低版本支持的ngx.re.match 2015-05-14 12:07:14 +08:00
loveshell 20173bd93d find to match 2015-05-14 11:52:56 +08:00
loveshell caff7def0b delete ... 2015-04-28 18:26:26 +08:00
loveshell 1b21447698 w2b 2015-04-19 12:25:52 +08:00
loveshell ee2e656e5a fix match 2015-04-19 12:25:06 +08:00
loveshell ee40966545 修改文件上传的白名单为黑名单 2015-04-19 12:13:08 +08:00
loveshell ca4383accc update black filext 2015-04-19 12:12:33 +08:00
5 changed files with 26 additions and 19 deletions

View File

@ -63,8 +63,8 @@ nginx安装路径假设为:/usr/local/nginx/conf/
--是否拦截post攻击 --是否拦截post攻击
whiteModule = "on" whiteModule = "on"
--是否开启URL白名单 --是否开启URL白名单
fileExtension={"jpeg","gif","jpg","png","bmp","rar","zip","tar.gz"} black_fileExt={"php","jsp"}
--填写上传文件后缀类型 --填写不允许上传文件后缀类型
ipWhitelist={"127.0.0.1"} ipWhitelist={"127.0.0.1"}
--ip白名单多个ip用逗号分隔 --ip白名单多个ip用逗号分隔
ipBlocklist={"1.0.0.1"} ipBlocklist={"1.0.0.1"}
@ -106,8 +106,8 @@ nginx安装路径假设为:/usr/local/nginx/conf/
过滤规则在wafconf下可根据需求自行调整每条规则需换行,或者用|分割 过滤规则在wafconf下可根据需求自行调整每条规则需换行,或者用|分割
global是全局过滤文件里面的规则对post和get都过滤 args里面的规则get参数进行过滤的
get是只在get请求过滤的规则 url是只在get请求url过滤的规则
post是只在post请求过滤的规则 post是只在post请求过滤的规则
whitelist是白名单里面的url匹配到不做过滤 whitelist是白名单里面的url匹配到不做过滤
user-agent是对user-agent的过滤规则 user-agent是对user-agent的过滤规则

View File

@ -6,7 +6,7 @@ Redirect="on"
CookieMatch="on" CookieMatch="on"
postMatch="on" postMatch="on"
whiteModule="on" whiteModule="on"
fileExtension={"jpeg","gif","jpg","png","bmp","rar","zip","tar.gz"} black_fileExt={"php","jsp"}
ipWhitelist={"127.0.0.1"} ipWhitelist={"127.0.0.1"}
ipBlocklist={"1.0.0.1"} ipBlocklist={"1.0.0.1"}
CCDeny="off" CCDeny="off"

View File

@ -15,10 +15,7 @@ attacklog = optionIsOn(attacklog)
CCDeny = optionIsOn(CCDeny) CCDeny = optionIsOn(CCDeny)
Redirect=optionIsOn(Redirect) Redirect=optionIsOn(Redirect)
function getClientIp() function getClientIp()
IP = ngx.req.get_headers()["X-Real-IP"] IP = ngx.var.remote_addr
if IP == nil then
IP = ngx.var.remote_addr
end
if IP == nil then if IP == nil then
IP = "unknown" IP = "unknown"
end end
@ -90,12 +87,14 @@ function whiteurl()
return false return false
end end
function fileExtCheck(ext) function fileExtCheck(ext)
local items = Set(fileExtension) local items = Set(black_fileExt)
ext=string.lower(ext) ext=string.lower(ext)
if ext then if ext then
if not items[ext] then for rule in pairs(items) do
log('POST',ngx.var.request_uri,"-","file attack with ext "..ext) if ngx.re.match(ext,rule,"isjo") then
log('POST',ngx.var.request_uri,"-","file attack with ext "..ext)
say_html() say_html()
end
end end
end end
return false return false
@ -110,9 +109,14 @@ function args()
local args = ngx.req.get_uri_args() local args = ngx.req.get_uri_args()
for key, val in pairs(args) do for key, val in pairs(args) do
if type(val)=='table' then if type(val)=='table' then
if val ~= false then local t={}
data=table.concat(val, " ") for k,v in pairs(val) do
if v == true then
v=""
end
table.insert(t,v)
end end
data=table.concat(t, " ")
else else
data=val data=val
end end

12
waf.lua
View File

@ -1,5 +1,6 @@
local content_length=tonumber(ngx.req.get_headers()['content-length']) local content_length=tonumber(ngx.req.get_headers()['content-length'])
local method=ngx.req.get_method() local method=ngx.req.get_method()
local ngxmatch=ngx.re.match
if whiteip() then if whiteip() then
elseif blockip() then elseif blockip() then
elseif denycc() then elseif denycc() then
@ -41,12 +42,12 @@ elseif PostCheck then
return true return true
end end
size = size + len(data) size = size + len(data)
local m = ngx.re.match(data,'Content-Disposition: form-data;(.+)filename="(.+)\\.(.*)"','ijo') local m = ngxmatch(data,[[Content-Disposition: form-data;(.+)filename="(.+)\\.(.*)"]],'ijo')
if m then if m then
fileExtCheck(m[3]) fileExtCheck(m[3])
filetranslate = true filetranslate = true
else else
if ngx.re.find(data,"Content-Disposition:",'isjo') then if ngxmatch(data,"Content-Disposition:",'isjo') then
filetranslate = false filetranslate = false
end end
if filetranslate==false then if filetranslate==false then
@ -68,13 +69,16 @@ elseif PostCheck then
return return
end end
for key, val in pairs(args) do for key, val in pairs(args) do
if type(val) == "table" or val == false then if type(val) == "table" then
if type(val[1]) == "boolean" then
return
end
data=table.concat(val, ", ") data=table.concat(val, ", ")
else else
data=val data=val
end end
if data and type(data) ~= "boolean" and body(data) then if data and type(data) ~= "boolean" and body(data) then
return true body(key)
end end
end end
end end

View File

@ -1,4 +1,3 @@
\.\./
select.+(from|limit) select.+(from|limit)
(?:(union(.*?)select)) (?:(union(.*?)select))
having|rongjitest having|rongjitest