Skip to content

Commit

Permalink
Add packet attribute triage function
Browse files Browse the repository at this point in the history
- Add triage functionality for scoring with attributes of each raw
  event.
  - Used the attrievent crate. The kinds of raw events and their
    attributes change as our software evolves. The purpose of attrievent
    is to provide a comprehensive list of attributes for both review and
    the UI simultaneously.
  - Add the `to_attr_value` to the `Match` trait.
  - Implement `score_by_attr` under `Match` trait.
- Modify the `ValueKind` enum to support different types of input.

Close: #354
  • Loading branch information
kimhanbeom committed Mar 6, 2025
1 parent 2870c28 commit 5f4466a
Show file tree
Hide file tree
Showing 26 changed files with 1,166 additions and 149 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added triage functionality for scoring with attributes of each raw event.
- Used the attrievent crate. The kinds of raw events and their attributes
change as our software evolves. The purpose of attrievent is to provide a
comprehensive list of attributes for both review and the UI simultaneously.
- Added a new enum type `AttrValue`. This type is used to convert the
attribute value of each raw event to its corresponding type to perform
comparison operations.
- Added the `to_attr_value` to the `Match` trait to generate an `AttrValue`
from the field in all detection event.
- Implemented `score_by_attr` under `Match` trait.

### Changed

- Modified the `ValueKind` enum to support different types of input for packet
attribute triage.

## Fixed

- Fixed learning method matches for the detected events. The previous
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ futures = "0.3"
humantime-serde = "1"
ip2location = "0.5.4"
ipnet = { version = "2", features = ["serde"] }
memchr = "2"
num-derive = "0.4"
num-traits = "0.2"
postgres-protocol = "0.6"
Expand All @@ -51,6 +52,7 @@ tokio = { version = "1", features = ["macros"] }
tokio-postgres-rustls = "0.13"
toml = "0.8.13"
tracing = "0.1"
attrievent = { git = "https://github.com/aicers/attrievent.git", tag = "0.1.0" }

