forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rekey() VQL function (Velocidex#1604)
This forces the client to regenerate it's own client id and reconnect using the new client id. Sometimes client writeback files are accidentally copied across deployments (e.g. in VM images). This PR adds a Server.Monitor.ClientConflict server event artifact to watch for the 409 conflict events and force clients to rekey when detected. It should be used in situations where it is possible to client writeback files to be duplicated. This PR also fixes the client comms mechanism so it can be gracefully cancelled and recreated without restarting the process.
- Loading branch information
Showing
44 changed files
with
887 additions
and
484 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,30 @@ | ||
name: Generic.Client.Rekey | ||
description: | | ||
This artifact forces the client to reinitialize it's client id. | ||
It is normally not needed! You will want to use this artifact in | ||
very specific situation, such as the Velociraptor service was | ||
accidentally incorporated into a VM image with an existing write | ||
back file. This will cause multiple systems to connect with the same | ||
client id, and the server will reject clients with a HTTP 409 | ||
Rejected message. | ||
If this happens, you can use the Server.Monitor.ClientConflict | ||
artifact to schedule this artifact automatically. | ||
The Wait parameter controls how long we wait before restarting the | ||
client. Reduce this number if you need to rekey a lot of clients | ||
quickly. | ||
required_permissions: | ||
- EXECVE | ||
|
||
parameters: | ||
- name: Wait | ||
description: Wait this long before restarting the client. | ||
type: int | ||
default: '10' | ||
|
||
sources: | ||
- query: | ||
SELECT rekey(wait=Wait) FROM scope() |
This file contains 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,11 @@ | ||
name: Server.Internal.ClientConflict | ||
description: | | ||
This event artifact is an internal event stream receiving events | ||
about client conflict. | ||
When two clients attempt to connect to the server with the same | ||
client id, the server rejects one of these with a 409 Conflict HTTP | ||
message. The client id will be forwarded on this artifact as well so | ||
the server may take action. | ||
type: INTERNAL |
This file contains 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,21 @@ | ||
name: Server.Monitor.ClientConflict | ||
type: SERVER_EVENT | ||
description: | | ||
Sometimes the Velociraptor client is installed into a VM template | ||
image with an existing write back file. In this case each VM | ||
instance will start the client with the same client id. | ||
When clients connect to the server multiple times, the server will | ||
reject one with the HTTP 409 Conflict response. | ||
This artifact will also force conflicting clients to rekey | ||
themselves. Clients will generate a new client id and reconnect with | ||
the server, saving their new keys into their write back files. | ||
sources: | ||
- query: | | ||
SELECT | ||
collect_client(client_id=ClientId, | ||
artifacts="Generic.Client.Rekey", env=dict()) | ||
AS NewCollection | ||
FROM watch_monitoring(artifact="Server.Internal.ClientConflict") |
This file contains 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 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 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
Oops, something went wrong.