|
1 | 1 | from comfy import high |
2 | | - |
| 2 | +import re |
3 | 3 |
|
4 | 4 | @high( |
5 | 5 | name='rule_cve202220623', |
|
11 | 11 | ) |
12 | 12 | def rule_cve202220623(configuration, commands, device, devices): |
13 | 13 | """ |
14 | | - This rule checks for the CVE-2022-20623 vulnerability in Cisco NX-OS Software. |
15 | | - The vulnerability is due to a logic error in the BFD rate limiter functionality of Nexus 9000 Series Switches. |
16 | | - An unauthenticated, remote attacker could exploit this vulnerability by sending a crafted stream of traffic |
17 | | - through the device, causing BFD traffic to be dropped and resulting in BFD session flaps, route instability, |
18 | | - and a denial of service condition. |
| 14 | + CVE-2022-20623: BFD DoS vulnerability in Cisco NX-OS. |
| 15 | + Affects Nexus 9000 Series if BFD is enabled and version ≤ 7.0(3)I7(10) or ≤ 9.3(8). |
19 | 16 | """ |
20 | | - # Extract the platform information |
21 | 17 | platform_output = commands.show_version |
| 18 | + bfd_output = commands.check_bfd |
22 | 19 |
|
23 | | - # Check if the device is a Nexus 9000 Series |
| 20 | + # 1. Check if device is a Nexus 9000 |
24 | 21 | is_n9k = 'Nexus 9000' in platform_output |
25 | | - |
26 | | - # If not a Nexus 9000 device, it's not vulnerable |
27 | 22 | if not is_n9k: |
28 | 23 | return |
29 | 24 |
|
30 | | - # Extract the output of the command to check BFD configuration |
31 | | - bfd_output = commands.check_bfd |
32 | | - |
33 | | - # Check if BFD is enabled |
| 25 | + # 2. Check if BFD is enabled |
34 | 26 | bfd_enabled = 'feature bfd' in bfd_output |
| 27 | + if not bfd_enabled: |
| 28 | + return |
| 29 | + |
| 30 | + # 3. Extract NX-OS version |
| 31 | + match = re.search(r'NXOS:\s+version\s+([\w\.\(\)]+)', platform_output, re.IGNORECASE) |
| 32 | + if not match: |
| 33 | + return # Can't extract version |
| 34 | + |
| 35 | + version = match.group(1) |
| 36 | + |
| 37 | + def parse_version(ver): |
| 38 | + return [int(x) if x.isdigit() else x for x in re.split(r'[\.\(\)I]+', ver) if x] |
| 39 | + |
| 40 | + v = parse_version(version) |
| 41 | + is_vulnerable = False |
| 42 | + |
| 43 | + # 4. Compare version against vulnerable builds |
| 44 | + if version.startswith("7.0.3") and 'I' in version: |
| 45 | + is_vulnerable = v <= parse_version("7.0.3.I7.10") |
| 46 | + elif version.startswith("9.3"): |
| 47 | + is_vulnerable = v <= parse_version("9.3.8") |
35 | 48 |
|
36 | | - # Assert that the device is not vulnerable |
37 | | - assert not bfd_enabled, ( |
| 49 | + # 5. Assert only if BFD is enabled and version is affected |
| 50 | + assert not is_vulnerable, ( |
38 | 51 | f"Device {device.name} is vulnerable to CVE-2022-20623. " |
39 | | - "The device is a Nexus 9000 Series switch with BFD enabled, " |
40 | | - "which could allow an unauthenticated attacker to cause BFD session flaps and a denial of service " |
41 | | - "through crafted traffic. " |
42 | | - "For more information, see" |
43 | | - "https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-nxos-bfd-dos-wGQXrzxn" |
| 52 | + f"Nexus 9000 Series switch with NX-OS version {version} has BFD enabled, " |
| 53 | + "which could allow a remote attacker to cause BFD session flaps and a denial of service. " |
| 54 | + "See: https://sec.cloudapps.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-nxos-bfd-dos-wGQXrzxn" |
44 | 55 | ) |
0 commit comments