fastjson漏洞拦截过滤阶段:请求阶段规则描述:拦截fastjson漏洞漏洞攻击规则内容:12345678910111213141516171819local jsonFilter = waf.jsonFilterlocal function rMatch(v) if v == "@type" then return true, v end return falseendlocal form = waf.formif form then
0 Comments
fastjson漏洞拦截
过滤阶段:请求阶段
规则描述:拦截fastjson漏洞漏洞攻击
规则内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
local jsonFilter = waf.jsonFilter
localfunctionrMatch(v) if v == "@type"then returntrue, v end returnfalse end
local form = waf.form if form then local raw = form["RAW"] local m = jsonFilter(raw, rMatch, false) if m then return m, raw, true end end
local form = waf.form local rct = waf.reqContentType local rgx = waf.rgxMatch
if rct and waf.contains(waf.toLower(rct), "application/json") and form then local raw = form["RAW"] if raw then if rgx(raw, "^\\s*$", "jos") then returnfalse end local err = waf.checkJson(raw) if err then returntrue, err .. ":" .. raw, true end end end returnfalse
local kvFilter = waf.kvFilter local rgx = waf.rgxMatch local urlDecode = waf.urlDecode local requestLine = waf.requestLine local check = waf.plugins.javaClassDetection.check
local function sMatch(v) local m = rgx(v, "(?:\\$\\{)+(?:j(?:n|\\$\\{)|\\$\\{(?:\\w*:)+)", "joi") if m then return m, "Potential Log4j / Log4shell Attack: ".. v end m = rgx(v, "\\xac\\xed\\x00\\x05|rO0ABQ|KztAAU|Cs7QAF", "jo") if m then return m, "Magic bytes Detected, probable java serialization Attack: ".. v end m = rgx(v, "classLoader\\s*\\.\\s*resources\\s*\\.\\s*context\\s*\\.\\s*parent\\s*\\.\\s*pipeline|springframework\\s*\\.\\s*context\\s*\\.\\s*support\\s*\\.\\s*FileSystemXmlApplicationContext", "jos") if m then return m, "Spring Framework RCE(CVE-2022-22965): ".. v end m = check(v) if m then return m, "Potential dangerous java class: ".. v end returnfalse end
local form = waf.form if form then local m, d = kvFilter(form["FORM"], sMatch) if m then return m, d, true end local raw = form["RAW"] m = rgx(raw, "\\xac\\xed\\x00\\x05|rO0ABQ|KztAAU|Cs7QAF", "jo") if m then return m, raw, true end m = check(raw) if m then return m, raw, true end end
local queryString = waf.queryString if queryString then local m, d = kvFilter(queryString, sMatch) if m then return m, d, true end end
local cookies = waf.cookies if cookies then local m, d = kvFilter(cookies, sMatch) if m then return m, d, true end end
local m, d = kvFilter(waf.reqHeaders, sMatch) if m then return m, d, true end
local m = rgx(urlDecode(requestLine), "(?:\\$\\{)+(?:j(?:n|\\$\\{)|\\$\\{(?:\\w*:)+)", "joi") if m then return m, requestLine, true end
returnfalse
Shellshock漏洞
过滤阶段:请求阶段
规则描述:检测对“Shellshock”(CVE-2014-6271和CVE-2014-7169) GNU Bash RCE漏洞的攻击。
local kvFilter = waf.kvFilter local rgx = waf.rgxMatch local host = waf.host local counter = waf.strCounter local str_find = string.find local str_sub = string.sub
localfunctionrMatch(v) local m = rgx(v, "^(?:url:)?file|ftps?|https?)://(?:[^@]+@)?([^/]+", "joi") if m then local i, j = str_find(v, host, 1, true) if i then if counter(str_sub(v, 1, j), "/") == 2then returnfalse end end end return m, v end
local form = waf.form if form then local m, d = kvFilter(form["FORM"], rMatch) if m then return m, d, true end end
local queryString = waf.queryString if queryString then local m, d = kvFilter(queryString, rMatch) if m then return m, d, true end end
if waf.form and waf.form["RAW"] then local m = waf.rgxMatch(waf.form["RAW"], "<!(?:DOCTYPE|ENTITY)[^>]+?\\bSYSTEM\\b", "jos") if m then return m, waf.form["RAW"], true end end returnfalse
ImageMagick漏洞
过滤阶段:请求阶段
规则描述:ImageMagick是一个功能强大的开源图形处理软件,该漏洞可以执行任意命令和读写文件
规则内容:
1 2 3 4 5 6 7 8 9 10 11 12 13
local rgx = waf.rgxMatch localfunctionimgContentMatch(v) local m = rgx(v, "\\bpush\\s+graphic-context\\b|\\<\\s*image\\b", "joi") if m then return m, v end returnfalse end if waf.form then local m, d = waf.knFilter(waf.form["FILES"], imgContentMatch, 0) return m, d, true end returnfalse
local kvFilter = waf.kvFilter local rgx = waf.rgxMatch local htmlEntityDecode = waf.htmlEntityDecode
local function rMatch(v) local m = rgx(htmlEntityDecode(v), "^[^:\\(\\)\\&\\|\\!\\<\\>\\~]*\\)\\s*(?:\\((?:[^,\\(\\)\\=\\&\\|\\!\\<\\>\\~]+[><~]?=|\\s*[&!|]\\s*(?:\\)|\\()?\\s*)|\\)\\s*\\(\\s*[\\&\\|\\!]\\s*|[&!|]\\s*\\([^\\(\\)\\=\\&\\|\\!\\<\\>\\~]+[><~]?=[^:\\(\\)\\&\\|\\!\\<\\>\\~]*)", "jos") if m then return m, v end returnfalse end
local form = waf.form if form then local m, d = kvFilter(form["FORM"], rMatch) if m then return m, d, true end end
local queryString = waf.queryString if queryString then local m, d = kvFilter(queryString, rMatch) if m then return m, d, true end end
local cookies = waf.cookies if cookies then local m, d = kvFilter(cookies, rMatch) if m then return m, d, true end end returnfalse
HTTP Splitting
过滤阶段:请求阶段
规则描述:此规则检测请求文件名中的\n或\r。
规则内容:
1 2 3 4 5 6 7 8 9 10 11 12 13
local rgx = waf.rgxMatch localfunctionfMatch(v) local m = rgx(v, "[\\n\\r]", "jo") if m then return m, v end returnfalse end local m, d = fMatch(waf.uri) if m then return m, d, true end returnfalse
local rgx = waf.rgxMatch local htmlEntityDecode = waf.htmlEntityDecode localconcat = table.concat
localfunctionhMatch(v) local m = rgx(htmlEntityDecode(v), "[\\n\\r]", "jo") if m then return m, v end returnfalse end
localfunctionvMatch(v) local m = rgx(htmlEntityDecode(v), "[\\n\\r]+(?:\\s|location|refresh|(?:set-)?cookie|(?:x-)?(?:forwarded-(?:for|host|server)|host|via|remote-ip|remote-addr|originating-IP))\\s*:", "josi") if m then return m, v end returnfalse end
local m, d = waf.kvFilter(waf.reqHeaders, hMatch) if m then return m, d, true end
local queryString = waf.queryString if queryString then for k, v inpairs(waf.queryString) do m, d = hMatch(k) if m then return m, d, true end iftype(v)=="table"then v = concat(v,",") end m, d = vMatch(v) if m then return m, d, true end end end
local form = waf.form if form then for k, _ inpairs(form["FORM"]) do m, d = hMatch(k) if m then return m, d, true end end end
if ct then iftype(ct) ~= "string"then returntrue, "Malform Content-Type", true elseif waf.contains(ct, "boundary") and (waf.strCounter(ct, "boundary") > 1ornot waf.rgxMatch(ct, "boundary=[\\w\\-]+$", "jo")) then returntrue, ct, true end end
returnfalse
asp畸形编码过滤
过滤阶段:请求阶段
规则描述:asp中unicode畸形编码会造成waf绕过危害
规则内容:
1 2 3 4
if waf.rgxMatch(waf.reqUri,"%u00(?:aa|ba|d0|de|e2|f0|fe)","i") then returntrue,waf.reqUri,true end returnfalse
local kvFilter = waf.kvFilter local rgx = waf.rgxMatch local htmlEntityDecode = waf.htmlEntityDecode
local function rMatch(v) local m = rgx(v, "[\\r\\n]\\W*?(?:content-(?:type|length)|set-cookie|location):\\s*\\w", "josi") if m then return m, v end returnfalse end
local function hMatch(v) local m = rgx(htmlEntityDecode(v), "(?:\\bhttp/\\d|<(?:html|meta)\\b)", "josi") if m then return m, v end returnfalse end
local form = waf.form if form then local m, d = kvFilter(form["FORM"], rMatch) if m then return m, d, true end m, d = kvFilter(form["FORM"], hMatch) if m then return m, d, true end end
local queryString = waf.queryString if queryString then local m, d = kvFilter(queryString, rMatch) if m then return m, d, true end m, d = kvFilter(queryString, hMatch) if m then return m, d, true end end
local cookies = waf.cookies if cookies then local m, d = kvFilter(cookies, rMatch) if m then return m, d, true end m, d = kvFilter(cookies, hMatch) if m then return m, d, true end end returnfalse
local kvFilter = waf.kvFilter local rgx = waf.rgxMatch local htmlEntityDecode = waf.htmlEntityDecode
localfunctionrMatch(v) local m = rgx(htmlEntityDecode(v), "(?:get|post|head|options|connect|put|delete|trace|track|patch|propfind|propatch|mkcol|copy|move|lock|unlock)\\s+[^\\s]+\\s+http/\\d", "josi") if m then return m, v end returnfalse end
local form = waf.form if form then local m, d = kvFilter(form["FORM"], rMatch) if m then return m, d, true end m, d = rMatch(form["RAW"]) if m then return m, d, true end end
local queryString = waf.queryString if queryString then local m, d = kvFilter(queryString, rMatch) if m then return m, d, true end end
local cookies = waf.cookies if cookies then local m, d = kvFilter(cookies, rMatch) if m then return m, d, true end end returnfalse
上传文件内容过滤
过滤阶段:请求阶段
规则描述:过滤上传的文件内容,拦截webshell上传
规则内容:
1 2 3 4 5 6 7 8 9 10 11 12 13
local rgx = waf.rgxMatch localfunction fileContentMatch(v) local m = rgx(v, "<\\?.+?\\$(?:GLOBALS|_(?:GET|POST|COOKIE|REQUEST|SERVER|FILES|SESSION|ENV))|<\\?php|<jsp:|<%(?i:!|\\s*@|.*?\\brequest\\s*(?:\\.|\\())", "jos") if m then return m, v end returnfalse end if waf.form then local m, d = waf.knFilter(waf.form["FILES"], fileContentMatch, 0) return m, d, true end returnfalse
上传文件名过滤
过滤阶段:请求阶段
规则描述:过滤上传文件名中的网页脚本扩展名,拦截webshell上传
规则内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
local rgx = waf.rgxMatch
localfunctionfileNameMatch(v) local m = rgx(v, "\\.(?:as|cer\\b|cdx|ph|jsp|war|class|exe|ht|env|user\\.ini)|php\\.ini", "joi") if m then return m, v end returnfalse end if waf.form then local m, d = waf.knFilter(waf.form["FILES"], fileNameMatch, 1) return m, d, true end
returnfalse
防持续攻击
过滤阶段:请求阶段
规则描述:累计攻击超过100次,则在10分钟内拦截该ip访问
规则内容:
1 2 3 4 5 6 7
local ib = waf.ipBlock local c = ib:get(waf.ip) if c and c >= 100then ib:set(waf.ip, c, 600, 1) returntrue, "ip blocked for continue attack: " .. waf.ip, true end returnfalse
Invalid protocol
过滤阶段:请求阶段
规则描述:非法post协议
规则内容:
1 2 3 4 5 6 7
if waf.form == nil then if waf.contains(waf.fErr, "content_type") then returntrue, waf.fErr .. ": " .. waf.reqContentType, true end returntrue, waf.fErr, true end returnfalse
4 评论