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

Fix env unwrap #794

Merged
merged 4 commits into from
Jul 10, 2024
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
6 changes: 3 additions & 3 deletions docs/_data/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
url: "dev-guide/imix"
children:
- title: "Overview"
url: "dev-guide/eldritch#overview"
- title: "Developing a host uniqueness engine"
url: "dev-guide/eldritch#develop-a-host-uniqueness-engine"
url: "dev-guide/imix#overview"
- title: "Develop a host uniqueness selector"
url: "dev-guide/imix#develop-a-host-uniqueness-selector"

- title: "About"
url: "" # Index
4 changes: 2 additions & 2 deletions docs/_docs/dev-guide/imix.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Out of the box realm comes with two options `File` and `Env` to determine what h

If no selectors succeed a random UUID4 ID will be generated and used for the bot. This should be avoided.

## Develop A Host Uniqueness Engine
## Develop A Host Uniqueness Selector

To create your own:

- Navigate to `implants/lib/host_unique`
- Create a file for your selector `touch mac_address.rs`
- Create an implementation of the `HostUniqueEngine`
- Create an implementation of the `HostIDSelector`

```rust
use uuid::Uuid;
Expand Down
4 changes: 2 additions & 2 deletions docs/_docs/user-guide/imix.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ We recommend that you use the `File` for the most reliability:
- Garunteed to be unique per host (because the bot creates it)
- Can be used by multiple instances of the beacon on the same host.

If you cannot use the `File` engine we highly recommend manually setting the `Env` engine with the environment variable `IMIX_HOST_ID`. This will override the `File` one avoiding writes to disk but must be managed by the operators.
If you cannot use the `File` selector we highly recommend manually setting the `Env` selector with the environment variable `IMIX_HOST_ID`. This will override the `File` one avoiding writes to disk but must be managed by the operators.

If all uniqueness engines fail imix will randomly generate a UUID to avoid crashing.
If all uniqueness selectors fail imix will randomly generate a UUID to avoid crashing.
This isn't ideal as in the UI each new beacon will appear as thought it were on a new host.

## Static cross compilation
Expand Down
13 changes: 10 additions & 3 deletions implants/lib/host_unique/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ impl HostIDSelector for Env {
}

fn get_host_id(&self) -> Option<uuid::Uuid> {
let host_id_env = env::var("IMIX_HOST_ID").unwrap();
let host_id_env = match env::var("IMIX_HOST_ID") {
Ok(res) => res,
Err(_err) => {
#[cfg(debug_assertions)]
log::debug!("No environment variable set {:?}", _err);
return None;
}
};
match Uuid::parse_str(&host_id_env) {
Ok(res) => Some(res),
Err(_err) => {
Expand All @@ -38,8 +45,8 @@ mod tests {
#[test]
fn test_id_env() {
std::env::set_var("IMIX_HOST_ID", "f17b92c0-e383-4328-9017-952e5d9fd53d");
let engine = Env {};
let id = engine.get_host_id().unwrap();
let selector = Env {};
let id = selector.get_host_id().unwrap();

assert_eq!(id, uuid!("f17b92c0-e383-4328-9017-952e5d9fd53d"));
}
Expand Down
6 changes: 3 additions & 3 deletions implants/lib/host_unique/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ mod tests {
let tmp_file = NamedTempFile::new().unwrap();
let path = String::from(tmp_file.path().to_str().unwrap());

let engine = File {
let selector = File {
path_override: Some(path),
};
let id_one = engine.get_host_id();
let id_two = engine.get_host_id();
let id_one = selector.get_host_id();
let id_two = selector.get_host_id();

assert_eq!(id_one, id_two);
}
Expand Down
1 change: 0 additions & 1 deletion implants/lib/pb/src/generated/c2.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion implants/lib/pb/src/generated/eldritch.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading