diff --git a/implants/lib/eldritch/Cargo.toml b/implants/lib/eldritch/Cargo.toml index b659ac002..0afa7d1c6 100644 --- a/implants/lib/eldritch/Cargo.toml +++ b/implants/lib/eldritch/Cargo.toml @@ -29,7 +29,6 @@ hex-literal = { workspace = true } ipnetwork = { workspace = true } log = { workspace = true } md5 = { workspace = true } -netstat2 = { workspace = true } nix = { workspace = true } notify = { workspace = true } object = { workspace = true } @@ -76,6 +75,9 @@ winreg = { workspace = true } [target.'cfg(not(windows))'.dependencies] pnet = { workspace = true } +[target.'cfg(not(target_os = "freebsd"))'.dependencies] +netstat2 = { workspace = true } + [dev-dependencies] transport = { workspace = true, features = ["mock"]} httptest = { workspace = true } diff --git a/implants/lib/eldritch/src/file/list_impl.rs b/implants/lib/eldritch/src/file/list_impl.rs index f5451f490..4412789f3 100644 --- a/implants/lib/eldritch/src/file/list_impl.rs +++ b/implants/lib/eldritch/src/file/list_impl.rs @@ -16,6 +16,8 @@ use std::os::macos::fs::MetadataExt; use std::os::unix::fs::PermissionsExt; #[cfg(target_os = "windows")] use std::os::windows::fs::MetadataExt; +#[cfg(target_os = "freebsd")] +use std::os::freebsd::fs::MetadataExt; use sysinfo::{System, SystemExt, UserExt}; const UNKNOWN: &str = "UNKNOWN"; diff --git a/implants/lib/eldritch/src/process/netstat_impl.rs b/implants/lib/eldritch/src/process/netstat_impl.rs index 4d82dc968..4dae95b9e 100644 --- a/implants/lib/eldritch/src/process/netstat_impl.rs +++ b/implants/lib/eldritch/src/process/netstat_impl.rs @@ -1,5 +1,8 @@ use super::super::insert_dict_kv; use anyhow::Result; +#[cfg(target_os = "freebsd")] +use anyhow::anyhow; +#[cfg(not(target_os = "freebsd"))] use netstat2::*; use starlark::{ collections::SmallMap, @@ -7,6 +10,12 @@ use starlark::{ values::{dict::Dict, Heap, Value}, }; +#[cfg(target_os = "freebsd")] +pub fn netstat(_: &Heap) -> Result> { + Err(anyhow!("Not implemented for FreeBSD")) +} + +#[cfg(not(target_os = "freebsd"))] pub fn netstat(starlark_heap: &Heap) -> Result> { let mut out: Vec = Vec::new(); let af_flags = AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6; diff --git a/implants/lib/eldritch/src/sys/exec_impl.rs b/implants/lib/eldritch/src/sys/exec_impl.rs index 6578ac67a..1071bf3d7 100644 --- a/implants/lib/eldritch/src/sys/exec_impl.rs +++ b/implants/lib/eldritch/src/sys/exec_impl.rs @@ -1,7 +1,7 @@ use super::super::insert_dict_kv; use super::CommandOutput; use anyhow::{Context, Result}; -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))] use nix::{ sys::wait::waitpid, unistd::{fork, ForkResult}, @@ -11,7 +11,7 @@ use starlark::{ const_frozen_string, values::{dict::Dict, Heap}, }; -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))] use std::process::exit; use std::process::Command; // https://stackoverflow.com/questions/62978157/rust-how-to-spawn-child-process-that-continues-to-live-after-parent-receives-si#:~:text=You%20need%20to%20double%2Dfork,is%20not%20related%20to%20rust.&text=You%20must%20not%20forget%20to,will%20become%20a%20zombie%20process. @@ -54,7 +54,7 @@ fn handle_exec(path: String, args: Vec, disown: Option) -> Result< "Windows is not supported for disowned processes." )); - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))] match unsafe { fork()? } { ForkResult::Parent { child } => { // Wait for intermediate process to exit.