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

Update known flaws files 4.5.2 #4379

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

nico-stefani
Copy link
Member

@nico-stefani nico-stefani commented Jul 31, 2023

Related issue
#4445

Description

This PR updates the known flaws files with the recent scan results.

Updated

  • Known flaws in the framework file

Testing performed

(wqa310) ➜  wazuh-qa git:(4282-update-framework-known-flaws-4-5-0) pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test
================================================================================================ test session starts ================================================================================================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.2.0
rootdir: /home/nstefani/git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, metadata-3.0.0, testinfra-5.0.0
collected 1 item

tests/scans/code_analysis/test_python_flaws.py .                                                                                                                                                              [100%]

=========================================================================================== 1 passed, 3 warnings in 9.42s ===========================================================================================

@nico-stefani nico-stefani self-assigned this Jul 31, 2023
@nico-stefani nico-stefani linked an issue Jul 31, 2023 that may be closed by this pull request
4 tasks
@Rebits Rebits changed the base branch from 4.5.0 to 4.5.1 August 11, 2023 10:45
Copy link
Contributor

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

Could you change the base branch to 4.5.2 in this PR @nico-stefani?

Also, if these known flaws are merged in QA 4.5.2, they should reflect the Wazuh code in v4.5.2 too. However, it seems to find some flaws currently:

$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item                                                                                                                                                                                             

tests/scans/code_analysis/test_python_flaws.py F                                                                                                                                                       [100%]

================================================================================================== FAILURES ==================================================================================================
_________________________________________________________________________________________ test_check_security_flaws __________________________________________________________________________________________

clone_wazuh_repository = '/tmp/tmp22p01_mf'
get_test_parameters = {'directories_to_check': ['framework/', 'api/', 'wodles/'], 'directories_to_exclude': 'tests,test', 'min_confidence_level': 'MEDIUM', 'min_severity_level': 'LOW', ...}

    def test_check_security_flaws(clone_wazuh_repository, get_test_parameters):
        """Test whether the directory to check has python files with possible vulnerabilities or not.
    
        The test passes if there are no new vulnerabilities. The test fails in other case and generates a report.
    
        In case there is at least one vulnerability, a json file will be generated with the report. If we consider this
        result or results are false positives, we will move the json object containing each specific result to the
        `known_flaws/known_flaws_{framework|api|wodles}.json` file.
    
        Args:
            clone_wazuh_repository (fixture): Pytest fixture returning the path of the temporary directory path the
                repository cloned. This directory is removed at the end of the pytest session.
            get_test_parameters (fixture): Pytest fixture returning the a dictionary with all the test parameters.
                These parameters are the directories to check, directories to exclude, the minimum confidence level, the
                minimum severity level and the repository name.
        """
        # Wazuh is cloned from GitHub using the clone_wazuh_repository fixture
        assert clone_wazuh_repository, "Error while cloning the Wazuh repository from GitHub, " \
                                       "please check the Wazuh branch set in the parameter."
        # Change to the cloned Wazuh repository directory
        os.chdir(clone_wazuh_repository)
    
        directories_to_check = get_test_parameters['directories_to_check']
        bandit_output_list = \
            run_bandit_multiple_directories(directories_to_check,
                                            get_test_parameters['directories_to_exclude'],
                                            get_test_parameters['min_severity_level'],
                                            get_test_parameters['min_confidence_level'])
    
        flaws_already_found = {}
        for bandit_output, directory in zip(bandit_output_list, directories_to_check):
            assert not bandit_output['errors'], \
                f"\nBandit returned errors when trying to get possible vulnerabilities in the directory " \
                f"{directory}:\n{bandit_output['errors']}"
    
            bandit_result = bandit_output['results']
    
            known_flaws = update_known_flaws_in_file(known_flaws_directory=KNOWN_FLAWS_DIRECTORY,
                                                     directory=directory,
                                                     is_default_check_dir=
                                                     directory.replace('/', '') in
                                                     DEFAULT_DIRECTORIES_TO_CHECK.replace('/', '').split(','),
                                                     bandit_results=bandit_result)
    
            flaws_already_found = get_new_flaws(bandit_results=bandit_result,
                                                known_flaws=known_flaws,
                                                directory=directory,
                                                flaws_already_found=flaws_already_found,
                                                new_flaws_output_dir=TEST_PYTHON_CODE_PATH)
    
