From 995aa1d75b4b7b5c93bbf83f65dcfed2382ea63e Mon Sep 17 00:00:00 2001 From: DustInDark Date: Mon, 23 May 2022 00:20:08 +0900 Subject: [PATCH] output not found field to n/a (#531) * changed no found placeholder output to n/a #528 * added n/a output to details when not found placeholder * added v1.3.0 changelog describe and #528 enhance * fixed typo and fixed markdown format * fixed test * readme, changelog, version update Co-authored-by: Tanaka Zakku <71482215+YamatoSecurity@users.noreply.github.com> --- CHANGELOG-Japanese.md | 16 ++++++++++++++++ CHANGELOG.md | 14 ++++++++++++++ Cargo.toml | 2 +- README-Japanese.md | 2 +- README.md | 2 +- src/detections/print.rs | 12 ++++++------ 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CHANGELOG-Japanese.md b/CHANGELOG-Japanese.md index 7ea52b63..ad45edfb 100644 --- a/CHANGELOG-Japanese.md +++ b/CHANGELOG-Japanese.md @@ -1,5 +1,19 @@ # 変更点 +## v1.3.0 [2022/xx/xx] + +**新機能:** + +- xxx + +**改善:** + +- ルールの`details`でeventkey_alias.txtやEvent.EventData内に存在しない情報を`n/a` (not available)と表記するようにした。(#528) (@hitenkoku) + +**バグ修正:** + +- xxx + ## v1.2.2 [2022/05/20] **新機能:** @@ -19,10 +33,12 @@ ## v1.2.1 [2022/04/20] Black Hat Asia Arsenal 2022 RC2 **新機能:** + - `./config/channel_abbreviations`の設定ファイルにより、`Channel`列も出力されるようになった。 (@hitenkoku) - ルールとルールの設定ファイルは強制的に上書きされる。 (@hitenkoku) **バグ修正:** + - ルールがnoisyもしくはexcludedと設定された場合は、`--level-tuning`オプションで`level`が更新されなかったが、修正した。 (@hitenkoku) ## v1.2.0 [2022/04/15] Black Hat Asia Arsenal 2022 RC1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ad24e8..65f8d9bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changes +## v1.3.0 [2022/xx/xx] + +**New Features:** + +- xxx + +**Enhancements:** + +- In the `details` line in a rule, when a placeholder points to a field that does not exist or there is an incorrect alias mapping, it will be outputted as `n/a` (not available). (#528) (@hitenkoku) + +**Bug Fixes:** + +- xxx + ## v1.2.2 [2022/05/20] **New Features:** diff --git a/Cargo.toml b/Cargo.toml index 34c0d79b..68399b4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hayabusa" -version = "1.2.2" +version = "1.3.0-dev" authors = ["Yamato Security @SecurityYamato"] edition = "2021" diff --git a/README-Japanese.md b/README-Japanese.md index 26e3a2ce..819b7d54 100644 --- a/README-Japanese.md +++ b/README-Japanese.md @@ -485,7 +485,7 @@ Hayabusaの結果を標準出力に表示しているとき(デフォルト) * `Event ID`: イベントログの``フィールドから来ています。 * `Level`: YML検知ルールの`level`フィールドから来ています。(例:`informational`, `low`, `medium`, `high`, `critical`) デフォルトでは、すべてのレベルのアラートとイベントが出力されますが、`-m`オプションで最低のレベルを指定することができます。例えば`-m high`オプションを付けると、`high`と`critical`アラートしか出力されません。 * `Title`: YML検知ルールの`title`フィールドから来ています。 -* `Details`: YML検知ルールの`details`フィールドから来ていますが、このフィールドはHayabusaルールにしかありません。このフィールドはアラートとイベントに関する追加情報を提供し、ログの``部分から有用なデータを抽出することができます。 +* `Details`: YML検知ルールの`details`フィールドから来ていますが、このフィールドはHayabusaルールにしかありません。このフィールドはアラートとイベントに関する追加情報を提供し、ログの``部分から有用なデータを抽出することができます。イベントキーのマッピングが間違っている場合、もしくはフィールドが存在しない場合で抽出ができなかった箇所は`n/a` (not available)と記載されます。 CSVファイルとして保存する場合、以下の列が追加されます: diff --git a/README.md b/README.md index 73b9e095..8122c4af 100644 --- a/README.md +++ b/README.md @@ -482,7 +482,7 @@ When hayabusa output is being displayed to the screen (the default), it will dis * `Event ID`: This comes from the `` field in the event log. * `Level`: This comes from the `level` field in the YML detection rule. (`informational`, `low`, `medium`, `high`, `critical`) By default, all level alerts will be displayed but you can set the minimum level with `-m`. For example, you can set `-m high`) in order to only scan for and display high and critical alerts. * `Title`: This comes from the `title` field in the YML detection rule. -* `Details`: This comes from the `details` field in the YML detection rule, however, only hayabusa rules have this field. This field gives extra information about the alert or event and can extract useful data from the `` portion of the log. For example, usernames, command line information, process information, etc... +* `Details`: This comes from the `details` field in the YML detection rule, however, only hayabusa rules have this field. This field gives extra information about the alert or event and can extract useful data from the `` portion of the log. For example, usernames, command line information, process information, etc... When a placeholder points to a field that does not exist or there is an incorrect alias mapping, it will be outputted as `n/a` (not available). The following additional columns will be added to the output when saving to a CSV file: diff --git a/src/detections/print.rs b/src/detections/print.rs index 18027808..bf6b6ab2 100644 --- a/src/detections/print.rs +++ b/src/detections/print.rs @@ -161,22 +161,22 @@ impl Message { }; let split: Vec<&str> = array_str.split('.').collect(); - let mut is_exist_event_key = false; let mut tmp_event_record: &Value = event_record; for s in &split { if let Some(record) = tmp_event_record.get(s) { - is_exist_event_key = true; tmp_event_record = record; } } - if is_exist_event_key { - let hash_value = get_serde_number_to_string(tmp_event_record); + let hash_value = get_serde_number_to_string(tmp_event_record); + if hash_value.is_some() { if let Some(hash_value) = hash_value { // UnicodeのWhitespace characterをそのままCSVに出力すると見難いので、スペースに変換する。なお、先頭と最後のWhitespace characterは単に削除される。 let hash_value: Vec<&str> = hash_value.split_whitespace().collect(); let hash_value = hash_value.join(" "); hash_map.insert(full_target_str.to_string(), hash_value); } + } else { + hash_map.insert(full_target_str.to_string(), "n/a".to_string()); } } @@ -492,7 +492,7 @@ mod tests { } "##; let event_record: Value = serde_json::from_str(json_str).unwrap(); - let expected = "NoExistAlias:%NoAliasNoHit%"; + let expected = "NoExistAlias:n/a"; assert_eq!( message.parse_message(&event_record, "NoExistAlias:%NoAliasNoHit%".to_owned()), expected, @@ -517,7 +517,7 @@ mod tests { } "##; let event_record: Value = serde_json::from_str(json_str).unwrap(); - let expected = "commandline:parsetest3 computername:%ComputerName%"; + let expected = "commandline:parsetest3 computername:n/a"; assert_eq!( message.parse_message( &event_record,