Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added low memory mode option and organize menu #1302

Merged
merged 5 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/afterfact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv.csv").to_path_buf()),
Expand Down Expand Up @@ -2381,6 +2382,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -2625,6 +2627,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv_multiline.csv").to_path_buf()),
Expand Down Expand Up @@ -2725,6 +2728,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -2953,6 +2957,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv_remove_duplicate.csv").to_path_buf()),
Expand Down Expand Up @@ -3043,6 +3048,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -3282,6 +3288,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv_remove_duplicate.json").to_path_buf()),
Expand Down Expand Up @@ -3372,6 +3379,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -3684,6 +3692,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_multiple_data_in_details.json").to_path_buf()),
Expand Down Expand Up @@ -3775,6 +3784,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -4032,6 +4042,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv_json.json").to_path_buf()),
Expand Down Expand Up @@ -4123,6 +4134,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down Expand Up @@ -4305,6 +4317,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv_jsonl.jsonl").to_path_buf()),
Expand Down Expand Up @@ -4396,6 +4409,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
};
let ch = mock_ch_filter
.get(&CompactString::from("security"))
Expand Down
31 changes: 24 additions & 7 deletions src/detections/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,12 @@
.collect(),
_ => HashSet::default(),
};

let is_low_memory = match &input_config.as_ref().unwrap().action {
Some(Action::CsvTimeline(opt)) => opt.output_options.low_memory_mode,
Some(Action::JsonTimeline(opt)) => opt.output_options.low_memory_mode,
_ => false,
};
let mut ret = StoredStatic {
is_low_memory: false,
config: input_config.as_ref().unwrap().to_owned(),
config_path: config_path.to_path_buf(),
ch_config: create_output_filter_config(
Expand Down Expand Up @@ -674,6 +677,7 @@
enable_recover_records,
timeline_offset,
include_status,
is_low_memory,
};
ret.profiles = load_profile(
check_setting_path(
Expand All @@ -694,7 +698,6 @@
.unwrap(),
Some(&ret),
);
ret.is_low_memory = false;
ret
}
/// detailsのdefault値をファイルから読み取る関数
Expand Down Expand Up @@ -914,7 +917,7 @@
#[derive(Args, Clone, Debug)]
pub struct DetectCommonOption {
/// Scan JSON formatted logs instead of .evtx (.json or .jsonl)
#[arg(help_heading = Some("Input"), short = 'J', long = "JSON-input", conflicts_with = "live_analysis", display_order = 390)]
#[arg(help_heading = Some("General Options"), short = 'J', long = "JSON-input", conflicts_with = "live_analysis", display_order = 390)]
pub json_input: bool,

/// Specify additional evtx file extensions (ex: evtx_data)
Expand Down Expand Up @@ -1534,17 +1537,22 @@
help_heading = Some("Output"),
short = 'R',
long = "remove-duplicate-data",
conflicts_with = "low_memory_mode",
display_order = 440
)]
pub remove_duplicate_data: bool,

/// Remove duplicate detections (default: disabled)
#[arg(help_heading = Some("Output"), short = 'X', long = "remove-duplicate-detections", display_order = 441)]
#[arg(help_heading = Some("Output"), short = 'X', long = "remove-duplicate-detections", conflicts_with = "low_memory_mode", display_order = 441)]
pub remove_duplicate_detections: bool,

/// Do not ask questions. Scan for all events and alerts.
#[arg(help_heading = Some("General Options"), short = 'w', long = "no-wizard", display_order = 400)]
pub no_wizard: bool,

/// Scan with the minimal amount of memory by not sorting events
#[arg(help_heading = Some("General Options"), short='s', long = "low-memory-mode", display_order = 380)]
pub low_memory_mode: bool,

Check warning on line 1555 in src/detections/configs.rs

View check run for this annotation

Codecov / codecov/patch

src/detections/configs.rs#L1555

Added line #L1555 was not covered by tests
}

#[derive(Copy, Args, Clone, Debug)]
Expand Down Expand Up @@ -1578,7 +1586,7 @@
pub live_analysis: bool,

/// Carve evtx records from slack space (default: disabled)
#[arg(help_heading = Some("Input"), short = 'x', long = "recover-records", conflicts_with = "json_input", display_order = 440)]
#[arg(help_heading = Some("General Options"), short = 'x', long = "recover-records", conflicts_with = "json_input", display_order = 440)]
pub recover_records: bool,

/// Scan recent events based on an offset (ex: 1y, 3M, 30d, 24h, 30m)
Expand Down Expand Up @@ -1648,7 +1656,7 @@
pub common_options: CommonOptions,

/// Scan JSON formatted logs instead of .evtx (.json or .jsonl)
#[arg(help_heading = Some("Input"), short = 'J', long = "JSON-input", conflicts_with = "live_analysis", display_order = 390)]
#[arg(help_heading = Some("General Options"), short = 'J', long = "JSON-input", conflicts_with = "live_analysis", display_order = 390)]
pub json_input: bool,

/// Specify additional evtx file extensions (ex: evtx_data)
Expand Down Expand Up @@ -2218,6 +2226,7 @@
remove_duplicate_detections: false,
no_wizard: option.no_wizard,
include_status: option.include_status.clone(),
low_memory_mode: false,
}),
Action::EidMetrics(option) => Some(OutputOption {
input_args: option.input_args.clone(),
Expand Down Expand Up @@ -2258,6 +2267,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
}),
Action::LogonSummary(option) => Some(OutputOption {
input_args: option.input_args.clone(),
Expand Down Expand Up @@ -2298,6 +2308,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
}),
Action::ComputerMetrics(option) => Some(OutputOption {
input_args: option.input_args.clone(),
Expand Down Expand Up @@ -2347,6 +2358,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
}),
Action::Search(option) => Some(OutputOption {
input_args: option.input_args.clone(),
Expand Down Expand Up @@ -2396,6 +2408,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
}),
Action::SetDefaultProfile(option) => Some(OutputOption {
input_args: InputOption {
Expand Down Expand Up @@ -2451,6 +2464,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,

Check warning on line 2467 in src/detections/configs.rs

View check run for this annotation

Codecov / codecov/patch

src/detections/configs.rs#L2467

Added line #L2467 was not covered by tests
}),
Action::UpdateRules(option) => Some(OutputOption {
input_args: InputOption {
Expand Down Expand Up @@ -2506,6 +2520,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
}),
_ => None,
}
Expand Down Expand Up @@ -2758,6 +2773,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down Expand Up @@ -2833,6 +2849,7 @@
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
5 changes: 5 additions & 0 deletions src/detections/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down Expand Up @@ -1553,6 +1554,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: Some(Path::new("test_files/mmdb").to_path_buf()),
output: Some(Path::new("./test_emit_csv.csv").to_path_buf()),
Expand Down Expand Up @@ -1689,6 +1691,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: Some(Path::new("test_files/mmdb").to_path_buf()),
output: Some(Path::new("./test_emit_csv.csv").to_path_buf()),
Expand Down Expand Up @@ -1820,6 +1823,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv.csv").to_path_buf()),
Expand Down Expand Up @@ -1967,6 +1971,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: Some(Path::new("./test_emit_csv.csv").to_path_buf()),
Expand Down
1 change: 1 addition & 0 deletions src/detections/rule/condition_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions src/detections/rule/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions src/detections/rule/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions src/detections/rule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions src/detections/rule/selectionnodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions src/detections/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ mod tests {
remove_duplicate_detections: false,
no_wizard: true,
include_status: None,
low_memory_mode: false,
},
geo_ip: None,
output: None,
Expand Down
Loading
Loading