-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_scanner.py
More file actions
425 lines (274 loc) · 8.98 KB
/
web_scanner.py
File metadata and controls
425 lines (274 loc) · 8.98 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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
import requests
import socket
import urllib3
import re
from urllib.parse import urlparse, parse_qs, urlencode
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("""
=================================
web scanner PYTHON3
Simple Web Vulnerability Tool
=================================
""")
target = input("Enter target URL (example: https://example.com): ").strip()
headers = {"User-Agent": "Mozilla/5.0"}
parsed = urlparse(target)
domain = parsed.netloc
# --------------------------------
# Site Status
# --------------------------------
def check_site():
try:
r = requests.get(target, headers=headers, timeout=10, verify=False)
print("\n[+] Site is UP")
print("Status Code:", r.status_code)
except:
print("\n[-] Site unreachable")
exit()
# --------------------------------
# Header Security Check
# --------------------------------
def header_check():
print("\n[+] Checking Security Headers")
try:
r = requests.get(target, headers=headers, timeout=10, verify=False)
important = [
"X-Frame-Options",
"Content-Security-Policy",
"X-XSS-Protection",
"Strict-Transport-Security"
]
for h in important:
if h in r.headers:
print("[SAFE]", h, "found")
else:
print("[WARNING]", h, "missing")
except:
print("[WARNING] Header check failed")
# --------------------------------
# Technology Detection
# --------------------------------
def tech_detect():
print("\n[+] Detecting Technologies")
try:
r = requests.get(target, headers=headers, timeout=10, verify=False)
html = r.text.lower()
cookies = r.cookies.get_dict()
server = r.headers.get("Server")
powered = r.headers.get("X-Powered-By")
if server:
print("[INFO] Server:", server)
if powered:
print("[INFO] Powered By:", powered)
for cookie in cookies:
c = cookie.lower()
if "phpsessid" in c:
print("[FOUND] PHP detected")
if "laravel_session" in c:
print("[FOUND] Laravel detected")
if "csrftoken" in c:
print("[FOUND] Django detected")
if "jsessionid" in c:
print("[FOUND] Java / JSP detected")
if "wp-content" in html:
print("[FOUND] WordPress detected")
if "react" in html:
print("[FOUND] ReactJS detected")
if "angular" in html:
print("[FOUND] Angular detected")
if "vue" in html:
print("[FOUND] VueJS detected")
if "jquery" in html:
print("[INFO] jQuery detected")
if "bootstrap" in html:
print("[INFO] Bootstrap detected")
except:
print("[WARNING] Technology detection failed")
# --------------------------------
# XSS Scan
# --------------------------------
def xss_scan():
print("\n[+] Starting XSS Scan")
payload = "<script>alert(1)</script>"
params = parse_qs(parsed.query)
if not params:
print("[INFO] No parameters found in URL")
return
try:
for p in params:
params[p] = payload
query = urlencode(params, doseq=True)
test_url = parsed.scheme + "://" + parsed.netloc + parsed.path + "?" + query
r = requests.get(test_url, headers=headers, verify=False)
if payload in r.text:
print("[!] Possible XSS vulnerability detected")
else:
print("[SAFE] No XSS detected")
except:
print("[WARNING] XSS scan failed")
# --------------------------------
# SQL Injection Scan
# --------------------------------
def sqli_scan():
print("\n[+] Starting SQL Injection Scan")
payload = "'"
params = parse_qs(parsed.query)
if not params:
print("[INFO] No parameters found in URL")
return
try:
for p in params:
params[p] = payload
query = urlencode(params, doseq=True)
test_url = parsed.scheme + "://" + parsed.netloc + parsed.path + "?" + query
r = requests.get(test_url, headers=headers, verify=False)
errors = ["sql syntax","mysql","syntax error","database error"]
for err in errors:
if err in r.text.lower():
print("[!] Possible SQL Injection vulnerability detected")
return
print("[SAFE] No SQL Injection detected")
except:
print("[WARNING] SQL scan failed")
# --------------------------------
# Admin Panel Finder (Accurate)
# --------------------------------
def admin_scan():
print("\n[+] Starting Admin Panel Scan")
paths = [
"admin",
"administrator",
"login",
"panel",
"cpanel",
"dashboard"
]
extensions = ["",".php",".html",".asp",".aspx",".jsp"]
login_keywords = ["password","username","login","signin"]
try:
fake = requests.get(target.rstrip("/") + "/random_admin_test",
headers=headers,
timeout=5,
verify=False)
baseline_length = len(fake.text)
except:
baseline_length = 0
for p in paths:
for ext in extensions:
url = target.rstrip("/") + "/" + p + ext
try:
r = requests.get(url,
headers=headers,
timeout=5,
verify=False)
page = r.text.lower()
if r.status_code in [200,301,302]:
if abs(len(r.text) - baseline_length) > 120:
if any(word in page for word in login_keywords):
print("[FOUND] Admin Panel:", url)
except:
pass
# --------------------------------
# Directory Scan
# --------------------------------
def directory_scan():
print("\n[+] Starting Directory Scan")
dirs = ["backup","uploads","config","private","logs","data","api"]
try:
fake = requests.get(target+"/random_test",
headers=headers,
verify=False)
base_len = len(fake.text)
except:
base_len = 0
for d in dirs:
url = target.rstrip("/") + "/" + d
try:
r = requests.get(url,
headers=headers,
timeout=5,
verify=False)
if abs(len(r.text) - base_len) > 100:
print("[FOUND] Directory:", url)
except:
pass
# --------------------------------
# Robots.txt
# --------------------------------
def robots_scan():
print("\n[+] Checking robots.txt")
try:
r = requests.get(target.rstrip("/")+"/robots.txt",
headers=headers,
verify=False)
if r.status_code == 200:
print("[FOUND] robots.txt")
for line in r.text.split("\n"):
if "Disallow" in line:
print("[INFO]", line.strip())
else:
print("[SAFE] robots.txt not found")
except:
pass
# --------------------------------
# Email Extractor
# --------------------------------
def email_scan():
print("\n[+] Extracting Emails")
try:
r = requests.get(target, headers=headers, verify=False)
emails = re.findall(
r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}",
r.text
)
if emails:
for e in set(emails):
print("[FOUND] Email:", e)
else:
print("[SAFE] No emails found")
except:
print("[WARNING] Email scan failed")
# --------------------------------
# Port Scan
# --------------------------------
def port_scan():
print("\n[+] Starting Port Scan")
ports = [21,22,23,25,53,80,110,139,143,443,3306,8080]
for port in ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((domain, port))
if result == 0:
print("[OPEN] Port", port)
sock.close()
except:
pass
# --------------------------------
# Subdomain Scan
# --------------------------------
def subdomain_scan():
print("\n[+] Starting Subdomain Scan")
subs = ["www","mail","ftp","admin","blog","test","dev","api","portal"]
for s in subs:
url = f"https://{s}.{domain}"
try:
requests.get(url, timeout=3, verify=False)
print("[FOUND]", url)
except:
pass
# --------------------------------
# Run Scanner
# --------------------------------
check_site()
header_check()
tech_detect()
xss_scan()
sqli_scan()
admin_scan()
directory_scan()
robots_scan()
email_scan()
port_scan()
subdomain_scan()
print("\nScan Completed")