Save implant Wireguard session keys #893
Merged
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.
Details
If the Wireguard implant is setup as a beacon it will connect using the implant private key at every beacon interval and request a new key. It's like in The Highlander, there can be only one... session for each private key. If someone had a large number of wg beacons connecting there's potential for multiples to be trying at one time.
This rabbit hole started when I noticed every Wireguard connection wasn't able to connect immediately and required a retransmit after 5 seconds.
The way the Wireguard transport is setup, server/c2/jobs.go->StartWGListenerJob() sets up a Ticker to fire every 5 seconds and if the count of WG peers is greater than before it reloads the config. In all but the luckiest timing, this means it takes 0-5 seconds from when the new WG peer is added till it is actually available to connect. I tried changing up the method of reloading the WG peers but the implant always tries to connect too quickly before the keys are loaded (unless there's only a small amount of peers).
This PR changes it so the session WG keys/IP is saved for the duration the implant is operational.
I'm going to send an email about some other related issues.