Skip to content

Commit

Permalink
fix: update threatbook check_valuable
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-tastic-z committed Jun 3, 2024
1 parent 752aac0 commit d8a7400
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
35 changes: 7 additions & 28 deletions src/grab/threatbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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<bool> {
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)
}
}

Expand All @@ -148,7 +127,7 @@ pub struct Data {
pub struct HighRisk {
pub id: String,
pub vuln_name_zh: String,
pub vuln_update_time: Option<String>,
pub vuln_update_time: String,
pub affects: Vec<String>,
pub vuln_publish_time: String,
#[serde(rename = "pocExist")]
Expand Down
13 changes: 11 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub fn check_over_two_week(date: &str) -> Result<bool> {
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
Expand Down Expand Up @@ -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(())
}
}

0 comments on commit d8a7400

Please sign in to comment.