forked from fagci/h4ck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webmap.py
executable file
·283 lines (231 loc) · 7.24 KB
/
webmap.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python3
"""Scan web application for CMS, used techs, vulns"""
from collections import defaultdict
import re
from urllib.parse import urlparse
from fire import Fire
import requests
from requests.models import Response
from lib.colors import *
from lib.files import DATA_DIR, FUZZ_DIR
from lib.http import iri_to_uri
from lib.progress import Progress
from lib.scan import get_domains_from_cert
from lib.utils import interruptable, tim
BANNER = r"""
%s__ _____| |__ _ __ ___ __ _ _ __
%s\ \ /\ / / _ \ '_ \| '_ ` _ \ / _` | '_ \
%s \ V V / __/ |_) | | | | | | (_| | |_) |
%s \_/\_/ \___|_.__/|_| |_| |_|\__,_| .__/
%s |_|%s""" % (
CEND,
CEND,
CGREY,
CGREY,
CDGREY,
CEND
)
# file, allow_html
FUZZ_FILES = [
(str(FUZZ_DIR / 'web_fw.txt'), True),
(str(FUZZ_DIR / 'web.txt'), False),
(str(FUZZ_DIR / 'web_dir.txt'), True),
]
with (DATA_DIR / 'web_headers.txt').open() as f:
HEADER_LIST = [p.rstrip() for p in f]
with (DATA_DIR / 'web_cms.txt').open() as f:
CMS_LIST = [p.rstrip() for p in f]
with (DATA_DIR / 'web_tech.txt').open() as f:
TECH_LIST = [p.rstrip() for p in f]
session = requests.Session()
headers = {'User-Agent': 'Mozilla/5.0'}
@interruptable
def check_path(allow_html: bool, url: str):
try:
r = session.get(url, timeout=5, allow_redirects=False,
verify=False, stream=True, headers=headers)
if (
allow_html or r.headers.get('Content-Type') != 'text/html'
) and r.status_code == 200:
return True, url, len(r.content)
except requests.ConnectionError as e:
print(end='\r')
err(repr(e))
except:
pass
return False, url, 0
def check_src(text: str, inclusions):
return filter(lambda x: x in text, inclusions)
@interruptable
def check_domains(url, _):
"""Get linked domains"""
try:
up = urlparse(url)
hostname, port = up.hostname, up.port
port = port if port and port != 80 else 443
linked_domains = get_domains_from_cert(hostname, port)
if linked_domains:
found('Domains:', ', '.join(linked_domains))
else:
nfound('No domains found')
except Exception as e:
nfound('Failed:', repr(e))
@interruptable
def check_headers(_, r):
"""Check headers"""
h = r.headers
vulns = {
'csp': not h.get('Content-Security-Policy', False),
'mitm': not h.get('Strict-Transport-Security', False),
'xct': 'nosniff' not in h.get('X-Content-Type-Options', ''),
'xframe': not h.get('X-Frame-Options', False),
'xss': not h.get('X-XSS-Protection', False),
}
vulns = list(filter(lambda v: v[1], vulns.items()))
for hk, hv in h.items():
if hk in HEADER_LIST:
info('%s: %s' % (hk, hv))
if vulns:
found('Client side vulns:', ', '.join(v[0] for v in vulns))
else:
nfound('No client side vulns')
@interruptable
def check_analytics(_, r: Response):
"""Check analytics"""
regs = {
'adsense': r'pub-\d+',
'google': r'ua-[0-9-]+',
'googleTagManager': r'gtm-[^&\'"%]+',
'mail.ru': r'top.mail.ru[^\'"]+from=(\d+)',
'yandexMetrika': r'metrika.yandex[^\'"]+?id=(\d+)',
'vk': r'vk-[^&"\'%]+'
}
for name, reg in regs.items():
m = re.findall(reg, r.text, re.IGNORECASE)
if m:
found(name, m[0])
@interruptable
def check_social(_, r):
"""Check social"""
regs = {
'facebook': r'facebook\.com/([^"\'/]+)',
'github': r'github\.com/([^"\'/]+)',
'instagram': r'instagram\.com/([^"\'/]+)',
'ok': r'ok\.ru/([^"\'/]+)',
'telegram': r't\.me/([^"\'/]+)',
'twitter': r'twitter\.com/([^"\'/]+)',
'vk': r'vk\.com/([^"\'/]+)',
'youtube': r'youtube\.\w+?(/channel/[^"\']+)',
}
for name, reg in regs.items():
m = re.findall(reg, r.text, re.IGNORECASE)
if m:
found(name, m[0])
@interruptable
def check_contacts(_, r):
"""Check contacts"""
regs = {
'mail': r'[\w\-][\w\-\.]+@[\w\-][\w\-]+\.[\w]{1,5}',
'phone': r'\+\d[-()\s\d]{5,}?(?=\s*[+<])',
'tel': r'tel:(\+?[^\'"]+)',
'mailto': r'mailto:(\+?[^\'"]+)',
}
contacts = defaultdict(set)
for name, reg in regs.items():
for m in re.findall(reg, r.text):
if m.endswith(('png', 'svg')):
continue
contacts[name].add(m)
for n, cc in contacts.items():
for c in cc:
found(n, c)
@interruptable
def check_cms(_, r):
"""Check CMS"""
cmses = list(check_src(r.text, CMS_LIST))
if cmses:
found(', '.join(cmses))
else:
nfound('No CMS found in source')
@interruptable
def check_techs(_, r):
"""Check techs"""
techs = list(check_src(r.text, TECH_LIST))
if techs:
found(', '.join(techs))
else:
nfound('No tech found')
@interruptable
def check_robots(url, _):
"""Check robots.txt"""
urls = set()
try:
r = session.get('%s/robots.txt' % url, timeout=5, allow_redirects=False,
verify=False, stream=True, headers=headers)
if r.status_code == 200:
if 'Disallow' in r.text:
for ln in r.text.splitlines():
if 'Disallow' in ln:
_, url = ln.split(None, 2)
urls.add(url.strip())
if urls:
found('Disallowed:', ', '.join(urls))
else:
nfound('No disallowed found')
return
except Exception as e:
print(end='\r')
err(repr(e))
nfound('Get robots.txt failed')
@interruptable
def check_vulns(url, _):
"""Check vulns"""
from functools import partial
from concurrent.futures import ThreadPoolExecutor
urlen = len(url) + 1
for file, allow_html in FUZZ_FILES:
process(tim(), 'Fuzz', file)
with open(file) as f:
progress = Progress(sum(1 for _ in f))
f.seek(0)
ff = ('%s%s' % (url, ln.rstrip()) for ln in f)
check = partial(check_path, allow_html)
with ThreadPoolExecutor() as ex:
for r, rurl, cl in ex.map(check, ff):
path = rurl[urlen:]
if r:
print(end='\r')
found(tim(), '(%s)' % cl, path)
progress(path)
def main(url, nofuzz=False):
print('='*42)
print(BANNER.strip())
print('Target:', url)
print('='*42)
tasks = [
check_domains,
check_headers,
check_analytics,
check_contacts,
check_social,
check_cms,
check_techs,
check_robots,
]
if not nofuzz:
tasks.append(check_vulns)
url = iri_to_uri(url)
try:
initial_response = session.get(
url, timeout=10, verify=False, headers=headers)
except requests.ConnectionError as e:
print(ERR, e, CEND)
exit(e.errno)
for task in tasks:
print()
process(task.__doc__)
task(url, initial_response)
if __name__ == "__main__":
import warnings
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
Fire(main)