| 1 | //! Exploit Maturity (E) |
| 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 | /// Exploit Maturity (E) - CVSS v4.0 Threat Metric Group |
| 11 | /// |
| 12 | /// Described in CVSS v4.0 Specification: Section 3.1 |
| 13 | /// |
| 14 | /// > This metric measures the likelihood of the vulnerability being attacked, |
| 15 | /// > and is based on the current state of exploit techniques, exploit code |
| 16 | /// > availability, or active, “in-the-wild” exploitation. Public availability |
| 17 | /// > of easy-to-use exploit code or exploitation instructions increases the |
| 18 | /// > number of potential attackers by including those who are unskilled. |
| 19 | /// > Initially, real-world exploitation may only be theoretical. Publication of |
| 20 | /// > proof-of-concept exploit code, functional exploit code, or sufficient |
| 21 | /// > technical details necessary to exploit the vulnerability may follow. |
| 22 | /// > Furthermore, the available exploit code or instructions may progress from |
| 23 | /// > a proof-of-concept demonstration to exploit code that is successful in |
| 24 | /// > exploiting the vulnerability consistently. In severe cases, it may be |
| 25 | /// > delivered as the payload of a network-based worm or virus or other |
| 26 | /// > automated attack tools. |
| 27 | /// |
| 28 | /// > It is the responsibility of the CVSS consumer to populate the values of |
| 29 | /// > Exploit Maturity (E) based on information regarding the availability of |
| 30 | /// > exploitation code/processes and the state of exploitation techniques. This |
| 31 | /// > information will be referred to as “threat intelligence” throughout this |
| 32 | /// > document. |
| 33 | /// |
| 34 | /// > Operational Recommendation: Threat intelligence sources that provide |
| 35 | /// > Exploit Maturity information for all vulnerabilities should be preferred |
| 36 | /// > over those with only partial coverage. Also, it is recommended to use |
| 37 | /// > multiple sources of threat intelligence as many are not comprehensive. |
| 38 | /// > This information should be updated as frequently as possible and its |
| 39 | /// > application to CVSS assessment should be automated. |
| 40 | #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 41 | pub enum ExploitMaturity { |
| 42 | /// Not Defined (X) |
| 43 | /// |
| 44 | /// > Reliable threat intelligence is not available to determine Exploit |
| 45 | /// > Maturity characteristics. This is the default value and is equivalent |
| 46 | /// > to Attacked (A) for the purposes of the calculation of the score by |
| 47 | /// > assuming the worst case. |
| 48 | NotDefined, |
| 49 | /// Unreported (U) |
| 50 | /// |
| 51 | /// > Based on available threat intelligence each of the following must |
| 52 | /// > apply: No knowledge of publicly available proof-of-concept exploit |
| 53 | /// > code No knowledge of reported attempts to exploit this vulnerability |
| 54 | /// > No knowledge of publicly available solutions used to simplify attempts |
| 55 | /// > to exploit the vulnerability (i.e., neither the “POC” nor “Attacked” |
| 56 | /// > values apply) |
| 57 | Unreported, |
| 58 | /// Proof-of-Concept (P) |
| 59 | /// |
| 60 | /// > Based on available threat intelligence each of the following must |
| 61 | /// > apply: Proof-of-concept exploit code is publicly available No |
| 62 | /// > knowledge of reported attempts to exploit this vulnerability No |
| 63 | /// > knowledge of publicly available solutions used to simplify attempts to |
| 64 | /// > exploit the vulnerability (i.e., the “Attacked” value does not apply) |
| 65 | ProofOfConcept, |
| 66 | /// Attacked (A) |
| 67 | /// |
| 68 | /// > Based on available threat intelligence either of the following must |
| 69 | /// > apply: Attacks targeting this vulnerability (attempted or successful) |
| 70 | /// > have been reported Solutions to simplify attempts to exploit the |
| 71 | /// > vulnerability are publicly or privately available (such as exploit |
| 72 | /// > toolkits) |
| 73 | Attacked, |
| 74 | } |
| 75 | |
| 76 | impl Default for ExploitMaturity { |
| 77 | fn default() -> Self { |
| 78 | Self::NotDefined |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | impl Metric for ExploitMaturity { |
| 83 | const TYPE: MetricType = MetricType::E; |
| 84 | |
| 85 | fn as_str(self) -> &'static str { |
| 86 | match self { |
| 87 | ExploitMaturity::NotDefined => "X", |
| 88 | ExploitMaturity::Attacked => "A", |
| 89 | ExploitMaturity::ProofOfConcept => "P", |
| 90 | ExploitMaturity::Unreported => "U", |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl fmt::Display for ExploitMaturity { |
| 96 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 97 | write!(f, "{}:{}", Self::name(), self.as_str()) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | impl FromStr for ExploitMaturity { |
| 102 | type Err = Error; |
| 103 | |
| 104 | fn from_str(s: &str) -> Result<Self> { |
| 105 | match s { |
| 106 | "X" => Ok(ExploitMaturity::NotDefined), |
| 107 | "A" => Ok(ExploitMaturity::Attacked), |
| 108 | "P" => Ok(ExploitMaturity::ProofOfConcept), |
| 109 | "U" => Ok(ExploitMaturity::Unreported), |
| 110 | _ => Err(Error::InvalidMetricV4 { |
| 111 | metric_type: Self::TYPE, |
| 112 | value: s.to_owned(), |
| 113 | }), |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | #[cfg(feature = "std")] |
| 119 | pub(crate) mod merge { |
| 120 | use super::*; |
| 121 | use crate::{ |
| 122 | Error, |
| 123 | v4::{MetricType, metric::MetricLevel}, |
| 124 | }; |
| 125 | use alloc::borrow::ToOwned; |
| 126 | use core::str::FromStr; |
| 127 | |
| 128 | #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 129 | pub(crate) enum MergedExploitMaturity { |
| 130 | Attacked, |
| 131 | ProofOfConcept, |
| 132 | Unreported, |
| 133 | } |
| 134 | |
| 135 | impl Default for MergedExploitMaturity { |
| 136 | fn default() -> Self { |
| 137 | Self::Attacked |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | impl FromStr for MergedExploitMaturity { |
| 142 | type Err = Error; |
| 143 | |
| 144 | fn from_str(s: &str) -> Result<Self> { |
| 145 | match s { |
| 146 | "A" => Ok(MergedExploitMaturity::Attacked), |
| 147 | "P" => Ok(MergedExploitMaturity::ProofOfConcept), |
| 148 | "U" => Ok(MergedExploitMaturity::Unreported), |
| 149 | _ => Err(Error::InvalidMetricV4 { |
| 150 | metric_type: MetricType::E, |
| 151 | value: s.to_owned(), |
| 152 | }), |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | impl ExploitMaturity { |
| 158 | pub(crate) fn merge(self) -> MergedExploitMaturity { |
| 159 | match self { |
| 160 | Self::Attacked => MergedExploitMaturity::Attacked, |
| 161 | Self::ProofOfConcept => MergedExploitMaturity::ProofOfConcept, |
| 162 | Self::Unreported => MergedExploitMaturity::Unreported, |
| 163 | Self::NotDefined => MergedExploitMaturity::Attacked, |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | impl MetricLevel for MergedExploitMaturity { |
| 169 | fn level(self) -> f64 { |
| 170 | // E_levels = {'U': 0.2, 'P': 0.1, 'A': 0} |
| 171 | match self { |
| 172 | Self::Unreported => 0.2, |
| 173 | Self::ProofOfConcept => 0.1, |
| 174 | Self::Attacked => 0.0, |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |