Skip to content

Commit 2b0f8ff

Browse files
authored
Add banner plugin (#86)
1 parent 8b633bb commit 2b0f8ff

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

.pre-commit-config.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
---
22
repos:
3-
- repo: https://github.com/gitguardian/ggshield
4-
rev: main
5-
hooks:
6-
- id: ggshield
7-
language_version: python3
8-
stages: [commit]
93
- repo: https://github.com/adrienverge/yamllint.git
104
sha: v1.26.3
115
hooks:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# flake8: noqa
2+
3+
from ..core.base_plugin import GenericPlugin
4+
from ..issue.cisco_ios_issue import CiscoIOSIssue
5+
6+
class PluginBanner(GenericPlugin):
7+
8+
def __init__(self):
9+
super().__init__()
10+
11+
def name(self):
12+
return "Banner"
13+
14+
def _has_banner_login_defined(self, filename: str) -> bool:
15+
parser = self.parse_cisco_ios_config_file(filename)
16+
banner_text_defined = parser.find_objects("banner login ")
17+
if (len(banner_text_defined) > 0):
18+
return True
19+
else:
20+
return False
21+
22+
def get_banner_login_text(self, filename: str):
23+
if not self._has_banner_login_defined(filename):
24+
return CiscoIOSIssue(
25+
"Banner Login",
26+
"Network banners are electronic messages that provide notice of legal rights to users of computer networks. When a user connects to the router, the message-of-the-day (MOTD) banner (if configured) appears first, followed by the login banner and prompts. After the user successfully logs into the router, the EXEC banner or incoming banner will be displayed, depending on the type of connection", # noqa: E501
27+
"Organizations should provide appropriate legal notice(s) and warning(s) to persons accessing their networks by using a 'banner-text' for the banner login command", # noqa: E501
28+
"Not have a Login Banner with law impact is a bad practice to an organization. Users that access to the device should know the impact of their actions.", # noqa: E501
29+
"Configure the device so a login banner presented to a user attempting to access the device: banner login <char>" # noqa: E501
30+
)
31+
32+
def _has_banner_motd_defined(self, filename: str) -> bool:
33+
parser = self.parse_cisco_ios_config_file(filename)
34+
banner_text_defined = parser.find_objects("banner motd ")
35+
if (len(banner_text_defined) > 0):
36+
return True
37+
else:
38+
return False
39+
40+
def get_banner_motd_text(self, filename: str):
41+
if not self._has_banner_motd_defined(filename):
42+
return CiscoIOSIssue(
43+
"Banner MOTD",
44+
"Network banners are electronic messages that provide notice to users of computer networks. The MOTD banner is displayed to all terminals connected and is useful for sending messages that affect all users (such as impending system shutdowns).", # noqa: E501
45+
"Organizations should provide appropriate legal notice(s) and warning(s) to persons accessing their networks by using a 'banner-text' for the banner motd command.", # noqa: E501
46+
"Not have a MOTD Banner with law impact is a bad practice to an organization. Users that access to the device should know the impact of their actions.", # noqa: E501
47+
"Configure the message of the day (MOTD) banner presented when a user first connects to the device: banner motd <char>" # noqa: E501
48+
)
49+
50+
def _has_banner_webauth_defined(self, filename: str) -> bool:
51+
parser = self.parse_cisco_ios_config_file(filename)
52+
banner_text_defined = parser.find_objects("ip admission auth-proxy-banner http ")
53+
if (len(banner_text_defined) > 0):
54+
return True
55+
else:
56+
return False
57+
58+
def get_banner_webauth_text(self, filename: str):
59+
if not self._has_banner_webauth_defined(filename):
60+
return CiscoIOSIssue(
61+
"Banner WebAuth",
62+
"Network banners are electronic messages that provide notice to users of computer networks. The WebAuth banner is displayed to all terminals connected and is useful for sending messages that affect all users connected by HTTP.", # noqa: E501
63+
"Organizations should provide appropriate legal notice(s) and warning(s) to persons accessing their networks by using a 'banner-text' for the banner webauth command.", # noqa: E501
64+
"Not have a MOTD Banner with law impact is a bad practice to an organization. Users that access to the device by HTTP should know the impact of their actions.", # noqa: E501
65+
"Configure the message of the day (MOTD) WebAuth banner presented when a user first connects to the device: ip admission auth-proxy-banner http <banner-text | filepath>" # noqa: E501
66+
)
67+
68+
def analyze(self, config_file) -> None:
69+
issues = []
70+
71+
issues.append(self.get_banner_login_text(config_file))
72+
issues.append(self.get_banner_motd_text(config_file))
73+
issues.append(self.get_banner_webauth_text(config_file))
74+
75+
for issue in issues:
76+
if issue is not None:
77+
self.add_issue(issue)

0 commit comments

Comments
 (0)