mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-26 23:49:59 -07:00
feat: show rayhunter version/os/arch in pcap, ndjson, qmdl manifest
Create a util mod to provide information about the rayhunter binary and system.
This commit is contained in:
committed by
Will Greenberg
parent
b785a7f21c
commit
f2b5aa2743
@@ -7,13 +7,11 @@ use tokio::io::AsyncWrite;
|
||||
use std::borrow::Cow;
|
||||
use chrono::prelude::*;
|
||||
use deku::prelude::*;
|
||||
use nix::sys::utsname::uname;
|
||||
use pcap_file_tokio::pcapng::blocks::enhanced_packet::EnhancedPacketBlock;
|
||||
use pcap_file_tokio::pcapng::blocks::interface_description::InterfaceDescriptionBlock;
|
||||
use pcap_file_tokio::pcapng::blocks::section_header::{SectionHeaderBlock, SectionHeaderOption};
|
||||
use pcap_file_tokio::pcapng::PcapNgWriter;
|
||||
use pcap_file_tokio::{Endianness, PcapError};
|
||||
use std::env::consts::OS;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -63,23 +61,18 @@ struct UdpHeader {
|
||||
|
||||
impl<T> GsmtapPcapWriter<T> where T: AsyncWrite + Unpin + Send {
|
||||
pub async fn new(writer: T) -> Result<Self, GsmtapPcapError> {
|
||||
let package = format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||
let application = SectionHeaderOption::UserApplication(Cow::from(package));
|
||||
let operating_system = match uname() {
|
||||
Ok(utsname) => format!(
|
||||
"{} {}",
|
||||
utsname.sysname().to_string_lossy(),
|
||||
utsname.release().to_string_lossy()
|
||||
),
|
||||
Err(_) => OS.to_owned(),
|
||||
};
|
||||
let os = SectionHeaderOption::OS(Cow::from(operating_system));
|
||||
let metadata = crate::util::RayhunterMetadata::new();
|
||||
let package = format!("{} {}", metadata.name, metadata.version);
|
||||
let section = SectionHeaderBlock {
|
||||
endianness: Endianness::Big,
|
||||
major_version: 1,
|
||||
minor_version: 0,
|
||||
section_length: -1,
|
||||
options: vec![os, application],
|
||||
options: vec![
|
||||
SectionHeaderOption::Hardware(Cow::from(metadata.arch)),
|
||||
SectionHeaderOption::OS(Cow::from(metadata.os)),
|
||||
SectionHeaderOption::UserApplication(Cow::from(package)),
|
||||
],
|
||||
};
|
||||
let writer = PcapNgWriter::with_section_header(writer, section).await?;
|
||||
Ok(GsmtapPcapWriter { writer, ip_id: 0 })
|
||||
|
||||
Reference in New Issue
Block a user