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

fix: output Events with hits when agg/correlation rule #1376

Closed
wants to merge 1 commit into from
Closed
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
85 changes: 42 additions & 43 deletions src/afterfact.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
use crate::detections::configs::{
Action, OutputOption, StoredStatic, CONTROL_CHAT_REPLACE_MAP, CURRENT_EXE_PATH, GEOIP_DB_PARSER,
};
use crate::detections::message::{AlertMessage, DetectInfo, COMPUTER_MITRE_ATTCK_MAP, LEVEL_FULL};
use crate::detections::utils::{
self, format_time, get_writable_color, output_and_data_stack_for_html, write_color_buffer,
};
use crate::options::htmlreport;
use crate::options::profile::Profile;
use crate::yaml::ParseYaml;
use std::cmp::{self, min, Ordering};
use std::error::Error;
use std::fs::File;
use std::io::{self, BufWriter, Write};
use std::path::Path;
use std::process;
use std::str::FromStr;

use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
use chrono::{DateTime, Local, TimeZone, Utc};
use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use comfy_table::presets::UTF8_FULL;
use comfy_table::*;
use compact_str::CompactString;
use hashbrown::hash_map::RawEntryMut;
use terminal_size::terminal_size;

use csv::{QuoteStyle, Writer, WriterBuilder};
use hashbrown::hash_map::RawEntryMut;
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
use krapslog::{build_sparkline, build_time_markers};
use lazy_static::lazy_static;
use nested::Nested;
use std::path::Path;
use std::str::FromStr;
use yaml_rust::YamlLoader;

use comfy_table::*;
use hashbrown::{HashMap, HashSet};
use num_format::{Locale, ToFormattedString};
use std::cmp::{self, min, Ordering};
use std::error::Error;

use std::io::{self, BufWriter, Write};

use lazy_static::lazy_static;
use std::fs::File;
use std::process;
use termcolor::{Buffer, BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
use terminal_size::terminal_size;
use terminal_size::Width;
use yaml_rust::YamlLoader;

use crate::detections::configs::{
Action, OutputOption, StoredStatic, CONTROL_CHAT_REPLACE_MAP, CURRENT_EXE_PATH, GEOIP_DB_PARSER,
};
use crate::detections::message::{AlertMessage, DetectInfo, COMPUTER_MITRE_ATTCK_MAP, LEVEL_FULL};
use crate::detections::utils::{
self, format_time, get_writable_color, output_and_data_stack_for_html, write_color_buffer,
};
use crate::options::htmlreport;
use crate::options::profile::Profile;
use crate::yaml::ParseYaml;

lazy_static! {
// ここで字句解析するときに使う正規表現の一覧を定義する。
Expand Down Expand Up @@ -497,14 +495,12 @@ fn calc_statistic_info(
afterfact_info
.timestamps
.push(detect_info.detected_time.timestamp());
if !detect_info.is_condition {
afterfact_info
.detected_record_idset
.insert(CompactString::from(format!(
"{}_{}",
detect_info.detected_time, detect_info.eventid
)));
}
afterfact_info
.detected_record_idset
.insert(CompactString::from(format!(
"{}_{}",
detect_info.detected_time, detect_info.eventid
)));

if !output_option.no_summary {
let level_suffix = get_level_suffix(detect_info.level.as_str());
Expand Down Expand Up @@ -2204,7 +2200,15 @@ fn _output_html_computer_by_mitre_attck(html_output_stock: &mut Nested<String>)

#[cfg(test)]
mod tests {
use super::create_output_color_map;
use std::fs::{read_to_string, remove_file};
use std::path::Path;

use chrono::NaiveDateTime;
use chrono::{Local, TimeZone, Utc};
use compact_str::CompactString;
use hashbrown::HashMap;
use serde_json::Value;

use crate::afterfact::format_time;
use crate::afterfact::init_writer;
use crate::afterfact::output_afterfact_inner;
Expand All @@ -2226,13 +2230,8 @@ mod tests {
use crate::detections::message::DetectInfo;
use crate::detections::utils;
use crate::options::profile::{load_profile, Profile};
use chrono::NaiveDateTime;
use chrono::{Local, TimeZone, Utc};
use compact_str::CompactString;
use hashbrown::HashMap;
use serde_json::Value;
use std::fs::{read_to_string, remove_file};
use std::path::Path;

use super::create_output_color_map;

#[test]
fn test_emit_csv_output() {
Expand Down
Loading