From 9eb2d6e7c66e7182f345e730f68ffa2cb4c28404 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 27 Jan 2026 12:38:39 -0600 Subject: [PATCH 1/3] Fixed parsing Palo banners that start on the same line --- changes/780.fixed | 1 + netutils/config/conversion.py | 2 +- .../paloalto_panos/paloalto_backup.txt | 14 +++ .../paloalto_panos/paloalto_feature.py | 1 + .../paloalto_panos/paloalto_intended.txt | 16 ++++ .../paloalto_panos/paloalto_received.json | 10 ++ .../paloalto_banner_same_line_converted.txt | 45 +++++++++ .../paloalto_banner_same_line_sent.txt | 93 +++++++++++++++++++ 8 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 changes/780.fixed create mode 100644 tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_converted.txt create mode 100644 tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_sent.txt diff --git a/changes/780.fixed b/changes/780.fixed new file mode 100644 index 00000000..80b6c888 --- /dev/null +++ b/changes/780.fixed @@ -0,0 +1 @@ +Fixed parsing of login banner in Palo Alto Networks config. \ No newline at end of file diff --git a/netutils/config/conversion.py b/netutils/config/conversion.py index a1cc1177..909ccb9a 100644 --- a/netutils/config/conversion.py +++ b/netutils/config/conversion.py @@ -190,7 +190,7 @@ def paloalto_panos_brace_to_set(cfg: str, cfg_type: str = "file") -> str: line = line.split("config ", 1)[1] line = "set " + line cfg_value.append(line.strip()) - elif line.endswith('login-banner "') or line.endswith('content "'): + elif 'login-banner "' in line or line.endswith('content "'): _first_banner_line = "".join(str(s) for s in stack) + line cfg_value.append("set " + _first_banner_line.split("config ", 1)[1]) diff --git a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_backup.txt b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_backup.txt index 9f68533d..556cdf58 100644 --- a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_backup.txt +++ b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_backup.txt @@ -21,6 +21,20 @@ set deviceconfig system service disable-http yes set deviceconfig system service disable-snmp no set deviceconfig system snmp-setting snmp-system set deviceconfig system hostname firewall1 +set deviceconfig system login-banner " +************************************************************************ +* firewall1.example.com * [PROD VM500 firewalls] +************************************************************************ +* WARNING * +* Unauthorized access to this device or devices attached to * +* or accessible from this network is strictly prohibited. * +* Possession of passwords or devices enabling access to this * +* device or devices does not constitute authorization. Unauthorized * +* access will be prosecuted to the fullest extent of the law. * +* * +************************************************************************ + +" set deviceconfig system default-gateway 10.1.1.1 set deviceconfig system dns-setting servers primary 10.1.1.3 set deviceconfig system dns-setting servers secondary 10.1.1.4 diff --git a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_feature.py b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_feature.py index 077595c5..fed48207 100644 --- a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_feature.py +++ b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_feature.py @@ -1,3 +1,4 @@ features = [ {"name": "management", "ordered": False, "section": ["set mgt-config "]}, + {"name": "banner", "ordered": False, "section": ["set deviceconfig system login-banner "]}, ] diff --git a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_intended.txt b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_intended.txt index 9f68533d..1b71f71f 100644 --- a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_intended.txt +++ b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_intended.txt @@ -21,6 +21,22 @@ set deviceconfig system service disable-http yes set deviceconfig system service disable-snmp no set deviceconfig system snmp-setting snmp-system set deviceconfig system hostname firewall1 +set deviceconfig system login-banner "#################################################### +WARNING TO UNAUTHORIZED USERS: +This system is for use by authorized users only. +Any individual using this system, by such use, +acknowledges and consents to the right of the +company to monitor, access, use, and disclose any +information generated, received, or stored on the +systems, and waives any right of privacy or +expectation of privacy on the part of that +individual in connection with his or her use of +this system. Unauthorized and/or improper use of +this system, as delineated by corporate policies, +is not tolerated and the company may take formal +action against such individuals. +#################################################### +" set deviceconfig system default-gateway 10.1.1.1 set deviceconfig system dns-setting servers primary 10.1.1.3 set deviceconfig system dns-setting servers secondary 10.1.1.4 diff --git a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_received.json b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_received.json index b9561ada..d2d4fbc2 100644 --- a/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_received.json +++ b/tests/unit/mock/config/compliance/compliance/paloalto_panos/paloalto_received.json @@ -8,5 +8,15 @@ "missing": "", "ordered_compliant": true, "unordered_compliant": true + }, + "banner": { + "compliant": false, + "missing": "set deviceconfig system login-banner \"####################################################\nWARNING TO UNAUTHORIZED USERS:\nThis system is for use by authorized users only.\nAny individual using this system, by such use,\nacknowledges and consents to the right of the\ncompany to monitor, access, use, and disclose any\ninformation generated, received, or stored on the\nsystems, and waives any right of privacy or\nexpectation of privacy on the part of that\nindividual in connection with his or her use of\nthis system. Unauthorized and/or improper use of\nthis system, as delineated by corporate policies,\nis not tolerated and the company may take formal\naction against such individuals.\n####################################################\n\"", + "extra": "set deviceconfig system login-banner \"\n************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\"", + "cannot_parse": true, + "unordered_compliant": false, + "ordered_compliant": false, + "actual": "set deviceconfig system login-banner \"\n************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\"", + "intended": "set deviceconfig system login-banner \"####################################################\nWARNING TO UNAUTHORIZED USERS:\nThis system is for use by authorized users only.\nAny individual using this system, by such use,\nacknowledges and consents to the right of the\ncompany to monitor, access, use, and disclose any\ninformation generated, received, or stored on the\nsystems, and waives any right of privacy or\nexpectation of privacy on the part of that\nindividual in connection with his or her use of\nthis system. Unauthorized and/or improper use of\nthis system, as delineated by corporate policies,\nis not tolerated and the company may take formal\naction against such individuals.\n####################################################\n\"" } } \ No newline at end of file diff --git a/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_converted.txt b/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_converted.txt new file mode 100644 index 00000000..f9a33bf5 --- /dev/null +++ b/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_converted.txt @@ -0,0 +1,45 @@ +set deviceconfig system ip-address 192.0.2.72 +set deviceconfig system netmask 255.255.255.0 +set deviceconfig system update-server updates.paloaltonetworks.com +set deviceconfig system update-schedule threats recurring weekly day-of-week wednesday +set deviceconfig system update-schedule threats recurring weekly at 01:02 +set deviceconfig system update-schedule threats recurring weekly action download-only +set deviceconfig system timezone UTC +set deviceconfig system service disable-telnet yes +set deviceconfig system service disable-http yes +set deviceconfig system service disable-snmp no +set deviceconfig system hostname pa-ntc +set deviceconfig system type static +set deviceconfig system default-gateway 192.0.2.1 +set deviceconfig system domain ntc +set deviceconfig system locale en +set deviceconfig system speed-duplex auto-negotiate +set deviceconfig system dns-setting servers primary 8.8.8.8 +set deviceconfig system dns-setting servers secondary 1.1.1.1 +set deviceconfig system device-telemetry device-health-performance yes +set deviceconfig system device-telemetry product-usage yes +set deviceconfig system device-telemetry threat-prevention yes +set deviceconfig system device-telemetry region Americas +set deviceconfig system panorama local-panorama panorama-server 192.0.2.58 +set deviceconfig system server-verification no +set deviceconfig system ntp-servers primary-ntp-server ntp-server-address time.google.com +set deviceconfig system ntp-servers primary-ntp-server authentication-type none +set deviceconfig system login-banner "#################################################### +WARNING TO UNAUTHORIZED USERS: +This system is for use by authorized users only. +Any individual using this system, by such use, +acknowledges and consents to the right of the +company to monitor, access, use, and disclose any +information generated, received, or stored on the +systems, and waives any right of privacy or +expectation of privacy on the part of that +individual in connection with his or her use of +this system. Unauthorized and/or improper use of +this system, as delineated by corporate policies, +is not tolerated and the company may take formal +action against such individuals. +#################################################### +" +set deviceconfig system snmp-setting access-setting version v2c snmp-community-string ntc1234 +set deviceconfig system snmp-setting snmp-system location ntc +set deviceconfig system snmp-setting snmp-system contact "john smith" \ No newline at end of file diff --git a/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_sent.txt b/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_sent.txt new file mode 100644 index 00000000..5b6e4756 --- /dev/null +++ b/tests/unit/mock/config/conversion/paloalto_panos/paloalto_banner_same_line_sent.txt @@ -0,0 +1,93 @@ +config { + devices { + localhost.localdomain { + deviceconfig { + system { + ip-address 192.0.2.72; + netmask 255.255.255.0; + update-server updates.paloaltonetworks.com; + update-schedule { + threats { + recurring { + weekly { + day-of-week wednesday; + at 01:02; + action download-only; + } + } + } + } + timezone UTC; + service { + disable-telnet yes; + disable-http yes; + disable-snmp no; + } + hostname pa-ntc; + type { + static; + } + default-gateway 192.0.2.1; + domain ntc; + locale en; + speed-duplex auto-negotiate; + dns-setting { + servers { + primary 8.8.8.8; + secondary 1.1.1.1; + } + } + device-telemetry { + device-health-performance yes; + product-usage yes; + threat-prevention yes; + region Americas; + } + panorama { + local-panorama { + panorama-server 192.0.2.58; + } + } + server-verification no; + ntp-servers { + primary-ntp-server { + ntp-server-address time.google.com; + authentication-type { + none; + } + } + } + login-banner "#################################################### +WARNING TO UNAUTHORIZED USERS: +This system is for use by authorized users only. +Any individual using this system, by such use, +acknowledges and consents to the right of the +company to monitor, access, use, and disclose any +information generated, received, or stored on the +systems, and waives any right of privacy or +expectation of privacy on the part of that +individual in connection with his or her use of +this system. Unauthorized and/or improper use of +this system, as delineated by corporate policies, +is not tolerated and the company may take formal +action against such individuals. +#################################################### +"; + snmp-setting { + access-setting { + version { + v2c { + snmp-community-string ntc1234; + } + } + } + snmp-system { + location ntc; + contact "john smith"; + } + } + } + } + } + } +} \ No newline at end of file From 5cec59812c9cd083f838b7b4688adf56a725944e Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 27 Jan 2026 13:22:16 -0600 Subject: [PATCH 2/3] Added panos banner parsing --- .../paloalto_banner_same_line_received.py | 53 +++++++++++ .../paloalto_banner_same_line_sent.txt | 93 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_received.py create mode 100644 tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_sent.txt diff --git a/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_received.py b/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_received.py new file mode 100644 index 00000000..40279220 --- /dev/null +++ b/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_received.py @@ -0,0 +1,53 @@ +from netutils.config.parser import ConfigLine + +data = [ + ConfigLine(config_line="set deviceconfig system ip-address 192.0.2.72", parents=()), + ConfigLine(config_line="set deviceconfig system netmask 255.255.255.0", parents=()), + ConfigLine(config_line="set deviceconfig system update-server updates.paloaltonetworks.com", parents=()), + ConfigLine( + config_line="set deviceconfig system update-schedule threats recurring weekly day-of-week wednesday", parents=() + ), + ConfigLine(config_line="set deviceconfig system update-schedule threats recurring weekly at 01:02", parents=()), + ConfigLine( + config_line="set deviceconfig system update-schedule threats recurring weekly action download-only", parents=() + ), + ConfigLine(config_line="set deviceconfig system timezone UTC", parents=()), + ConfigLine(config_line="set deviceconfig system service disable-telnet yes", parents=()), + ConfigLine(config_line="set deviceconfig system service disable-http yes", parents=()), + ConfigLine(config_line="set deviceconfig system service disable-snmp no", parents=()), + ConfigLine(config_line="set deviceconfig system hostname pa-ntc", parents=()), + ConfigLine(config_line="set deviceconfig system type static", parents=()), + ConfigLine(config_line="set deviceconfig system default-gateway 192.0.2.1", parents=()), + ConfigLine(config_line="set deviceconfig system domain ntc", parents=()), + ConfigLine(config_line="set deviceconfig system locale en", parents=()), + ConfigLine(config_line="set deviceconfig system speed-duplex auto-negotiate", parents=()), + ConfigLine(config_line="set deviceconfig system dns-setting servers primary 8.8.8.8", parents=()), + ConfigLine(config_line="set deviceconfig system dns-setting servers secondary 1.1.1.1", parents=()), + ConfigLine(config_line="set deviceconfig system device-telemetry device-health-performance yes", parents=()), + ConfigLine(config_line="set deviceconfig system device-telemetry product-usage yes", parents=()), + ConfigLine(config_line="set deviceconfig system device-telemetry threat-prevention yes", parents=()), + ConfigLine(config_line="set deviceconfig system device-telemetry region Americas", parents=()), + ConfigLine(config_line="set deviceconfig system panorama local-panorama panorama-server 192.0.2.58", parents=()), + ConfigLine(config_line="set deviceconfig system server-verification no", parents=()), + ConfigLine( + config_line="set deviceconfig system ntp-servers primary-ntp-server ntp-server-address time.google.com", + parents=(), + ), + ConfigLine( + config_line="set deviceconfig system ntp-servers primary-ntp-server authentication-type none", parents=() + ), + ConfigLine( + config_line='set deviceconfig system login-banner "####################################################', + parents=(), + ), + ConfigLine( + config_line='WARNING TO UNAUTHORIZED USERS:\nThis system is for use by authorized users only.\nAny individual using this system, by such use,\nacknowledges and consents to the right of the\ncompany to monitor, access, use, and disclose any\ninformation generated, received, or stored on the\nsystems, and waives any right of privacy or\nexpectation of privacy on the part of that\nindividual in connection with his or her use of\nthis system. Unauthorized and/or improper use of\nthis system, as delineated by corporate policies,\nis not tolerated and the company may take formal\naction against such individuals.\n####################################################\n"', + parents=('set deviceconfig system login-banner "####################################################',), + ), + ConfigLine( + config_line="set deviceconfig system snmp-setting access-setting version v2c snmp-community-string ntc1234", + parents=(), + ), + ConfigLine(config_line="set deviceconfig system snmp-setting snmp-system location ntc", parents=()), + ConfigLine(config_line='set deviceconfig system snmp-setting snmp-system contact "john smith"', parents=()), +] diff --git a/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_sent.txt b/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_sent.txt new file mode 100644 index 00000000..5b6e4756 --- /dev/null +++ b/tests/unit/mock/config/parser/base/paloalto_panos/paloalto_banner_same_line_sent.txt @@ -0,0 +1,93 @@ +config { + devices { + localhost.localdomain { + deviceconfig { + system { + ip-address 192.0.2.72; + netmask 255.255.255.0; + update-server updates.paloaltonetworks.com; + update-schedule { + threats { + recurring { + weekly { + day-of-week wednesday; + at 01:02; + action download-only; + } + } + } + } + timezone UTC; + service { + disable-telnet yes; + disable-http yes; + disable-snmp no; + } + hostname pa-ntc; + type { + static; + } + default-gateway 192.0.2.1; + domain ntc; + locale en; + speed-duplex auto-negotiate; + dns-setting { + servers { + primary 8.8.8.8; + secondary 1.1.1.1; + } + } + device-telemetry { + device-health-performance yes; + product-usage yes; + threat-prevention yes; + region Americas; + } + panorama { + local-panorama { + panorama-server 192.0.2.58; + } + } + server-verification no; + ntp-servers { + primary-ntp-server { + ntp-server-address time.google.com; + authentication-type { + none; + } + } + } + login-banner "#################################################### +WARNING TO UNAUTHORIZED USERS: +This system is for use by authorized users only. +Any individual using this system, by such use, +acknowledges and consents to the right of the +company to monitor, access, use, and disclose any +information generated, received, or stored on the +systems, and waives any right of privacy or +expectation of privacy on the part of that +individual in connection with his or her use of +this system. Unauthorized and/or improper use of +this system, as delineated by corporate policies, +is not tolerated and the company may take formal +action against such individuals. +#################################################### +"; + snmp-setting { + access-setting { + version { + v2c { + snmp-community-string ntc1234; + } + } + } + snmp-system { + location ntc; + contact "john smith"; + } + } + } + } + } + } +} \ No newline at end of file From 0d603b31f98d8688ee62a25481079452c594a646 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Wed, 28 Jan 2026 13:03:38 -0600 Subject: [PATCH 3/3] Changed login banner detection to be quote agnostic --- netutils/config/conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netutils/config/conversion.py b/netutils/config/conversion.py index 909ccb9a..b6399a1d 100644 --- a/netutils/config/conversion.py +++ b/netutils/config/conversion.py @@ -190,7 +190,7 @@ def paloalto_panos_brace_to_set(cfg: str, cfg_type: str = "file") -> str: line = line.split("config ", 1)[1] line = "set " + line cfg_value.append(line.strip()) - elif 'login-banner "' in line or line.endswith('content "'): + elif "login-banner" in line or line.endswith('content "'): _first_banner_line = "".join(str(s) for s in stack) + line cfg_value.append("set " + _first_banner_line.split("config ", 1)[1])