Merge pull request #576 from Yamato-Security/574-add-more-timestamp-format-options

added three time option #574
This commit is contained in:
Yamato Security
2022-06-10 15:03:29 +09:00
committed by GitHub
7 changed files with 91 additions and 41 deletions

View File

@@ -9,6 +9,12 @@
**改善:**
- LinuxとmacOSのバイナリサイズをより小さくするために、デバッグシンボルをストリップします。(#568) (@YamatoSecurity)
- 新たな時刻表示のオプションとして`--US-time``--US-military-time``--European-time`の3つを追加した (#574) (@hitenkoku)
- `--rfc-3339` オプションの時刻表示形式を変更した。 (#574) (@hitenkoku)
**バグ修正:**
- xxx
**バグ修正:**

View File

@@ -9,6 +9,12 @@
**Enhancements:**
- Strip debug symbols by default for smaller Linux and macOS binaries. (#568) (@YamatoSecurity)
- Added new output time format options. (`--US-time`, `--US-military-time`, `--European-time`) (#574) (@hitenkoku)
- Changed output time format when `--rfc-3339` option is enabled. (#574) (@hitenkoku)
**Bug Fixes:**
- xxx
**Bug Fixes:**
@@ -37,7 +43,7 @@
**Bug Fixes:**
- Fixed the `--start-timeline` and `--end-timeline` options as they were not working. (#546) @hitenkoku)
- Fixed the `--start-timeline` and `--end-timeline` options as they were not working. (#546) (@hitenkoku)
- Fixed crash bug when level in rule is not valid. (#560) (@hitenkoku)
## v1.2.2 [2022/05/20]

View File

@@ -325,11 +325,11 @@ USAGE:
-d, --directory [DIRECTORY] '.evtxファイルを持つディレクトリのパス。'
-f, --filepath [FILE_PATH] '1つの.evtxファイルのパス。'
-F, --full-data '全てのフィールド情報を出力する。'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'ルールファイルまたはルールファイルを持つディレクトリ。(デフォルト: ./rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'ルールフォルダのコンフィグディレクトリ(デフォルト: ./rules/config)'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'ルールファイルまたはルールファイルを持つディレクトリ。(デフォルト: .\rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'ルールフォルダのコンフィグディレクトリ(デフォルト: .\rules\config)'
-o, --output [CSV_TIMELINE] 'タイムラインをCSV形式で保存する。(例: results.csv)'
--all-tags '出力したCSVファイルにルール内のタグ情報を全て出力する。'
-R, --display-record-id 'EventRecordIDを出力する。'
-R, --display-record-id 'イベントレコードIDを出力する。'
-v, --verbose '詳細な情報を出力する。'
-V, --visualize-timeline 'イベント頻度タイムラインを出力する。'
-D, --enable-deprecated-rules 'Deprecatedルールを有効にする。'
@@ -337,18 +337,21 @@ USAGE:
-u, --update-rules 'rulesフォルダをhayabusa-rulesのgithubリポジトリの最新版に更新する。'
-m, --min-level [LEVEL] '結果出力をするルールの最低レベル。(デフォルト: informational)'
-l, --live-analysis 'ローカル端末のC:\Windows\System32\winevt\Logsフォルダを解析する。(Windowsのみ。管理者権限が必要。)'
--start-timeline [START_TIMELINE] '解析対象とするイベントログの開始時刻。(例: "2018-11-28 12:00:00 +09:00")'
--end-timeline [END_TIMELINE] '解析対象とするイベントログの終了時刻。(例: "2021-11-28 12:00:00 +09:00")'
--rfc-2822 'RFC 2822形式で日付と時刻を出力する。(例: Mon, 07 Aug 2006 12:34:56 -0600)'
--rfc-3339 'RFC 3339形式で日付と時刻を出力する。 (例: 2006-08-07T12:34:56.485214 -06:00)'
--start-timeline [START_TIMELINE] '解析対象とするイベントログの開始時刻。(例: "2020-02-22 00:00:00 +09:00")'
--end-timeline [END_TIMELINE] '解析対象とするイベントログの終了時刻。(例: "2022-02-22 23:59:59 +09:00")'
--rfc-2822 'RFC 2822形式で日付と時刻を出力する。(例: Fri, 22 Feb 2022 22:00:00 -0600)'
--rfc-3339 'RFC 3339形式で日付と時刻を出力する。 (例: 2022-02-22 22:00:00.123456-06:00)'
--US-time 'アメリカ形式で日付と時刻を出力する。 (例: 02-22-2022 10:00:00.123 PM -06:00)'
--US-military-time '24時間制(ミリタリータイム)のアメリカ形式で日付と時刻を出力する。 (例: 02-22-2022 22:00:00.123 -06:00)'
--European-time 'ヨーロッパ形式で日付と時刻を出力する。 (例: 22-02-2022 22:00:00.123 +02:00)'
-U, --utc 'UTC形式で日付と時刻を出力する。(デフォルト: 現地時間)'
--no-color 'カラー出力を無効にする。'
-t, --thread-number [NUMBER] 'スレッド数。(デフォルト: パフォーマンスに最適な数値)'
-s, --statistics 'イベント ID の統計情報を表示する。'
-s, --statistics 'イベントIDの統計情報を表示する。'
-L, --logon-summary '成功と失敗したログオン情報の要約を出力する。'
-q, --quiet 'Quietモード。起動バナーを表示しない。'
-Q, --quiet-errors 'Quiet errorsモード。エラーログを保存しない。'
--level-tuning [LEVEL_TUNING_FILE] 'ルールlevelのチューニング (default: ./rules/config/level_tuning.txt)'
--level-tuning [LEVEL_TUNING_FILE] 'ルールlevelのチューニング (デフォルト: .\rules\config\level_tuning.txt)'
-p, --pivot-keywords-list 'ピボットキーワードの一覧作成。'
--contributors 'コントリビュータの一覧表示。'
```

View File

@@ -323,11 +323,11 @@ USAGE:
-d, --directory [DIRECTORY] 'Directory of multiple .evtx files.'
-f, --filepath [FILE_PATH] 'File path to one .evtx file.'
-F, --full-data 'Print all field information.'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'Rule file or directory (default: ./rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'Rule config folder. (Default: ./rules/config)'
-o, --output [CSV_TIMELINE] 'Save the timeline in CSV format. (Example: results.csv)'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'Rule file or directory (Default: .\rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'Rule config folder. (Default: .\rules\config)'
-o, --output [CSV_TIMELINE] 'Save the timeline in CSV format. (Ex: results.csv)'
--all-tags 'Output all tags when saving to a CSV file.'
-R, --display-record-id 'Display EventRecordID.'
-R, --display-record-id 'Display event record ID.'
-v, --verbose 'Output verbose information.'
-V, --visualize-timeline 'Output event frequency timeline.'
-D, --enable-deprecated-rules 'Enable rules marked as deprecated.'
@@ -335,10 +335,13 @@ USAGE:
-u, --update-rules 'Update to the latest rules in the hayabusa-rules github repository.'
-m, --min-level [LEVEL] 'Minimum level for rules. (Default: informational)'
-l, --live-analysis 'Analyze the local C:\Windows\System32\winevt\Logs folder (Windows Only. Administrator privileges required.)'
--start-timeline [START_TIMELINE] 'Start time of the event logs to load. (Example: "2018-11-28 12:00:00 +09:00")'
--end-timeline [END_TIMELINE] 'End time of the event logs to load. (Example: "2021-11-28 12:00:00 +09:00")'
--rfc-2822 'Output date and time in RFC 2822 format. (Example: Mon, 07 Aug 2006 12:34:56 -0600)'
--rfc-3339 'Output date and time in RFC 3339 format. (Example: 2006-08-07T12:34:56.485214 -06:00)'
--start-timeline [START_TIMELINE] 'Start time of the event logs to load. (Ex: "2020-02-22 00:00:00 +09:00")'
--end-timeline [END_TIMELINE] 'End time of the event logs to load. (Ex: "2022-02-22 23:59:59 +09:00")'
--rfc-2822 'Output timestamp in RFC 2822 format. (Ex: Fri, 22 Feb 2022 22:00:00 -0600)'
--rfc-3339 'Output timestamp in RFC 3339 format. (Ex: 2022-02-22 22:00:00.123456-06:00)'
--US-time 'Output timestamp in US time format. (Ex: 02-22-2022 10:00:00.123 PM -06:00)'
--US-military-time 'Output timestamp in US military time format. (Ex: 02-22-2022 22:00:00.123 -06:00)'
--European-time 'Output timestamp in European time format. (Ex: 22-02-2022 22:00:00.123 +02:00)'
-U, --utc 'Output time in UTC format. (Default: local time)'
--no-color 'Disable color output.'
-t, --thread-number [NUMBER] 'Thread number. (Default: Optimal number for performance.)'
@@ -346,7 +349,7 @@ USAGE:
-L, --logon-summary 'Successful and failed logons summary.'
-q, --quiet 'Quiet mode. Do not display the launch banner.'
-Q, --quiet-errors 'Quiet errors mode. Do not save error logs.'
--level-tuning [LEVEL_TUNING_FILE] 'Adjust rule level.(default: ./rules/config/level_tuning.txt) '
--level-tuning [LEVEL_TUNING_FILE] 'Tune alert levels. (Default: .\rules\config\level_tuning.txt)'
-p, --pivot-keywords-list 'Create a list of pivot keywords.'
--contributors 'Prints the list of contributors.'
```

2
rules

Submodule rules updated: e8e335e58d...3b48e17720

View File

@@ -237,7 +237,7 @@ fn emit_csv<W: std::io::Write>(
if level == "informational" {
level = "info".to_string();
}
let time_str = format_time(time);
let time_str = format_time(time, false);
if displayflag {
let record_id = detect_info
.record_id
@@ -301,7 +301,7 @@ fn emit_csv<W: std::io::Write>(
let level_suffix = *configs::LEVELMAP
.get(&detect_info.level.to_uppercase())
.unwrap_or(&0) as usize;
let time_str_date = &time_str[0..10];
let time_str_date = format_time(time, true);
let mut detect_counts_by_date = detect_counts_by_date_and_level
.get(&detect_info.level.to_lowercase())
.unwrap_or_else(|| detect_counts_by_date_and_level.get("undefined").unwrap())
@@ -585,11 +585,11 @@ fn _print_detection_summary_by_computer(
buf_wtr.print(&wtr).ok();
}
fn format_time(time: &DateTime<Utc>) -> String {
fn format_time(time: &DateTime<Utc>, date_only: bool) -> String {
if configs::CONFIG.read().unwrap().args.is_present("utc") {
format_rfc(time)
format_rfc(time, date_only)
} else {
format_rfc(&time.with_timezone(&Local))
format_rfc(&time.with_timezone(&Local), date_only)
}
}
@@ -604,14 +604,43 @@ fn _get_timestamp(time: &DateTime<Utc>) -> i64 {
}
/// return rfc time format string by option
fn format_rfc<Tz: TimeZone>(time: &DateTime<Tz>) -> String
fn format_rfc<Tz: TimeZone>(time: &DateTime<Tz>, date_only: bool) -> String
where
Tz::Offset: std::fmt::Display,
{
if configs::CONFIG.read().unwrap().args.is_present("rfc-2822") {
time.to_rfc2822()
} else if configs::CONFIG.read().unwrap().args.is_present("rfc-3339") {
time.to_rfc3339()
let time_args = &configs::CONFIG.read().unwrap().args;
if time_args.is_present("rfc-2822") {
if date_only {
time.format("%a, %e %b %Y").to_string()
} else {
time.format("%a, %e %b %Y %H:%M:%S %:z").to_string()
}
} else if time_args.is_present("rfc-3339") {
if date_only {
time.format("%Y-%m-%d").to_string()
} else {
time.format("%Y-%m-%d %H:%M:%S%.6f%:z").to_string()
}
} else if time_args.is_present("US-time") {
if date_only {
time.format("%m-%d-%Y").to_string()
} else {
time.format("%m-%d-%Y %I:%M:%S%.3f %p %:z").to_string()
}
} else if time_args.is_present("US-military-time") {
if date_only {
time.format("%m-%d-%Y").to_string()
} else {
time.format("%m-%d-%Y %H:%M:%S%.3f %:z").to_string()
}
} else if time_args.is_present("European-time") {
if date_only {
time.format("%d-%m-%Y").to_string()
} else {
time.format("%d-%m-%Y %H:%M:%S%.3f %:z").to_string()
}
} else if date_only {
time.format("%Y-%m-%d").to_string()
} else {
time.format("%Y-%m-%d %H:%M:%S%.3f %:z").to_string()
}
@@ -777,7 +806,7 @@ mod tests {
assert_eq!(_get_serialized_disp_output(None,), expect_header);
assert_eq!(
_get_serialized_disp_output(Some(DisplayFormat {
timestamp: &format_time(&test_timestamp),
timestamp: &format_time(&test_timestamp, false),
level: test_level,
computer: test_computername,
event_i_d: test_eventid,

View File

@@ -72,11 +72,11 @@ fn build_app<'a>() -> ArgMatches<'a> {
let usages = "-d, --directory [DIRECTORY] 'Directory of multiple .evtx files.'
-f, --filepath [FILE_PATH] 'File path to one .evtx file.'
-F, --full-data 'Print all field information.'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'Rule directory or file (default: ./rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'Rule config folder. (Default: ./rules/config)'
-o, --output [CSV_TIMELINE] 'Save the timeline in CSV format. (Example: results.csv)'
-r, --rules [RULE_DIRECTORY/RULE_FILE] 'Rule directory or file (Default: .\\rules)'
-C, --config [RULE_CONFIG_DIRECTORY] 'Rule config folder. (Default: .\\rules\\config)'
-o, --output [CSV_TIMELINE] 'Save the timeline in CSV format. (Ex: results.csv)'
--all-tags 'Output all tags when saving to a CSV file.'
-R, --display-record-id 'Display EventRecordID.'
-R, --display-record-id 'Display event record ID.'
-v, --verbose 'Output verbose information.'
-V, --visualize-timeline 'Output event frequency timeline.'
-D, --enable-deprecated-rules 'Enable rules marked as deprecated.'
@@ -84,10 +84,13 @@ fn build_app<'a>() -> ArgMatches<'a> {
-u, --update-rules 'Update to the latest rules in the hayabusa-rules github repository.'
-m, --min-level [LEVEL] 'Minimum level for rules. (Default: informational)'
-l, --live-analysis 'Analyze the local C:\\Windows\\System32\\winevt\\Logs folder (Windows Only. Administrator privileges required.)'
--start-timeline [START_TIMELINE] 'Start time of the event logs to load. (Example: \"2018-11-28 12:00:00 +09:00\")'
--end-timeline [END_TIMELINE] 'End time of the event logs to load. (Example: \"2021-11-28 12:00:00 +09:00\")'
--rfc-2822 'Output date and time in RFC 2822 format. (Example: Mon, 07 Aug 2006 12:34:56 -0600)'
--rfc-3339 'Output date and time in RFC 3339 format. (Example: 2006-08-07T12:34:56.485214 -06:00)'
--start-timeline [START_TIMELINE] 'Start time of the event logs to load. (Ex: \"2020-02-22 00:00:00 +09:00\")'
--end-timeline [END_TIMELINE] 'End time of the event logs to load. (Ex: \"2022-02-22 23:59:59 +09:00\")'
--rfc-2822 'Output timestamp in RFC 2822 format. (Ex: Fri, 22 Feb 2022 22:00:00 -0600)'
--rfc-3339 'Output timestamp in RFC 3339 format. (Ex: 2022-02-22 22:00:00.123456-06:00)'
--US-time 'Output timestamp in US time format. (Ex: 02-22-2022 10:00:00.123 PM -06:00)'
--US-military-time 'Output timestamp in US military time format. (Ex: 02-22-2022 22:00:00.123 -06:00)'
--European-time 'Output timestamp in European time format. (Ex: 22-02-2022 22:00:00.123 +02:00)'
-U, --utc 'Output time in UTC format. (Default: local time)'
--no-color 'Disable color output.'
-t, --thread-number [NUMBER] 'Thread number. (Default: Optimal number for performance.)'
@@ -99,12 +102,12 @@ fn build_app<'a>() -> ArgMatches<'a> {
--contributors 'Prints the list of contributors.'";
App::new(&program)
.about("Hayabusa: Aiming to be the world's greatest Windows event log analysis tool!")
.version("1.3.0")
.version("1.3.1-dev")
.author("Yamato Security (https://github.com/Yamato-Security/hayabusa) @SecurityYamato")
.setting(AppSettings::VersionlessSubcommands)
.arg(
// TODO: When update claps to 3.x, these can write in usage texts...
Arg::from_usage("--level-tuning=[LEVEL_TUNING_FILE] 'Adjust rule level.'")
Arg::from_usage("--level-tuning [LEVEL_TUNING_FILE] 'Tune alert levels. (Default: .\\rules\\config\\level_tuning.txt)'")
.default_value("./rules/config/level_tuning.txt"),
)
.usage(usages)