From d8a7400869ddb36d228e878717ab40f8481a05a1 Mon Sep 17 00:00:00 2001 From: fan-tastic-z Date: Mon, 3 Jun 2024 17:09:02 +0800 Subject: [PATCH] fix: update threatbook check_valuable --- src/grab/threatbook.rs | 35 +++++++---------------------------- src/utils/mod.rs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/grab/threatbook.rs b/src/grab/threatbook.rs index 1e385a5..4a44be8 100644 --- a/src/grab/threatbook.rs +++ b/src/grab/threatbook.rs @@ -35,7 +35,7 @@ impl Grab for ThreadBookCrawler { is_valuable = res } - let disclosure = self.get_disclosure(&v); + let disclosure = v.vuln_update_time.clone(); let mut tags = Vec::new(); if let Some(is_0day) = v.is_0day { @@ -52,6 +52,7 @@ impl Grab for ThreadBookCrawler { if v.solution { tags.push("有修复方案".to_string()); } + let vuln = VulnInfo { unique_key: v.id, title: v.vuln_name_zh, @@ -98,38 +99,16 @@ impl ThreadBookCrawler { } } - pub fn get_disclosure(&self, data: &HighRisk) -> String { - if !data.vuln_publish_time.is_empty() { - data.vuln_publish_time.clone() - } else if let Some(vuln_update_time) = &data.vuln_update_time { - if !vuln_update_time.is_empty() { - vuln_update_time.to_string() - } else { - "".to_string() - } - } else { - "".to_string() - } - } - + // The data currently judged to be high risk are all updated data. + // This is the judgment for the time being. If there are any problems, adjustments will be made later. pub fn check_valuable(&self, data: &HighRisk) -> Result { if !data.poc_exist && !data.premium { return Ok(false); } - - if data.vuln_publish_time.is_empty() && data.vuln_update_time.is_none() { + if check_over_two_week(&data.vuln_update_time)? { return Ok(false); } - if !data.vuln_publish_time.is_empty() { - return check_over_two_week(&data.vuln_publish_time); - } - if let Some(vuln_update_time) = &data.vuln_update_time { - if !vuln_update_time.is_empty() { - return check_over_two_week(vuln_update_time); - } - } - - Ok(false) + Ok(true) } } @@ -148,7 +127,7 @@ pub struct Data { pub struct HighRisk { pub id: String, pub vuln_name_zh: String, - pub vuln_update_time: Option, + pub vuln_update_time: String, pub affects: Vec, pub vuln_publish_time: String, #[serde(rename = "pocExist")] diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a68cc72..afb9b1e 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -11,9 +11,9 @@ pub fn check_over_two_week(date: &str) -> Result { let now = Utc::now().naive_utc().date(); let two_weeks_ago = now - Duration::weeks(2); if target_date >= two_weeks_ago && target_date <= now { - return Ok(true); + return Ok(false); } - Ok(false) + Ok(true) } // data_str_format convernt 20240603 to 2024-06-03 @@ -51,4 +51,13 @@ mod tests { let res = timestamp_to_date(1715931545000).unwrap(); assert_eq!(res, "2024-05-17"); } + + #[test] + pub fn test_check_over_two_week() -> Result<()> { + let res = check_over_two_week("2024-06-03")?; + assert!(!res); + let res = check_over_two_week("2024-05-03")?; + assert!(res); + Ok(()) + } }