Openresty增加waf配置
PS:1、git clone https://github.com/loveshell/ngx_lua_waf.git
防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击
防止svn/备份之类文件泄漏
防止ApacheBench之类压力测试工具的攻击
屏蔽常见的扫描黑客工具,扫描器
屏蔽异常的网络请求
屏蔽图片附件类目录php执行权限
防止webshell上传
2、下载解压后,将整 ngx_lua_waf 放到 nginx conf 目录中,并命名为 waf;
(PS:为了方面..)
3、在nginx.conf配置(根据自己的NGINX位置修改路径)
lua_package_path "/usr/local/nginx/conf/waf/?.lua";4、配置config.lua
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;
RulePath = "/usr/local/nginx/conf/waf/wafconf/"5、修改init.lua say_html与denycc函数
--规则存放目录
attacklog = "off"
--是否开启攻击信息记录,需要配置logdir
logdir = "/usr/local/nginx/logs/hack/"
--log存储目录,该目录需要用户自己新建,切需要nginx用户的可写权限
UrlDeny="on"
--是否拦截url访问
Redirect="on"
--是否拦截后重定向
CookieMatch = "on"
--是否拦截cookie攻击
postMatch = "on"
--是否拦截post攻击
whiteModule = "on"
--是否开启URL白名单
black_fileExt={"php","jsp"}
--填写不允许上传文件后缀类型
ipWhitelist={"127.0.0.1"}
--ip白名单,多个ip用逗号分隔
ipBlocklist={"1.0.0.1"}
--ip黑名单,多个ip用逗号分隔
CCDeny="on"
--是否开启拦截cc攻击(需要nginx.conf的http段增加lua_shared_dict limit 10m;)
CCrate = "100/60"
--设置cc攻击频率,单位为秒.
--默认1分钟同一个IP只能请求同一个地址100次
html=[[Please go away~~]]
--警告内容,可在中括号内自定义
function say_html()6、nginx -s reload 并测试
if Redirect then
ngx.header.content_type = "text/html;charset=UTF-8"
ngx.status = ngx.HTTP_FORBIDDEN
ngx.say(html)
ngx.exit(ngx.status)
end
end
function denycc()
if CCDeny then
local uri=ngx.var.uri
CCcount=tonumber(string.match(CCrate,'(.*)/'))
CCseconds=tonumber(string.match(CCrate,'/(.*)'))
local token = getClientIp()..uri
local limit = ngx.shared.limit
local req,_=limit:get(token)
if req then
if req > CCcount then
ngx.header.content_type = "application/json;charset=UTF-8"
local ret={returncode='22000',messages='请求拒绝,请稍后再试',body={}}
--ngx.header['Content-Type']="text/html;charset=UTF-8"
ngx.say(json.encode(ret))
ngx.exit(200)
return true
else
limit:incr(token,1)
end
else
limit:set(token,1,CCseconds)
end
end
return false
end
PS(http://ip/index?id=../etc/passwd)
7、记得给/usr/local/nginx/logs/hack文件夹授权 chown www:www -R hack/
没有找到相关结果
已邀请:
1 个回复
qk356 - IT男有人权吗?
赞同来自: