Closed mcarmona99 closed 2 years ago
API tests after the requested changes:
root@db6c3b064a20:/wazuh-api# mocha test/test_active_response.js
Active Response
PUT/active-response/:agent_id
(node:1577) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
✔ Request (270ms)
✔ Command not found (253ms)
✔ Custom command (248ms)
✔ Wrong custom parameter (77ms)
✔ Wrong arguments parameter (74ms)
✔ Agent does not exist (240ms)
✔ Agent ID not valid (81ms)
✔ Wrong command (unsafe path - Ubuntu) (81ms)
✔ Wrong command (unsafe path - Ubuntu) (73ms)
✔ Wrong command (unsafe path with ! - Ubuntu) (74ms)
✔ Wrong command (unsafe path - Windows) (80ms)
✔ Wrong command (unsafe path - Windows) (74ms)
✔ Wrong command (unsafe path with ! - Windows) (78ms)
✔ Other valid commands (Ubuntu) (275ms)
✔ Other valid commands (Windows) (257ms)
15 passing (2s)
LGTM
Description
This PR adds a
command
validation for thePUT /active-response
API endpoint and new test cases.Manual tests
curl -u foo:bar -k -X PUT -d '{"command":"restart-ossec0", "arguments": ["-", "null", "(from_the_server)", "(no_rule_id)"]}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
curl -u foo:bar -k -X PUT -d '{"command":"custom_command", "custom": true, "arguments": ["-", "null", "(from_the_server)", "(no_rule_id)"]}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
curl -u foo:bar -k -X PUT -d '{"command":"custom_command", "custom": true, "arguments": "not_an_array"}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
curl -u foo:bar -k -X PUT -d '{"command":"custom_command", "custom": "hi", "arguments": ["-", "null", "(from_the_server)", "(no_rule_id)"]}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
"command": "../../../test.sh"
curl -u foo:bar -k -X PUT -d '{"command":"../../../test.sh", "custom": true}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
"command": "..\\..\\..\\test.ps1"
curl -u foo:bar -k -X PUT -d '{"command":"..\\..\\..\\test.ps1", "custom": true}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
"command": "!../../../test.sh"
curl -u foo:bar -k -X PUT -d '{"command":"!../../../test.sh"}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
"command": "!..\\..\\..\\test.ps1"
curl -u foo:bar -k -X PUT -d '{"command":"!..\\..\\..\\test.ps1"}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
curl -u foo:bar -k -X PUT -d '{"command":".\\test.ps1", "custom": true}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
curl -u foo:bar -k -X PUT -d '{"command":"./test.sh", "custom": true}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/active-response/000?pretty"
API tests