Debian Codegraph @

src/v4/metric/base/va.rs

raw symbols SCIP
1 //! Availability Impact to the Vulnerable System (VA)
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 /// Availability Impact to the Vulnerable System (VA) - CVSS v4.0 Base Metric
11 /// Group
12 ///
13 /// Described in CVSS v4.0 Specification: Section 2.2.7
14 ///
15 /// > This metric measures the impact to the availability of the impacted system
16 /// > resulting from a successfully exploited vulnerability. While the
17 /// > Confidentiality and Integrity impact metrics apply to the loss of
18 /// > confidentiality or integrity of data (e.g., information, files) used by
19 /// > the system, this metric refers to the loss of availability of the impacted
20 /// > system itself, such as a networked service (e.g., web, database, email).
21 /// > Since availability refers to the accessibility of information resources,
22 /// > attacks that consume network bandwidth, processor cycles, or disk space
23 /// > all impact the availability of a system. The resulting score is greatest
24 /// > when the consequence to the system is highest.
25 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
26 pub enum AvailabilityImpactToTheVulnerableSystem {
27 /// None (N)
28 ///
29 /// > There is no impact to availability within the Vulnerable System.
30 None,
31
32 /// Low (L)
33 ///
34 /// > Performance is reduced or there are interruptions in resource
35 /// > availability. Even if repeated exploitation of the vulnerability is
36 /// > possible, the attacker does not have the ability to completely deny
37 /// > service to legitimate users. The resources in the Vulnerable System
38 /// > are either partially available all of the time, or fully available
39 /// > only some of the time, but overall there is no direct, serious
40 /// > consequence to the Vulnerable System.
41 Low,
42
43 /// High (H)
44 ///
45 /// > There is a total loss of availability, resulting in the attacker being
46 /// > able to fully deny access to resources in the Vulnerable System; this
47 /// > loss is either sustained (while the attacker continues to deliver the
48 /// > attack) or persistent (the condition persists even after the attack
49 /// > has completed). Alternatively, the attacker has the ability to deny
50 /// > some availability, but the loss of availability presents a direct,
51 /// > serious consequence to the Vulnerable System (e.g., the attacker
52 /// > cannot disrupt existing connections, but can prevent new connections;
53 /// > the attacker can repeatedly exploit a vulnerability that, in each
54 /// > instance of a successful attack, leaks a only small amount of memory,
55 /// > but after repeated exploitation causes a service to become completely
56 /// > unavailable).
57 High,
58 }
59
60 impl Default for AvailabilityImpactToTheVulnerableSystem {
61 fn default() -> Self {
62 Self::High
63 }
64 }
65
66 impl Metric for AvailabilityImpactToTheVulnerableSystem {
67 const TYPE: MetricType = MetricType::VA;
68
69 fn as_str(self) -> &'static str {
70 match self {
71 AvailabilityImpactToTheVulnerableSystem::None => "N",
72 AvailabilityImpactToTheVulnerableSystem::Low => "L",
73 AvailabilityImpactToTheVulnerableSystem::High => "H",
74 }
75 }
76 }
77
78 impl fmt::Display for AvailabilityImpactToTheVulnerableSystem {
79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80 write!(f, "{}:{}", Self::name(), self.as_str())
81 }
82 }
83
84 impl FromStr for AvailabilityImpactToTheVulnerableSystem {
85 type Err = Error;
86
87 fn from_str(s: &str) -> Result<Self> {
88 match s {
89 "N" => Ok(AvailabilityImpactToTheVulnerableSystem::None),
90 "L" => Ok(AvailabilityImpactToTheVulnerableSystem::Low),
91 "H" => Ok(AvailabilityImpactToTheVulnerableSystem::High),
92 _ => Err(Error::InvalidMetricV4 {
93 metric_type: Self::TYPE,
94 value: s.to_owned(),
95 }),
96 }
97 }
98 }
99
100 #[cfg(feature = "std")]
101 pub(crate) mod merge {
102 use super::*;
103 use crate::{
104 Error,
105 v4::{
106 MetricType,
107 metric::{MetricLevel, environmental::ModifiedAvailabilityImpactToTheVulnerableSystem},
108 },
109 };
110 use alloc::borrow::ToOwned;
111 use core::str::FromStr;
112
113 /// Result of the merging of the base and modified metrics.
114 ///
115 /// Used in scoring.
116 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
117 pub(crate) enum MergedAvailabilityImpactToTheVulnerableSystem {
118 High,
119 Low,
120 None,
121 }
122
123 impl Default for MergedAvailabilityImpactToTheVulnerableSystem {
124 fn default() -> Self {
125 Self::High
126 }
127 }
128
129 impl FromStr for MergedAvailabilityImpactToTheVulnerableSystem {
130 type Err = Error;
131
132 fn from_str(s: &str) -> Result<Self> {
133 match s {
134 "H" => Ok(MergedAvailabilityImpactToTheVulnerableSystem::High),
135 "L" => Ok(MergedAvailabilityImpactToTheVulnerableSystem::Low),
136 "N" => Ok(MergedAvailabilityImpactToTheVulnerableSystem::None),
137 _ => Err(Error::InvalidMetricV4 {
138 metric_type: MetricType::VA,
139 value: s.to_owned(),
140 }),
141 }
142 }
143 }
144
145 impl MetricLevel for MergedAvailabilityImpactToTheVulnerableSystem {
146 fn level(self) -> f64 {
147 // VA_levels = {'H': 0.0, 'L': 0.1, 'N': 0.2}
148 match self {
149 Self::High => 0.0,
150 Self::Low => 0.1,
151 Self::None => 0.2,
152 }
153 }
154 }
155
156 impl AvailabilityImpactToTheVulnerableSystem {
157 pub(crate) fn merge(
158 self,
159 value: Option<ModifiedAvailabilityImpactToTheVulnerableSystem>,
160 ) -> MergedAvailabilityImpactToTheVulnerableSystem {
161 match value {
162 Some(ModifiedAvailabilityImpactToTheVulnerableSystem::NotDefined) | None => {
163 match self {
164 Self::High => MergedAvailabilityImpactToTheVulnerableSystem::High,
165 Self::Low => MergedAvailabilityImpactToTheVulnerableSystem::Low,
166 Self::None => MergedAvailabilityImpactToTheVulnerableSystem::None,
167 }
168 }
169 Some(ModifiedAvailabilityImpactToTheVulnerableSystem::High) => {
170 MergedAvailabilityImpactToTheVulnerableSystem::High
171 }
172 Some(ModifiedAvailabilityImpactToTheVulnerableSystem::Low) => {
173 MergedAvailabilityImpactToTheVulnerableSystem::Low
174 }
175 Some(ModifiedAvailabilityImpactToTheVulnerableSystem::None) => {
176 MergedAvailabilityImpactToTheVulnerableSystem::None
177 }
178 }
179 }
180 }
181 }