| 1 | //! User Interaction (MUI) |
| 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 | /// User Interaction (MUI) - CVSS v4.0 Environmental Metric Group |
| 11 | /// |
| 12 | /// Described in CVSS v4.0 Specification: Section 4.2 |
| 13 | /// |
| 14 | /// > This metric captures the requirement for a human user, other than the |
| 15 | /// > attacker, to participate in the successful compromise of the vulnerable |
| 16 | /// > system. This metric determines whether the vulnerability can be exploited |
| 17 | /// > solely at the will of the attacker, or whether a separate user (or |
| 18 | /// > user-initiated process) must participate in some manner. The resulting |
| 19 | /// > score is greatest when no user interaction is required. |
| 20 | #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 21 | pub enum ModifiedUserInteraction { |
| 22 | /// Not Defined (X) |
| 23 | /// |
| 24 | /// > The metric has not been evaluated. |
| 25 | NotDefined, |
| 26 | /// Active (A) |
| 27 | /// |
| 28 | /// > Successful exploitation of this vulnerability requires a targeted user |
| 29 | /// > to perform specific, conscious interactions with the vulnerable system |
| 30 | /// > and the attacker’s payload, or the user’s interactions would actively |
| 31 | /// > subvert protection mechanisms which would lead to exploitation of the |
| 32 | /// > vulnerability. Examples include: importing a file into a vulnerable |
| 33 | /// > system in a specific manner placing files into a specific directory |
| 34 | /// > prior to executing code submitting a specific string into a web |
| 35 | /// > application (e.g. reflected or self XSS) dismiss or accept prompts or |
| 36 | /// > security warnings prior to taking an action (e.g. opening/editing a |
| 37 | /// > file, connecting a device). |
| 38 | Active, |
| 39 | /// Passive (P) |
| 40 | /// |
| 41 | /// > Successful exploitation of this vulnerability requires limited |
| 42 | /// > interaction by the targeted user with the vulnerable system and the |
| 43 | /// > attacker’s payload. These interactions would be considered involuntary |
| 44 | /// > and do not require that the user actively subvert protections built |
| 45 | /// > into the vulnerable system. Examples include: utilizing a website that |
| 46 | /// > has been modified to display malicious content when the page is |
| 47 | /// > rendered (most stored XSS or CSRF) running an application that calls a |
| 48 | /// > malicious binary that has been planted on the system using an |
| 49 | /// > application which generates traffic over an untrusted or compromised |
| 50 | /// > network (vulnerabilities requiring an on-path attacker) |
| 51 | Passive, |
| 52 | /// None (N) |
| 53 | /// |
| 54 | /// > The vulnerable system can be exploited without interaction from any |
| 55 | /// > human user, other than the attacker. Examples include: a remote |
| 56 | /// > attacker is able to send packets to a target system a locally |
| 57 | /// > authenticated attacker executes code to elevate privileges |
| 58 | None, |
| 59 | } |
| 60 | |
| 61 | impl Default for ModifiedUserInteraction { |
| 62 | fn default() -> Self { |
| 63 | Self::NotDefined |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl Metric for ModifiedUserInteraction { |
| 68 | const TYPE: MetricType = MetricType::MUI; |
| 69 | |
| 70 | fn as_str(self) -> &'static str { |
| 71 | match self { |
| 72 | ModifiedUserInteraction::NotDefined => "X", |
| 73 | ModifiedUserInteraction::None => "N", |
| 74 | ModifiedUserInteraction::Passive => "P", |
| 75 | ModifiedUserInteraction::Active => "A", |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl fmt::Display for ModifiedUserInteraction { |
| 81 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 82 | write!(f, "{}:{}", Self::name(), self.as_str()) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl FromStr for ModifiedUserInteraction { |
| 87 | type Err = Error; |
| 88 | |
| 89 | fn from_str(s: &str) -> Result<Self> { |
| 90 | match s { |
| 91 | "X" => Ok(ModifiedUserInteraction::NotDefined), |
| 92 | "N" => Ok(ModifiedUserInteraction::None), |
| 93 | "P" => Ok(ModifiedUserInteraction::Passive), |
| 94 | "A" => Ok(ModifiedUserInteraction::Active), |
| 95 | _ => Err(Error::InvalidMetricV4 { |
| 96 | metric_type: Self::TYPE, |
| 97 | value: s.to_owned(), |
| 98 | }), |
| 99 | } |
| 100 | } |
| 101 | } |