Skip to content

Commit

Permalink
Merge branch 'main' into tonic-url
Browse files Browse the repository at this point in the history
  • Loading branch information
Cictrone authored Jan 22, 2024
2 parents 99aff43 + 9600009 commit a9d85ae
Show file tree
Hide file tree
Showing 87 changed files with 2,557 additions and 548 deletions.
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ url: "https://docs.realm.pub" # the base hostname & protocol for your site

# Social (First three Required)
repo: "https://github.com/spellshift/realm"
github_user: "kcarretto"
github_user: "spellshift"
github_repo: "realm"
github_branch: "main"

Expand Down
2 changes: 2 additions & 0 deletions implants/imix/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ print(sys.shell(input_params["cmd"])["stdout"])
.to_string(),
parameters: HashMap::from([("cmd".to_string(), "echo hello_from_stdout".to_string())]),
file_names: Vec::new(),
quest_name: "test_quest".to_string(),
};

let runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down Expand Up @@ -134,6 +135,7 @@ aoeu
.to_string(),
parameters: HashMap::new(),
file_names: Vec::new(),
quest_name: "test_quest".to_string(),
};

let runtime: tokio::runtime::Runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down
32 changes: 16 additions & 16 deletions implants/imix/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ fn get_primary_ip() -> Result<String> {
"DANGER-UNKNOWN".to_string()
}
}
Err(e) => {
Err(_err) => {
#[cfg(debug_assertions)]
eprintln!("Error getting primary ip address:\n{e}");
eprintln!("Error getting primary ip address:\n{_err}");
"DANGER-UNKNOWN".to_string()
}
};
Expand All @@ -95,7 +95,7 @@ fn get_host_platform() -> Result<Platform> {
}
}

