diff --git a/securite/dm/pcap_analyzer/Cargo.lock b/securite/dm/pcap_analyzer/Cargo.lock index 757ec58..73094ba 100644 --- a/securite/dm/pcap_analyzer/Cargo.lock +++ b/securite/dm/pcap_analyzer/Cargo.lock @@ -60,6 +60,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "bitflags" version = "1.3.2" @@ -145,6 +151,15 @@ dependencies = [ "libc", ] +[[package]] +name = "etherparse" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21696e6dfe1057a166a042c6d27b89a46aad2ee1003e6e1e03c49d54fd3270d7" +dependencies = [ + "arrayvec", +] + [[package]] name = "heck" version = "0.5.0" @@ -199,6 +214,7 @@ name = "pcap_analyzer" version = "0.1.0" dependencies = [ "clap", + "etherparse", "pcap", ] diff --git a/securite/dm/pcap_analyzer/Cargo.toml b/securite/dm/pcap_analyzer/Cargo.toml index f29330d..1dce43a 100644 --- a/securite/dm/pcap_analyzer/Cargo.toml +++ b/securite/dm/pcap_analyzer/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] clap = { version = "4.5.7", features = ["derive"] } +etherparse = "0.15.0" pcap = "2.0.0" diff --git a/securite/dm/pcap_analyzer/src/main.rs b/securite/dm/pcap_analyzer/src/main.rs index e68cc3f..83ce841 100644 --- a/securite/dm/pcap_analyzer/src/main.rs +++ b/securite/dm/pcap_analyzer/src/main.rs @@ -1,6 +1,7 @@ use std::{error::Error, path::PathBuf}; use clap::{Parser, Subcommand}; +use etherparse::{NetSlice, SlicedPacket}; use pcap::Capture; fn main() -> Result<(), Box> { @@ -20,11 +21,11 @@ fn main() -> Result<(), Box> { let mut total_ipv4 = 0; let mut total = 0; while let Ok(packet) = pcap.next_packet() { - total += 1; - let ether_type = &packet.data[20..][..2]; - if ether_type == [0x00, 0x08] { + let packet = SlicedPacket::from_ethernet(packet.data)?; + if let Some(NetSlice::Ipv4(_)) = packet.net { total_ipv4 += 1; } + total += 1; } println!("Count: {total: >9}"); println!("Count IPv4: {total_ipv4: >9}"); diff --git a/securite/dm/push.sh b/securite/dm/push.sh index cc2cef5..c2e2219 100755 --- a/securite/dm/push.sh +++ b/securite/dm/push.sh @@ -1,5 +1,16 @@ #!/bin/sh +set -e +cd "$(dirname "$(realpath "$0")")" + + +echo "checks compile" + cd pcap_analyzer + cargo build + cd .. + + +echo "pushing" + git add . + git commit -m "dm secu" + git push -git add . -git commit -m "dm secu" -git push \ No newline at end of file