-
Notifications
You must be signed in to change notification settings - Fork 32
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
CVEs alerts inventory for Vulnerability Detector: partial scan type #1428
Merged
BraulioV
merged 4 commits into
1261-cve-alerts-inventory
from
1425-cve-alerts-inventory-partial_scan
Jun 9, 2021
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7df26f3
Add test_partial_scan_type to vulnerability detector tests
mdengra 1639efa
Add documentation for test_partial_scan_type #1425
mdengra 1d7710d
Improve modify_nvd_metadata_vuldet function of vulnerability_detector…
mdengra d0b7c1d
Change alerts.log to alerts.json as a file to process alerts
mdengra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ | |||||||||||||||||||||||||||||||
from wazuh_testing.tools import file | ||||||||||||||||||||||||||||||||
from wazuh_testing.tools import agent_simulator as ag | ||||||||||||||||||||||||||||||||
from wazuh_testing.tools.services import control_service, check_if_process_is_running | ||||||||||||||||||||||||||||||||
from wazuh_testing.tools.utils import retry | ||||||||||||||||||||||||||||||||
from wazuh_testing.wazuh_db import query_wdb | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
VULN_DETECTOR_GLOBAL_TIMEOUT = 20 | ||||||||||||||||||||||||||||||||
|
@@ -813,6 +814,22 @@ def modify_metadata_vuldet_feed(feed, timestamp): | |||||||||||||||||||||||||||||||
control_service('start', daemon='wazuh-db') | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def modify_nvd_metadata_vuldet(timestamp): | ||||||||||||||||||||||||||||||||
"""Function to modify the timestamp value of the nvd_metadata table. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||
timestamp (int): The new timestamp value to set. | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
query_string = f"UPDATE NVD_METADATA SET LAST_UPDATE={timestamp};" | ||||||||||||||||||||||||||||||||
for _ in range(VULN_DETECTOR_GLOBAL_TIMEOUT): | ||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||
make_query(CVE_DB_PATH, [query_string]) | ||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||
except sqlite3.OperationalError: | ||||||||||||||||||||||||||||||||
sleep(1) | ||||||||||||||||||||||||||||||||
raise sqlite3.OperationalError | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in: 1d7710d |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def check_vulnerability_scan_event(wazuh_log_monitor, package, cve): | ||||||||||||||||||||||||||||||||
"""Check if inserted vulnerable packages are reported by vulnerability detector. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
@@ -928,17 +945,18 @@ def create_mocked_agent(name="centos8-agent", ip="127.0.0.1", register_ip="127.0 | |||||||||||||||||||||||||||||||
return agent_id_str | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def create_simulated_agent(manager_address="localhost", os="debian10"): | ||||||||||||||||||||||||||||||||
@retry(AttributeError, attempts=2, delay=2, delay_multiplier=1) | ||||||||||||||||||||||||||||||||
def create_simulated_agent(manager_address="localhost", operating_system="debian10"): | ||||||||||||||||||||||||||||||||
BraulioV marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
"""Create a new agent using the Agent class of agent_simulator module with a minimal functionality. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||
manager_address (str, optional): Manager address. Defaults to "localhost". | ||||||||||||||||||||||||||||||||
os (str, optional): Operating system of the simulated agent. Defaults to "Debian 10". | ||||||||||||||||||||||||||||||||
operating_system (str, optional): Operating system of the simulated agent. Defaults to "Debian 10". | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||
(str, Sender, Injector): A tuple with the id, the Sender and the Injector of the simulated agent. | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
agent = ag.Agent(manager_address=manager_address, os=os) | ||||||||||||||||||||||||||||||||
agent = ag.Agent(manager_address=manager_address, os=operating_system) | ||||||||||||||||||||||||||||||||
agent.set_module_status('syscollector', 'enabled') | ||||||||||||||||||||||||||||||||
agent.set_module_status('fim', 'disabled') | ||||||||||||||||||||||||||||||||
sender, injector = ag.connect(agent) | ||||||||||||||||||||||||||||||||
|
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
29 changes: 29 additions & 0 deletions
29
docs/tests/integration/test_vulnerability_detector/test_scan_types/index.md
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,29 @@ | ||
# Overview | ||
|
||
## Objective | ||
|
||
The purpose of testing general settings is to check the scan types of the Vulnerability Detector module are working as | ||
expected. These are the general scan types: | ||
|
||
- `PARTIAL_SCAN` | ||
|
||
## General info | ||
|
||
|Tier | Number of tests | Time spent | | ||
|:--:|:--:|:--:| | ||
| 0 | 1 | 0:02:40 | | ||
|
||
## Expected behavior | ||
|
||
- `PARTIAL_SCAN`: Alerts should be generated only for vulnerabilities detected in new packages installed during | ||
this kind of scanning. | ||
|
||
## Testing | ||
|
||
### Generic tests | ||
|
||
- **[test_partial_scan_type](test_partial_scan_type.md#test-partial-scan-type)**: | ||
Test that adds a simulated agent to the system with a test package containing a vulnerability then starts | ||
a `BASELINE` scan and, after finishing it, adds a new test package with another vulnerability. | ||
It then launches a `PARTIAL_SCAN` and checks that the alert has only been generated for the last package installed. | ||
|
33 changes: 33 additions & 0 deletions
33
...tegration/test_vulnerability_detector/test_scan_types/test_partial_scan_type.md
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,33 @@ | ||
# Test partial scan type | ||
|
||
The test will check if the Vulnerability Detector module performs the `PARTIAL_SCAN` type correctly. | ||
|
||
## General info | ||
|
||
|Tier | Number of tests | Time spent| Test file | | ||
|:--:|:--:|:--:|:--:| | ||
| 0 | 1 | 2m40s | test_partial_scan_type.py | | ||
|
||
## Test logic | ||
|
||
The manager is configured to use custom feeds that include vulnerabilities associated with the test packages. | ||
The first package is added to the database of the simulated agent and, after enrollment of the agent, | ||
the vulnerability detector must launch the first scan on it, which is of `BASELINE` type. | ||
|
||
When the `BASELINE` scan is done, we will insert a new test package and wait for the `PARTIAL_SCAN` to start. | ||
Once the `PARTIAL_SCAN` is completed, it will check that a new vulnerability has been detected and an alert | ||
has been generated for that vulnerability by analyzing its respective logs. It will also be checked that | ||
no alerts have been generated for the first package that had already been previously analyzed by | ||
the `BASELINE` scan. | ||
|
||
|
||
## Checks | ||
|
||
- [x] The `BASELINE` and `PARTIAL_SCAN` scan startup, checking messages in the logs file. | ||
- [x] The NVD vulnerabilities for the test packages are detected during the scans, checking messages in the logs file. | ||
- [x] Completion of the scans, checking messages in the logs file. | ||
- [x] Alert is generated only for the vulnerability detected during `PARTIAL_SCAN` scanning, checking messages in the alerts file. | ||
|
||
## Code documentation | ||
|
||
::: tests.integration.test_vulnerability_detector.test_scan_types.test_partial_scan_type |
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.
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.
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.
Raises
field is missingThere 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.
Done in: 1d7710d