change from black to allow. (#164)

This commit is contained in:
James
2021-11-09 00:41:21 +09:00
committed by GitHub
parent e77a193c5c
commit c5d5d25817
7 changed files with 48 additions and 48 deletions

View File

@@ -236,12 +236,12 @@ detection:
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
* whitelist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
* allowlist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
### regexes.txtとwhitelist.txt
hayabusaではregexesやwhitelistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとwhitelist.txtを参照しています。regexes.txtとwhitelist.txtを書き換えることで、参照する全てのルールの挙動を一度に変更することが可能です。
### regexes.txtとallowlist.txt
hayabusaではregexesやallowlistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとallowlist.txtを参照しています。regexes.txtとallowlist.txtを書き換えることで、参照する全てのルールの挙動を一度に変更することが可能です。
また、regexesやwhitelistに指定するファイルは、ユーザーが独自に作成することも可能です。作成する場合、regexes.txtとwhitelist.txtを参考にしてください。
また、regexesやallowlistに指定するファイルは、ユーザーが独自に作成することも可能です。作成する場合、regexes.txtとallowlist.txtを参考にしてください。
## condition
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。

View File

@@ -236,12 +236,12 @@ detection:
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
* whitelist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
* allowlist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
### regexes.txtとwhitelist.txt
hayabusaではregexesやwhitelistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとwhitelist.txtを参照しています。regexes.txtとwhitelist.txtを書き換えることで、参照する全てのルールの挙動を一度に変更することが可能です。
### regexes.txtとallowlist.txt
hayabusaではregexesやallowlistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとallowlist.txtを参照しています。regexes.txtとallowlist.txtを書き換えることで、参照する全てのルールの挙動を一度に変更することが可能です。
また、regexesやwhitelistに指定するファイルは、ユーザーが独自に作成することも可能です。作成する場合、regexes.txtとwhitelist.txtを参考にしてください。
また、regexesやallowlistに指定するファイルは、ユーザーが独自に作成することも可能です。作成する場合、regexes.txtとallowlist.txtを参考にしてください。
## condition
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。

View File

@@ -9,7 +9,7 @@ detection:
regexes: ./regexes.txt
ImagePath:
min_length: 1000
whitelist: ./whitelist.txt
allowlist: ./allowlist.txt
condition: selection
falsepositives:
- unknown

View File

@@ -128,25 +128,25 @@ impl LeafMatcher for RegexesFileMatcher {
/// ファイルに列挙された文字列に一致する場合に検知するロジックを表す
/// DeepBlueCLIのcheck_cmdメソッドの一部に同様の処理が実装されていた。
pub struct WhitelistFileMatcher {
whitelist_csv_content: Vec<String>,
pub struct AllowlistFileMatcher {
allowlist_csv_content: Vec<String>,
}
impl WhitelistFileMatcher {
pub fn new() -> WhitelistFileMatcher {
return WhitelistFileMatcher {
whitelist_csv_content: vec![],
impl AllowlistFileMatcher {
pub fn new() -> AllowlistFileMatcher {
return AllowlistFileMatcher {
allowlist_csv_content: vec![],
};
}
}
impl LeafMatcher for WhitelistFileMatcher {
impl LeafMatcher for AllowlistFileMatcher {
fn is_target_key(&self, key_list: &Vec<String>) -> bool {
if key_list.len() != 2 {
return false;
}
return key_list.get(1).unwrap() == "whitelist";
return key_list.get(1).unwrap() == "allowlist";
}
fn init(&mut self, key_list: &Vec<String>, select_value: &Yaml) -> Result<(), Vec<String>> {
@@ -158,28 +158,28 @@ impl LeafMatcher for WhitelistFileMatcher {
};
if value.is_none() {
let errmsg = format!(
"whitelist value should be String. [key:{}]",
"allowlist value should be String. [key:{}]",
utils::concat_selection_key(key_list)
);
return Result::Err(vec![errmsg]);
}
let whitelist_content = utils::read_txt(&value.unwrap());
if whitelist_content.is_err() {
return Result::Err(vec![whitelist_content.unwrap_err()]);
let allowlist_content = utils::read_txt(&value.unwrap());
if allowlist_content.is_err() {
return Result::Err(vec![allowlist_content.unwrap_err()]);
}
self.whitelist_csv_content = whitelist_content.unwrap();
self.allowlist_csv_content = allowlist_content.unwrap();
return Result::Ok(());
}
fn is_match(&self, event_value: Option<&Value>) -> bool {
return match event_value.unwrap_or(&Value::Null) {
Value::String(s) => !utils::check_whitelist(s, &self.whitelist_csv_content),
Value::String(s) => !utils::check_allowlist(s, &self.allowlist_csv_content),
Value::Number(n) => {
!utils::check_whitelist(&n.to_string(), &self.whitelist_csv_content)
!utils::check_allowlist(&n.to_string(), &self.allowlist_csv_content)
}
Value::Bool(b) => !utils::check_whitelist(&b.to_string(), &self.whitelist_csv_content),
Value::Bool(b) => !utils::check_allowlist(&b.to_string(), &self.allowlist_csv_content),
_ => true,
};
}
@@ -487,7 +487,7 @@ impl PipeElement {
#[cfg(test)]
mod tests {
use super::super::matchers::{
DefaultMatcher, MinlengthMatcher, PipeElement, RegexesFileMatcher, WhitelistFileMatcher,
AllowlistFileMatcher, DefaultMatcher, MinlengthMatcher, PipeElement, RegexesFileMatcher,
};
use super::super::selectionnodes::{
AndSelectionNode, LeafSelectionNode, OrSelectionNode, SelectionNode,
@@ -514,7 +514,7 @@ mod tests {
ImagePath:
min_length: 1234321
regexes: ./regexes.txt
whitelist: ./whitelist.txt
allowlist: ./allowlist.txt
falsepositives:
- unknown
level: medium
@@ -664,7 +664,7 @@ mod tests {
);
}
// whitelist.txtが読み込めることを確認
// allowlist.txtが読み込めることを確認
{
let ancestor_node = ancestors[2].as_ref() as &dyn SelectionNode;
assert_eq!(ancestor_node.is::<LeafSelectionNode>(), true);
@@ -673,12 +673,12 @@ mod tests {
let ancestor_node = &ancestor_node.matcher;
assert_eq!(ancestor_node.is_some(), true);
let ancestor_matcher = ancestor_node.as_ref().unwrap();
assert_eq!(ancestor_matcher.is::<WhitelistFileMatcher>(), true);
assert_eq!(ancestor_matcher.is::<AllowlistFileMatcher>(), true);
let ancestor_matcher = ancestor_matcher
.downcast_ref::<WhitelistFileMatcher>()
.downcast_ref::<AllowlistFileMatcher>()
.unwrap();
let csvcontent = &ancestor_matcher.whitelist_csv_content;
let csvcontent = &ancestor_matcher.allowlist_csv_content;
assert_eq!(csvcontent.len(), 2);
assert_eq!(
@@ -1068,14 +1068,14 @@ mod tests {
#[test]
fn test_detect_regexes() {
// regexes.txtが正しく検知できることを確認
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
let rule_str = r#"
enabled: true
detection:
selection:
EventID: 4103
Channel:
- whitelist: whitelist.txt
- allowlist: allowlist.txt
output: 'command=%CommandLine%'
"#;
@@ -1098,16 +1098,16 @@ mod tests {
}
#[test]
fn test_detect_whitelist() {
// whitelistが正しく検知できることを確認
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
fn test_detect_allowlist() {
// allowlistが正しく検知できることを確認
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
let rule_str = r#"
enabled: true
detection:
selection:
EventID: 4103
Channel:
- whitelist: whitelist.txt
- allowlist: allowlist.txt
output: 'command=%CommandLine%'
"#;
@@ -1130,16 +1130,16 @@ mod tests {
}
#[test]
fn test_detect_whitelist2() {
// whitelistが正しく検知できることを確認
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
fn test_detect_allowlist2() {
// allowlistが正しく検知できることを確認
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
let rule_str = r#"
enabled: true
detection:
selection:
EventID: 4103
Channel:
- whitelist: whitelist.txt
- allowlist: allowlist.txt
output: 'command=%CommandLine%'
"#;

View File

@@ -291,7 +291,7 @@ impl LeafSelectionNode {
return vec![
Box::new(matchers::MinlengthMatcher::new()),
Box::new(matchers::RegexesFileMatcher::new()),
Box::new(matchers::WhitelistFileMatcher::new()),
Box::new(matchers::AllowlistFileMatcher::new()),
Box::new(matchers::DefaultMatcher::new()),
];
}

View File

@@ -41,8 +41,8 @@ pub fn check_regex(string: &str, regex_list: &Vec<String>) -> bool {
return false;
}
pub fn check_whitelist(target: &str, whitelist: &Vec<String>) -> bool {
for line in whitelist {
pub fn check_allowlist(target: &str, allowlist: &Vec<String>) -> bool {
for line in allowlist {
if line.is_empty() {
continue;
}
@@ -170,12 +170,12 @@ mod tests {
}
#[test]
fn test_check_whitelist() {
fn test_check_allowlist() {
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate.exe\"";
let whitelist = utils::read_txt("whitelist.txt").unwrap();
assert!(true == utils::check_whitelist(commandline, &whitelist));
let allowlist = utils::read_txt("allowlist.txt").unwrap();
assert!(true == utils::check_allowlist(commandline, &allowlist));
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate2.exe\"";
assert!(false == utils::check_whitelist(commandline, &whitelist));
assert!(false == utils::check_allowlist(commandline, &allowlist));
}
}