-
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
Update scanning tools documentation #4444
Conversation
3b54a89
to
be4d4eb
Compare
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.
I think it is better to rewrite this sentence:
In order to run the scripts, you should install the wazuh_testing package and the dependencies listed in the requirements file.
To run the scripts, install the wazuh_testing
package and the dependencies listed in the requirements file.
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.
Rewrite proposal to increase clarity in tests/dependencies/README.md
, avoiding passive voice phrase and using a direct style.
It's a tool used to scan for vulnerabilities in a requirements.txt file.
It can generate reports via console output or json file. Can be run withpytest
and manage to handle remote "requirements.txt" files under github repositories. Requirements file can be specified withrepo
,branch
,requirements-path
parameters giving flexibility on file location.
It can generate reports via console output or json file. Can be run withpytest
and manage to handle remote files under github repositories. Requirements file can be specified withrepo
,reference
,requirements-path
parameters giving flexibility on file location.
Output file in which the report will be generated can be specified withreport-path
parameter.
The Dependencies Scanner is a tool for scanning vulnerabilities in a requirements.txt file. It can generate reports via console output or JSON file. The Dependencies Scanner uses pytest
to run. The tool scans remote requirement files located in GitHub repositories. Requirements files can be specified with repo
, reference
, and requirements-path
parameters, giving flexibility on a file location. The report-path
parameter can specify the output file that the tool generates.
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.
I think that the whole code_analysis README.md file needs to be improved. This is my proposal, please review if the content is fine or needs to be corrected.
Proposed Text
Code Analysis
The code_analysis
directory contains Python tests to verify potential vulnerabilities in the Wazuh Python code.
Test Python Flaws
Description
test_python_flaws.py
is a Pytest test located at wazuh-qa/tests/scans/code_analysis
directory. The test looks for vulnerabilities in Python code directories and uses Bandit to search for these potential flaws.
The test checks the framework/
, api/
and wodles/
directories of the Wazuh repository by default, comparing the Bandit output with the vulnerabilities identified as false positives or vulnerabilities to fix. It saves the results in three JSON files (one JSON file for each module).
The contents of the code_analysis directory are:
README.md
file: this file.known_flaws
directory: The directory contains three JSON files, one for each module (api, framework and wodles). Each file has a dictionary with two keys: false_positives and to_fix. The values are the list of vulnerabilities considered false positives and the list of vulnerabilities you must fix (with issues). After running the test and analyzing the new vulnerabilities, you must edit these files.conftest.py
: The Pytest configuration file. It adds the possibility to use specific parameters when passing the test.test_python_flaws.py
: The test itself. You should run this test using the same Python virtual environment used in the Wazuh framework and API unit tests. If the test fails, a new JSON file will be created in wazuh-qa/tests/scans/code_analysis, showing information about the possible new vulnerabilities found.
Usage
The usage for this test is the following:
- Run the test.
- If the test passes without failures, everything is correct, and no action is needed.
- If the test fails, wazuh-qa/tests/scans/code_analysis/new_flaws_{module}.json file will report the new code vulnerabilities found.
You should analyze the new vulnerabilities found in the module and report them in GitHub issues.
If you need to fix a new vulnerability, add it to the to_fix key module's JSON file entry found in the known_flaws. If the new vulnerability is a false positive, add it to the false_positives key module's JSON file entry found in the known_flaws. The test updates the known_flaws files automatically with information like the line number or range of the flaws in the to_fix dictionary. The test also removes flaws from the known_flaws file if Bandit did not report them.
Parameters
As the description says, the test uses Bandit to look for possible Python flaws. By default, the test checks the framework, wodles and api directories in the Wazuh repository's master branch.
You can set the directories, repository, and branch parameters to test any directory containing Python code inside the Wazuh organization.
You can also use more parameters to customize the test functionality. The test will only succeed if you check different directories and repositories, as you don't have known_flaws files for non-default directories.
- --repo: the repository used. Default: wazuh
- --reference: the repository branch. Default: master
- --check_directories: the directory/ies name/s to check; This parameter accepts multiple directories separated by commas. Default: framework/,api/,wodles/.
- --exclude_directories: the directory/ies name/s to exclude; This parameter accepts multiple directories separated by commas. Default: test/,tests/.
- --confidence: the minimum value of confidence of the Bandit scan. This value must be 'UNDEFINED', 'LOW', 'MEDIUM' or 'HIGH'. Default: MEDIUM
- --severity: the minimum value of severity of the Bandit scan. This value must be 'UNDEFINED', 'LOW', 'MEDIUM' or 'HIGH'. Default: LOW
@mhamra I think this is out of the scope of the issue, but given that it's just documentation changes I'll go ahead and implement them |
50688f7
to
2c9e219
Compare
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.
LGTM!
Thanks @GGP1
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.
LGTM!
Thanks @GGP1
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.
There are some conflicts
2c9e219
to
9b97442
Compare
a79b351
to
4517545
Compare
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.
Greato job! Some minor changes are required
4517545
to
63c6ef3
Compare
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.
LGTM
Dependencies Scan 🟢
tests/scans/dependencies/test_dependencies.py::test_python_dependencies_vuln_scan FAILED [100%]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
pytestconfig = <_pytest.config.Config object at 0x7fcb30adb340>
def test_python_dependencies_vuln_scan(pytestconfig):
"""Check that the specified dependencies do not have any known vulnerabilities.
Args:
pytestconfig (fixture): Fixture that returns the :class:`_pytest.config.Config` object.
"""
branch = pytestconfig.getoption('--reference')
repo = pytestconfig.getoption('--repo')
requirements_path = pytestconfig.getoption('--requirements-path')
report_path = pytestconfig.getoption('--report-path')
requirements_url = f"https://raw.githubusercontent.com/wazuh/{repo}/{branch}/{requirements_path}"
urlretrieve(requirements_url, REQUIREMENTS_TEMP_FILE.name)
result = report_for_pytest(REQUIREMENTS_TEMP_FILE.name,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "known_flaws_deps.json"))
REQUIREMENTS_TEMP_FILE.close()
export_report(result, report_path)
> assert loads(result)['vulnerabilities_found'] == 0, f'Vulnerables packages were found, full report at: ' \
f"{report_path}"
E AssertionError: Vulnerables packages were found, full report at: test_file.json
E assert 25 == 0
tests/scans/dependencies/test_dependencies.py:30: AssertionError
Description
Adds a README file with instructions on how to setup the environment to run the vulnerability scanning tools and modifies the documentations from both scripts to reference to the correct parameters. It also adds a line to the dependencies script to skip empty lines and comments in requirements files.
Added
Updated
Executions
Run 1
Run 2
Run 3
Report