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