|
| 1 | +from comfy import high |
| 2 | + |
| 3 | + |
| 4 | +@high( |
| 5 | + name='rule_cve202220846', |
| 6 | + platform=['cisco_xr'], |
| 7 | + commands=dict( |
| 8 | + show_version='show version', |
| 9 | + check_cdp='show running-config | include cdp' |
| 10 | + ), |
| 11 | +) |
| 12 | +def rule_cve202220846(configuration, commands, device, devices): |
| 13 | + """ |
| 14 | + This rule checks for the CVE-2022-20846 vulnerability in Cisco IOS XR Software. |
| 15 | + The vulnerability is due to a heap buffer overflow in certain Cisco Discovery Protocol messages. |
| 16 | + An unauthenticated, adjacent attacker could exploit this vulnerability by sending malicious |
| 17 | + Cisco Discovery Protocol packets to an affected device, causing the CDP process to reload. |
| 18 | + """ |
| 19 | + # List of vulnerable versions |
| 20 | + vulnerable_versions = [ |
| 21 | + '6.5.1', '6.5.2', '6.5.3', '6.5.15', '6.5.25', '6.5.26', '6.5.28', '6.5.29', |
| 22 | + '6.5.31', '6.5.32', '6.5.90', '6.5.92', '6.5.93', |
| 23 | + '6.6.1', '6.6.2', '6.6.3', '6.6.4', '6.6.11', '6.6.12', '6.6.25', |
| 24 | + '6.7.1', '6.7.2', '6.7.3', '6.7.4', '6.7.35', |
| 25 | + '6.8.1', '6.8.2', '6.9.1', |
| 26 | + '7.0.0', '7.0.1', '7.0.2', '7.0.11', '7.0.12', '7.0.14', '7.0.90', |
| 27 | + '7.1.1', '7.1.2', '7.1.3', '7.1.15', '7.1.25', |
| 28 | + '7.2.0', '7.2.1', '7.2.2', '7.2.12', |
| 29 | + '7.3.1', '7.3.2', '7.3.3', '7.3.4', '7.3.15', '7.3.16', '7.3.27', |
| 30 | + '7.4.1', '7.4.2', '7.4.15', '7.4.16', |
| 31 | + '7.5.1', '7.5.2', '7.5.12', |
| 32 | + '7.6.1', '7.6.15' |
| 33 | + ] |
| 34 | + |
| 35 | + # Extract the version information |
| 36 | + version_output = commands.show_version |
| 37 | + |
| 38 | + # Check if version is vulnerable |
| 39 | + version_vulnerable = any(version in version_output for version in vulnerable_versions) |
| 40 | + |
| 41 | + # If version is not vulnerable, no need to check further |
| 42 | + if not version_vulnerable: |
| 43 | + return |
| 44 | + |
| 45 | + # Extract the output of the command to check CDP configuration |
| 46 | + cdp_output = commands.check_cdp |
| 47 | + |
| 48 | + # Check if CDP is enabled (CDP is enabled by default unless explicitly disabled) |
| 49 | + cdp_disabled = 'no cdp' in cdp_output |
| 50 | + |
| 51 | + # Assert that the device is not vulnerable |
| 52 | + assert cdp_disabled, ( |
| 53 | + f"Device {device.name} is vulnerable to CVE-2022-20846. " |
| 54 | + "The device is running a vulnerable version with CDP enabled, " |
| 55 | + "which could allow an adjacent attacker to cause a denial of service through malicious CDP packets. " |
| 56 | + "For more information, see" |
| 57 | + "https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-xr-cdp-wnALzvT2" |
| 58 | + ) |
0 commit comments