-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodsec_rule_extract.py
45 lines (39 loc) · 1.25 KB
/
modsec_rule_extract.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
import os
def FindXSS(rules_name):
#rules="community.rules"
f=open(rules_name,"r",encoding="utf-8")
lines=f.readlines()
f.close()
#print(lines)
for rule in lines:
#print(i)
#break
if rule.lower().find(find_word)>=0:
#rule=rule[rule.find("alert"):]
#rule=rule.strip()
print(rule)
RuleWrite(rule)
#print(1)
def Search(dirname):
try:
filenames = os.listdir(dirname)
for filename in filenames:
full_filename = os.path.join(dirname, filename)
if os.path.isdir(full_filename):
Search(full_filename)
else:
ext = os.path.splitext(full_filename)[-1]
#print(full_filename)
if ext == rule_ext:
print(full_filename)
FindXSS(full_filename)
except PermissionError:
pass
def RuleWrite(rule):
with open(output_file,"a",encoding="utf-8") as f:
f.writelines(rule)
rule_path="C:\\Users\\Administrator\\Documents\\GitHub\\Templete_Detection\\modsec_xss"
rule_ext=".conf"
find_word="secrule"
output_file="C:\\Users\\Administrator\\Documents\\GitHub\\Templete_Detection\\modsec_xss\\modsec_xss.rules"
Search(rule_path)