| 1 | //! Attack Vector (MAV) |
| 2 | |
| 3 | use crate::{ |
| 4 | Error, Result, |
| 5 | v4::metric::{Metric, MetricType}, |
| 6 | }; |
| 7 | use alloc::borrow::ToOwned; |
| 8 | use core::{fmt, str::FromStr}; |
| 9 | |
| 10 | /// Attack Vector (MAV) - CVSS v4.0 Environmental Metric Group |
| 11 | /// |
| 12 | /// Described in CVSS v4.0 Specification: Section 4.2 |
| 13 | /// |
| 14 | /// > This metric reflects the context by which vulnerability exploitation is |
| 15 | /// > possible. This metric value (and consequently the resulting severity) will |
| 16 | /// > be larger the more remote (logically, and physically) an attacker can be |
| 17 | /// > in order to exploit the vulnerable system. The assumption is that the |
| 18 | /// > number of potential attackers for a vulnerability that could be exploited |
| 19 | /// > from across a network is larger than the number of potential attackers |
| 20 | /// > that could exploit a vulnerability requiring physical access to a device, |
| 21 | /// > and therefore warrants a greater severity. |
| 22 | #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 23 | pub enum ModifiedAttackVector { |
| 24 | /// Physical (P) |
| 25 | /// |
| 26 | /// > The attack requires the attacker to physically touch or manipulate the |
| 27 | /// > vulnerable system. Physical interaction may be brief (e.g., evil maid |
| 28 | /// > attack1) or persistent. An example of such an attack is a cold boot |
| 29 | /// > attack in which an attacker gains access to disk encryption keys after |
| 30 | /// > physically accessing the target system. Other examples include |
| 31 | /// > peripheral attacks via FireWire/USB Direct Memory Access (DMA). |
| 32 | Physical, |
| 33 | /// Local (L) |
| 34 | /// |
| 35 | /// > The vulnerable system is not bound to the network stack and the |
| 36 | /// > attacker’s path is via read/write/execute capabilities. Either: the |
| 37 | /// > attacker exploits the vulnerability by accessing the target system |
| 38 | /// > locally (e.g., keyboard, console), or through terminal emulation |
| 39 | /// > (e.g., SSH); or the attacker relies on User Interaction by another |
| 40 | /// > person to perform actions required to exploit the vulnerability (e.g., |
| 41 | /// > using social engineering techniques to trick a legitimate user into |
| 42 | /// > opening a malicious document). |
| 43 | Local, |
| 44 | /// Adjacent (A) |
| 45 | /// |
| 46 | /// > The vulnerable system is bound to a protocol stack, but the attack is |
| 47 | /// > limited at the protocol level to a logically adjacent topology. This |
| 48 | /// > can mean an attack must be launched from the same shared proximity |
| 49 | /// > (e.g., Bluetooth, NFC, or IEEE 802.11) or logical network (e.g., local |
| 50 | /// > IP subnet), or from within a secure or otherwise limited |
| 51 | /// > administrative domain (e.g., MPLS, secure VPN within an administrative |
| 52 | /// > network zone). One example of an Adjacent attack would be an ARP |
| 53 | /// > (IPv4) or neighbor discovery (IPv6) flood leading to a denial of |
| 54 | /// > service on the local LAN segment (e.g., CVE-2013-6014). |
| 55 | Adjacent, |
| 56 | /// Network (N) |
| 57 | /// |
| 58 | /// > The vulnerable system is bound to the network stack and the set of |
| 59 | /// > possible attackers extends beyond the other options listed below, up |
| 60 | /// > to and including the entire Internet. Such a vulnerability is often |
| 61 | /// > termed “remotely exploitable” and can be thought of as an attack being |
| 62 | /// > exploitable at the protocol level one or more network hops away (e.g., |
| 63 | /// > across one or more routers). An example of a network attack is an |
| 64 | /// > attacker causing a denial of service (DoS) by sending a specially |
| 65 | /// > crafted TCP packet across a wide area network (e.g., CVE-2004-0230). |
| 66 | Network, |
| 67 | /// Not Defined (X) |
| 68 | /// |
| 69 | /// > The metric has not been evaluated. |
| 70 | NotDefined, |
| 71 | } |
| 72 | |
| 73 | impl Default for ModifiedAttackVector { |
| 74 | fn default() -> Self { |
| 75 | Self::NotDefined |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | impl Metric for ModifiedAttackVector { |
| 80 | const TYPE: MetricType = MetricType::MAV; |
| 81 | |
| 82 | fn as_str(self) -> &'static str { |
| 83 | match self { |
| 84 | ModifiedAttackVector::NotDefined => "X", |
| 85 | ModifiedAttackVector::Network => "N", |
| 86 | ModifiedAttackVector::Adjacent => "A", |
| 87 | ModifiedAttackVector::Local => "L", |
| 88 | ModifiedAttackVector::Physical => "P", |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | impl fmt::Display for ModifiedAttackVector { |
| 94 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 95 | write!(f, "{}:{}", Self::name(), self.as_str()) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | impl FromStr for ModifiedAttackVector { |
| 100 | type Err = Error; |
| 101 | |
| 102 | fn from_str(s: &str) -> Result<Self> { |
| 103 | match s { |
| 104 | "X" => Ok(ModifiedAttackVector::NotDefined), |
| 105 | "N" => Ok(ModifiedAttackVector::Network), |
| 106 | "A" => Ok(ModifiedAttackVector::Adjacent), |
| 107 | "L" => Ok(ModifiedAttackVector::Local), |
| 108 | "P" => Ok(ModifiedAttackVector::Physical), |
| 109 | _ => Err(Error::InvalidMetricV4 { |
| 110 | metric_type: Self::TYPE, |
| 111 | value: s.to_owned(), |
| 112 | }), |
| 113 | } |
| 114 | } |
| 115 | } |