From 7de9eff708ac19f29ef6b0f99776edf36fc7cfea Mon Sep 17 00:00:00 2001 From: Sandesh Grangdan Date: Sun, 8 Sep 2024 18:29:15 +0545 Subject: [PATCH] Update scan summary for infected file & styling for google chat. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/antivirus.rs | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8089759..673b640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ dependencies = [ [[package]] name = "antivirus" -version = "0.1.3" +version = "0.1.4" dependencies = [ "clap", "rand", diff --git a/Cargo.toml b/Cargo.toml index dc53cf8..e5d577b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "antivirus" -version = "0.1.3" +version = "0.1.4" edition = "2021" # Github Repo diff --git a/src/antivirus.rs b/src/antivirus.rs index feb6974..b71c573 100644 --- a/src/antivirus.rs +++ b/src/antivirus.rs @@ -225,7 +225,6 @@ impl Antivirus { .expect("Failed to execute clamscan"); let regex_patterns = vec![ - Regex::new(r": FOUND$").unwrap(), Regex::new(r"^----------- SCAN SUMMARY -----------").unwrap(), Regex::new(r"^Known viruses:").unwrap(), Regex::new(r"^Engine version:").unwrap(), @@ -240,10 +239,13 @@ impl Antivirus { ]; let infected_regex_patterns = vec![ - Regex::new(r": FOUND$").unwrap(), + Regex::new(r" FOUND$").unwrap(), ]; - self.summary.push_str(&format!("{}\n\n", self.home_dir)); + self.summary.push_str(&format!("_Scanned directory_: `{}`\n", dir)); + self.summary.push_str(&format!("_Result Output_: `{}`\n\n", self.tmp_file)); + + let mut found_infected = false; if let Some(stdout) = child.stdout.take() { let reader = io::BufReader::new(stdout); @@ -255,7 +257,13 @@ impl Antivirus { self.summary.push_str(&format!("{}\n", line)); } if infected_regex_patterns.iter().any(|regex| regex.is_match(&line)) { - self.infected_files.push_str(&format!("{}\n", line)); + if found_infected == false { + found_infected = true; + self.infected_files.push_str("===================================================\n"); + self.infected_files.push_str(" *Infected File Summary*\n"); + self.infected_files.push_str("===================================================\n\n"); + } + self.infected_files.push_str(&format!("- {}\n", line)); } }, Err(err) => eprintln!("Error reading line: {}", err), @@ -264,6 +272,11 @@ impl Antivirus { } let status = child.wait().expect("Failed to wait on child"); + if self.infected_files != "" { + self.infected_files.push_str("\n_Action Required:_\n"); + self.infected_files.push_str("- Review the file and determine if it needs further action.\n"); + self.infected_files.push_str("- Consider running additional scans or consulting with security team.\n"); + } println!("Scan Process exited with: {}", status); @@ -273,8 +286,7 @@ impl Antivirus { if self.google_chat_url != "" { self.google_chat(&self.summary); if self.infected_files != "" { - self.infected_files.push_str(&format!("\nResult Output: {}\n", self.tmp_file)); - self.google_chat(&self.infected_files); + self.google_chat(&format!("{}",&self.infected_files)); } } }