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

Add BOOT and DHCP event structure #120

Merged
merged 2 commits into from
Jun 20, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added `Bootp` and `Dhcp` event structures.

### Changed

- Modified connection log structure to include total L2 frame length of a session.
Expand Down
124 changes: 124 additions & 0 deletions src/ingest/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,127 @@ impl ResponseRangeData for Nfs {
bincode::serialize(&Some((timestamp, source, &nfs_csv.as_bytes())))
}
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Bootp {
pub orig_addr: IpAddr,
pub orig_port: u16,
pub resp_addr: IpAddr,
pub resp_port: u16,
pub proto: u8,
pub last_time: i64,
pub op: u8,
pub htype: u8,
pub hops: u8,
pub xid: u32,
pub ciaddr: IpAddr,
pub yiaddr: IpAddr,
pub siaddr: IpAddr,
pub giaddr: IpAddr,
pub chwaddr: Vec<u8>,
pub sname: String,
pub file: String,
}

impl Display for Bootp {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(
f,
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
self.orig_addr,
self.orig_port,
self.resp_addr,
self.resp_port,
self.proto,
convert_time_format(self.last_time),
self.op,
self.htype,
self.hops,
self.xid,
self.ciaddr,
self.yiaddr,
self.siaddr,
self.giaddr,
vec_to_string_or_default(&self.chwaddr),
as_str_or_default(&self.sname),
as_str_or_default(&self.file),
)
}
}

impl ResponseRangeData for Bootp {
fn response_data(&self, timestamp: i64, source: &str) -> Result<Vec<u8>, bincode::Error> {
let bootp_csv = format!("{}\t{source}\t{self}", convert_time_format(timestamp));

bincode::serialize(&Some((timestamp, source, &bootp_csv.as_bytes())))
}
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Dhcp {
pub orig_addr: IpAddr,
pub orig_port: u16,
pub resp_addr: IpAddr,
pub resp_port: u16,
pub proto: u8,
pub last_time: i64,
pub msg_type: u8,
pub ciaddr: IpAddr,
pub yiaddr: IpAddr,
pub siaddr: IpAddr,
pub giaddr: IpAddr,
pub subnet_mask: IpAddr,
pub router: Vec<IpAddr>,
pub domain_name_server: Vec<IpAddr>,
pub req_ip_addr: IpAddr,
pub lease_time: u32,
pub server_id: IpAddr,
pub param_req_list: Vec<u8>,
pub message: String,
pub renewal_time: u32,
pub rebinding_time: u32,
pub class_id: Vec<u8>,
pub client_id_type: u8,
pub client_id: Vec<u8>,
}

impl Display for Dhcp {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(
f,
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
self.orig_addr,
self.orig_port,
self.resp_addr,
self.resp_port,
self.proto,
convert_time_format(self.last_time),
self.msg_type,
self.ciaddr,
self.yiaddr,
self.siaddr,
self.giaddr,
self.subnet_mask,
vec_to_string_or_default(&self.router),
vec_to_string_or_default(&self.domain_name_server),
self.req_ip_addr,
self.lease_time,
self.server_id,
vec_to_string_or_default(&self.param_req_list),
as_str_or_default(&self.message),
self.renewal_time,
self.rebinding_time,
vec_to_string_or_default(&self.class_id),
self.client_id_type,
vec_to_string_or_default(&self.client_id),
)
}
}

impl ResponseRangeData for Dhcp {
fn response_data(&self, timestamp: i64, source: &str) -> Result<Vec<u8>, bincode::Error> {
let dhcp_csv = format!("{}\t{source}\t{self}", convert_time_format(timestamp));

bincode::serialize(&Some((timestamp, source, &dhcp_csv.as_bytes())))
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum RawEventKind {
Smb = 18,
Nfs = 19,
SecuLog = 20,
Bootp = 21,
Dhcp = 22,

// Windows Sysmon
ProcessCreate = 31,
Expand Down
Loading