Debian Codegraph @

src/v3/base/ac.rs

raw symbols SCIP
1 //! Attack Complexity (AC)
2
3 use crate::{Error, Metric, MetricType, Result};
4 use alloc::borrow::ToOwned;
5 use core::{fmt, str::FromStr};
6
7 /// Attack Complexity (AC) - CVSS v3.1 Base Metric Group
8 ///
9 /// Described in CVSS v3.1 Specification: Section 2.1.2:
10 /// <https://www.first.org/cvss/specification-document#t6>
11 ///
12 /// > This metric describes the conditions beyond the attacker’s control that
13 /// > must exist in order to exploit the vulnerability. As described below,
14 /// > such conditions may require the collection of more information about the
15 /// > target, or computational exceptions. Importantly, the assessment of this
16 /// > metric excludes any requirements for user interaction in order to exploit
17 /// > the vulnerability (such conditions are captured in the User Interaction
18 /// > metric). If a specific configuration is required for an attack to
19 /// > succeed, the Base metrics should be scored assuming the vulnerable
20 /// > component is in that configuration. The Base Score is greatest for the
21 /// > least complex attacks.
22 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
23 pub enum AttackComplexity {
24 /// High (H)
25 ///
26 /// > A successful attack depends on conditions beyond the attacker's control.
27 /// > That is, a successful attack cannot be accomplished at will, but requires
28 /// > the attacker to invest in some measurable amount of effort in preparation
29 /// > or execution against the vulnerable component before a successful attack
30 /// > can be expected. For example, a successful attack may depend on an
31 /// > attacker overcoming any of the following conditions:
32 /// >
33 /// > - The attacker must gather knowledge about the environment in which
34 /// > the vulnerable target/component exists. For example, a requirement
35 /// > to collect details on target configuration settings, sequence numbers,
36 /// > or shared secrets.
37 /// > - The attacker must prepare the target environment to improve exploit
38 /// > reliability. For example, repeated exploitation to win a race
39 /// > condition, or overcoming advanced exploit mitigation techniques.
40 /// > - The attacker must inject themselves into the logical network path
41 /// > between the target and the resource requested by the victim in order
42 /// > to read and/or modify network communications (e.g., a man in the middle
43 /// > attack).
44 High,
45
46 /// Low (L)
47 ///
48 /// > Specialized access conditions or extenuating circumstances do not exist.
49 /// > An attacker can expect repeatable success when attacking the vulnerable component.
50 Low,
51 }
52
53 #[allow(clippy::derivable_impls)]
54 impl Default for AttackComplexity {
55 fn default() -> AttackComplexity {
56 AttackComplexity::High
57 }
58 }
59
60 impl Metric for AttackComplexity {
61 const TYPE: MetricType = MetricType::AC;
62
63 fn score(self) -> f64 {
64 match self {
65 AttackComplexity::High => 0.44,
66 AttackComplexity::Low => 0.77,
67 }
68 }
69
70 fn as_str(self) -> &'static str {
71 match self {
72 AttackComplexity::High => "H",
73 AttackComplexity::Low => "L",
74 }
75 }
76 }
77
78 impl fmt::Display for AttackComplexity {
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 AttackComplexity {
85 type Err = Error;
86
87 fn from_str(s: &str) -> Result<Self> {
88 match s {
89 "H" => Ok(AttackComplexity::High),
90 "L" => Ok(AttackComplexity::Low),
91 _ => Err(Error::InvalidMetric {
92 metric_type: Self::TYPE,
93 value: s.to_owned(),
94 }),
95 }
96 }
97 }