From 3d9b25343884110904212ad86473ecfe3d49cd46 Mon Sep 17 00:00:00 2001 From: Matt Ehrnschwender Date: Sun, 11 Aug 2024 16:08:57 -0400 Subject: [PATCH] Fix lint warnings --- .../thanatos/agent/ffiwrappers/src/lib.rs | 3 +++ .../thanatos/agent/profiles/http/src/lib.rs | 2 +- Payload_Type/thanatos/agent/protos/build.rs | 2 +- .../thanatos/agent/thanatos/binary/build.rs | 2 +- .../agent/thanatos/core/src/agent/mod.rs | 6 +++-- .../agent/thanatos/core/src/errors.rs | 2 ++ .../agent/thanatos/core/src/guardrails.rs | 16 ++++++------ .../thanatos/agent/thanatos/core/src/lib.rs | 25 +++++++++++-------- .../agent/thanatos/core/src/os/linux/mod.rs | 2 ++ 9 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Payload_Type/thanatos/agent/ffiwrappers/src/lib.rs b/Payload_Type/thanatos/agent/ffiwrappers/src/lib.rs index b12321e..f1dadd8 100644 --- a/Payload_Type/thanatos/agent/ffiwrappers/src/lib.rs +++ b/Payload_Type/thanatos/agent/ffiwrappers/src/lib.rs @@ -9,5 +9,8 @@ pub mod linux; pub mod windows; mod internal { + // This is used but clippy complains + // TODO: Need to rewrite all of this + #[allow(dead_code)] pub trait SealedTrait {} } diff --git a/Payload_Type/thanatos/agent/profiles/http/src/lib.rs b/Payload_Type/thanatos/agent/profiles/http/src/lib.rs index b4ba3fc..7c1da20 100644 --- a/Payload_Type/thanatos/agent/profiles/http/src/lib.rs +++ b/Payload_Type/thanatos/agent/profiles/http/src/lib.rs @@ -3,7 +3,7 @@ use thanatos_protos::config; pub struct HttpC2Profile {} impl HttpC2Profile { - pub fn new(agent_config: &config::Config) -> HttpC2Profile { + pub fn new(_agent_config: &config::Config) -> HttpC2Profile { HttpC2Profile {} } } diff --git a/Payload_Type/thanatos/agent/protos/build.rs b/Payload_Type/thanatos/agent/protos/build.rs index 623b3de..9b6690f 100644 --- a/Payload_Type/thanatos/agent/protos/build.rs +++ b/Payload_Type/thanatos/agent/protos/build.rs @@ -14,7 +14,7 @@ fn main() { .unwrap() .join("protobuf"); - let proto_srcs: Vec = PROTO_SRCS.into_iter().map(|s| proto_path.join(s)).collect(); + let proto_srcs: Vec = PROTO_SRCS.iter().map(|s| proto_path.join(s)).collect(); proto_build .compile_protos(&proto_srcs, &[proto_path]) diff --git a/Payload_Type/thanatos/agent/thanatos/binary/build.rs b/Payload_Type/thanatos/agent/thanatos/binary/build.rs index a5e21ae..145b71c 100644 --- a/Payload_Type/thanatos/agent/thanatos/binary/build.rs +++ b/Payload_Type/thanatos/agent/thanatos/binary/build.rs @@ -18,7 +18,7 @@ fn main() { println!( "cargo:rerun-if-changed={}", - fallback_config.to_string_lossy().to_string() + fallback_config.to_string_lossy() ); } } diff --git a/Payload_Type/thanatos/agent/thanatos/core/src/agent/mod.rs b/Payload_Type/thanatos/agent/thanatos/core/src/agent/mod.rs index 4f3fbf0..8bf4038 100644 --- a/Payload_Type/thanatos/agent/thanatos/core/src/agent/mod.rs +++ b/Payload_Type/thanatos/agent/thanatos/core/src/agent/mod.rs @@ -11,10 +11,12 @@ enum C2Profile { } struct ConfiguredProfile { + #[allow(dead_code)] profile: C2Profile, killdate: u64, } +#[allow(dead_code)] pub struct Agent { uuid: [u8; 16], profiles: Vec, @@ -26,12 +28,12 @@ impl Agent { if let Some(ref http) = agent_config.http { profiles.push(ConfiguredProfile { - profile: C2Profile::Http(HttpC2Profile::new(&agent_config)), + profile: C2Profile::Http(HttpC2Profile::new(agent_config)), killdate: http.killdate, }) } - if let Some(ref profile) = profiles.iter().max_by_key(|v| v.killdate) { + if let Some(profile) = profiles.iter().max_by_key(|v| v.killdate) { let e = system::time::epoch_timestamp(); if profile.killdate <= e { return Err(ThanatosError::PastKilldate); diff --git a/Payload_Type/thanatos/agent/thanatos/core/src/errors.rs b/Payload_Type/thanatos/agent/thanatos/core/src/errors.rs index 126c316..770b7e1 100644 --- a/Payload_Type/thanatos/agent/thanatos/core/src/errors.rs +++ b/Payload_Type/thanatos/agent/thanatos/core/src/errors.rs @@ -5,7 +5,9 @@ pub enum ThanatosError { PastKilldate, OutOfProfiles, ConfigParse(ConfigParseError), + #[allow(dead_code)] IoError(ErrorKind), + #[allow(dead_code)] FfiError(ffiwrappers::errors::FfiError), } diff --git a/Payload_Type/thanatos/agent/thanatos/core/src/guardrails.rs b/Payload_Type/thanatos/agent/thanatos/core/src/guardrails.rs index 61c8fcf..3bde301 100644 --- a/Payload_Type/thanatos/agent/thanatos/core/src/guardrails.rs +++ b/Payload_Type/thanatos/agent/thanatos/core/src/guardrails.rs @@ -32,16 +32,16 @@ where F: Fn() -> Result, { if !list.is_empty() { - let check_val = match f().map(|v| { - let mut h = Sha256::new(); - h.update(v.to_lowercase().as_bytes()); - h.finalize() - }) { - Ok(v) => v, - Err(_) => return false, + let check_info = if let Ok(info) = f() { + info + } else { + return false; }; - return list.chunks_exact(32).any(|v| v == &check_val); + let mut h = Sha256::new(); + h.update(check_info.to_lowercase().as_bytes()); + let check_val = h.finalize(); + return list.chunks_exact(32).any(|v| v == check_val); } true diff --git a/Payload_Type/thanatos/agent/thanatos/core/src/lib.rs b/Payload_Type/thanatos/agent/thanatos/core/src/lib.rs index 9372b9e..fb21268 100644 --- a/Payload_Type/thanatos/agent/thanatos/core/src/lib.rs +++ b/Payload_Type/thanatos/agent/thanatos/core/src/lib.rs @@ -1,6 +1,5 @@ #![forbid(unsafe_code)] -use agent::Agent; use prost::Message; use thanatos_protos::config::{self, InitAction}; @@ -24,6 +23,17 @@ pub fn entrypoint(config: &[u8]) { return; } + let t = system::time::epoch_timestamp(); + let http_active = agent_config + .http + .as_ref() + .and_then(|profile| (profile.killdate <= t).then_some(())); + + if http_active.is_none() { + log!("All profiles are past their killdates"); + return; + } + match agent_config.initaction() { InitAction::None => run_agent(agent_config), InitAction::Thread => { @@ -37,7 +47,6 @@ pub fn entrypoint(config: &[u8]) { Ok(fork::ForkProcess::Child) => run_agent(agent_config), Err(e) => { log!("Failed to fork process: {:?}", e); - return; } _ => (), } @@ -49,12 +58,8 @@ pub fn entrypoint(config: &[u8]) { }; } -fn run_agent(agent_config: config::Config) { - let agent = match Agent::initialize(&agent_config) { - Ok(a) => a, - Err(e) => { - log!("Failed to initialize agent: {:?}", e); - return; - } - }; +fn run_agent(_agent_config: config::Config) { + std::thread::scope(|_scope| { + todo!(); + }); } diff --git a/Payload_Type/thanatos/agent/thanatos/core/src/os/linux/mod.rs b/Payload_Type/thanatos/agent/thanatos/core/src/os/linux/mod.rs index 18138b7..40fdb5e 100644 --- a/Payload_Type/thanatos/agent/thanatos/core/src/os/linux/mod.rs +++ b/Payload_Type/thanatos/agent/thanatos/core/src/os/linux/mod.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] // TODO: Fix use std::io::{BufRead, BufReader}; use crate::errors::ThanatosError; @@ -16,6 +17,7 @@ mod integrity; mod selinux; +#[allow(dead_code)] pub fn container_environment() -> ContainerEnv { if let Ok(readdir) = std::fs::read_dir("/") { for entry in readdir.flatten() {