From 276889338d45afae2605c28044988f6ac3a7d1d3 Mon Sep 17 00:00:00 2001 From: itiB Date: Mon, 28 Feb 2022 21:58:35 +0900 Subject: [PATCH] Add: --level-tuning option's outline --- config/rule_level.txt | 0 src/detections/configs.rs | 6 +++++- src/main.rs | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 config/rule_level.txt diff --git a/config/rule_level.txt b/config/rule_level.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/detections/configs.rs b/src/detections/configs.rs index 9ad2185a..ef8e6d50 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -1,7 +1,7 @@ use crate::detections::print::AlertMessage; use crate::detections::utils; use chrono::{DateTime, Utc}; -use clap::{App, AppSettings, ArgMatches}; +use clap::{App, Arg, AppSettings, ArgMatches}; use hashbrown::HashMap; use hashbrown::HashSet; use lazy_static::lazy_static; @@ -92,6 +92,10 @@ fn build_app<'a>() -> ArgMatches<'a> { .version("1.1.0") .author("Yamato Security (https://github.com/Yamato-Security/hayabusa)") .setting(AppSettings::VersionlessSubcommands) + .arg( // TODO: When update claps to 3.x, these can write in usage texts... + Arg::from_usage("--level-tuning=[RULE_LEVEL_FILE] 'Fix rule file's level'") + .default_value("./config/rule_level.txt") + ) .usage(usages) .args_from_usage(usages) .get_matches() diff --git a/src/main.rs b/src/main.rs index 3461b1d9..a09bd0c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,29 @@ impl App { println!(); return; } + + if configs::CONFIG + .read() + .unwrap() + .args.is_present("level-tuning") + { + if let Some(level_tuning_path) = configs::CONFIG.read().unwrap().args.value_of("level-tuning") { + if Path::new(level_tuning_path).exists() { + println!("level-tuning file exist: {}", level_tuning_path); + println!("WIP: level-tuning...."); + } else { + AlertMessage::alert( + &mut BufWriter::new(std::io::stderr().lock()), + &format!( + "Need rule_levels.txt file to use --level-tuning option" + ), + ) + .ok(); + return; + } + } + } + if !Path::new("./config").exists() { AlertMessage::alert( &mut BufWriter::new(std::io::stderr().lock()),