Skip to content

Commit

Permalink
Get Agent IP every callback (#711)
Browse files Browse the repository at this point in the history
* added ip to each callback

* move ip refresh to own function

* cleaning

* comment

* oops
  • Loading branch information
Cictrone authored Mar 14, 2024
1 parent b2aa17e commit 91052d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"rust-analyzer"
],
"rust-analyzer.check.command": "clippy",
"rust-analyzer.showUnlinkedFileNotification": false,
}
5 changes: 5 additions & 0 deletions implants/imix/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ impl Agent {
loop {
let start = Instant::now();

// Sometimes Imix starts too quickly in a boot sequence, a NIC is down during the initial callback,
// or the box Imix is on changes its IP. In any case, for each callback we should refresh our claimed
// IP.
self.cfg.refresh_primary_ip();

match self.callback().await {
Ok(_) => {}
Err(_err) => {
Expand Down
22 changes: 22 additions & 0 deletions implants/imix/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ impl Default for Config {
}
}

impl Config {
pub fn refresh_primary_ip(&mut self) {
let fresh_ip = get_primary_ip();
if self
.info
.host
.as_ref()
.is_some_and(|h| h.primary_ip != fresh_ip)
{
match self.info.host.as_mut() {
Some(h) => {
h.primary_ip = fresh_ip;
}
None => {
#[cfg(debug_assertions)]
log::error!("host struct was never initialized, failed to set primary ip");
}
}
}
}
}

/*
* Returns which Platform imix has been compiled for.
*/
Expand Down

0 comments on commit 91052d1

Please sign in to comment.