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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SetCallbackIntervalMessage {
}

impl SyncDispatcher for SetCallbackIntervalMessage {
fn dispatch(self, _transport: &mut impl Transport, cfg: Config) -> Result<Config> {
fn dispatch(self, transport: &mut impl Transport, cfg: Config) -> Result<Config> {
let mut c = cfg.clone();
let b = match cfg.info {
Some(i) => Ok(i),
Expand All @@ -28,6 +28,7 @@ impl SyncDispatcher for SetCallbackIntervalMessage {
host: b.host,
agent: b.agent,
interval: self.new_interval,
transport: transport.get_type() as i32,
});
Ok(c)
}
Expand Down
3 changes: 3 additions & 0 deletions implants/lib/pb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.0.5"
edition = "2021"

[features]
default = []
imix = []
grpc = []
http1 = []


[dependencies]
Expand Down
11 changes: 11 additions & 0 deletions implants/lib/pb/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use tonic::transport;
use uuid::Uuid;

use crate::c2::beacon::Transport;
/// Config holds values necessary to configure an Agent.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -102,6 +105,13 @@ impl Config {
let beacon_id =
std::env::var("IMIX_BEACON_ID").unwrap_or_else(|_| String::from(Uuid::new_v4()));

#[cfg(feature = "http1")]
let transport = crate::c2::beacon::Transport::Http1;
#[cfg(feature = "grpc")]
let transport = crate::c2::beacon::Transport::Grpc;
#[cfg(not(any(feature = "http1", feature = "grpc")))]
let transport = crate::c2::beacon::Transport::Unspecified;

let info = crate::c2::Beacon {
identifier: beacon_id,
principal: whoami::username(),
Expand All @@ -114,6 +124,7 @@ impl Config {
5_u64
}
},
transport: transport as i32,
host: Some(host),
agent: Some(agent),
};
Expand Down
44 changes: 44 additions & 0 deletions implants/lib/pb/src/generated/c2.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions implants/lib/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ edition = "2021"

[features]
default = []
grpc = []
grpc = ["pb/grpc"]
grpc-doh = ["grpc", "dep:hickory-resolver"]
http1 = []
http1 = ["pb/http1"]
mock = ["dep:mockall"]

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions implants/lib/transport/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ impl Transport for GRPC {
Ok(())
}

fn get_type(&mut self) -> pb::c2::beacon::Transport {
return pb::c2::beacon::Transport::Grpc;
}
fn is_active(&self) -> bool {
self.grpc.is_some()
}
Expand Down
4 changes: 4 additions & 0 deletions implants/lib/transport/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ impl Transport for HTTP {
))
}

fn get_type(&mut self) -> pb::c2::beacon::Transport {
return pb::c2::beacon::Transport::Http1;
}

fn is_active(&self) -> bool {
!self.base_url.is_empty()
}
Expand Down
12 changes: 12 additions & 0 deletions implants/lib/transport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ impl Transport for ActiveTransport {
}
}

fn get_type(&mut self) -> beacon::Transport {
match self {
#[cfg(feature = "grpc")]
Self::Grpc(t) => t.get_type(),
#[cfg(feature = "http1")]
Self::Http(t) => t.get_type(),
#[cfg(feature = "mock")]
Self::Mock(t) => t.get_type(),
Self::Empty => beacon::Transport::Unspecified,
}
}

fn is_active(&self) -> bool {
match self {
#[cfg(feature = "grpc")]
Expand Down
3 changes: 3 additions & 0 deletions implants/lib/transport/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ mock! {
tx: tokio::sync::mpsc::Sender<ReverseShellResponse>,
) -> Result<()>;

fn get_type(&mut self) -> pb::c2::beacon::Transport {
return Transport::Unspecified
}
fn is_active(&self) -> bool;

fn name(&self) -> &'static str;
Expand Down
4 changes: 3 additions & 1 deletion implants/lib/transport/src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use pb::c2::*;
use pb::c2::{beacon, *};
use std::sync::mpsc::{Receiver, Sender};

#[trait_variant::make(Transport: Send)]
Expand Down Expand Up @@ -79,6 +79,8 @@ pub trait UnsafeTransport: Clone + Send {
tx: tokio::sync::mpsc::Sender<ReverseShellResponse>,
) -> Result<()>;

#[allow(dead_code)]
fn get_type(&mut self) -> beacon::Transport;
/// Returns true if the transport is fully initialized and active
#[allow(dead_code)]
fn is_active(&self) -> bool;
Expand Down
1 change: 1 addition & 0 deletions tavern/internal/c2/api_claim_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (srv *Server) ClaimTasks(ctx context.Context, req *c2pb.ClaimTasksRequest)
SetLastSeenAt(now).
SetNextSeenAt(now.Add(time.Duration(req.Beacon.Interval) * time.Second)).
SetInterval(req.Beacon.Interval).
SetTransport(req.Beacon.Transport).
OnConflict().
UpdateNewValues().
ID(ctx)
Expand Down
Loading
Loading