forked from h3h3da/MicroWAF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.py
73 lines (63 loc) · 2.21 KB
/
detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# !/usr/bin/env python
# -*- coding:utf-8 -*-
import re
from sql import query_rule
#from rexrules import Rules
class Detect:
"""
检测web攻击行为
user-agent, cookies, uri, body
匹配特征
"""
def __init__(self, http_data):
self.uri = str(http_data.uri)
user_agent_data = http_data.headers.get("user-agent", False)
if user_agent_data:
self.user_agent = str(http_data.headers["user-agent"])
else:
self.user_agent = ""
if http_data.headers.get("cookie"):
self.cookie = str(http_data.headers["cookie"])
else:
self.cookie = ""
if http_data.body:
self.body = str(http_data.body)
else:
self.body = ""
def run(self):
'''检查url user-agent cookie body'''
result = {
"status": False,
"type": [],
"url": ""
}
#print("uri ", self.uri)
result["url"] = self.uri
Rules = query_rule()
for rule in Rules:
res = re.compile(Rules[rule]["rex"], re.IGNORECASE).findall(self.uri)
# print("1: ", res)
if res:
# print(self.uri)
result["status"] = result["status"] or True
result["type"].append(Rules[rule]["name"])
res = re.compile(Rules[rule]["rex"],
re.IGNORECASE).findall(self.user_agent)
# print("2: ", res)
if res:
result["status"] = result["status"] or True
result["type"].append(Rules[rule]["name"])
res = re.compile(Rules[rule]["rex"],
re.IGNORECASE).findall(self.cookie)
# print("3: ", res)
if res:
result["status"] = result["status"] or True
result["type"].append(Rules[rule]["name"])
res = re.compile(Rules[rule]["rex"],
re.IGNORECASE).findall(self.body)
# print("4: ", res)
if res:
# print(self.body)
result["status"] = result["status"] or True
result["type"].append(Rules[rule]["name"])
return result