forked from op7ic/meraki-hunting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getMXfirewallrules.py
137 lines (119 loc) · 6.59 KB
/
getMXfirewallrules.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
##########################################################
# Author : Jerzy 'Yuri' Kramarz (op7ic) #
# Version : 1.0 #
# Type : Python #
# Description : See README.md for details #
# License : See LICENSE for details #
##########################################################
import csv
from datetime import datetime
import meraki
import os
# Instructions:
# Set APIKEY in environment variable MERAKI_DASHBOARD_API_KEY.
# Install meraki via 'pip install meraki' command
def select_org(dashboard):
# Fetch and select the organization
print('[+] Fetching organizations...')
organizations = dashboard.organizations.getOrganizations()
organizations.sort(key=lambda x: x['name'])
counter = 0
print('[+] Select organization to query:')
for organization in organizations:
orgName = organization['name']
print(f'{counter} - {orgName}')
counter+=1
isDone = False
while isDone == False:
selected = input('[+] Select the organization ID you would like to query: ')
try:
if int(selected) in range(0,counter):
isDone = True
else:
print('\tInvalid Organization Number\n')
except:
print('\tInvalid Organization Number\n')
return(organizations[int(selected)]['id'], organizations[int(selected)]['name'])
os.makedirs('./logs/', exist_ok=True)
dashboard = meraki.DashboardAPI(output_log=True, log_path="./logs/",log_file_prefix=os.path.basename(__file__), print_console=False)
selected_org, orgName = select_org(dashboard)
print("[+] Organization ID: %s " % (selected_org))
print("[+] Grabbing Network Device List")
devices = dashboard.organizations.getOrganizationDevicesAvailabilities(organizationId=selected_org)
networkIDs = []
for a in devices:
if (a['status'] == 'online'):
netID = a['network']['id']
if netID not in networkIDs:
networkIDs.append(netID)
print("[+] Dumping Cellular Firewall Rules")
with open('cellular-firewall-rules.csv', 'w', newline='', encoding='utf-8') as f:
csv_header = ['network ID','firewall rule type','network name','timezone','policy', 'protocol', 'destCidr','destPort','srcCidr','srcPort','syslogEnabled','comment']
writer = csv.writer(f)
writer.writerow(csv_header)
for x in networkIDs:
network_meta = dashboard.networks.getNetwork(x)
print("[+] Grabbing cellular firewall rules for %s" % (network_meta['name']))
try:
cell_events = dashboard.appliance.getNetworkApplianceFirewallCellularFirewallRules(networkId=x)
for rules in cell_events['rules']:
writer.writerow([x,'CellularFirewallRules',network_meta['name'],network_meta['timeZone'],rules['policy'],rules['protocol'],rules['destCidr'],rules['destPort'],rules['srcCidr'],rules['srcPort'],rules['syslogEnabled'],rules['comment']])
except:
pass
print("[+] Dumping Inbound Firewall Rules")
with open('inbound-firewall-rules.csv', 'w', newline='', encoding='utf-8') as f:
csv_header = ['network ID','firewall rule type','network name','timezone','policy', 'protocol', 'destCidr','destPort','srcCidr','srcPort','syslogEnabled','comment']
writer = csv.writer(f)
writer.writerow(csv_header)
for x in networkIDs:
network_meta = dashboard.networks.getNetwork(x)
print("[+] Grabbing inbound firewall rules for %s" % (network_meta['name']))
try:
inbound_events = dashboard.appliance.getNetworkApplianceFirewallInboundFirewallRules(networkId=x)
for rules in inbound_events['rules']:
writer.writerow([x,'InboundFirewallRules',network_meta['name'],network_meta['timeZone'],rules['policy'],rules['protocol'],rules['destCidr'],rules['destPort'],rules['srcCidr'],rules['srcPort'],rules['syslogEnabled'],rules['comment']])
except:
pass
print("[+] Dumping Layer 3 Firewall Rules")
with open('l3-firewall-rules.csv', 'w', newline='', encoding='utf-8') as f:
csv_header = ['network ID','firewall rule type','network name','timezone','policy', 'protocol', 'destCidr','destPort','srcCidr','srcPort','syslogEnabled','comment']
writer = csv.writer(f)
writer.writerow(csv_header)
for x in networkIDs:
network_meta = dashboard.networks.getNetwork(x)
print("[+] Grabbing l3 firewall rules for %s" % (network_meta['name']))
try:
l3_events = dashboard.appliance.getNetworkApplianceFirewallL3FirewallRules(networkId=x)
for rules in l3_events['rules']:
writer.writerow([x,'L3FirewallRules',network_meta['name'],network_meta['timeZone'],rules['policy'],rules['protocol'],rules['destCidr'],rules['destPort'],rules['srcCidr'],rules['srcPort'],rules['syslogEnabled'],rules['comment']])
except:
pass
print("[+] Dumping Layer 7 Firewall Rules")
with open('l7-firewall-rules.csv', 'w', newline='', encoding='utf-8') as f:
csv_header = ['network ID','firewall rule type','network name','timezone','policy', 'type', 'value']
writer = csv.writer(f)
writer.writerow(csv_header)
for x in networkIDs:
network_meta = dashboard.networks.getNetwork(x)
print("[+] Grabbing l7 firewall rules for %s" % (network_meta['name']))
try:
l7_events = dashboard.appliance.getNetworkApplianceFirewallL7FirewallRules(networkId=x)
for rules in l7_events['rules']:
writer.writerow([x,'L7FirewallRules',network_meta['name'],network_meta['timeZone'],rules['policy'],rules['type'],rules['value']])
except:
pass
print("[+] Dumping Firewall Port Forwarding Rules")
with open('port-fw-firewall-rules.csv', 'w', newline='', encoding='utf-8') as f:
csv_header = ['network ID','firewall rule type','network name','timezone','lanIp', 'allowedIps', 'protocol','publicPort','localPort','uplink','name']
writer = csv.writer(f)
writer.writerow(csv_header)
for x in networkIDs:
network_meta = dashboard.networks.getNetwork(x)
print("[+] Grabbing port forwarding firewall rules for %s" % (network_meta['name']))
try:
l7_events = dashboard.appliance.getNetworkApplianceFirewallL7FirewallRules(networkId=x)
for rules in l7_events['rules']:
writer.writerow([x,'portForwardingRules',network_meta['name'],network_meta['timeZone'],rules['lanIp'],rules['allowedIps'],rules['protocol'], rules['publicPort'], rules['localPort'] , rules['uplink'], rules['name'] ])
except:
pass
print("[+] Done. Happy hunting !")