Closed Selutario closed 4 months ago
The required modifications have been applied and manually tested with the PUT /manager/configuration
endpoint.
Wazuh configuration update with a public API key when not allowed:
{
"data": {
"affected_items": [],
"total_affected_items": 0,
"total_failed_items": 1,
"failed_items": [
{
"error": {
"code": 1130,
"message": "Public Virus Total API Key detected: integrations > virustotal",
"remediation": "To solve this, either use a premium VirusTotal API key or disable the public key protection in the API settings: https://documentation.wazuh.com/current/user-manual/api/configuration.html"
},
"id": [
"wd_master_1"
]
}
]
},
"message": "Could not update configuration in specified node",
"error": 1
}
Wazuh configuration update results in a request error when communicating with the VirusTotal API:
{
"data": {
"affected_items": [],
"total_affected_items": 0,
"total_failed_items": 1,
"failed_items": [
{
"error": {
"code": 1131,
"message": "Virus Total API request error",
"remediation": "The use of Virus Total Public API keys is disabled but could not be checked. To solve this, check your connection to the Virus Total API or disable the public key protection in the API settings: https://documentation.wazuh.com/current/user-manual/api/configuration.html"
},
"id": [
"wd_master_1"
]
}
]
},
"message": "Could not update configuration in specified node",
"error": 1
}
Next tasks:
4.8.0
.
(integrationtest-env-3.10) fdalmau@wazuhFW:~/.../api/test/integration(enhancement/23741-virustotal-api-option)$ pytest test_cluster_endpoints.tavern.yaml
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.10.14, pytest-7.3.1, pluggy-0.13.1
rootdir: /home/fdalmau/git/wazuh/api/test/integration
configfile: pytest.ini
plugins: aiohttp-1.0.4, anyio-4.1.0, trio-0.7.0, metadata-2.0.2, tavern-1.23.5, asyncio-0.18.1, html-2.1.1
asyncio: mode=auto
collected 49 items
test_cluster_endpoints.tavern.yaml ................................................. [100%]
============================================================================== 49 passed, 50 warnings in 1066.51s (0:17:46) =============================================================================== (integrationtest-env-3.10) fdalmau@wazuhFW:~/.../api/test/integration(enhancement/23741-virustotal-api-option)$ pytest test_manager_endpoints.tavern.yaml =========================================================================================== test session starts =========================================================================================== platform linux -- Python 3.10.14, pytest-7.3.1, pluggy-0.13.1 rootdir: /home/fdalmau/git/wazuh/api/test/integration configfile: pytest.ini plugins: aiohttp-1.0.4, anyio-4.1.0, trio-0.7.0, metadata-2.0.2, tavern-1.23.5, asyncio-0.18.1, html-2.1.1 asyncio: mode=auto collected 33 items
test_manager_endpoints.tavern.yaml ................................. [100%]
=============================================================================== 33 passed, 34 warnings in 978.94s (0:16:18) ===============================================================================
- Documentation update in the `enhancement/23741-virustotal-public-key-api-option` wazuh-documentation branch.
- The `Integration API tests` are being extended adding the new feature tests. A mock server to simulate the Virus Total service is being developed.
A docker image has been built to expose a simple https server with a self-signed certificate to respond to the possible requests made by the server. When running the container, the VM executing the API Integration Tests found in tests/integration/test_api/test_config
needed to be modified with the following commands:
# Modify /etc/hosts to redirect requests to www.virustotal.com to localhost
sed -i '/^$/i\I127.0.0.1 www.virustotal.com' /etc/hosts
# Redirect HTTPS traffic from www.virustotal.com to localhost:8080
sudo iptables -t nat -A OUTPUT -p tcp --dport 443 -d www.virustotal.com -j REDIRECT --to-port 8080
The manual tests of the HTTPS mock server worked as expected:
root@vagrant:/# curl -s -k https://virustotal.com/api/v3/users/expected_api_key/overall_quotas --header 'x-apikey: expected_api_key'
{"data": {"api_requests_hourly": {"user": {"allowed": 240, "used": 0}}}}
root@vagrant:/# curl -s -k https://virustotal.com/api/v3/users/error_api_key/overall_quotas --header 'x-apikey: error_api_key'
{"error": {"code": "WrongCredentialsError", "message": "Wrong API key"}}
root@vagrant:/# docker run -p 8080:8080 http_server
Listening on port 8080...
172.17.0.1 - - [31/May/2024 09:42:13] "GET /api/v3/users/expected_api_key/overall_quotas HTTP/1.1" 200 -
172.17.0.1 - - [31/May/2024 09:42:16] "GET /api/v3/users/error_api_key/overall_quotas HTTP/1.1" 401 -
The problem is when the Framework tries to get the information from the mock server. Since a self-signed certificate is used, and the requests.get()
method is not used with the verify=False
argument, the request fails and the PUT /manager/configuration
returns:
{"data": {"affected_items": [], "total_affected_items": 0, "total_failed_items": 1, "failed_items": [{"error": {"code": 1131, "message": "Virus Total API request error: HTTPSConnectionPool(host='www.virustotal.com', port=443): Max retries exceeded with url: /api/v3/users/expected_api_key/overall_quotas (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1007)')))", "remediation": "The use of Virus Total Public API keys is disabled but could not be checked. To solve this, check your connection to the Virus Total API or disable the public key protection in the API settings: https://documentation.wazuh.com/4.8/user-manual/api/configuration.html"}, "id": ["manager"]}]}, "message": "Could not update configuration", "error": 1}
Therefore, one of the test's steps will be to modify the line that sends the request to the VirusTotal API to avoid certificate verification, being the result:
# curl -k -X PUT "https://localhost:55000/manager/configuration" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/octet-stream" -d '<ossec_config>
<integration>
<name>virustotal</name>
<api_key>expected_api_key</api_key>
<group>syscheck</group>
<alert_format>json</alert_format>
</integration>
</ossec_config>'
{"data": {"affected_items": [], "total_affected_items": 0, "total_failed_items": 1, "failed_items": [{"error": {"code": 1130, "message": "Public Virus Total API Key detected: integrations > virustotal", "remediation": "To solve this, either use a premium VirusTotal API key or disable the public key protection in the API settings: https://documentation.wazuh.com/4.8/user-manual/api/configuration.html"}, "id": ["manager"]}]}, "message": "Could not update configuration", "error": 1}
Description
We need a new development, similar to what was done for the
<limits>
and<indexer>
blocks, to prevent users from using Public VirustTotal API keys in the<integration><name>virustotal</name>
block (link)Using or not the Public API key shown above should only be allowed when explicitly permitted in the
api.yaml
(it will be allowed by default). Therefore, a new configuration must be added:Checks
The following elements have been updated or reviewed (should also be checked if no modification is required):
api/test/integration/mapping/_test_mapping.py
).