Skip to content
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

Fix arbitrary code execution flaw in Active Response #14801

Merged
merged 6 commits into from Sep 9, 2022
Merged

Conversation

vikman90
Copy link
Member

@vikman90 vikman90 commented Sep 5, 2022

Affected versions Module Component Cause Credits
3.6.1 - 3.13.5, 4.0.0 - 4.2.7, 4.3.0 - 4.3.7 Active Response Agent & manager #1217 All credits to Roshan Guragain

Thanks to Roshan Guragain for reporting the flaw and helping us improve the product!

Flaw

References to a parent folder are possible in a custom AR API request:

Method Endpoint Data
PUT /active-response {"command":"!../../../../../../bin/ls"}

Impact

A manager administrator with RBAC permissions active-response:command might execute a program outside the Active Response binary folder (/var/ossec/active-response/bin).

  • In versions below 4.2.0, the target command would receive the extra arguments (extra_args) as a command-line parameter list.
  • In 4.2.0 and higher, the target command receives all data (including the extra arguments) in a JSON string via standard input.

Agents from 3.6.1 to 4.1.5

Running a custom Active Response with these parameters:

Command Custom Arguments
../../../../root/test.sh true [arg1, arg2, arg3]

This will cause the agent to run /root/test.sh with the following arguments:

/var/ossec/active-response/bin/../../../../root/test.sh add arg1 arg2 arg3

Agents from 4.2.0 to 4.3.7

Running a custom Active Response with these parameters:

Command Arguments
!../../../../root/test.sh [arg1, arg2, arg3]

This will cause the agent to run /root/test.sh with no extra arguments, but the agent will send the following string via stdin:

{"version":1,"origin":{"name":null,"module":"wazuh-execd"},"command":"add","parameters":{"extra_args":["arg1","arg2","arg3"],"alert":{},"program":"active-response/bin/../../../../root/test.sh"}}

Proposed fix

We're implementing protection at two levels:

  1. Prevent the agent (wazuh-execd) from running a custom AR outside active-response/bin.
  2. Filter custom Active Response commands by the API and reject those whose member command contains any reference to a parent folder (../).

Tests

  • Send a custom AR command to Execd containing a reference to the parent folder:
echo -n '{"version": 1, "origin": {"name": null, "module": "framework"}, "command": "!../../../../../../bin/ls", "parameters": {"extra_args": [], "alert": {}}}' | nc -w0 -Uu /var/ossec/queue/alerts/execq
2022/09/05 14:48:51 wazuh-execd[6848] exec.c:163 at GetCommandbyName(): WARNING: Active response command '../../../../../../bin/ls' vulnerable to directory traversal attack. Ignoring.
2022/09/05 14:48:51 wazuh-execd[6848] execd.c:465 at ExecdStart(): ERROR: (1311): Invalid command name '!../../../../../../bin/ls' provided.
  • Unit tests to check that GetCommandbyName rejects custom commands with path traversal.
  • The API rejects custom ARs with commands referring to the parent folder:
curl -H "Content-Type: application/json" -X PUT https://localhost:55000/active-response?agents_list=001 --data '{"command":"!../../../../../../bin/ls"}'
{"title": "Bad Request", "detail": "'!../../../../../../bin/l' is not a 'active_response_command' - 'command'"}

@vikman90 vikman90 added type/bug Something isn't working type/bug/vulnerability Exploitable vulnerability labels Sep 5, 2022
Copy link
Contributor

@chemamartinez chemamartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jmv74211
Copy link
Contributor

jmv74211 commented Sep 8, 2022

QA review

@vikman90 vikman90 merged commit b59855d into 4.3 Sep 9, 2022
@vikman90 vikman90 deleted the fix-ar-custom-comm branch September 9, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug/vulnerability Exploitable vulnerability type/bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants