Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions implants/imixv2/src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::{Context, Result};
use eldritch_agent::Agent;
use pb::c2::active_transport::Type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hulto is this available_transport now?

use pb::c2::host::Platform;
use pb::c2::{self, ClaimTasksRequest};
use pb::config::Config;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -347,14 +349,23 @@ impl<T: Transport + Send + Sync + 'static> Agent for ImixAgent<T> {
);
if let Some(host) = &info.host {
map.insert("hostname".to_string(), host.name.clone());
map.insert("platform".to_string(), host.platform.to_string());
map.insert(
"platform".to_string(),
Platform::try_from(host.platform)
.unwrap_or_default()
.as_str_name()
.into(),
);
map.insert("primary_ip".to_string(), host.primary_ip.clone());
}
if let Some(active_transport) = &info.active_transport {
map.insert("uri".to_string(), active_transport.uri.clone());
map.insert(
"type".to_string(),
active_transport.r#type.clone().to_string(),
Type::try_from(active_transport.r#type)
.unwrap_or_default()
.as_str_name()
.into(),
);
map.insert(
"extra".to_string(),
Expand Down
65 changes: 64 additions & 1 deletion implants/imixv2/src/tests/agent_trait_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::super::agent::ImixAgent;
use super::super::task::TaskRegistry;
use eldritch_libagent::agent::Agent;
use pb::c2;
use pb::c2::active_transport::Type;
use pb::c2::host::Platform;
use pb::c2::{self, Host};
use pb::config::Config;
use std::sync::Arc;
use transport::MockTransport;
Expand Down Expand Up @@ -228,3 +230,64 @@ async fn test_imix_agent_config_access() {
assert_eq!(map.get("callback_uri").unwrap(), "http://localhost:8080");
assert_eq!(map.get("beacon_id").unwrap(), "agent1");
}

#[tokio::test]
#[allow(clippy::field_reassign_with_default)]
async fn test_agent_config_platform_as_enum_variant_name() {
let mut config = Config::default();

config.info = Some(pb::c2::Beacon {
active_transport: Some(pb::c2::ActiveTransport::default()),
host: Some(Host {
platform: Platform::Linux as i32,
..Default::default()
}),
..Default::default()
});

let mut transport = MockTransport::default();
transport.expect_is_active().returning(|| true);

let handle = tokio::runtime::Handle::current();
let registry = Arc::new(TaskRegistry::new());
let agent = ImixAgent::new(config, transport, handle, registry);

let agent_clone = agent.clone();
let result = std::thread::spawn(move || agent_clone.get_config())
.join()
.unwrap();

assert!(result.is_ok());
let map = result.unwrap();
assert_eq!(map.get("platform").unwrap(), "PLATFORM_LINUX");
}

#[tokio::test]
#[allow(clippy::field_reassign_with_default)]
async fn test_agent_config_active_transport_type_as_enum_variant_name() {
let mut config = Config::default();

config.info = Some(pb::c2::Beacon {
active_transport: Some(pb::c2::ActiveTransport {
r#type: Type::TransportGrpc as i32,
..Default::default()
}),
..Default::default()
});

let mut transport = MockTransport::default();
transport.expect_is_active().returning(|| true);

let handle = tokio::runtime::Handle::current();
let registry = Arc::new(TaskRegistry::new());
let agent = ImixAgent::new(config, transport, handle, registry);

let agent_clone = agent.clone();
let result = std::thread::spawn(move || agent_clone.get_config())
.join()
.unwrap();

assert!(result.is_ok());
let map = result.unwrap();
assert_eq!(map.get("type").unwrap(), "TRANSPORT_GRPC");
}
Loading