-
Notifications
You must be signed in to change notification settings - Fork 3
/
Scan.py
68 lines (51 loc) · 1.58 KB
/
Scan.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
#!/usr/bin/env python
import json
import os
import tldextract
from dotenv import load_dotenv
from zapv2 import ZAPv2
load_dotenv()
APIKEY = os.getenv('ZAP_APIKEY')
PROXIES = {'http': os.getenv('ZAP_PROXIES_HTTP'),
'https': os.getenv('ZAP_PROXIES_HTTPS')}
FILEPATH = os.getenv("FILEPATH")
TIMEOUT = os.getenv("TIME_OUT")
def spider_scan(target):
zap = ZAPv2(apikey=APIKEY,
proxies=PROXIES)
scanID = zap.spider.scan(target)
while int(zap.spider.status(scanID)) < 100:
pass
return list((map(str, zap.spider.results(scanID))))
def passive_scan():
zap = ZAPv2(apikey=APIKEY,
proxies=PROXIES)
while int(zap.pscan.records_to_scan) > 0:
pass
return {
'Hosts': zap.core.hosts,
'Active Scan Alerts': zap.core.alerts()
}
def active_scan(target):
zap = ZAPv2(apikey=APIKEY,
proxies=PROXIES)
scanID = zap.ascan.scan(target)
zap.core.set_option_timeout_in_secs(int(TIMEOUT))
while int(zap.ascan.status(scanID)) < 100:
pass
return {
'Hosts': zap.core.hosts,
'Active Scan Alerts': zap.core.alerts(baseurl=target)
}
def scan(target):
try:
host_list = spider_scan(target)
alerts = active_scan(target)
json.dump({
'target': target,
'paths': host_list,
'scan': alerts,
}, open('{}/{}.json'.format(FILEPATH, tldextract.extract(target).fqdn), "w"))
return 0
except Exception as e:
return e