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
20 changes: 15 additions & 5 deletions implants/lib/host_unique/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ pub struct File {
}

impl File {
/*
* Allow creation of a new file with a custom path
*/
pub fn new_with_file(path: &str) -> Self {
Self {
path_override: Some(path.to_string()),
}
}
/*
* Returns a predefined path to the host id file based on the current platform.
*/
Expand All @@ -27,14 +35,16 @@ impl File {
#[cfg(target_os = "windows")]
return String::from("C:\\ProgramData\\system-id");

#[cfg(target_os = "linux")]
return String::from("/etc/system-id");
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
))]
return String::from("/var/tmp/system-id");

#[cfg(target_os = "macos")]
return String::from("/Users/Shared/system-id");

#[cfg(target_os = "freebsd")]
return String::from("/etc/systemd-id");
}
}

Expand Down
13 changes: 12 additions & 1 deletion implants/lib/host_unique/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ pub fn get_id_with_selectors(selectors: Vec<Box<dyn HostIDSelector>>) -> Uuid {
// List is evaluated in order and will take the first successful
// result.
pub fn defaults() -> Vec<Box<dyn HostIDSelector>> {
vec![Box::<Env>::default(), Box::<File>::default()]
vec![
Box::<Env>::default(),
Box::<File>::default(),
// Fallback for unix systems / legacy implementation
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
))]
Box::new(File::new_with_file("/etc/system-id")),
]
}
Loading