aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorWill Dillon <william@housedillon.com>2025-11-08 06:54:10 +0000
committerWill Dillon <william@housedillon.com>2025-11-08 06:54:10 +0000
commit6ce2b201ae021f055df181fac19ea53b41d77895 (patch)
tree7cc778bef6969270ee571d7afd633412bcfddec1 /src/bin
parentBack over to the laptop (diff)
downloadmeshcore-rs-6ce2b201ae021f055df181fac19ea53b41d77895.tar.gz
meshcore-rs-6ce2b201ae021f055df181fac19ea53b41d77895.zip
Getting pretty close to finished
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/packet_analyzer.rs67
1 files changed, 62 insertions, 5 deletions
diff --git a/src/bin/packet_analyzer.rs b/src/bin/packet_analyzer.rs
index ee3c3fe..9348a08 100644
--- a/src/bin/packet_analyzer.rs
+++ b/src/bin/packet_analyzer.rs
@@ -1,11 +1,15 @@
-use std::path::PathBuf;
+use std::{borrow::Cow, path::PathBuf};
+use hex::encode;
+use log::{error, trace};
use tokio::fs::File;
+use tokio_util::bytes::Bytes;
use clap::Parser;
use color_eyre::eyre::Result;
-use meshcore::{crypto::Keychain, identity::KeystoreInput};
+use meshcore::{identity::{Keystore, KeystoreInput}, packet::Packet};
use pretty_env_logger;
-use pcap_file_tokio::pcapng::{Block::*, PcapNgReader, PcapNgWriter, blocks::interface_description::InterfaceDescriptionBlock};
+use pcap_file_tokio::pcapng::PcapNgReader;
+
#[derive(Parser)]
struct AnalyzerArguments {
@@ -16,6 +20,16 @@ struct AnalyzerArguments {
pcap_file: PathBuf,
}
+fn process_packet(data: Cow<[u8]>, keystore: &Keystore) {
+ // Convert the Cow into Bytes so we can do the packet analysis.
+ let bytes = Bytes::copy_from_slice(&data);
+
+ let mut packet = Packet::from(bytes);
+ packet.try_decrypt(keystore);
+
+ println!("{}", packet);
+}
+
#[tokio::main]
async fn main() -> Result<()> {
pretty_env_logger::init();
@@ -25,12 +39,55 @@ async fn main() -> Result<()> {
// Attempt to load the identities file from disk and load all the identities
let identity_string = std::fs::read_to_string(args.identities_file)?;
let keystore_in: KeystoreInput = toml::from_str(&identity_string)?;
+
let keystore = keystore_in.compile();
+ // println!("Keystore: \n{:#?}", keystore);
+
// Pcapng file for loading packets
let pcap_file = File::open(args.pcap_file).await?;
- let pcap_reader = PcapNgReader::new(pcap_file).await?;
-
+ let mut pcap_reader = PcapNgReader::new(pcap_file).await?;
+
+ println!(" ROUTE T | v1 | Transp Fl. | Route Summary | I | Pkt. Type | Summary....");
+
+ // Iterate through the packets in the pacap
+ // and print out their contents! Wheeeee!
+ while let Some(pkt) = pcap_reader.next_block().await {
+ use pcap_file_tokio::pcapng::Block::*;
+ match pkt {
+ Ok(SectionHeader(section_header_block)) => {
+ trace!("SectionHeader: {:#?}", section_header_block);
+ }
+ Ok(InterfaceDescription(interface_description_block)) => {
+ trace!("InterfaceDescription: {:#?}", interface_description_block);
+ }
+ Ok(Packet(packet_block)) => {
+ trace!("Packet: {:#?}", packet_block);
+ }
+ Ok(SimplePacket(simple_packet_block)) => {
+ trace!("SimplePacket: {:#?}", simple_packet_block);
+ }
+ Ok(NameResolution(name_resolution_block)) => {
+ trace!("NameResolution: {:#?}", name_resolution_block);
+ }
+ Ok(InterfaceStatistics(interface_statistics_block)) => {
+ trace!("InterfaceStatistics: {:#?}", interface_statistics_block);
+ }
+ Ok(EnhancedPacket(enhanced_packet_block)) => {
+ trace!("EnhancedPacket: {}", encode(&enhanced_packet_block.data));
+ process_packet(enhanced_packet_block.data.clone(), &keystore);
+ }
+ Ok(SystemdJournalExport(systemd_journal_export_block)) => {
+ trace!("SystemdJournalExport: {:#?}", systemd_journal_export_block);
+ }
+ Ok(Unknown(unknown_block)) => {
+ trace!("Unknown: {:#?}", unknown_block);
+ }
+ Err(e) => {
+ error!("Error in Pcap file! {}", e);
+ }
+ }
+ }
Ok(())
} \ No newline at end of file