Debian Codegraph @

src/v4/metric/base/av.rs

raw symbols SCIP
1 //! Attack Vector (AV)
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 (AV) - CVSS v4.0 Base Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 2.1.1
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 AttackVector {
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
34 /// Local (L)
35 ///
36 /// > The vulnerable system is not bound to the network stack and the
37 /// > attacker’s path is via read/write/execute capabilities. Either: the
38 /// > attacker exploits the vulnerability by accessing the target system
39 /// > locally (e.g., keyboard, console), or through terminal emulation
40 /// > (e.g., SSH); or the attacker relies on User Interaction by another
41 /// > person to perform actions required to exploit the vulnerability (e.g.,
42 /// > using social engineering techniques to trick a legitimate user into
43 /// > opening a malicious document).
44 Local,
45
46 /// Adjacent (A)
47 ///
48 /// > The vulnerable system is bound to a protocol stack, but the attack is
49 /// > limited at the protocol level to a logically adjacent topology. This
50 /// > can mean an attack must be launched from the same shared proximity
51 /// > (e.g., Bluetooth, NFC, or IEEE 802.11) or logical network (e.g., local
52 /// > IP subnet), or from within a secure or otherwise limited
53 /// > administrative domain (e.g., MPLS, secure VPN within an administrative
54 /// > network zone). One example of an Adjacent attack would be an ARP
55 /// > (IPv4) or neighbor discovery (IPv6) flood leading to a denial of
56 /// > service on the local LAN segment (e.g., CVE-2013-6014).
57 Adjacent,
58
59 /// Network (N)
60 ///
61 /// > The vulnerable system is bound to the network stack and the set of
62 /// > possible attackers extends beyond the other options listed below, up
63 /// > to 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 (e.g.,
66 /// > across one or more routers). An example of a network attack is an
67 /// > 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 Default for AttackVector {
73 fn default() -> Self {
74 Self::Network
75 }
76 }
77
78 impl Metric for AttackVector {
79 const TYPE: MetricType = MetricType::AV;
80
81 fn as_str(self) -> &'static str {
82 match self {
83 AttackVector::Network => "N",
84 AttackVector::Adjacent => "A",
85 AttackVector::Local => "L",
86 AttackVector::Physical => "P",
87 }
88 }
89 }
90
91 impl fmt::Display for AttackVector {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 write!(f, "{}:{}", Self::name(), self.as_str())
94 }
95 }
96
97 impl FromStr for AttackVector {
98 type Err = Error;
99
100 fn from_str(s: &str) -> Result<Self> {
101 match s {
102 "N" => Ok(AttackVector::Network),
103 "A" => Ok(AttackVector::Adjacent),
104 "L" => Ok(AttackVector::Local),
105 "P" => Ok(AttackVector::Physical),
106 _ => Err(Error::InvalidMetricV4 {
107 metric_type: Self::TYPE,
108 value: s.to_owned(),
109 }),
110 }
111 }
112 }
113
114 #[cfg(feature = "std")]
115 pub(crate) mod merge {
116 use super::*;
117 use crate::{
118 Error,
119 v4::{
120 MetricType,
121 metric::{MetricLevel, environmental::ModifiedAttackVector},
122 },
123 };
124 use alloc::borrow::ToOwned;
125 use core::str::FromStr;
126
127 /// Result of the merging of the base and modified metrics.
128 ///
129 /// Used in scoring.
130 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
131 pub(crate) enum MergedAttackVector {
132 Physical,
133 Local,
134 Adjacent,
135 Network,
136 }
137
138 impl Default for MergedAttackVector {
139 fn default() -> Self {
140 Self::Network
141 }
142 }
143
144 impl FromStr for MergedAttackVector {
145 type Err = Error;
146
147 fn from_str(s: &str) -> Result<Self> {
148 match s {
149 "P" => Ok(MergedAttackVector::Physical),
150 "L" => Ok(MergedAttackVector::Local),
151 "A" => Ok(MergedAttackVector::Adjacent),
152 "N" => Ok(MergedAttackVector::Network),
153 _ => Err(Error::InvalidMetricV4 {
154 metric_type: MetricType::AV,
155 value: s.to_owned(),
156 }),
157 }
158 }
159 }
160
161 impl MetricLevel for MergedAttackVector {
162 fn level(self) -> f64 {
163 // AV_levels = {"N": 0.0, "A": 0.1, "L": 0.2, "P": 0.3}
164 match self {
165 Self::Physical => 0.3,
166 Self::Local => 0.2,
167 Self::Adjacent => 0.1,
168 Self::Network => 0.0,
169 }
170 }
171 }
172
173 impl AttackVector {
174 pub(crate) fn merge(self, value: Option<ModifiedAttackVector>) -> MergedAttackVector {
175 match value {
176 Some(ModifiedAttackVector::NotDefined) | None => match self {
177 Self::Network => MergedAttackVector::Network,
178 Self::Adjacent => MergedAttackVector::Adjacent,
179 Self::Local => MergedAttackVector::Local,
180 Self::Physical => MergedAttackVector::Physical,
181 },
182 Some(ModifiedAttackVector::Network) => MergedAttackVector::Network,
183 Some(ModifiedAttackVector::Adjacent) => MergedAttackVector::Adjacent,
184 Some(ModifiedAttackVector::Local) => MergedAttackVector::Local,
185 Some(ModifiedAttackVector::Physical) => MergedAttackVector::Physical,
186 }
187 }
188 }
189 }