Skip to content

Commit

Permalink
Fix env unwrap (#794)
Browse files Browse the repository at this point in the history
* Fix env unwrap

* gen update

* Fix docs.

* Finish engine to selector
  • Loading branch information
hulto authored Jul 10, 2024
1 parent 16134b9 commit 79bdf00
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
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.

0 comments on commit 79bdf00

Please sign in to comment.