-
Notifications
You must be signed in to change notification settings - Fork 54
Make host uniqueness modular #785
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| title: Imix | ||
| tags: | ||
| - Dev Guide | ||
| description: Want to implement new functionality in the agent? Start here! | ||
| permalink: dev-guide/imix | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| Imix in the main bot for Realm. | ||
|
|
||
| ## Host Selector | ||
|
|
||
| The host selector defined in `implants/lib/host_selector` allow imix to reliably identify which host it's running on. This is helpful for operators when creating tasking across multiple beacons as well as when searching for command results. Uniqueness is stored as a UUID4 value. | ||
|
|
||
| Out of the box realm comes with two options `File` and `Env` to determine what host it's on. | ||
|
|
||
| `File` will create a file on disk that stores the UUID4 Eg. Linux: | ||
|
|
||
| ```bash | ||
| [~]$ cat /etc/system-id | ||
| 36b3c472-d19b-46cc-b3e6-ee6fd8da5b9c | ||
| ``` | ||
|
|
||
| `Env` will read from the agent environment variables looking for `IMIX_HOST_ID` if it's set it will use the UUID4 string set there. | ||
|
|
||
| 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 | ||
|
|
||
| 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` | ||
|
|
||
| ```rust | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::HostIDSelector; | ||
|
|
||
| pub struct MacAddress {} | ||
|
|
||
| impl Default for MacAddress { | ||
| fn default() -> Self { | ||
| MacAddress {} | ||
| } | ||
| } | ||
|
|
||
| impl HostIDSelector for MacAddress { | ||
| fn get_name(&self) -> String { | ||
| "mac_address".to_string() | ||
| } | ||
|
|
||
| fn get_host_id(&self) -> Option<uuid::Uuid> { | ||
| // Get the mac address | ||
| // Generate a UUID using it | ||
| // Return the UUID | ||
| // Return None if anything fails | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use uuid::uuid; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_id_mac_consistent() { | ||
| let selector = MacAddress {}; | ||
| let id_one = selector.get_host_id(); | ||
| let id_two = selector.get_host_id(); | ||
|
|
||
| assert_eq!(id_one, id_two); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - Update `lib.rs` to re-export your implementation | ||
|
|
||
| ```rust | ||
| mod mac_address; | ||
| pub use mac_address::MacAddress; | ||
| ``` | ||
|
|
||
| - Update the `defaults()` function to include your implementation. N.B. The order from left to right is the order engines will be evaluated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [package] | ||
| name = "host_unique" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] | ||
| uuid = { workspace = true, features = ["v4", "fast-rng"] } | ||
| log = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| pretty_env_logger = "0.5.0" | ||
| tempfile = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| use std::env; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::HostIDSelector; | ||
|
|
||
| pub struct Env {} | ||
|
|
||
| impl Default for Env { | ||
| fn default() -> Self { | ||
| Env {} | ||
| } | ||
| } | ||
|
|
||
| impl HostIDSelector for Env { | ||
| fn get_name(&self) -> String { | ||
| "env".to_string() | ||
| } | ||
|
|
||
| fn get_host_id(&self) -> Option<uuid::Uuid> { | ||
| let host_id_env = env::var("IMIX_HOST_ID").unwrap(); | ||
| match Uuid::parse_str(&host_id_env) { | ||
| Ok(res) => Some(res), | ||
| Err(_err) => { | ||
| #[cfg(debug_assertions)] | ||
| log::debug!("Failed to deploy {:?}", _err); | ||
| None | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use uuid::uuid; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[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(); | ||
|
|
||
| assert_eq!(id, uuid!("f17b92c0-e383-4328-9017-952e5d9fd53d")); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.