-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement commands expansion logic #229
Open
QU3B1M
wants to merge
23
commits into
master
Choose a base branch
from
enhancement/88-implement-commands-expansion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+582
−453
Conversation
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
QU3B1M
changed the title
Add getters to Target model
Implement commands expansion logic
Jan 19, 2025
Update RestPostCommandAction to consume the new Search class
Separate search-related code to a new function Add docstrings and validations
Convert the Target.type to Enum to validate possible values
Improve error messages
Agents are part of group
|
f-galland
approved these changes
Jan 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working.
Agent assigned to a group more than once:Group $ curl -s http://localhost:9200/wazuh-agents/_search | grep group004
"groups": ["group001","group004","group000","group004"],
"groups": ["group004","group001","group000"],
"groups": ["group004","group004"], Indexing command: curl -s http://localhost:9200/_plugins/_command_manager/commands -H 'Content-Type: application/json' -d '{
"commands": [
{
"source": "Engine",
"user": "user53",
"target": {
"id": "group004",
"type": "group"
},
"action": {
"name": "restart",
"args": {
"arg1": "/path/to/executable/arg6"
},
"version": "v4"
},
"timeout": 30
}
]
}' | jq
{
"_index": "wazuh-commands",
"_orders": [
{
"_id": "_6iXp5QBytahsG79A-l6"
},
{
"_id": "AKiXp5QBytahsG79A-p6"
},
{
"_id": "AaiXp5QBytahsG79A-p6"
}
],
"result": "OK"
} Only 3 commands are created: $ curl -s http://localhost:9200/wazuh-commands/_search | jq '.hits.hits[] | select(._id == "_6iXp5QBytahsG79A-l6" or ._id == "AKiXp5QBytahsG79A-p6" or ._id == "AaiXp5QBytahsG79A-p6") | ._source'
{
"agent": {
"groups": [
"group004",
"group004"
]
},
"@timestamp": "2025-01-27T11:47:59Z",
"delivery_timestamp": "2025-01-27T11:48:29Z",
"command": {
"action": {
"args": {
"arg1": "/path/to/executable/arg6"
},
"name": "restart",
"version": "v4"
},
"source": "Engine",
"user": "user53",
"order_id": "_qiXp5QBytahsG79A-l3",
"request_id": "_aiXp5QBytahsG79A-l3",
"timeout": 30,
"target": {
"id": "group004",
"type": "group"
},
"status": "failure"
}
}
{
"agent": {
"groups": [
"group001",
"group004",
"group000",
"group004"
]
},
"@timestamp": "2025-01-27T11:47:59Z",
"delivery_timestamp": "2025-01-27T11:48:29Z",
"command": {
"action": {
"args": {
"arg1": "/path/to/executable/arg6"
},
"name": "restart",
"version": "v4"
},
"source": "Engine",
"user": "user53",
"order_id": "_qiXp5QBytahsG79A-l3",
"request_id": "_aiXp5QBytahsG79A-l3",
"timeout": 30,
"target": {
"id": "group004",
"type": "group"
},
"status": "failure"
}
}
{
"agent": {
"groups": [
"group004",
"group001",
"group000"
]
},
"@timestamp": "2025-01-27T11:47:59Z",
"delivery_timestamp": "2025-01-27T11:48:29Z",
"command": {
"action": {
"args": {
"arg1": "/path/to/executable/arg6"
},
"name": "restart",
"version": "v4"
},
"source": "Engine",
"user": "user53",
"order_id": "_qiXp5QBytahsG79A-l3",
"request_id": "_aiXp5QBytahsG79A-l3",
"timeout": 30,
"target": {
"id": "group004",
"type": "group"
},
"status": "failure"
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Detect the commands which target type is
group
, search in the.agents
index for the agents of each group and generate the corresponding Orders.Renamed the
Document
class toOrders
, replacing the previously unused Orders class.Working validations
Command expansion
Group used for the test:
group000
Request
Response
Command creation log
Command indexed
% curl http://127.0.0.1:9200/.commands/_search {"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":1.0,"hits":[{"_index":".commands","_id":"WS5fjpQBDZQg8-hA8AYd","_score":1.0,"_source":{"agent":{"groups":["group000","group001","group003"]},"@timestamp":"2025-01-22T14:17:19Z","delivery_timestamp":"2025-01-22T14:17:49Z","command":{"action":{"args":{"arg1":"/path/to/executable/arg6"},"name":"restart","version":"v4"},"source":"Engine","user":"user53","order_id":"WC5fjpQBDZQg8-hA8AYP","request_id":"Vy5fjpQBDZQg8-hA8AYP","timeout":30,"target":{"id":"group000","type":"group"},"status":"failure"}}},{"_index":".commands","_id":"Wi5fjpQBDZQg8-hA8AYe","_score":1.0,"_source":{"agent":{"groups":["group000","group002","group002"]},"@timestamp":"2025-01-22T14:17:19Z","delivery_timestamp":"2025-01-22T14:17:49Z","command":{"action":{"args":{"arg1":"/path/to/executable/arg6"},"name":"restart","version":"v4"},"source":"Engine","user":"user53","order_id":"WC5fjpQBDZQg8-hA8AYP","request_id":"Vy5fjpQBDZQg8-hA8AYP","timeout":30,"target":{"id":"group000","type":"group"},"status":"failure"}}}]}}
Command expansion - Group assigned to the same agent more than once
Using the group
001
Basic command creation
Using agent id:
agent94
Issues Resolved
Resolves #88