Debian Codegraph @

src/v4/metric/environmental/mac.rs

raw symbols SCIP
1 //! Modified Attack Complexity (MAC)
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 /// Modified Attack Complexity (MAC) - CVSS v4.0 Environmental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 4.2
13 ///
14 /// > This metric captures measurable actions that must be taken by the attacker
15 /// > to actively evade or circumvent **existing built-in security-enhancing
16 /// > conditions** in order to obtain a working exploit. These are conditions
17 /// > whose primary purpose is to increase security and/or increase exploit
18 /// > engineering complexity. A vulnerability exploitable without a
19 /// > target-specific variable has a lower complexity than a vulnerability that
20 /// > would require non-trivial customization. This metric is meant to capture
21 /// > security mechanisms utilized by the vulnerable system, and does not relate
22 /// > to the amount of time or attempts it would take for an attacker to
23 /// > succeed, e.g. a race condition. If the attacker does not take action to
24 /// > overcome these conditions, the attack will always fail.
25 /// >
26 /// > The evasion or satisfaction of authentication mechanisms or requisites is
27 /// > included in the Privileges Required assessment and is *not* considered
28 /// > here as a factor of relevance for Attack Complexity.
29 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
30 pub enum ModifiedAttackComplexity {
31 /// Not Defined (X)
32 ///
33 /// > The metric has not been evaluated.
34 NotDefined,
35
36 /// High (H)
37 ///
38 /// > The successful attack depends on the evasion or circumvention of
39 /// > security-enhancing techniques in place that would otherwise hinder the
40 /// > attack. These include: Evasion of exploit mitigation techniques. The
41 /// > attacker must have additional methods available to bypass security
42 /// > measures in place. For example, circumvention of **address space
43 /// > randomization (ASLR) or data execution prevention (DEP)** must be
44 /// > performed for the attack to be successful. Obtaining target-specific
45 /// > secrets. The attacker must gather some **target-specific secret**
46 /// > before the attack can be successful. A secret is any piece of
47 /// > information that cannot be obtained through any amount of
48 /// > reconnaissance. To obtain the secret the attacker must perform
49 /// > additional attacks or break otherwise secure measures (e.g. knowledge
50 /// > of a secret key may be needed to break a crypto channel). This
51 /// > operation must be performed for each attacked target.
52 High,
53
54 /// Low (L)
55 ///
56 /// > The attacker must take no measurable action to exploit the
57 /// > vulnerability. The attack requires no target-specific circumvention to
58 /// > exploit the vulnerability. An attacker can expect repeatable success
59 /// > against the vulnerable system.
60 Low,
61 }
62
63 impl Default for ModifiedAttackComplexity {
64 fn default() -> Self {
65 Self::NotDefined
66 }
67 }
68
69 impl Metric for ModifiedAttackComplexity {
70 const TYPE: MetricType = MetricType::MAC;
71
72 fn as_str(self) -> &'static str {
73 match self {
74 ModifiedAttackComplexity::NotDefined => "X",
75 ModifiedAttackComplexity::High => "H",
76 ModifiedAttackComplexity::Low => "L",
77 }
78 }
79 }
80
81 impl fmt::Display for ModifiedAttackComplexity {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 write!(f, "{}:{}", Self::name(), self.as_str())
84 }
85 }
86
87 impl FromStr for ModifiedAttackComplexity {
88 type Err = Error;
89
90 fn from_str(s: &str) -> Result<Self> {
91 match s {
92 "X" => Ok(ModifiedAttackComplexity::NotDefined),
93 "H" => Ok(ModifiedAttackComplexity::High),
94 "L" => Ok(ModifiedAttackComplexity::Low),
95 _ => Err(Error::InvalidMetricV4 {
96 metric_type: Self::TYPE,
97 value: s.to_owned(),
98 }),
99 }
100 }
101 }