-
Notifications
You must be signed in to change notification settings - Fork 0
/
cisco_ios_cis_compliance.py
306 lines (262 loc) · 13.2 KB
/
cisco_ios_cis_compliance.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import napalm
from getpass import getpass
from ciscoconfparse import CiscoConfParse
from pprint import pprint
import csv
class Connection:
def __init__(self, hostname, operating_system, username, password):
self.hostname = hostname
self.operating_system = operating_system
self.username = username
self.password = password
self.napalm_driver = napalm.get_network_driver(operating_system)
self.napalm_connection = self.napalm_driver(hostname, username, password)
self.facts = self.get_facts()
self.config = self.get_config()
def get_facts(self):
self.napalm_connection.open()
facts = self.napalm_connection.get_facts()
self.napalm_connection.close()
return facts
def get_config(self):
self.napalm_connection.open()
config = self.napalm_connection.get_config()
self.napalm_connection.close()
return config
class Configuration:
def __init__(self, hostname, operating_system, configuration):
self.hostname = str(hostname)
self.operating_system = str(operating_system)
self.configuration = configuration
self.save_config()
self.parsed_config = CiscoConfParse(str(self.hostname) + '.conf', syntax=self.operating_system)
def save_config(self):
with open(str(self.hostname) + '.conf', 'w') as f:
f.write(self.configuration['running'])
def check_aaa_new_model(parsed_config):
'''
Description:
This command enables the AAA access control system.
Rationale:
Authentication, authorization and accounting (AAA) services provide an authoritative
source for managing and monitoring access for devices. Centralizing control improves
consistency of access control, the services that may be accessed once authenticated and
accountability by tracking services accessed. Additionally, centralizing access control
simplifies and reduces administrative costs of account provisioning and de-provisioning,
especially when managing a large number of devices.
Audit:
Perform the following to determine if AAA services are enabled:
hostname#show running-config | inc aaa new-model
'''
print('check aaa new-model')
aaa_new_model = parsed_config.find_objects('^aaa new-model')
no_aaa_new_model = parsed_config.find_objects('^no aaa new-model')
print(aaa_new_model)
if aaa_new_model != [] and no_aaa_new_model == []:
print('aaa new-model is in compliance\n\n')
elif aaa_new_model == [] and no_aaa_new_model != []:
print('aaa new-model is NOT in compliance\n\n')
def check_aaa_authentication_login(parsed_config):
'''
Description:
Sets authentication, authorization and accounting (AAA) authentication at login.
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA. Fallback mode should also be enabled to allow emergency
access to the router or switch in the event that the AAA server was unreachable, by
utilizing the LOCAL keyword after the AAA server-tag.
Audit:
Perform the following to determine if AAA authentication for login is enabled:
hostname#show running-config | incl aaa authentication login
'''
print('check aaa authentication login')
aaa_authentication_login = parsed_config.find_objects('^aaa authentication login')
print(aaa_authentication_login)
if aaa_authentication_login != []:
print('aaa authentication login is in compliance\n\n')
elif aaa_authentication_login == []:
print('aaa authentication login is NOT in compliance\n\n')
def check_aaa_authentication_enable_default(parsed_config):
'''
Description:
Authenticates users who access privileged EXEC mode when they use the enable command.
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA.
Audit:
Perform the following to determine if AAA authentication enable mode is enabled:
hostname#show running-config | incl aaa authentication enable
'''
print('check aaa authentication enable default')
aaa_authentication_enable = parsed_config.find_objects('^aaa authentication enable')
print(aaa_authentication_enable)
if aaa_authentication_enable != []:
print('aaa authentication enable is in compliance\n\n')
elif aaa_authentication_enable == []:
print('aaa authentication enable is NOT in compliance\n\n')
def check_line_con_0_authentication(parsed_config):
'''
Description:
Authenticates users who access the router or switch using the serial console port.
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA.
Audit:
Perform the following to determine if AAA authentication for line login is enabled:
If the command does not return a result for each management access method, the feature is
not enabled
hostname#show running-config | sec line | incl login authentication
'''
print('check line con 0 authentication')
line_con_auth = parsed_config.find_objects_w_parents(parentspec='^line con', childspec='^ login auth')
print(line_con_auth)
if line_con_auth != []:
print('line con 0 authenctication is in compliance\n\n')
else:
print('line con 0 authenctication is NOT in compliance\n\n')
def check_line_vty_authentication(parsed_config):
'''
Description:
Authenticates users who access the router or switch using the TTY port.
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA.
Audit:
Perform the following to determine if AAA authentication for line login is enabled:
If the command does not return a result for each management access method, the feature is
not enabled
hostname#show running-config | sec line | incl login authentication
'''
print('check line vty authentication')
line_vty_auth = parsed_config.find_objects_w_parents(parentspec='^line vty 0', childspec='^ login auth')
if line_vty_auth != []:
print(line_vty_auth)
print('line vty authenctication is in compliance\n\n')
else:
print('line vty authenctication is NOT in compliance\n\n')
def check_line_vty_5_authentication(parsed_config):
'''
Description:
Authenticates users who access the router or switch using the TTY port.
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA.
Audit:
Perform the following to determine if AAA authentication for line login is enabled:
If the command does not return a result for each management access method, the feature is
not enabled
hostname#show running-config | sec line | incl login authentication
'''
print('check line vty 5+ authentication')
line_vty_auth = parsed_config.find_objects_w_parents(parentspec='^line vty 5', childspec='^ login auth')
if line_vty_auth != []:
print(line_vty_auth)
print('line vty 5+ authenctication is in compliance\n\n')
else:
print('line vty 5+ authenctication is NOT in compliance\n\n')
def check_http_auth(parsed_config):
'''
Description:
If account management functions are not automatically enforced, an attacker could gain
privileged access to a vital element of the network security architecture
Rationale:
Using AAA authentication for interactive management access to the device provides
consistent, centralized control of your network. The default under AAA (local or network)
is to require users to log in using a valid user name and password. This rule applies for
both local and network AAA.
Audit:
Perform the following to determine if AAA authentication for line login is enabled:
If the command does not return a result for each management access method, the feature is
not enabled
hostname#show running-config | inc ip http authentication
'''
print('check http auth')
if (parsed_config.find_objects('^ip http server') or parsed_config.find_objects('^ip http secure-server')) != []:
if 'ip http authentication' in (parsed_config.find_objects('^ip http auth')):
print(parsed_config.find_objects('^ip http auth'))
print('http auth is in compliance\n\n')
else:
print('http auth is NOT in compliance\n\n')
else:
print('http(s) server not configured\n\n')
def check_aaa_accounting(parsed_config):
'''
Description:
Runs accounting for all commands at the specified privilege level.
Rationale:
Authentication, authorization and accounting (AAA) systems provide an authoritative
source for managing and monitoring access for devices. Centralizing control improves
consistency of access control, the services that may be accessed once authenticated and
accountability by tracking services accessed. Additionally, centralizing access control
simplifies and reduces administrative costs of account provisioning and de-provisioning,
especially when managing a large number of devices. AAA Accounting provides a
management and audit trail for user and administrative sessions through RADIUS or
TACACS+.
Audit:
Perform the following to determine if aaa accounting for commands is required:
Verify a command string result returns
hostname#show running-config | incl aaa accounting commands
'''
print('aaa accounting check')
aaa_accounting = parsed_config.find_objects('^aaa accounting commands')
print(aaa_accounting)
if aaa_accounting != []:
print('aaa accounting is in compliance\n\n')
elif aaa_accounting == []:
print('aaa accounting is NOT in compliance\n\n')
def check_aaa_accounting_connection(parsed_config):
'''
Description:
Provides information about all outbound connections made from the network access
server.
Rationale:
Authentication, authorization and accounting (AAA) systems provide an authoritative
source for managing and monitoring access for devices. Centralizing control improves
consistency of access control, the services that may be accessed once authenticated and
accountability by tracking services accessed. Additionally, centralizing access control
simplifies and reduces administrative costs of account provisioning and de-provisioning,
especially when managing a large number of devices. AAA Accounting provides a
management and audit trail for user and administrative sessions through RADIUS and
TACACS+.
Audit:
Perform the following to determine if aaa accounting for connection is required:
Verify a command string result returns
hostname#show running-config | incl aaa accounting connection
'''
print('aaa accounting connection check')
aaa_accounting_connection = parsed_config.find_objects('^aaa accounting connection')
print(aaa_accounting_connection)
if aaa_accounting_connection != []:
print('aaa accounting connection is in compliance\n\n')
elif aaa_accounting_connection == []:
print('aaa accounting connection is NOT in compliance\n\n')
def main():
with open('devices.csv') as csv_file:
csv_dict = csv.DictReader(csv_file, delimiter=',')
devices = []
for row in csv_dict:
devices.append(row)
for device in devices:
device_connection = Connection(device['hostname'], device['operating_system'], device['username'], device['password'])
device_configuration = Configuration(device_connection.hostname, device_connection.operating_system, device_connection.config)
check_aaa_new_model(device_configuration.parsed_config)
check_aaa_authentication_login(device_configuration.parsed_config)
check_aaa_authentication_enable_default(device_configuration.parsed_config)
check_line_con_0_authentication(device_configuration.parsed_config)
check_line_vty_authentication(device_configuration.parsed_config)
check_line_vty_5_authentication(device_configuration.parsed_config)
check_http_auth(device_configuration.parsed_config)
check_aaa_accounting(device_configuration.parsed_config)
check_aaa_accounting_connection(device_configuration.parsed_config)
if __name__ == "__main__":
main()