diff options
| author | Adam Janovsky | 2023-03-10 21:04:43 +0100 |
|---|---|---|
| committer | Adam Janovsky | 2023-03-10 21:04:43 +0100 |
| commit | 67cfddbd764332cd939086594f86820ea5094fa4 (patch) | |
| tree | 83b4d12d013422a2d776be4ee11d546d698811e9 | |
| parent | fe2e1de73191aa0f9c229179f43dc15ba1a1ab37 (diff) | |
| download | sec-certs-67cfddbd764332cd939086594f86820ea5094fa4.tar.gz sec-certs-67cfddbd764332cd939086594f86820ea5094fa4.tar.zst sec-certs-67cfddbd764332cd939086594f86820ea5094fa4.zip | |
finalize cpe matching for on/with configurations
| -rw-r--r-- | src/sec_certs/dataset/cve.py | 38 | ||||
| -rw-r--r-- | src/sec_certs/dataset/dataset.py | 15 | ||||
| -rw-r--r-- | src/sec_certs/sample/cpe.py | 19 | ||||
| -rw-r--r-- | src/sec_certs/sample/cve.py | 170 | ||||
| -rw-r--r-- | tests/cc/test_cc_analysis.py | 77 | ||||
| -rw-r--r-- | tests/data/cc/analysis/auxiliary_datasets/cve_dataset.json | 497 | ||||
| -rw-r--r-- | tests/data/cc/analysis/auxiliary_datasets/cve_dset_with_cpe_configs.json | 385 | ||||
| -rw-r--r-- | tests/fips/test_fips_analysis.py | 57 | ||||
| -rw-r--r-- | tests/test_cpe.py | 79 | ||||
| -rw-r--r-- | tests/test_cve.py | 69 |
10 files changed, 701 insertions, 705 deletions
diff --git a/src/sec_certs/dataset/cve.py b/src/sec_certs/dataset/cve.py index 65d141c3..43cd5b80 100644 --- a/src/sec_certs/dataset/cve.py +++ b/src/sec_certs/dataset/cve.py @@ -1,5 +1,6 @@ from __future__ import annotations +import collections import datetime import glob import itertools @@ -57,7 +58,7 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): def _filter_cves_with_cpe_configurations(self) -> None: """ - Method filters the subset of CVEs, which contain at least one CPE configuration. + Method filters the subset of CVE dataset thah contain at least one CPE configuration in the CVE. """ self.cves_with_vulnerable_configurations = [cve for cve in self if cve.vulnerable_cpe_configurations] @@ -83,7 +84,7 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): for cve in tqdm(self, desc="Building-up lookup dictionaries for fast CVE matching"): # See note above, we use matching_dict.get(cpe, []) instead of matching_dict[cpe] as would be expected if use_nist_mapping: - vulnerable_configurations = set( + vulnerable_configurations = list( itertools.chain.from_iterable(matching_dict.get(cpe, []) for cpe in cve.vulnerable_cpes) ) else: @@ -133,7 +134,6 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): cls.download_cves(tmp_dir, start_year, end_year) json_files = glob.glob(tmp_dir + "/*.json") - all_cves = {} logger.info("Downloaded required resources. Building CVEDataset from jsons.") results = process_parallel( cls.from_nist_json, @@ -141,38 +141,30 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): use_threading=False, progress_bar_desc="Building CVEDataset from jsons", ) - for r in results: - all_cves.update(r.cves) - - return cls(all_cves, json_path) + return cls(dict(collections.ChainMap(*(x.cves for x in results))), json_path) def _get_cve_ids_for_cpe_uri(self, cpe_uri: str) -> set[str]: return self.cpe_to_cve_ids_lookup.get(cpe_uri, set()) - def _get_cves_from_exactly_matched_cpes(self, cpe_matches: set[str]) -> set[str]: - return set(itertools.chain.from_iterable([self._get_cve_ids_for_cpe_uri(cpe_uri) for cpe_uri in cpe_matches])) - - def _get_cves_from_cpe_configurations(self, cpe_matches: set[str]) -> set[str]: - def do_cve_configurations_match_cpe_matches(cve: CVE, cpe_matches: set[str]) -> bool: - return any( - [cpe_configuration.match(cpe_matches) for cpe_configuration in cve.vulnerable_cpe_configurations] - ) + def _get_cves_from_exactly_matched_cpes(self, cpe_uris: set[str]) -> set[str]: + return set(itertools.chain.from_iterable([self._get_cve_ids_for_cpe_uri(cpe_uri) for cpe_uri in cpe_uris])) + def _get_cves_from_cpe_configurations(self, cpe_uris: set[str]) -> set[str]: return { cve.cve_id for cve in self.cves_with_vulnerable_configurations - if do_cve_configurations_match_cpe_matches(cve, cpe_matches) + if any(configuration.matches(cpe_uris) for configuration in cve.vulnerable_cpe_configurations) } - def get_cves_from_matched_cpes(self, cpe_matches: set[str]) -> set[str]: + def get_cves_from_matched_cpes(self, cpe_uris: set[str]) -> set[str]: """ Method returns the set of CVEs which are matched to the set of CPEs. First are matched the classic CPEs to CVEs with lookup dict and then are matched the 'AND' type CPEs containing platform. """ return { - *self._get_cves_from_exactly_matched_cpes(cpe_matches), - *self._get_cves_from_cpe_configurations(cpe_matches), + *self._get_cves_from_exactly_matched_cpes(cpe_uris), + *self._get_cves_from_cpe_configurations(cpe_uris), } def filter_related_cpes(self, relevant_cpes: set[CPE]): @@ -186,7 +178,13 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): cve_ids_to_delete = [] for cve in self: n_cpes_orig = len(cve.vulnerable_cpes) - cve.vulnerable_cpes = list(filter(lambda x: x in relevant_cpes, cve.vulnerable_cpes)) + cve.vulnerable_cpes = [x for x in cve.vulnerable_cpes if x in relevant_cpes] + cve.vulnerable_cpe_configurations = [ + x + for x in cve.vulnerable_cpe_configurations + if x.platform.uri in relevant_cpes and any(y.uri in relevant_cpes for y in x.cpes) + ] + total_deleted_cpes += n_cpes_orig - len(cve.vulnerable_cpes) if not cve.vulnerable_cpes: cve_ids_to_delete.append(cve.cve_id) diff --git a/src/sec_certs/dataset/dataset.py b/src/sec_certs/dataset/dataset.py index 9481d9f7..614f60cf 100644 --- a/src/sec_certs/dataset/dataset.py +++ b/src/sec_certs/dataset/dataset.py @@ -1,6 +1,5 @@ from __future__ import annotations -import itertools import json import logging import re @@ -527,18 +526,14 @@ class Dataset(Generic[CertSubType, AuxiliaryDatasetsSubType], ComplexSerializabl ) return - relevant_cpes = set(itertools.chain.from_iterable(x.heuristics.cpe_matches for x in cpe_rich_certs)) - self.auxiliary_datasets.cve_dset.filter_related_cpes(relevant_cpes) + # The following lines don't bring any speed-up. They may potentially save memory if rest of CVEs is cleaned explicitly + # relevant_cpes = set(itertools.chain.from_iterable(x.heuristics.cpe_matches for x in cpe_rich_certs)) + # self.auxiliary_datasets.cve_dset.filter_related_cpes(relevant_cpes) cert: Certificate for cert in tqdm(cpe_rich_certs, desc="Computing related CVES"): - if cert.heuristics.cpe_matches: - related_cves = self.auxiliary_datasets.cve_dset.get_cves_from_matched_cpes(cert.heuristics.cpe_matches) - - if related_cves: - cert.heuristics.related_cves = related_cves - else: - cert.heuristics.related_cves = None + related_cves = self.auxiliary_datasets.cve_dset.get_cves_from_matched_cpes(cert.heuristics.cpe_matches) + cert.heuristics.related_cves = related_cves if related_cves else None n_vulnerable = len([x for x in cpe_rich_certs if x.heuristics.related_cves]) n_vulnerabilities = sum([len(x.heuristics.related_cves) for x in cpe_rich_certs if x.heuristics.related_cves]) diff --git a/src/sec_certs/sample/cpe.py b/src/sec_certs/sample/cpe.py index 664e70e3..1e3cbf12 100644 --- a/src/sec_certs/sample/cpe.py +++ b/src/sec_certs/sample/cpe.py @@ -10,13 +10,12 @@ from sec_certs.serialization.pandas import PandasSerializableType from sec_certs.utils import helpers +@dataclass class CPEConfiguration(ComplexSerializableType): __slots__ = ["platform", "cpes"] - def __init__(self, platform: str, cpes: set[str]) -> None: - super().__init__() - self.platform: str = platform - self.cpes: set[str] = cpes + platform: CPE + cpes: list[CPE] def __hash__(self) -> int: return hash(self.platform) + sum([hash(cpe) for cpe in self.cpes]) @@ -25,17 +24,19 @@ class CPEConfiguration(ComplexSerializableType): return self.platform < other.platform def __eq__(self, other: Any) -> bool: - return isinstance(other, self.__class__) and self.platform == other.platform and self.cpes == other.cpes + return ( + isinstance(other, self.__class__) and self.platform == other.platform and set(self.cpes) == set(other.cpes) + ) - def match(self, set_of_cpes: set[str]) -> bool: + def matches(self, other_cpe_uris: set[str]) -> bool: """ For a given set of CPEs method returns boolean if the CPE configuration is matched or not. """ - return self.platform in set_of_cpes and any(list(set_of_cpes)) + return self.platform.uri in other_cpe_uris and any(x.uri in other_cpe_uris for x in self.cpes) -@dataclass(init=False) +@dataclass class CPE(PandasSerializableType, ComplexSerializableType): uri: str version: str @@ -113,6 +114,8 @@ class CPE(PandasSerializableType, ComplexSerializableType): def pandas_tuple(self) -> tuple: return self.uri, self.vendor, self.item_name, self.version, self.title + # We cannot use frozen=True. It does not work with __slots__ prior to Python 3.10 dataclasses + # Hence we manually provide __hash__ and __eq__ despite not guaranteeing immutability def __hash__(self) -> int: return hash((self.uri, self.start_version, self.end_version)) diff --git a/src/sec_certs/sample/cve.py b/src/sec_certs/sample/cve.py index 9b2c2437..2289b0e1 100644 --- a/src/sec_certs/sample/cve.py +++ b/src/sec_certs/sample/cve.py @@ -3,7 +3,7 @@ from __future__ import annotations import datetime import itertools from dataclasses import dataclass -from typing import Any, ClassVar +from typing import Any, ClassVar, Iterable from dateutil.parser import isoparse @@ -12,9 +12,9 @@ from sec_certs.serialization.json import ComplexSerializableType from sec_certs.serialization.pandas import PandasSerializableType -@dataclass(init=False) +@dataclass class CVE(PandasSerializableType, ComplexSerializableType): - @dataclass(eq=True) + @dataclass class Impact(ComplexSerializableType): base_score: float severity: str @@ -47,8 +47,8 @@ class CVE(PandasSerializableType, ComplexSerializableType): raise ValueError("NIST Dict for CVE Impact badly formatted.") cve_id: str - vulnerable_cpes: set[CPE] - vulnerable_cpe_configurations: set[CPEConfiguration] + vulnerable_cpes: list[CPE] + vulnerable_cpe_configurations: list[CPEConfiguration] impact: Impact published_date: datetime.datetime | None cwe_ids: set[str] | None @@ -66,30 +66,13 @@ class CVE(PandasSerializableType, ComplexSerializableType): "cwe_ids", ] - def __init__( - self, - cve_id: str, - vulnerable_cpes: set[CPE], - vulnerable_cpe_configurations: set[CPEConfiguration], - impact: Impact, - published_date: str, - cwe_ids: set[str] | None, - ): - super().__init__() - self.cve_id = cve_id - self.vulnerable_cpes = vulnerable_cpes - self.vulnerable_cpe_configurations = vulnerable_cpe_configurations - self.impact = impact - self.published_date = isoparse(published_date) - self.cwe_ids = cwe_ids - + # We cannot use frozen=True. It does not work with __slots__ prior to Python 3.10 dataclasses + # Hence we manually provide __hash__ and __eq__ despite not guaranteeing immutability def __hash__(self) -> int: return hash(self.cve_id) def __eq__(self, other: object) -> bool: - if not isinstance(other, CVE): - return False - return self.cve_id == other.cve_id + return isinstance(other, CVE) and self.cve_id == other.cve_id def __lt__(self, other: object) -> bool: if not isinstance(other, CVE): @@ -124,11 +107,35 @@ class CVE(PandasSerializableType, ComplexSerializableType): "cwe_ids": self.cwe_ids, } + @classmethod + def from_dict(cls, dct: dict[str, Any]) -> CVE: + date_to_take = ( + isoparse(dct["published_date"]) if isinstance(dct["published_date"], str) else dct["published_date"] + ) + return cls( + dct["cve_id"], + dct["vulnerable_cpes"], + dct["vulnerable_cpe_configurations"], + dct["impact"], + date_to_take, + dct["cwe_ids"], + ) + + @classmethod + def from_nist_dict(cls, dct: dict) -> CVE: + cve_id = dct["cve"]["CVE_data_meta"]["ID"] + impact = cls.Impact.from_nist_dict(dct) + published_date = isoparse(dct["publishedDate"]) + cwe_ids = cls.parse_cwe_data(dct) + cpes, cpe_configurations = CVE.get_cpe_data_from_nodes_list(dct["configurations"]["nodes"]) + + return cls(cve_id, cpes, cpe_configurations, impact, published_date, cwe_ids) + @staticmethod - def _parse_nist_cpe_dicts(lst: list[dict[str, Any]]) -> list[CPE]: + def _parse_nist_cpe_dicts(dictionaries: Iterable[dict[str, Any]]) -> list[CPE]: cpes: list[CPE] = [] - for x in lst: + for x in dictionaries: cpe_uri = x["cpe23Uri"] version_start: tuple[str, str] | None version_end: tuple[str, str] | None @@ -157,82 +164,51 @@ class CVE(PandasSerializableType, ComplexSerializableType): The <parse_only_vulnerable_cpes> parameter specifies if we want to parse only vulnerable CPEs or not. """ - cpe_dicts_to_be_parsed = cpe_list + return CVE._parse_nist_cpe_dicts(dct for dct in cpe_list if dct["vulnerable"] or not parse_only_vulnerable_cpes) - if parse_only_vulnerable_cpes: - cpe_dicts_to_be_parsed = [dct for dct in cpe_list if dct["vulnerable"]] + @staticmethod + def parse_cwe_data(dct: dict) -> set[str] | None: + descriptions = dct["cve"]["problemtype"]["problemtype_data"][0]["description"] + return {x["value"] for x in descriptions} if descriptions else None - return CVE._parse_nist_cpe_dicts(cpe_dicts_to_be_parsed) + @staticmethod + def get_cpe_data_from_nodes_list(lst: list) -> tuple[list[CPE], list[CPEConfiguration]]: + or_nodes = [x for x in lst if x["operator"] == "OR"] + and_nodes = [x for x in lst if x["operator"] == "AND"] + return CVE.get_simple_cpes_from_nodes_list(or_nodes), CVE.get_cpe_configurations_from_node_list(and_nodes) - @classmethod - def from_nist_dict(cls, dct: dict) -> CVE: + @staticmethod + def get_simple_cpes_from_nodes_list(lst: list) -> list[CPE]: + return list( + itertools.chain.from_iterable( + CVE._parse_nist_dict(node["cpe_match"], parse_only_vulnerable_cpes=True) for node in lst + ) + ) + + @staticmethod + def get_cpe_configurations_from_node_list(lst: list) -> list[CPEConfiguration]: """ - Will load CVE from dictionary defined at https://nvd.nist.gov/feeds/json/cve/1.1 + Retrieves only running on/with configurations, not the advanced ones. + See more at https://nvd.nist.gov/vuln/vulnerability-detail-pages, section `Configurations` """ + configurations = [CVE.get_cpe_confiugration_from_node(x) for x in lst] + return [x for x in configurations if x] - def get_cpe_configurations_from_and_cpe_dict(children: list[dict]) -> list[CPEConfiguration]: - configurations: list[CPEConfiguration] = [] - - if not children or len(children) != 2: - return configurations - - cpes = CVE._parse_nist_dict(children[0]["cpe_match"], True) - vulnerable_cpe_uris = {cpe.uri for cpe in cpes} - - if not cpes: - return configurations - - # Platform does not have to be vulnerable necessarily - platforms = CVE._parse_nist_dict(children[1]["cpe_match"], False) - - return [CPEConfiguration(platform.uri, vulnerable_cpe_uris) for platform in platforms] - - def get_vulnerable_cpes_from_nist_dict(dct: dict) -> list[list]: - def get_vulnerable_cpes_and_cpe_configurations( - node: dict, cpes: list[CPE], cpe_configurations: list[CPEConfiguration] - ) -> tuple[list[CPE], list[CPEConfiguration]]: - """ - Method traverses node of CPE tree and returns the list of CPEs and CPE configuratios, - which depends on if the parent node is OR/AND type. - """ - if node["operator"] == "AND": - cpe_configurations.extend(get_cpe_configurations_from_and_cpe_dict(node["children"])) - return cpes, cpe_configurations - - if "children" in node: - for child in node["children"]: - get_vulnerable_cpes_and_cpe_configurations(child, cpes, cpe_configurations) - - if "cpe_match" not in node: - return cpes, cpe_configurations - - candidates = node["cpe_match"] - cpes.extend(CVE._parse_nist_dict(candidates, True)) - - return cpes, cpe_configurations - - cpes_and_cpe_configurations = [ - get_vulnerable_cpes_and_cpe_configurations(x, [], []) for x in dct["configurations"]["nodes"] - ] + @staticmethod + def get_cpe_confiugration_from_node(node: dict) -> CPEConfiguration | None: + if node["children"]: + if len(node["children"]) != 2: + return None - return [list(t) for t in zip(*cpes_and_cpe_configurations)] + # Deep variant should have two children, get CPEs from the first one and declare that product, second is platform + cpes = CVE._parse_nist_dict(node["children"][0]["cpe_match"], parse_only_vulnerable_cpes=True) + platform = CVE._parse_nist_dict(node["children"][1]["cpe_match"], parse_only_vulnerable_cpes=False) + return CPEConfiguration(platform[0], cpes) + else: + # Shallow variant should have exactly 2 matching CPEs, we declare one a platform, second one the vuln. thing + cpes = CVE._parse_nist_dict(node["cpe_match"], parse_only_vulnerable_cpes=True) - cve_id = dct["cve"]["CVE_data_meta"]["ID"] - impact = cls.Impact.from_nist_dict(dct) - cpe_and_cpe_configurations = get_vulnerable_cpes_from_nist_dict(dct) - # There exist CVEs such as (CVE-2022-0177) which are rejected and do not contain any assinged CPEs - vulnerable_cpes = ( - set(itertools.chain.from_iterable(cpe_and_cpe_configurations[0])) if cpe_and_cpe_configurations else set() - ) - vulnerable_cpe_configurations = ( - set(itertools.chain.from_iterable(cpe_and_cpe_configurations[1])) if cpe_and_cpe_configurations else set() - ) - published_date = dct["publishedDate"] - cwe_ids = cls.parse_cwe_data(dct) + if len(cpes) != 2: + return None - return cls(cve_id, vulnerable_cpes, vulnerable_cpe_configurations, impact, published_date, cwe_ids) - - @staticmethod - def parse_cwe_data(dct: dict) -> set[str] | None: - descriptions = dct["cve"]["problemtype"]["problemtype_data"][0]["description"] - return {x["value"] for x in descriptions} if descriptions else None + return CPEConfiguration(cpes[0], [cpes[1]]) diff --git a/tests/cc/test_cc_analysis.py b/tests/cc/test_cc_analysis.py index a5b5e04a..a5088338 100644 --- a/tests/cc/test_cc_analysis.py +++ b/tests/cc/test_cc_analysis.py @@ -5,6 +5,7 @@ from pathlib import Path import pytest import tests.data.cc.analysis +from dateutil.parser import isoparse from sec_certs.cert_rules import SARS_IMPLIED_FROM_EAL from sec_certs.dataset import CCDataset @@ -55,24 +56,25 @@ def cpe_dset(cpes: set[CPE]) -> CPEDataset: @pytest.fixture(scope="module") -def cves(cpe_single_sign_on) -> set[CVE]: +def cves(cpe_single_sign_on: CPE, ibm_xss_cve: CVE) -> set[CVE]: return { CVE( "CVE-2017-1732", - {cpe_single_sign_on}, - set(), + [cpe_single_sign_on], + [], CVE.Impact(5.3, "MEDIUM", 3.9, 1.4), - "2021-05-26T04:15Z", + isoparse("2021-05-26T04:15Z"), {"CWE-200"}, ), CVE( "CVE-2019-4513", - {cpe_single_sign_on}, - set(), + [cpe_single_sign_on], + [], CVE.Impact(8.2, "HIGH", 3.9, 4.2), - "2000-05-26T04:15Z", + isoparse("2000-05-26T04:15Z"), {"CVE-611"}, ), + ibm_xss_cve, } @@ -97,13 +99,6 @@ def cc_dset(data_dir: Path, cve_dset: CVEDataset, tmp_path_factory) -> CCDataset return cc_dset -@pytest.fixture(scope="module") -def cve_config_dset(ibm_xss_cve) -> CVEDataset: - cve_dset = CVEDataset({ibm_xss_cve.cve_id: ibm_xss_cve}) - cve_dset.build_lookup_dict(use_nist_mapping=False) - return cve_dset - - @pytest.fixture def reference_dataset(data_dir) -> CCDataset: return CCDataset.from_json(data_dir / "reference_dataset.json") @@ -117,20 +112,20 @@ def transitive_vulnerability_dataset(data_dir) -> CCDataset: @pytest.fixture(scope="module") def ibm_cpe_configuration() -> CPEConfiguration: return CPEConfiguration( - "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", - { - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - }, + CPE("cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*"), + [ + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*"), + ], ) @@ -138,33 +133,25 @@ def ibm_cpe_configuration() -> CPEConfiguration: def ibm_xss_cve(ibm_cpe_configuration) -> CVE: return CVE( "CVE-2010-2325", - set(), - {ibm_cpe_configuration}, + [], + [ibm_cpe_configuration], CVE.Impact(4.3, "MEDIUM", 2.9, 8.6), - "2000-06-18T04:15Z", + isoparse("2000-06-18T04:15Z"), {"CWE-79"}, ) -@pytest.fixture(scope="module") -def cpes_ibm_websphere_app_with_platform() -> set[CPE]: - return { - CPE("cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", "IBM zOS"), - CPE("cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", "IBM WebSphere Application Server"), - } - - def test_find_related_cves_for_cpe_configuration( cc_dset: CCDataset, - cpes_ibm_websphere_app_with_platform: set[CPE], ibm_xss_cve: CVE, - cve_config_dset: CVEDataset, ): cert = cc_dset["37e1b22e5933b0ed"] - cert.heuristics.cpe_matches = {cve.uri for cve in cpes_ibm_websphere_app_with_platform} - cc_dset.auxiliary_datasets.cve_dset = cve_config_dset + cert.heuristics.cpe_matches = { + "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", + "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", + } cc_dset.compute_related_cves() - assert {ibm_xss_cve.cve_id} == cert.heuristics.related_cves + assert cert.heuristics.related_cves == {ibm_xss_cve.cve_id} @pytest.fixture @@ -181,7 +168,7 @@ def test_find_related_cves( ): random_certificate.heuristics.cpe_matches = {cpe_single_sign_on.uri} cc_dset.compute_related_cves() - assert {x.cve_id for x in cves} == random_certificate.heuristics.related_cves + assert {"CVE-2017-1732", "CVE-2019-4513"} == random_certificate.heuristics.related_cves def test_version_extraction(random_certificate: CCCertificate): diff --git a/tests/data/cc/analysis/auxiliary_datasets/cve_dataset.json b/tests/data/cc/analysis/auxiliary_datasets/cve_dataset.json index 4caf45d1..6d27b918 100644 --- a/tests/data/cc/analysis/auxiliary_datasets/cve_dataset.json +++ b/tests/data/cc/analysis/auxiliary_datasets/cve_dataset.json @@ -8,7 +8,7 @@ { "_type": "sec_certs.sample.cpe.CPE", "uri": "cpe:2.3:a:ibm:security_access_manager_for_enterprise_single_sign-on:8.2.2:*:*:*:*:*:*:*", - "title": "IBM Security Access Manager For Enterprise Single Sign-On 8.2.2", + "title": null, "start_version": null, "end_version": null } @@ -21,7 +21,7 @@ "exploitability_score": 3.9, "impact_score": 1.4 }, - "published_date": "2021-05-26T04:15Z", + "published_date": "2018-08-17T16:29:00+00:00", "cwe_ids": { "_type": "Set", "elements": [ @@ -36,7 +36,7 @@ { "_type": "sec_certs.sample.cpe.CPE", "uri": "cpe:2.3:a:ibm:security_access_manager_for_enterprise_single_sign-on:8.2.2:*:*:*:*:*:*:*", - "title": "IBM Security Access Manager For Enterprise Single Sign-On 8.2.2", + "title": null, "start_version": null, "end_version": null } @@ -49,7 +49,7 @@ "exploitability_score": 3.9, "impact_score": 4.2 }, - "published_date": "2000-05-26T04:15Z", + "published_date": "2019-08-26T15:15:00+00:00", "cwe_ids": { "_type": "Set", "elements": [ @@ -64,23 +64,95 @@ "vulnerable_cpe_configurations": [ { "_type": "sec_certs.sample.cpe.CPEConfiguration", - "platform": "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", - "cpes": { - "_type": "Set", - "elements": [ - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*" - ] - } + "platform": { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + "cpes": [ + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": [ + "including", + "7.0.0.10" + ] + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + } + ] } ], "impact": { @@ -97,6 +169,389 @@ "CWE-79" ] } + }, + "CVE-2003-0001": { + "_type": "sec_certs.sample.cve.CVE", + "cve_id": "CVE-2003-0001", + "vulnerable_cpes": [ + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.15:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:netbsd:netbsd:1.5.3:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:sp1:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:netbsd:netbsd:1.6:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.11:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:netbsd:netbsd:1.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.12:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.13:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000:*:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.7:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.16:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000:*:sp1:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.19:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.9:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000:*:sp2:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:netbsd:netbsd:1.5.1:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.10:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.17:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.7:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.8:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.4:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.14:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:netbsd:netbsd:1.5.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.1:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.6:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.4:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.6:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:freebsd:freebsd:4.3:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.18:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:sp2:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.20:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:o:linux:linux_kernel:2.4.3:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + } + ], + "vulnerable_cpe_configurations": [], + "impact": { + "_type": "sec_certs.sample.cve.CVE.Impact", + "base_score": 5.0, + "severity": "MEDIUM", + "exploitability_score": 10.0, + "impact_score": 2.9 + }, + "published_date": "2003-01-17T05:00:00+00:00", + "cwe_ids": { + "_type": "Set", + "elements": [ + "CWE-200" + ] + } + }, + "CVE-2003-0070": { + "_type": "sec_certs.sample.cve.CVE", + "cve_id": "CVE-2003-0070", + "vulnerable_cpes": [], + "vulnerable_cpe_configurations": [ + { + "_type": "sec_certs.sample.cpe.CPEConfiguration", + "platform": { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:gnome:gnome-terminal:2.0:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + "cpes": [ + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.15.0:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.14.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.17.4:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.12.2:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.24.3:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.22.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.16.14:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.11.21:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.20.5:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + }, + { + "_type": "sec_certs.sample.cpe.CPE", + "uri": "cpe:2.3:a:nalin_dahyabhai:vte:0.25.1:*:*:*:*:*:*:*", + "title": null, + "start_version": null, + "end_version": null + } + ] + } + ], + "impact": { + "_type": "sec_certs.sample.cve.CVE.Impact", + "base_score": 6.8, + "severity": "MEDIUM", + "exploitability_score": 8.6, + "impact_score": 6.4 + }, + "published_date": "2003-03-03T05:00:00+00:00", + "cwe_ids": { + "_type": "Set", + "elements": [ + "NVD-CWE-Other" + ] + } } } }
\ No newline at end of file diff --git a/tests/data/cc/analysis/auxiliary_datasets/cve_dset_with_cpe_configs.json b/tests/data/cc/analysis/auxiliary_datasets/cve_dset_with_cpe_configs.json deleted file mode 100644 index 32d188f5..00000000 --- a/tests/data/cc/analysis/auxiliary_datasets/cve_dset_with_cpe_configs.json +++ /dev/null @@ -1,385 +0,0 @@ -{ - "_type": "sec_certs.dataset.cve.CVEDataset", - "cves": { - "CVE-2003-0001": { - "_type": "sec_certs.sample.cve.CVE", - "cve_id": "CVE-2003-0001", - "vulnerable_cpes": [ - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.15:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:netbsd:netbsd:1.5.3:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:sp1:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:netbsd:netbsd:1.6:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.11:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:netbsd:netbsd:1.5:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.12:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.13:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000:*:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.7:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.16:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.5:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000:*:sp1:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.2:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.19:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.2:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.9:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000:*:sp2:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:netbsd:netbsd:1.5.1:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.10:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.17:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.7:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.8:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.4:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.5:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.14:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:netbsd:netbsd:1.5.2:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.1:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.6:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.4:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.6:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:freebsd:freebsd:4.3:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.18:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:microsoft:windows_2000_terminal_services:*:sp2:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.20:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - }, - { - "_type": "sec_certs.sample.cpe.CPE", - "uri": "cpe:2.3:o:linux:linux_kernel:2.4.3:*:*:*:*:*:*:*", - "title": null, - "start_version": null, - "end_version": null - } - ], - "vulnerable_cpe_configurations": [], - "impact": { - "_type": "sec_certs.sample.cve.CVE.Impact", - "base_score": 5.0, - "severity": "MEDIUM", - "exploitability_score": 10.0, - "impact_score": 2.9 - }, - "published_date": "2003-01-17T05:00:00+00:00", - "cwe_ids": { - "_type": "Set", - "elements": [ - "CWE-200" - ] - } - }, - "CVE-2003-0070": { - "_type": "sec_certs.sample.cve.CVE", - "cve_id": "CVE-2003-0070", - "vulnerable_cpes": [], - "vulnerable_cpe_configurations": [ - { - "_type": "sec_certs.sample.cpe.CPEConfiguration", - "platform": "cpe:2.3:a:gnome:gnome-terminal:2.0:*:*:*:*:*:*:*", - "cpes": { - "_type": "Set", - "elements": [ - "cpe:2.3:a:nalin_dahyabhai:vte:0.11.21:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.12.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.14.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.15.0:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.16.14:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.17.4:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.20.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.22.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.24.3:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.25.1:*:*:*:*:*:*:*" - ] - } - }, - { - "_type": "sec_certs.sample.cpe.CPEConfiguration", - "platform": "cpe:2.3:a:gnome:gnome-terminal:2.2:*:*:*:*:*:*:*", - "cpes": { - "_type": "Set", - "elements": [ - "cpe:2.3:a:nalin_dahyabhai:vte:0.11.21:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.12.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.14.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.15.0:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.16.14:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.17.4:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.20.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.22.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.24.3:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.25.1:*:*:*:*:*:*:*" - ] - } - } - ], - "impact": { - "_type": "sec_certs.sample.cve.CVE.Impact", - "base_score": 6.8, - "severity": "MEDIUM", - "exploitability_score": 8.6, - "impact_score": 6.4 - }, - "published_date": "2003-03-03T05:00:00+00:00", - "cwe_ids": { - "_type": "Set", - "elements": [ - "NVD-CWE-Other" - ] - } - }, - "CVE-2010-2325": { - "_type": "sec_certs.sample.cve.CVE", - "cve_id": "CVE-2010-2325", - "vulnerable_cpes": [], - "vulnerable_cpe_configurations": [ - { - "_type": "sec_certs.sample.cpe.CPEConfiguration", - "platform": "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", - "cpes": { - "_type": "Set", - "elements": [ - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*" - ] - } - } - ], - "impact": { - "_type": "sec_certs.sample.cve.CVE.Impact", - "base_score": 4.3, - "severity": "MEDIUM", - "exploitability_score": 8.6, - "impact_score": 2.9 - }, - "published_date": "2010-06-18T18:30:00+00:00", - "cwe_ids": { - "_type": "Set", - "elements": [ - "CWE-79" - ] - } - } - } -}
\ No newline at end of file diff --git a/tests/fips/test_fips_analysis.py b/tests/fips/test_fips_analysis.py index 6c5b032e..90de70f0 100644 --- a/tests/fips/test_fips_analysis.py +++ b/tests/fips/test_fips_analysis.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest import tests.data.fips.dataset +from dateutil.parser import isoparse from sec_certs.dataset import CPEDataset, CVEDataset from sec_certs.dataset.fips import FIPSDataset @@ -33,10 +34,10 @@ def some_random_cpe() -> CPE: def cve(vulnerable_cpe: CPE) -> CVE: return CVE( "CVE-1234-123456", - {vulnerable_cpe}, - set(), + [vulnerable_cpe], + [], CVE.Impact(10, "HIGH", 10, 10), - "2021-05-26T04:15Z", + isoparse("2021-05-26T04:15Z"), {"CWE-200"}, ) @@ -45,31 +46,31 @@ def cve(vulnerable_cpe: CPE) -> CVE: def some_other_cve(some_random_cpe: CPE) -> CVE: return CVE( "CVE-2019-4513", - {some_random_cpe}, - set(), + [some_random_cpe], + [], CVE.Impact(8.2, "HIGH", 3.9, 4.2), - "2000-05-26T04:15Z", + isoparse("2000-05-26T04:15Z"), {"CVE-611"}, ) @pytest.fixture(scope="module") -def ibm_cpe_configurations() -> CPEConfiguration: +def ibm_cpe_configuration() -> CPEConfiguration: return CPEConfiguration( - "cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", - { - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - }, + CPE("cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*"), + [ + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*"), + ], ) @@ -82,13 +83,13 @@ def cpes_ibm_websphere_app_with_platform() -> set[CPE]: @pytest.fixture(scope="module") -def ibm_xss_cve(ibm_cpe_configurations) -> CVE: +def ibm_xss_cve(ibm_cpe_configuration: CPEConfiguration) -> CVE: return CVE( "CVE-2010-2325", - set(), - {ibm_cpe_configurations}, + [], + [ibm_cpe_configuration], CVE.Impact(4.3, "MEDIUM", 2.9, 8.6), - "2000-06-18T04:15Z", + isoparse("2000-06-18T04:15Z"), {"CWE-79"}, ) @@ -131,7 +132,7 @@ def toy_static_dataset(data_dir: Path) -> FIPSDataset: def processed_dataset( toy_static_dataset: FIPSDataset, cpe_dataset: CPEDataset, cve_dataset: CVEDataset, tmp_path_factory ) -> FIPSDataset: - tmp_dir = tmp_path_factory.mktemp("cc_dset") + tmp_dir = tmp_path_factory.mktemp("fips_dset") toy_static_dataset.copy_dataset(tmp_dir) tested_certs = [ @@ -270,10 +271,10 @@ def test_find_related_cves_for_cpe_configuration( ): cve_dataset.cves = {ibm_xss_cve.cve_id: ibm_xss_cve} cert = processed_dataset["2441"] - cert.heuristics.cpe_matches = {cve.uri for cve in cpes_ibm_websphere_app_with_platform} + cert.heuristics.cpe_matches = {cpe.uri for cpe in cpes_ibm_websphere_app_with_platform} processed_dataset.auxiliary_datasets.cve_dset = cve_dataset processed_dataset.compute_related_cves() - assert {ibm_xss_cve.cve_id} == cert.heuristics.related_cves + assert cert.heuristics.related_cves == {ibm_xss_cve.cve_id} def test_keywords_heuristics(processed_dataset: FIPSDataset): diff --git a/tests/test_cpe.py b/tests/test_cpe.py index 9cee5459..52b5acb0 100644 --- a/tests/test_cpe.py +++ b/tests/test_cpe.py @@ -18,18 +18,13 @@ def cpe_dset_path() -> Path: @pytest.fixture(scope="module") -def cve_dset_with_cpe_configs_path() -> Path: - return Path(tests.data.cc.analysis.auxiliary_datasets.__path__[0]) / "cve_dset_with_cpe_configs.json" - - -@pytest.fixture(scope="module") def cpe_dset(cpe_dset_path: Path) -> CPEDataset: return CPEDataset.from_json(cpe_dset_path) @pytest.fixture(scope="module") -def cve_dset_with_cpe_configs(cve_dset_with_cpe_configs_path: Path) -> CVEDataset: - return CVEDataset.from_json(cve_dset_with_cpe_configs_path) +def cve_dataset() -> CVEDataset: + return CVEDataset.from_json(Path(tests.data.cc.analysis.auxiliary_datasets.__path__[0]) / "cve_dataset.json") @pytest.fixture(scope="module") @@ -150,57 +145,27 @@ def test_serialization_missing_path(): dummy_dset.to_json() -def test_single_platform_config_cpe(cve_dset_with_cpe_configs: CVEDataset): - tested_cpe_config = cve_dset_with_cpe_configs["CVE-2010-2325"].vulnerable_cpe_configurations - cpe_set = { - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - } - cpe_config = CPEConfiguration( - platform="cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", - cpes=cpe_set, +def test_single_platform_config_cpe(cve_dataset: CVEDataset): + tested_cpe_config = cve_dataset["CVE-2010-2325"].vulnerable_cpe_configurations + cpe_configuration = CPEConfiguration( + platform=CPE("cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*"), + cpes=[ + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", end_version=("including", "7.0.0.10")), + ], ) - assert cpe_config in tested_cpe_config - - -def test_multiple_platform_config_cpe(cve_dset_with_cpe_configs: CVEDataset): - tested_cpe_configs = cve_dset_with_cpe_configs["CVE-2003-0070"].vulnerable_cpe_configurations - cpe_set = { - "cpe:2.3:a:nalin_dahyabhai:vte:0.11.21:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.12.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.14.2:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.15.0:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.16.14:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.17.4:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.20.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.22.5:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.24.3:*:*:*:*:*:*:*", - "cpe:2.3:a:nalin_dahyabhai:vte:0.25.1:*:*:*:*:*:*:*", - } - cpe_configs = [ - CPEConfiguration( - platform="cpe:2.3:a:gnome:gnome-terminal:2.0:*:*:*:*:*:*:*", - cpes=cpe_set, - ), - CPEConfiguration( - platform="cpe:2.3:a:gnome:gnome-terminal:2.2:*:*:*:*:*:*:*", - cpes=cpe_set, - ), - ] - for cpe_config in cpe_configs: - assert cpe_config in tested_cpe_configs + assert cpe_configuration in tested_cpe_config -def test_no_cpe_configuration(cve_dset_with_cpe_configs: CVEDataset): - tested_cpe_configs = cve_dset_with_cpe_configs["CVE-2003-0001"].vulnerable_cpe_configurations - assert tested_cpe_configs == [] +def test_no_cpe_configuration(cve_dataset: CVEDataset): + assert not cve_dataset["CVE-2003-0001"].vulnerable_cpe_configurations diff --git a/tests/test_cve.py b/tests/test_cve.py index 0382974a..7d21f2cd 100644 --- a/tests/test_cve.py +++ b/tests/test_cve.py @@ -4,6 +4,7 @@ from pathlib import Path from typing import Any import pytest +from dateutil.parser import isoparse import tests.data.cc.analysis.auxiliary_datasets from sec_certs.dataset import CVEDataset @@ -12,16 +13,6 @@ from sec_certs.sample.cpe import CPE from sec_certs.serialization.json import SerializationError -@pytest.mark.slow -@pytest.mark.monitor_test -@pytest.mark.xfail(reason="May fail due to errors on NIST server.") -def test_from_web(): - dset = CVEDataset.from_web() - assert dset is not None - assert "CVE-2019-15809" in dset.cves - assert "CVE-2017-15361" in dset.cves - - @pytest.fixture(scope="module") def cve_dataset_path() -> Path: return Path(tests.data.cc.analysis.auxiliary_datasets.__path__[0]) / "cve_dataset.json" @@ -60,20 +51,20 @@ def cve_dict() -> dict[str, Any]: @pytest.fixture(scope="module") -def cve_2010_2325_cpe_configs(): - return { - "cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*", - "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", - } +def cve_2010_2325_cpe_configs() -> list[CPE]: + return [ + CPE("cpe:2.3:a:ibm:websphere_application_server:*:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.2:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.3:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.4:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.5:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.6:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.7:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.8:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0.0.9:*:*:*:*:*:*:*"), + CPE("cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*"), + ] @pytest.fixture(scope="module") @@ -86,32 +77,42 @@ def cves(cve_2010_2325_cpe_configs) -> list[CVE]: return [ CVE( "CVE-2017-1732", - {cpe_single_sign_on}, - set(), + [cpe_single_sign_on], + [], CVE.Impact(5.3, "MEDIUM", 3.9, 1.4), - "2021-05-26T04:15Z", + isoparse("2021-05-26T04:15Z"), {"CWE-200"}, ), CVE( "CVE-2019-4513", - {cpe_single_sign_on}, - set(), + [cpe_single_sign_on], + [], CVE.Impact(8.2, "HIGH", 3.9, 4.2), - "2000-05-26T04:15Z", + isoparse("2000-05-26T04:15Z"), {"CWE-611"}, ), CVE( "CVE-2010-2325", - set(), + [], cve_2010_2325_cpe_configs, CVE.Impact(4.3, "MEDIUM", 8.6, 2.9), - "2010-06-18T18:30", + isoparse("2010-06-18T18:30"), {"CWE-79"}, ), ] -def test_cve_dset_lookup_dicts(cves: list[CVE], cve_dset: CVEDataset): +@pytest.mark.slow +@pytest.mark.monitor_test +@pytest.mark.xfail(reason="May fail due to errors on NIST server.") +def test_from_web(): + dset = CVEDataset.from_web() + assert dset is not None + assert "CVE-2019-15809" in dset.cves + assert "CVE-2017-15361" in dset.cves + + +def test_cve_dset_lookup_dicts(cve_dset: CVEDataset): alt_lookup = {x: set(y) for x, y in cve_dset.cpe_to_cve_ids_lookup.items()} assert alt_lookup == { "cpe:2.3:a:ibm:security_access_manager_for_enterprise_single_sign-on:8.2.2:*:*:*:*:*:*:*": { @@ -123,7 +124,7 @@ def test_cve_dset_lookup_dicts(cves: list[CVE], cve_dset: CVEDataset): def test_cve_dset_from_json(cve_dataset_path: Path, cve_dset: CVEDataset): dset = CVEDataset.from_json(cve_dataset_path) - assert dset == cve_dset + assert all(x in dset for x in cve_dset) def test_cve_from_to_dict(cve_dict: dict[str, Any]): |