>       assert not any(
            flaws_already_found.get(directory, None) for directory in directories_to_check), \
            f"\nThe following possible vulnerabilities were found: {json.dumps(flaws_already_found, indent=4, sort_keys=True)}"
E       AssertionError: 
E         The following possible vulnerabilities were found: {
E             "api/": "Vulnerabilities found in files: api/api/configuration.py, api/scripts/wazuh-apid.py, check them in /home/selu/Git/wazuh-qa/tests/scans/code_analysis/new_flaws_api.json",
E             "wodles/": "Vulnerabilities found in files: wodles/azure/azure-logs.py, check them in /home/selu/Git/wazuh-qa/tests/scans/code_analysis/new_flaws_wodles.json"
E         }
E       assert not True
E        +  where True = any(<generator object test_check_security_flaws.<locals>.<genexpr> at 0x7f0528a01bd0>)

/home/selu/Git/wazuh-qa/tests/scans/code_analysis/test_python_flaws.py:64: AssertionError
========================================================================================== short test summary info ===========================================================================================
FAILED tests/scans/code_analysis/test_python_flaws.py::test_check_security_flaws - AssertionError: 
======================================================================================= 1 failed, 2 warnings in 12.06s =======================================================================================
{
    "new_flaws": [
        {
            "code": "     # Build the request\n     md5_hash = md5(args.la_query.encode()).hexdigest()\n     url = f\"{url_analytics}/v1/workspaces/{args.workspace}/query\"\n",
            "filename": "wodles/azure/azure-logs.py",
            "issue_confidence": "HIGH",
            "issue_severity": "MEDIUM",
            "issue_text": "Use of insecure MD2, MD4, MD5, or SHA1 hash function.",
            "line_number": 305,
            "line_range": [
                305
            ],
            "more_info": "https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b303-md5",
            "test_id": "B303",
            "test_name": "blacklist"
        }
    ]
}

@nico-stefani nico-stefani changed the base branch from 4.5.1 to 4.5.2 August 22, 2023 20:46
@nico-stefani nico-stefani force-pushed the 4282-update-framework-known-flaws-4-5-0 branch from 6d8ea87 to fcc7215 Compare August 22, 2023 21:06
@nico-stefani
Copy link
Member Author

Now is Ok with v4.5.2 of wazuh.

(wqa310) ➜  wazuh-qa git:(4282-update-framework-known-flaws-4-5-0) pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
================================================================================================ test session starts ================================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.2.0
rootdir: /home/nstefani/git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, metadata-3.0.0, testinfra-5.0.0
collected 1 item

tests/scans/code_analysis/test_python_flaws.py .                                                                                                                                                              [100%]

========================================================================================== 1 passed, 2 warnings in 11.56s ===========================================================================================
(wqa310) ➜  wazuh-qa git:(4282-update-framework-known-flaws-4-5-0) git status
En la rama 4282-update-framework-known-flaws-4-5-0
nada para hacer commit, el árbol de trabajo está limpio

@nico-stefani nico-stefani changed the title Update known flaws files 4.5 Update known flaws files 4.5.2 Aug 23, 2023
@nico-stefani nico-stefani linked an issue Aug 23, 2023 that may be closed by this pull request
Copy link
Contributor

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

LGTM, I'm adding the execution outputs to speed up the process since this should be merged today.

Run 1
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item                                                                                                                                                                                             

tests/scans/code_analysis/test_python_flaws.py .                                                                                                                                                       [100%]

======================================================================================= 1 passed, 2 warnings in 9.60s ========================================================================================
Run 2
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item                                                                                                                                                                                             

tests/scans/code_analysis/test_python_flaws.py .                                                                                                                                                       [100%]

======================================================================================= 1 passed, 2 warnings in 9.14s ========================================================================================
Run 3
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item                                                                                                                                                                                             

tests/scans/code_analysis/test_python_flaws.py .                                                                                                                                                       [100%]

======================================================================================= 1 passed, 2 warnings in 9.47s ========================================================================================

@mauromalara mauromalara self-requested a review August 24, 2023 14:25
Copy link
Contributor

@mauromalara mauromalara left a comment

Choose a reason for hiding this comment

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

LGTM!

@davidjiglesias davidjiglesias merged commit 36c6d3b into 4.5.2 Aug 25, 2023
4 checks passed
@davidjiglesias davidjiglesias deleted the 4282-update-framework-known-flaws-4-5-0 branch August 25, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update known flaws files for 4.5.2
4 participants