fn get_os_pretty_name() -> Result<String> {
fn _get_os_pretty_name() -> Result<String> {
if cfg!(target_os = "linux") {
let linux_rel = linux_os_release()?;
let pretty_name = match linux_rel.pretty_name {
Expand All @@ -119,27 +119,27 @@ pub fn agent_init(config_path: String, host_id_path: String) -> Result<(AgentPro

let principal = match get_principal() {
Ok(username) => username,
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get process username\n{}", error);
eprintln!("Unable to get process username\n{}", _error);
"UNKNOWN".to_string()
}
};

let hostname = match get_hostname() {
Ok(tmp_hostname) => tmp_hostname,
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get system hostname\n{}", error);
eprintln!("Unable to get system hostname\n{}", _error);
"UNKNOWN".to_string()
}
};

let beacon_id = match get_beacon_id() {
Ok(tmp_beacon_id) => tmp_beacon_id,
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get a random beacon id\n{}", error);
eprintln!("Unable to get a random beacon id\n{}", _error);
"DANGER-UNKNOWN".to_string()
}
};
Expand All @@ -152,18 +152,18 @@ pub fn agent_init(config_path: String, host_id_path: String) -> Result<(AgentPro

let host_platform = match get_host_platform() {
Ok(tmp_host_platform) => tmp_host_platform,
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get host platform id\n{}", error);
eprintln!("Unable to get host platform id\n{}", _error);
Platform::Unspecified
}
};

let primary_ip = match get_primary_ip() {
Ok(tmp_primary_ip) => Some(tmp_primary_ip),
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get primary ip\n{}", error);
eprintln!("Unable to get primary ip\n{}", _error);
None
}
};
Expand All @@ -177,9 +177,9 @@ pub fn agent_init(config_path: String, host_id_path: String) -> Result<(AgentPro

let host_id = match get_host_id(host_id_path) {
Ok(tmp_host_id) => tmp_host_id,
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("Unable to get or create a host id\n{}", error);
eprintln!("Unable to get or create a host id\n{}", _error);
"DANGER-UNKNOWN".to_string()
}
};
Expand Down Expand Up @@ -262,7 +262,7 @@ mod tests {

#[test]
fn imix_test_get_os_pretty_name() {
assert!(get_os_pretty_name().is_ok());
assert!(_get_os_pretty_name().is_ok());
}

#[test]
Expand Down
6 changes: 1 addition & 5 deletions implants/imix/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use anyhow::Result;
use clap::{Arg, Command};
use std::collections::HashMap;
use std::fs;
use std::process;
use std::thread;

use eldritch::{eldritch_run, StdPrintHandler};
Expand Down Expand Up @@ -96,7 +92,7 @@ pub fn install_main(custom_config: Option<&str>) -> anyhow::Result<()> {
.build()
.unwrap();

let (error_code, result) = match runtime.block_on(execute_tomes_in_parallel(
let (_error_code, result) = match runtime.block_on(execute_tomes_in_parallel(
tome_files_and_content,
custom_config,
)) {
Expand Down
50 changes: 25 additions & 25 deletions implants/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn do_delay(interval: u64, loop_start_time: Instant) {
}

// Async handler for port scanning.
async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<()> {
async fn main_loop(config_path: String, _loop_count_max: Option<i32>) -> Result<()> {
#[cfg(debug_assertions)]
let mut debug_loop_count: i32 = 0;

Expand All @@ -51,7 +51,7 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(

loop {
// 0. Get loop start time
let loop_start_time = Instant::now();
let _loop_start_time = Instant::now();

#[cfg(debug_assertions)]
eprintln!("Get new tasks");
Expand All @@ -63,10 +63,10 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
// 1b) Setup the tavern client
let tavern_client = match TavernClient::connect(cur_callback_uri.clone()).await {
Ok(t) => t,
Err(err) => {
Err(_err) => {
#[cfg(debug_assertions)]
eprintln!("failed to create tavern client {}", err);
do_delay(imix_config.callback_config.interval, loop_start_time);
eprintln!("failed to create tavern client {}", _err);
do_delay(imix_config.callback_config.interval, _loop_start_time);
continue;
}
};
Expand All @@ -75,7 +75,7 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
#[cfg(debug_assertions)]
eprintln!(
"[{}]: collecting tasks",
(Instant::now() - loop_start_time).as_millis()
(Instant::now() - _loop_start_time).as_millis()
);

let new_tasks = match tasks::get_new_tasks(
Expand All @@ -86,14 +86,14 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
.await
{
Ok(local_new_tasks) => local_new_tasks,
Err(local_err) => {
Err(_local_err) => {
#[cfg(debug_assertions)]
eprintln!(
"[{}]: Error getting new tasks {}",
(Instant::now() - loop_start_time).as_millis(),
local_err
(Instant::now() - _loop_start_time).as_millis(),
_local_err
);
do_delay(imix_config.callback_config.interval, loop_start_time);
do_delay(imix_config.callback_config.interval, _loop_start_time);
continue;
}
};
Expand All @@ -102,18 +102,18 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
#[cfg(debug_assertions)]
eprintln!(
"[{}]: Starting {} new tasks",
(Instant::now() - loop_start_time).as_millis(),
(Instant::now() - _loop_start_time).as_millis(),
new_tasks.len()
);

match start_new_tasks(new_tasks, &mut all_exec_futures, loop_start_time).await {
Ok(is_ok) => {}
Err(local_err) => {
match start_new_tasks(new_tasks, &mut all_exec_futures, _loop_start_time).await {
Ok(_is_ok) => {}
Err(_local_err) => {
#[cfg(debug_assertions)]
eprintln!(
"[{}]: Failed to start new tasks: {}",
(Instant::now() - loop_start_time).as_millis(),
local_err
(Instant::now() - _loop_start_time).as_millis(),
_local_err
);
}
};
Expand All @@ -123,13 +123,13 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
.clone()
.callback_config
.interval
.checked_sub(loop_start_time.elapsed().as_secs())
.checked_sub(_loop_start_time.elapsed().as_secs())
.unwrap_or_else(|| 0);

#[cfg(debug_assertions)]
eprintln!(
"[{}]: Sleeping seconds {}",
(Instant::now() - loop_start_time).as_millis(),
(Instant::now() - _loop_start_time).as_millis(),
time_to_sleep
);

Expand All @@ -139,33 +139,33 @@ async fn main_loop(config_path: String, loop_count_max: Option<i32>) -> Result<(
#[cfg(debug_assertions)]
eprintln!(
"[{}]: Checking task status",
(Instant::now() - loop_start_time).as_millis()
(Instant::now() - _loop_start_time).as_millis()
);

// Update running tasks and results
match submit_task_output(
loop_start_time,
_loop_start_time,
tavern_client,
&mut all_exec_futures,
&mut all_task_res_map,
)
.await
{
Ok(_is_ok) => {}
Err(local_err) => {
Err(_local_err) => {
#[cfg(debug_assertions)]
eprintln!(
"[{}]: Error submitting task results {}",
(Instant::now() - loop_start_time).as_millis(),
local_err
(Instant::now() - _loop_start_time).as_millis(),
_local_err
);
do_delay(imix_config.callback_config.interval, loop_start_time);
do_delay(imix_config.callback_config.interval, _loop_start_time);
}
};

// Debug loop tracker
#[cfg(debug_assertions)]
if let Some(count_max) = loop_count_max {
if let Some(count_max) = _loop_count_max {
debug_loop_count += 1;
if debug_loop_count >= count_max {
return Ok(());
Expand Down
9 changes: 5 additions & 4 deletions implants/imix/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub async fn get_new_tasks(
});
let new_tasks = match tavern_client.claim_tasks(req).await {
Ok(resp) => resp.get_ref().tasks.clone(),
Err(error) => {
Err(_error) => {
#[cfg(debug_assertions)]
eprintln!("main_loop: error claiming task\n{:?}", error);
eprintln!("main_loop: error claiming task\n{:?}", _error);
let empty_vec = vec![];
empty_vec
}
Expand Down Expand Up @@ -201,9 +201,9 @@ pub async fn submit_task_output(
// Remove output that has been reported sucessfully.
running_task_res_map.remove(&task_id);
}
Err(local_err) => {
Err(_err) => {
#[cfg(debug_assertions)]
eprintln!("Failed to submit task resluts:\n{}", local_err.to_string());
eprintln!("Failed to submit task resluts:\n{}", _err.to_string());
{}
}
};
Expand Down Expand Up @@ -252,6 +252,7 @@ mod tests {
eldritch: "print('okay')".to_string(),
parameters: HashMap::from([("iter".to_string(), "3".to_string())]),
file_names: Vec::new(),
quest_name: "test_quest".to_string(),
}];
start_new_tasks(new_tasks, &mut all_exec_futures, debug_start_time).await?;
assert_eq!(all_exec_futures.len(), 1);
Expand Down
2 changes: 2 additions & 0 deletions implants/lib/c2/src/c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub struct Task {
>,
#[prost(string, repeated, tag = "4")]
pub file_names: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, tag = "5")]
pub quest_name: ::prost::alloc::string::String,
}
/// TaskError provides information when task execution fails.
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
Loading

0 comments on commit a9d85ae

Please sign in to comment.