-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathwappalyzer.py
More file actions
193 lines (143 loc) · 4.54 KB
/
wappalyzer.py
File metadata and controls
193 lines (143 loc) · 4.54 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import json
def parse_value(value):
if isinstance(value, str):
value_list = value.split("\\;")
else:
value_list = value
r = {
'regexp': value_list[0] if value_list[0] else ".*",
}
for value in value_list:
if value.startswith('confidence:'):
try:
r['confidence'] = int(value[len('confidence:'):])
except ValueError:
pass
if value.startswith('version:'):
version = value[len('version:'):]
if version.startswith('\\'):
try:
r['version'] = int(version[1:].split('?')[0])
except ValueError:
pass
return r
def parse_headers(rule):
matches = []
for key, value in rule['headers'].items():
value = parse_value(value)
match = {
"search": "headers[%s]" % key.lower(),
"regexp": value['regexp']
}
if 'version' in value:
match['offset'] = value['version']
if 'confidence' in value:
match['certainty'] = value['confidence']
matches.append(match)
return matches
def parse_cookies(rule):
matches = []
for key, value in rule['cookies'].items():
value = parse_value(value)
match = {
"search": "cookies[%s]" % key,
"regexp": value["regexp"]
}
if 'version' in value:
match['offset'] = value['version']
if 'confidence' in value:
match['certainty'] = value['confidence']
matches.append(match)
return matches
def parse_html(rule):
matches = []
if isinstance(rule['html'], str):
values = [rule['html']]
else:
values = rule['html']
for value in values:
value = parse_value(value)
match = {
"regexp": value['regexp']
}
if 'version' in value:
match['offset'] = value['version']
if 'confidence' in value:
match['certainty'] = value['confidence']
matches.append(match)
return matches
def parse_scripts(rule):
matches = []
if isinstance(rule['scripts'], str):
values = [rule['scripts']]
else:
values = rule['scripts']
for value in values:
value = parse_value(value)
match = {
'search': 'script',
'regexp': value['regexp']
}
if 'version' in value:
match['offset'] = value['version']
if 'confidence' in value:
match['certainty'] = value['confidence']
matches.append(match)
return matches
def parse_meta(rule):
matches = []
for key, value in rule['meta'].items():
value = parse_value(value)
match = {
"search": "meta[%s]" % key,
'regexp': value['regexp']
}
if 'version' in value:
match['offset'] = value['version']
if 'confidence' in value:
match['certainty'] = value['confidence']
matches.append(match)
return matches
def parse_rules(src, dst):
curdir = os.getcwd()
with open(os.path.join(curdir, src, "apps.json")) as fd:
c = json.load(fd)
m = {
'headers': parse_headers,
'html': parse_html,
'meta': parse_meta,
'scripts': parse_scripts,
'cookies': parse_cookies,
}
apps = c['technologies']
for name in apps:
matches = []
for key in apps[name]:
if key not in m:
continue
matches.extend(m[key](apps[name]))
with open(os.path.join(curdir, dst, "%s.json" % name.lower().replace('/', '_')), 'w') as fd:
data = {
'name': name,
'website': apps[name]['website'],
'matches': matches
}
if 'implies' in apps[name]:
if isinstance(apps[name]['implies'], str):
data['implies'] = apps[name]['implies'].split("\\;")[0]
else:
data['implies'] = []
for i in apps[name]['implies']:
data['implies'].append(i.split("\\;")[0])
if 'excludes' in apps[name]:
data['excludes'] = apps[name]['excludes']
fd.write(json.dumps(data, indent=4))
if __name__ == '__main__':
if len(sys.argv) != 3:
print("[*] Usage: %s src_dir dst_dir" % sys.argv[0])
sys.exit(-1)
parse_rules(sys.argv[1], sys.argv[2])