generated from emo-crab/rust-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f059c7a
commit 0475af6
Showing
9 changed files
with
356 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,181 @@ | ||
use chrono::NaiveDateTime; | ||
use serde::{Deserialize, Serialize}; | ||
use crate::{date_format, DescriptionData}; | ||
use crate::impact::ImpactMetrics; | ||
use crate::v4::{DescriptionData, ProblemTypeDataItem, Reference}; | ||
use crate::v4::configurations::{Node}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[serde(rename_all(deserialize = "camelCase"), deny_unknown_fields)] | ||
#[serde(rename_all(deserialize = "camelCase"))] | ||
pub struct CVE { | ||
pub id: String, | ||
pub source_identifier: String, | ||
#[serde(with = "date_format")] | ||
pub published_date: NaiveDateTime, | ||
pub published: NaiveDateTime, | ||
// 最后修改时间 | ||
#[serde(with = "date_format")] | ||
pub last_modified_date: NaiveDateTime, | ||
pub last_modified: NaiveDateTime, | ||
pub vuln_status: VulnStatus, | ||
pub descriptions: Vec<DescriptionData>, | ||
pub metrics: ImpactMetrics, | ||
pub weaknesses: Vec<ProblemTypeDataItem>, | ||
pub configurations: Vec<Node>, | ||
pub references: Vec<Reference>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub enum VulnStatus { | ||
Analyzed | ||
} | ||
Analyzed, | ||
#[serde(rename="Undergoing Analysis")] | ||
UndergoingAnalysis, | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::api::CVE; | ||
use crate::v4::configurations::Node; | ||
|
||
#[test] | ||
fn nodes() { | ||
let j = r#" | ||
[ | ||
{ | ||
"operator": "OR", | ||
"negate": false, | ||
"cpeMatch": [ | ||
{ | ||
"vulnerable": true, | ||
"criteria": "cpe:2.3:a:cherokee-project:cherokee_web_server:*:*:*:*:*:*:*:*", | ||
"versionEndIncluding": "1.2.103", | ||
"matchCriteriaId": "DCE1E311-F9E5-4752-9F51-D5DA78B7BBFA" | ||
} | ||
] | ||
} | ||
]"#; | ||
let i: Vec<Node> = serde_json::from_str(j).unwrap(); | ||
println!("{:?}", i); | ||
} | ||
|
||
#[test] | ||
fn cve() { | ||
let j = r#"{ | ||
"id": "CVE-2023-0001", | ||
"sourceIdentifier": "psirt@paloaltonetworks.com", | ||
"published": "2023-02-08T18:15:11.523", | ||
"lastModified": "2023-11-21T19:15:08.073", | ||
"vulnStatus": "Undergoing Analysis", | ||
"descriptions": [ | ||
{ | ||
"lang": "en", | ||
"value": "An information exposure vulnerability in the Palo Alto Networks Cortex XDR agent on Windows devices allows a local system administrator to disclose the admin password for the agent in cleartext, which bad actors can then use to execute privileged cytool commands that disable or uninstall the agent." | ||
} | ||
], | ||
"metrics": { | ||
"cvssMetricV31": [ | ||
{ | ||
"source": "nvd@nist.gov", | ||
"type": "Primary", | ||
"cvssData": { | ||
"version": "3.1", | ||
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H", | ||
"attackVector": "LOCAL", | ||
"attackComplexity": "LOW", | ||
"privilegesRequired": "HIGH", | ||
"userInteraction": "NONE", | ||
"scope": "UNCHANGED", | ||
"confidentialityImpact": "HIGH", | ||
"integrityImpact": "HIGH", | ||
"availabilityImpact": "HIGH", | ||
"baseScore": 6.7, | ||
"baseSeverity": "MEDIUM" | ||
}, | ||
"exploitabilityScore": 0.8, | ||
"impactScore": 5.9 | ||
}, | ||
{ | ||
"source": "psirt@paloaltonetworks.com", | ||
"type": "Secondary", | ||
"cvssData": { | ||
"version": "3.1", | ||
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:H/I:N/A:H", | ||
"attackVector": "LOCAL", | ||
"attackComplexity": "LOW", | ||
"privilegesRequired": "HIGH", | ||
"userInteraction": "NONE", | ||
"scope": "UNCHANGED", | ||
"confidentialityImpact": "HIGH", | ||
"integrityImpact": "NONE", | ||
"availabilityImpact": "HIGH", | ||
"baseScore": 6, | ||
"baseSeverity": "MEDIUM" | ||
}, | ||
"exploitabilityScore": 0.8, | ||
"impactScore": 5.2 | ||
} | ||
] | ||
}, | ||
"weaknesses": [ | ||
{ | ||
"source": "nvd@nist.gov", | ||
"type": "Primary", | ||
"description": [ | ||
{ | ||
"lang": "en", | ||
"value": "CWE-319" | ||
} | ||
] | ||
}, | ||
{ | ||
"source": "psirt@paloaltonetworks.com", | ||
"type": "Secondary", | ||
"description": [ | ||
{ | ||
"lang": "en", | ||
"value": "CWE-319" | ||
} | ||
] | ||
} | ||
], | ||
"configurations": [ | ||
{ | ||
"operator": "AND", | ||
"nodes": [ | ||
{ | ||
"operator": "OR", | ||
"negate": false, | ||
"cpeMatch": [ | ||
{ | ||
"vulnerable": true, | ||
"criteria": "cpe:2.3:a:paloaltonetworks:cortex_xdr_agent:*:*:*:*:critical_environment:*:*:*", | ||
"versionStartIncluding": "7.5", | ||
"versionEndExcluding": "7.5.101", | ||
"matchCriteriaId": "EC5B0E84-B9A5-4FE3-B2E5-A64AEF57BCF3" | ||
} | ||
] | ||
}, | ||
{ | ||
"operator": "OR", | ||
"negate": false, | ||
"cpeMatch": [ | ||
{ | ||
"vulnerable": false, | ||
"criteria": "cpe:2.3:o:microsoft:windows:-:*:*:*:*:*:*:*", | ||
"matchCriteriaId": "A2572D17-1DE6-457B-99CC-64AFD54487EA" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"url": "https://security.paloaltonetworks.com/CVE-2023-0001", | ||
"source": "psirt@paloaltonetworks.com", | ||
"tags": [ | ||
"Vendor Advisory" | ||
] | ||
} | ||
] | ||
}"#; | ||
let i: CVE = serde_json::from_str(j).unwrap(); | ||
println!("{:?}", i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.