change from black to allow. (#164)
This commit is contained in:
@@ -236,12 +236,12 @@ detection:
|
|||||||
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
|
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
|
||||||
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
|
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
|
||||||
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
|
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
|
||||||
* whitelist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
|
* allowlist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
|
||||||
|
|
||||||
### regexes.txtとwhitelist.txt
|
### regexes.txtとallowlist.txt
|
||||||
hayabusaではregexesやwhitelistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとwhitelist.txtを参照しています。regexes.txtとwhitelist.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
|
## condition
|
||||||
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。
|
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。
|
||||||
|
|||||||
@@ -236,12 +236,12 @@ detection:
|
|||||||
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
|
* value: 文字列による一致(ワイルドカードやパイプを指定することもできます)
|
||||||
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
|
* min_length: 指定した文字数以上である場合、条件に一致したものとして処理されます。
|
||||||
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
|
* regexes: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致した`ものとして処理されます。
|
||||||
* whitelist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
|
* allowlist: 指定したファイルに記載された正規表現のリストにひとつでも一致すれば、`条件に一致していない`ものとして処理されます。
|
||||||
|
|
||||||
### regexes.txtとwhitelist.txt
|
### regexes.txtとallowlist.txt
|
||||||
hayabusaではregexesやwhitelistを使用した組み込みのルールを用意しており、それらのルールはregexes.txtとwhitelist.txtを参照しています。regexes.txtとwhitelist.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
|
## condition
|
||||||
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。
|
これまでの記法を用いると、AND条件やOR条件を表現することができますが、ANDやOR等が複雑に入り組んだ条件を定義することは難しい場合があります。その場合、conditionというキーワードを使用することで、複雑な条件式を定義することができます。
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ detection:
|
|||||||
regexes: ./regexes.txt
|
regexes: ./regexes.txt
|
||||||
ImagePath:
|
ImagePath:
|
||||||
min_length: 1000
|
min_length: 1000
|
||||||
whitelist: ./whitelist.txt
|
allowlist: ./allowlist.txt
|
||||||
condition: selection
|
condition: selection
|
||||||
falsepositives:
|
falsepositives:
|
||||||
- unknown
|
- unknown
|
||||||
|
|||||||
@@ -128,25 +128,25 @@ impl LeafMatcher for RegexesFileMatcher {
|
|||||||
|
|
||||||
/// ファイルに列挙された文字列に一致する場合に検知するロジックを表す
|
/// ファイルに列挙された文字列に一致する場合に検知するロジックを表す
|
||||||
/// DeepBlueCLIのcheck_cmdメソッドの一部に同様の処理が実装されていた。
|
/// DeepBlueCLIのcheck_cmdメソッドの一部に同様の処理が実装されていた。
|
||||||
pub struct WhitelistFileMatcher {
|
pub struct AllowlistFileMatcher {
|
||||||
whitelist_csv_content: Vec<String>,
|
allowlist_csv_content: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WhitelistFileMatcher {
|
impl AllowlistFileMatcher {
|
||||||
pub fn new() -> WhitelistFileMatcher {
|
pub fn new() -> AllowlistFileMatcher {
|
||||||
return WhitelistFileMatcher {
|
return AllowlistFileMatcher {
|
||||||
whitelist_csv_content: vec![],
|
allowlist_csv_content: vec![],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LeafMatcher for WhitelistFileMatcher {
|
impl LeafMatcher for AllowlistFileMatcher {
|
||||||
fn is_target_key(&self, key_list: &Vec<String>) -> bool {
|
fn is_target_key(&self, key_list: &Vec<String>) -> bool {
|
||||||
if key_list.len() != 2 {
|
if key_list.len() != 2 {
|
||||||
return false;
|
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>> {
|
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() {
|
if value.is_none() {
|
||||||
let errmsg = format!(
|
let errmsg = format!(
|
||||||
"whitelist value should be String. [key:{}]",
|
"allowlist value should be String. [key:{}]",
|
||||||
utils::concat_selection_key(key_list)
|
utils::concat_selection_key(key_list)
|
||||||
);
|
);
|
||||||
return Result::Err(vec![errmsg]);
|
return Result::Err(vec![errmsg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let whitelist_content = utils::read_txt(&value.unwrap());
|
let allowlist_content = utils::read_txt(&value.unwrap());
|
||||||
if whitelist_content.is_err() {
|
if allowlist_content.is_err() {
|
||||||
return Result::Err(vec![whitelist_content.unwrap_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(());
|
return Result::Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_match(&self, event_value: Option<&Value>) -> bool {
|
fn is_match(&self, event_value: Option<&Value>) -> bool {
|
||||||
return match event_value.unwrap_or(&Value::Null) {
|
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) => {
|
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,
|
_ => true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -487,7 +487,7 @@ impl PipeElement {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::super::matchers::{
|
use super::super::matchers::{
|
||||||
DefaultMatcher, MinlengthMatcher, PipeElement, RegexesFileMatcher, WhitelistFileMatcher,
|
AllowlistFileMatcher, DefaultMatcher, MinlengthMatcher, PipeElement, RegexesFileMatcher,
|
||||||
};
|
};
|
||||||
use super::super::selectionnodes::{
|
use super::super::selectionnodes::{
|
||||||
AndSelectionNode, LeafSelectionNode, OrSelectionNode, SelectionNode,
|
AndSelectionNode, LeafSelectionNode, OrSelectionNode, SelectionNode,
|
||||||
@@ -514,7 +514,7 @@ mod tests {
|
|||||||
ImagePath:
|
ImagePath:
|
||||||
min_length: 1234321
|
min_length: 1234321
|
||||||
regexes: ./regexes.txt
|
regexes: ./regexes.txt
|
||||||
whitelist: ./whitelist.txt
|
allowlist: ./allowlist.txt
|
||||||
falsepositives:
|
falsepositives:
|
||||||
- unknown
|
- unknown
|
||||||
level: medium
|
level: medium
|
||||||
@@ -664,7 +664,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// whitelist.txtが読み込めることを確認
|
// allowlist.txtが読み込めることを確認
|
||||||
{
|
{
|
||||||
let ancestor_node = ancestors[2].as_ref() as &dyn SelectionNode;
|
let ancestor_node = ancestors[2].as_ref() as &dyn SelectionNode;
|
||||||
assert_eq!(ancestor_node.is::<LeafSelectionNode>(), true);
|
assert_eq!(ancestor_node.is::<LeafSelectionNode>(), true);
|
||||||
@@ -673,12 +673,12 @@ mod tests {
|
|||||||
let ancestor_node = &ancestor_node.matcher;
|
let ancestor_node = &ancestor_node.matcher;
|
||||||
assert_eq!(ancestor_node.is_some(), true);
|
assert_eq!(ancestor_node.is_some(), true);
|
||||||
let ancestor_matcher = ancestor_node.as_ref().unwrap();
|
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
|
let ancestor_matcher = ancestor_matcher
|
||||||
.downcast_ref::<WhitelistFileMatcher>()
|
.downcast_ref::<AllowlistFileMatcher>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let csvcontent = &ancestor_matcher.whitelist_csv_content;
|
let csvcontent = &ancestor_matcher.allowlist_csv_content;
|
||||||
assert_eq!(csvcontent.len(), 2);
|
assert_eq!(csvcontent.len(), 2);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -1068,14 +1068,14 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_detect_regexes() {
|
fn test_detect_regexes() {
|
||||||
// regexes.txtが正しく検知できることを確認
|
// regexes.txtが正しく検知できることを確認
|
||||||
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
|
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
|
||||||
let rule_str = r#"
|
let rule_str = r#"
|
||||||
enabled: true
|
enabled: true
|
||||||
detection:
|
detection:
|
||||||
selection:
|
selection:
|
||||||
EventID: 4103
|
EventID: 4103
|
||||||
Channel:
|
Channel:
|
||||||
- whitelist: whitelist.txt
|
- allowlist: allowlist.txt
|
||||||
output: 'command=%CommandLine%'
|
output: 'command=%CommandLine%'
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
@@ -1098,16 +1098,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_detect_whitelist() {
|
fn test_detect_allowlist() {
|
||||||
// whitelistが正しく検知できることを確認
|
// allowlistが正しく検知できることを確認
|
||||||
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
|
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
|
||||||
let rule_str = r#"
|
let rule_str = r#"
|
||||||
enabled: true
|
enabled: true
|
||||||
detection:
|
detection:
|
||||||
selection:
|
selection:
|
||||||
EventID: 4103
|
EventID: 4103
|
||||||
Channel:
|
Channel:
|
||||||
- whitelist: whitelist.txt
|
- allowlist: allowlist.txt
|
||||||
output: 'command=%CommandLine%'
|
output: 'command=%CommandLine%'
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
@@ -1130,16 +1130,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_detect_whitelist2() {
|
fn test_detect_allowlist2() {
|
||||||
// whitelistが正しく検知できることを確認
|
// allowlistが正しく検知できることを確認
|
||||||
// この場合ではEventIDが一致しているが、whitelistに一致するので検知しないはず。
|
// この場合ではEventIDが一致しているが、allowlistに一致するので検知しないはず。
|
||||||
let rule_str = r#"
|
let rule_str = r#"
|
||||||
enabled: true
|
enabled: true
|
||||||
detection:
|
detection:
|
||||||
selection:
|
selection:
|
||||||
EventID: 4103
|
EventID: 4103
|
||||||
Channel:
|
Channel:
|
||||||
- whitelist: whitelist.txt
|
- allowlist: allowlist.txt
|
||||||
output: 'command=%CommandLine%'
|
output: 'command=%CommandLine%'
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ impl LeafSelectionNode {
|
|||||||
return vec![
|
return vec![
|
||||||
Box::new(matchers::MinlengthMatcher::new()),
|
Box::new(matchers::MinlengthMatcher::new()),
|
||||||
Box::new(matchers::RegexesFileMatcher::new()),
|
Box::new(matchers::RegexesFileMatcher::new()),
|
||||||
Box::new(matchers::WhitelistFileMatcher::new()),
|
Box::new(matchers::AllowlistFileMatcher::new()),
|
||||||
Box::new(matchers::DefaultMatcher::new()),
|
Box::new(matchers::DefaultMatcher::new()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ pub fn check_regex(string: &str, regex_list: &Vec<String>) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_whitelist(target: &str, whitelist: &Vec<String>) -> bool {
|
pub fn check_allowlist(target: &str, allowlist: &Vec<String>) -> bool {
|
||||||
for line in whitelist {
|
for line in allowlist {
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -170,12 +170,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_whitelist() {
|
fn test_check_allowlist() {
|
||||||
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate.exe\"";
|
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate.exe\"";
|
||||||
let whitelist = utils::read_txt("whitelist.txt").unwrap();
|
let allowlist = utils::read_txt("allowlist.txt").unwrap();
|
||||||
assert!(true == utils::check_whitelist(commandline, &whitelist));
|
assert!(true == utils::check_allowlist(commandline, &allowlist));
|
||||||
|
|
||||||
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate2.exe\"";
|
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate2.exe\"";
|
||||||
assert!(false == utils::check_whitelist(commandline, &whitelist));
|
assert!(false == utils::check_allowlist(commandline, &allowlist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user