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
16 changes: 13 additions & 3 deletions implants/imix/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Context, Result};
use c2::pb::host::Platform;
use std::{
fs::{self, File},
Expand Down Expand Up @@ -59,7 +59,12 @@ fn get_primary_ip() -> Result<String> {
let res = match default_net::get_default_interface() {
Ok(default_interface) => {
if default_interface.ipv4.len() > 0 {
default_interface.ipv4[0].addr.to_string()
default_interface
.ipv4
.get(0)
.context("No ips found")?
.addr
.to_string()
} else {
"DANGER-UNKNOWN".to_string()
}
Expand Down Expand Up @@ -234,7 +239,12 @@ mod tests {
assert_ne!(properties.beacon_id, properties2.beacon_id);
assert!(properties2.agent_id.contains("imix-"));
assert_eq!(
config2.callback_config.c2_configs[0].uri,
config2
.callback_config
.c2_configs
.get(0)
.context("No callbacks configured")?
.uri,
"http://127.0.0.1/grpc"
);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion implants/lib/eldritch/src/assets/copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn copy(src: String, dst: String) -> Result<()> {

match fs::write(dst, src_file) {
Ok(_) => Ok(()),
Err(local_err) => Err(local_err.into()),
Err(local_err) => Err(local_err.try_into()?),
}
}

Expand Down
6 changes: 3 additions & 3 deletions implants/lib/eldritch/src/pivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ mod ssh_password_spray_impl;
use std::sync::Arc;

use allocative::Allocative;
use anyhow::Result;
use async_trait::async_trait;
use derive_more::Display;

use russh::{client, Disconnect};
use russh_keys::{decode_secret_key, key};
use russh_sftp::client::SftpSession;
Expand Down Expand Up @@ -222,7 +222,7 @@ struct CommandResult {
}

impl CommandResult {
fn output(&self) -> String {
String::from_utf8_lossy(&self.output).into()
fn output(&self) -> Result<String> {
Ok(String::from_utf8_lossy(&self.output).try_into()?)
}
}
7 changes: 6 additions & 1 deletion implants/lib/eldritch/src/pivot/ncat_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn ncat(address: String, port: i32, data: String, protocol: String) -> Resul
#[cfg(test)]
mod tests {
use super::*;
use anyhow::Context;
use tokio::io::copy;
use tokio::net::TcpListener;
use tokio::net::UdpSocket;
Expand Down Expand Up @@ -146,7 +147,11 @@ mod tests {

#[tokio::test]
async fn test_ncat_send_tcp() -> anyhow::Result<()> {
let test_port = allocate_localhost_unused_ports(1, "tcp".to_string()).await?[0];
let test_port = allocate_localhost_unused_ports(1, "tcp".to_string())
.await?
.get(0)
.context("Unable to allocate port")?
.clone();
// Setup a test echo server
let expected_response = String::from("Hello world!");
let listen_task = task::spawn(setup_test_listener(
Expand Down
12 changes: 8 additions & 4 deletions implants/lib/eldritch/src/pivot/port_scan_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ fn get_network_and_broadcast(target_cidr: String) -> Result<(Vec<u32>, Vec<u32>)

// Split on / to get host and cidr bits.
let tmpvec: Vec<&str> = target_cidr.split("/").collect();
let host = tmpvec[0].to_string();
let bits: u32 = tmpvec[1].parse::<u8>()?.into();
let host = tmpvec.get(0).context("Index 0 not found")?.to_string();
let bits: u32 = tmpvec
.get(1)
.context("Index 1 not found")?
.parse::<u8>()?
.try_into()?;

// Define our vector representations.
let mut addr: Vec<u64> = vec![0, 0, 0, 0];
let mut mask: Vec<u64> = vec![0, 0, 0, 0];
let mut bcas: Vec<u32> = vec![0, 0, 0, 0];
let mut netw: Vec<u32> = vec![0, 0, 0, 0];

let cidr: u64 = bits.into();
let cidr: u64 = bits.try_into()?;

let (octet_one, octet_two, octet_three, octet_four) = scanf!(host, ".", u64, u64, u64, u64);
addr[3] = octet_four.context(format!("Failed to extract fourth octet {}", host))?;
Expand Down Expand Up @@ -552,7 +556,7 @@ mod tests {
// Iterate over append port number and start listen server
let mut listen_tasks = vec![];
for listener in bound_listeners_vec.into_iter() {
test_ports.push(listener.local_addr()?.port().into());
test_ports.push(listener.local_addr()?.port().try_into()?);
listen_tasks.push(task::spawn(local_accept_tcp(listener)));
}

Expand Down
2 changes: 1 addition & 1 deletion implants/lib/eldritch/src/pivot/ssh_copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn handle_ssh_copy(
timeout: Option<u32>,
) -> Result<()> {
let mut ssh = tokio::time::timeout(
std::time::Duration::from_secs(timeout.unwrap_or(3).into()),
std::time::Duration::from_secs(timeout.unwrap_or(3).try_into()?),
Session::connect(
username,
password,
Expand Down
4 changes: 2 additions & 2 deletions implants/lib/eldritch/src/pivot/ssh_exec_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn handle_ssh_exec(
timeout: Option<u32>,
) -> Result<SSHExecOutput> {
let mut ssh = tokio::time::timeout(
std::time::Duration::from_secs(timeout.unwrap_or(3).into()),
std::time::Duration::from_secs(timeout.unwrap_or(3).try_into()?),
Session::connect(
username,
password,
Expand All @@ -38,7 +38,7 @@ async fn handle_ssh_exec(
ssh.close().await?;

Ok(SSHExecOutput {
stdout: r.output(),
stdout: r.output()?,
status: r.code.unwrap_or(0) as i32,
})
}
Expand Down