add exclude files and fix bugs.

This commit is contained in:
ichiichi11
2021-12-04 19:23:50 +09:00
parent 9169214553
commit 191d1df9f0
4 changed files with 19 additions and 13 deletions

View File

@@ -1,7 +1,5 @@
use std::collections::HashSet;
#[derive(Clone, Debug)]
pub struct RuleFill {
pub no_use_rule: HashSet<String>,

View File

@@ -131,7 +131,7 @@ fn analysis_files(evtx_files: Vec<PathBuf>) {
.args
.is_present("show-noisyalerts")
{
ids += "\n"; // 改行を入れないとexclude-rulesの一番最後の行とnoisy-rules.txtの一番最後の行が一行にまとめられてしまう。
ids += "\n"; // 改行を入れないとexclude-rulesの一番最後の行とnoisy-rules.txtの一番最後の行が一行にまとめられてしまう。
ids += &String::from_utf8(fs::read("config/noisy-rules.txt").unwrap()).unwrap();
}
@@ -140,7 +140,12 @@ fn analysis_files(evtx_files: Vec<PathBuf>) {
};
for v in ids.split_whitespace() {
fill_ids.no_use_rule.insert(v.to_string());
let v = v.to_string();
if v.is_empty() {
// 空行は無視する。
continue;
}
fill_ids.no_use_rule.insert(v);
}
let rule_files = detection::Detection::parse_rule_files(
level,

View File

@@ -138,14 +138,14 @@ impl ParseYaml {
}
//除外されたルールは無視する
match fill_ids
.no_use_rule
.get(&yaml_doc["id"].as_str().unwrap_or("").to_string())
{
None => (),
Some(_) => {
self.ignorerule_count += 1;
return Option::None;
let rule_id = &yaml_doc["id"].as_str();
if rule_id.is_some() {
match fill_ids.no_use_rule.get(&rule_id.unwrap_or("").to_string()) {
None => (),
Some(_) => {
self.ignorerule_count += 1;
return Option::None;
}
}
}
@@ -236,7 +236,8 @@ mod tests {
let fill_ids = RuleFill {
no_use_rule: HashSet::new(),
};
yaml.read_dir(path.to_path_buf(), &"LOW", &fill_ids).unwrap();
yaml.read_dir(path.to_path_buf(), &"LOW", &fill_ids)
.unwrap();
assert_eq!(yaml.files.len(), 4);
}
#[test]