Skip to content

Commit

Permalink
Fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Aug 11, 2024
1 parent 191846d commit 3d9b253
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Payload_Type/thanatos/agent/ffiwrappers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
2 changes: 1 addition & 1 deletion Payload_Type/thanatos/agent/profiles/http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
}
2 changes: 1 addition & 1 deletion Payload_Type/thanatos/agent/protos/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
.unwrap()
.join("protobuf");

let proto_srcs: Vec<PathBuf> = PROTO_SRCS.into_iter().map(|s| proto_path.join(s)).collect();
let proto_srcs: Vec<PathBuf> = PROTO_SRCS.iter().map(|s| proto_path.join(s)).collect();

proto_build
.compile_protos(&proto_srcs, &[proto_path])
Expand Down
2 changes: 1 addition & 1 deletion Payload_Type/thanatos/agent/thanatos/binary/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

println!(
"cargo:rerun-if-changed={}",
fallback_config.to_string_lossy().to_string()
fallback_config.to_string_lossy()
);
}
}
6 changes: 4 additions & 2 deletions Payload_Type/thanatos/agent/thanatos/core/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfiguredProfile>,
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Payload_Type/thanatos/agent/thanatos/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pub enum ThanatosError {
PastKilldate,
OutOfProfiles,
ConfigParse(ConfigParseError),
#[allow(dead_code)]
IoError(ErrorKind),
#[allow(dead_code)]
FfiError(ffiwrappers::errors::FfiError),
}

Expand Down
16 changes: 8 additions & 8 deletions Payload_Type/thanatos/agent/thanatos/core/src/guardrails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ where
F: Fn() -> Result<String, ThanatosError>,
{
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
Expand Down
25 changes: 15 additions & 10 deletions Payload_Type/thanatos/agent/thanatos/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![forbid(unsafe_code)]

use agent::Agent;
use prost::Message;
use thanatos_protos::config::{self, InitAction};

Expand All @@ -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 => {
Expand All @@ -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;
}
_ => (),
}
Expand All @@ -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!();
});
}
2 changes: 2 additions & 0 deletions Payload_Type/thanatos/agent/thanatos/core/src/os/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)] // TODO: Fix
use std::io::{BufRead, BufReader};

use crate::errors::ThanatosError;
Expand All @@ -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() {
Expand Down

0 comments on commit 3d9b253

Please sign in to comment.