from core.requester import requester from core.log import setup_logger
logger = setup_logger(__name__)
defwafDetector(url, params, headers, GET, delay, timeout): withopen(sys.path[0] + '/db/wafSignatures.json', 'r') as file: wafSignatures = json.load(file) # a payload which is noisy enough to provoke the WAF noise = '<script>alert("XSS")</script>'# 明显的payload params['xss'] = noise # Opens the noise injected payload response = requester(url, params, headers, GET, delay, timeout) page = response.text # 返回包源码 code = str(response.status_code) # 状态码 headers = str(response.headers) # 头部 logger.debug('Waf Detector code: {}'.format(code)) logger.debug_json('Waf Detector headers:', response.headers)
ifint(code) >= 400: bestMatch = [0, None] for wafName, wafSignature in wafSignatures.items(): score = 0 pageSign = wafSignature['page'] codeSign = wafSignature['code'] headersSign = wafSignature['headers'] if pageSign: if re.search(pageSign, page, re.I): score += 1 if codeSign: if re.search(codeSign, code, re.I): score += 0.5# increase the overall score by a smaller amount because http codes aren't strong indicators # 状态码权重较低,因为不是一个特别准确的判断标识 if headersSign: if re.search(headersSign, headers, re.I): score += 1 # if the overall score of the waf is higher than the previous one if score > bestMatch[0]: # 保留权重最高的 del bestMatch[:] # delete the previous one bestMatch.extend([score, wafName]) # and add this one if bestMatch[0] != 0: return bestMatch[1] else: returnNone else: returnNone
主要流程
发送明显的恶意payload:
1 2 3 4 5
# a payload which is noisy enough to provoke the WAF noise = '<script>alert("XSS")</script>'# 明显的payload params['xss'] = noise # Opens the noise injected payload response = requester(url, params, headers, GET, delay, timeout)
if pageSign: if re.search(pageSign, page, re.I): score += 1 if codeSign: if re.search(codeSign, code, re.I): score += 0.5# increase the overall score by a smaller amount because http codes aren't strong indicators # 状态码权重较低,因为不是一个特别准确的判断标识 if headersSign: if re.search(headersSign, headers, re.I): score += 1 # if the overall score of the waf is higher than the previous one if score > bestMatch[0]: # 保留权重最高的 del bestMatch[:] # delete the previous one bestMatch.extend([score, wafName]) # and add this one