[dev-dependencies]
tempfile = "3"
Expand Down
6 changes: 3 additions & 3 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3407,7 +3407,7 @@ mod tests {
message: "message".to_string(),
renewal_time: 100,
rebinding_time: 200,
class_id: vec![4, 5, 6],
class_id: "MSFT 5.0".as_bytes().to_vec(),
client_id_type: 1,
client_id: vec![7, 8, 9],
category: EventCategory::InitialAccess,
Expand All @@ -3426,7 +3426,7 @@ mod tests {
let syslog_message = message.to_string();
assert_eq!(
&syslog_message,
r#"time="1970-01-01T01:01:01+00:00" event_kind="BlockListDhcp" category="InitialAccess" sensor="collector1" src_addr="127.0.0.1" src_port="68" dst_addr="127.0.0.2" dst_port="67" proto="17" last_time="100" msg_type="1" ciaddr="127.0.0.5" yiaddr="127.0.0.6" siaddr="127.0.0.7" giaddr="127.0.0.8" subnet_mask="255.255.255.0" router="127.0.0.1" domain_name_server="127.0.0.1" req_ip_addr="127.0.0.100" lease_time="100" server_id="127.0.0.1" param_req_list="1,2,3" message="message" renewal_time="100" rebinding_time="200" class_id="04:05:06" client_id_type="1" client_id="07:08:09""#,
r#"time="1970-01-01T01:01:01+00:00" event_kind="BlockListDhcp" category="InitialAccess" sensor="collector1" src_addr="127.0.0.1" src_port="68" dst_addr="127.0.0.2" dst_port="67" proto="17" last_time="100" msg_type="1" ciaddr="127.0.0.5" yiaddr="127.0.0.6" siaddr="127.0.0.7" giaddr="127.0.0.8" subnet_mask="255.255.255.0" router="127.0.0.1" domain_name_server="127.0.0.1" req_ip_addr="127.0.0.100" lease_time="100" server_id="127.0.0.1" param_req_list="1,2,3" message="message" renewal_time="100" rebinding_time="200" class_id="MSFT 5.0" client_id_type="1" client_id="07:08:09""#,
);

let block_list_dhcp = Event::BlockList(RecordType::Dhcp(BlockListDhcp::new(
Expand All @@ -3437,7 +3437,7 @@ mod tests {

assert_eq!(
&block_list_dhcp,
r#"time="1970-01-01T01:01:01+00:00" event_kind="BlockListDhcp" category="InitialAccess" sensor="collector1" src_addr="127.0.0.1" src_port="68" dst_addr="127.0.0.2" dst_port="67" proto="17" last_time="100" msg_type="1" ciaddr="127.0.0.5" yiaddr="127.0.0.6" siaddr="127.0.0.7" giaddr="127.0.0.8" subnet_mask="255.255.255.0" router="127.0.0.1" domain_name_server="127.0.0.1" req_ip_addr="127.0.0.100" lease_time="100" server_id="127.0.0.1" param_req_list="1,2,3" message="message" renewal_time="100" rebinding_time="200" class_id="04:05:06" client_id_type="1" client_id="07:08:09" triage_scores="""#
r#"time="1970-01-01T01:01:01+00:00" event_kind="BlockListDhcp" category="InitialAccess" sensor="collector1" src_addr="127.0.0.1" src_port="68" dst_addr="127.0.0.2" dst_port="67" proto="17" last_time="100" msg_type="1" ciaddr="127.0.0.5" yiaddr="127.0.0.6" siaddr="127.0.0.7" giaddr="127.0.0.8" subnet_mask="255.255.255.0" router="127.0.0.1" domain_name_server="127.0.0.1" req_ip_addr="127.0.0.100" lease_time="100" server_id="127.0.0.1" param_req_list="1,2,3" message="message" renewal_time="100" rebinding_time="200" class_id="MSFT 5.0" client_id_type="1" client_id="07:08:09" triage_scores="""#
);
}

Expand Down
37 changes: 33 additions & 4 deletions src/event/bootp.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
use std::{fmt, net::IpAddr, num::NonZeroU8};

use attrievent::attribute::{BootpAttr, RawEventAttrKind};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use super::{EventCategory, LearningMethod, MEDIUM, TriagePolicy, TriageScore, common::Match};
use crate::event::common::{to_hardware_address, triage_scores_to_string};
use super::{EventCategory, LearningMethod, MEDIUM, TriageScore, common::Match};
use crate::event::common::{AttrValue, to_hardware_address, triage_scores_to_string};

macro_rules! bootp_target_attr {
($event: expr, $raw_event_attr: expr) => {{
if let RawEventAttrKind::Bootp(attr) = $raw_event_attr {
let target_value = match attr {
BootpAttr::SrcAddr => AttrValue::Addr($event.src_addr),
BootpAttr::SrcPort => AttrValue::UInt($event.src_port.into()),
BootpAttr::DstAddr => AttrValue::Addr($event.dst_addr),
BootpAttr::DstPort => AttrValue::UInt($event.dst_port.into()),
BootpAttr::Proto => AttrValue::UInt($event.proto.into()),
BootpAttr::Op => AttrValue::UInt($event.op.into()),
BootpAttr::Htype => AttrValue::UInt($event.htype.into()),
BootpAttr::Hops => AttrValue::UInt($event.hops.into()),
BootpAttr::Xid => AttrValue::UInt($event.xid.into()),
BootpAttr::CiAddr => AttrValue::Addr($event.ciaddr),
BootpAttr::YiAddr => AttrValue::Addr($event.yiaddr),
BootpAttr::SiAddr => AttrValue::Addr($event.siaddr),
BootpAttr::GiAddr => AttrValue::Addr($event.giaddr),
BootpAttr::ChAddr => AttrValue::VecRaw(&$event.chaddr),
BootpAttr::SName => AttrValue::String(&$event.sname),
BootpAttr::File => AttrValue::String(&$event.file),
};
Some(target_value)
} else {
None
}
}};
}

#[derive(Serialize, Deserialize)]
pub struct BlockListBootpFields {
Expand Down Expand Up @@ -180,7 +209,7 @@ impl Match for BlockListBootp {
LearningMethod::SemiSupervised
}

fn score_by_packet_attr(&self, _triage: &TriagePolicy) -> f64 {
0.0
fn to_attr_value(&self, raw_event_attr: RawEventAttrKind) -> Option<AttrValue> {
bootp_target_attr!(self, raw_event_attr)

Check warning on line 213 in src/event/bootp.rs

View check run for this annotation

Codecov / codecov/patch

src/event/bootp.rs#L212-L213

Added lines #L212 - L213 were not covered by tests
}
}
Loading

0 comments on commit 5f4466a

Please sign in to comment.