-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecuritydetails.py
More file actions
138 lines (103 loc) · 4.87 KB
/
securitydetails.py
File metadata and controls
138 lines (103 loc) · 4.87 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
import requests
import xlsxwriter
from pathlib import Path
import time
from datetime import datetime
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
center_port = 443
center_base_url = "api/3.0"
def get(center_token, center_ip):
try:
headers = { "x-token-id": center_token }
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets",headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
#raw JSON data response
presets = r_get.json()
id = 0
dns_dict = dict()
http_dict = dict()
smb_dict = dict()
for preset in presets:
if preset['label'] == "All data":
id = preset['id']
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/dns/list",headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
dns = r_get.json()
for d in dns:
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/dns/components?property-value={d['label']}", headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
details = r_get.json()
dns_dict[d['label']] = details
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/http/list",headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
http = r_get.json()
for h in http:
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/http/components?property-value={h['label']}", headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
details = r_get.json()
http_dict[h['label']] = details
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/smb/list",headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
smb = r_get.json()
for s in smb:
r_get = requests.get(f"https://{center_ip}:{center_port}/{center_base_url}/presets/{id}/visualisations/dashboard-security/smb/components?property-value={s['label']}", headers=headers,verify=False)
r_get.raise_for_status() #if there are any request errors
details = r_get.json()
smb_dict[s['label']] = details
return [dns_dict, http_dict, smb_dict]
except Exception as e:
return f"Error when connecting: {e}"
def get_security_details(center_token, center_ip):
data = get(center_token, center_ip)
now = datetime.now()
current_time = now.strftime("%m-%d-%Y_%H-%M-%S")
file_name = "Cyber Vision Security Insights_" + current_time + ".xlsx"
workbook = xlsxwriter.Workbook(file_name)
sheet1 = workbook.add_worksheet("DNS")
sheet1.write(0, 0, 'DNS')
sheet1.write(0, 1, 'Request Count')
sheet1.write(0, 2, 'Component')
sheet1.write(0, 3, 'IP')
sheet1.write(0, 4, 'MAC')
index = 1
for dns in data[0].keys():
for component in data[0][dns]:
sheet1.write(index, 0, dns)
sheet1.write(index, 1, component['requestsCount'])
sheet1.write(index, 2, component['label'])
sheet1.write(index, 3, component['ip'])
sheet1.write(index, 4, component['mac'])
index += 1
sheet2 = workbook.add_worksheet("HTTP")
sheet2.write(0, 0, 'HTTP')
sheet2.write(0, 1, 'Request Count')
sheet2.write(0, 2, 'Component')
sheet2.write(0, 3, 'IP')
sheet2.write(0, 4, 'MAC')
index = 1
for http in data[1].keys():
for component in data[1][http]:
sheet2.write(index, 0, http)
sheet2.write(index, 1, component['requestsCount'])
sheet2.write(index, 2, component['label'])
sheet2.write(index, 3, component['ip'])
sheet2.write(index, 4, component['mac'])
index += 1
sheet3 = workbook.add_worksheet("SMB")
sheet3.write(0, 0, 'SMB')
sheet3.write(0, 1, 'Request Count')
sheet3.write(0, 2, 'Component')
sheet3.write(0, 3, 'IP')
sheet3.write(0, 4, 'MAC')
index = 1
for smb in data[2].keys():
for component in data[2][smb]:
sheet3.write(index, 0, smb)
sheet3.write(index, 1, component['requestsCount'])
sheet3.write(index, 2, component['label'])
sheet3.write(index, 3, component['ip'])
sheet3.write(index, 4, component['mac'])
index += 1
workbook.close()
print("Security Insight Report in this directory: " + str(Path.cwd()))