73 lines
4.1 KiB
Python
73 lines
4.1 KiB
Python
import pytest
|
|
|
|
from vuln_mcp.sources.parsers import parse
|
|
|
|
|
|
CVE = 'CVE-2024-25522'
|
|
CISA = '134c704f-9b21-4f2e-91b3-4a467353bcc0'
|
|
DATE = '2024-05-24T15:01:21Z'
|
|
|
|
|
|
def record(value, authority=CISA, subject=CVE):
|
|
return {'dataType': 'CVE_RECORD', 'dataVersion': '5.1', 'cveMetadata': {'cveId': CVE, 'state': 'PUBLISHED'},
|
|
'containers': {'cna': {'providerMetadata': {'shortName': 'Maintainer'}, 'references': [
|
|
{'url': 'https://www.exploit-db.com/exploits/123', 'tags': ['exploit']},
|
|
{'url': 'https://support.example.org/advisory.pdf', 'tags': ['vendor-advisory']},
|
|
{'url': 'https://support.example.org/example.py', 'tags': ['vendor-advisory']},
|
|
{'url': 'https://github.com/example/pkg/commit/' + 'a' * 40 + '.patch', 'tags': ['patch']}]},
|
|
'adp': [{'providerMetadata': {'orgId': authority}, 'metrics': [{'other': {'type': 'ssvc', 'content': {
|
|
'id': subject, 'options': [{'Exploitation': value}], 'timestamp': DATE}}}]}]}}
|
|
|
|
|
|
def _profile(cna_extra=None, ssvc=None, part='a'):
|
|
raw = {'dataType': 'CVE_RECORD', 'dataVersion': '5.1', 'cveMetadata': {'cveId': CVE, 'state': 'PUBLISHED'},
|
|
'containers': {'cna': {'providerMetadata': {'shortName': 'x'},
|
|
'affected': [{'cpes': [f'cpe:2.3:{part}:acme:portal:1.0:*:*:*:*:*:*:*'],
|
|
'versions': [{'version': '1.0', 'status': 'affected'}]}],
|
|
'metrics': [{'cvssV3_1': {'vectorString': 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H',
|
|
'baseScore': 9.8}}]} | (cna_extra or {})}}
|
|
if ssvc:
|
|
raw['containers']['adp'] = [{'providerMetadata': {'orgId': CISA}, 'metrics': [
|
|
{'other': {'type': 'ssvc', 'content': {'id': CVE, 'options': ssvc}}}]}]
|
|
return parse('cvelist', raw, 'https://www.cve.org/').issues[0].facts.get('exploitation') or {}
|
|
|
|
|
|
def test_path_interaction_and_component_role_are_extracted():
|
|
assert _profile() == {'cvss_av': 'N', 'cvss_pr': 'N', 'cvss_ui': 'N', 'component_role': 'application'}
|
|
|
|
|
|
def test_cisa_decision_points_fill_only_absent_keys():
|
|
facts = _profile(ssvc=[{'Exploitation': 'active'}, {'Automatable': 'yes'}, {'Technical Impact': 'total'}])
|
|
assert (facts['automatable'], facts['technical_impact'], facts['cvss_av']) == ('yes', 'total', 'N')
|
|
|
|
|
|
def test_platform_component_is_not_reported_as_application():
|
|
assert _profile(part='o')['component_role'] == 'operating_system'
|
|
|
|
|
|
def test_partial_vector_and_absent_ssvc_leave_keys_out():
|
|
raw = {'dataType': 'CVE_RECORD', 'dataVersion': '5.1', 'cveMetadata': {'cveId': CVE, 'state': 'PUBLISHED'},
|
|
'containers': {'cna': {'providerMetadata': {'shortName': 'x'}, 'metrics': [
|
|
{'cvssV3_1': {'vectorString': 'CVSS:3.1/AV:L/AC:H', 'baseScore': 1.0}}]}}}
|
|
facts = parse('cvelist', raw, 'https://www.cve.org/').issues[0].facts.get('exploitation')
|
|
assert facts == {'cvss_av': 'L'}
|
|
|
|
|
|
@pytest.mark.parametrize(('value', 'normalized'), [('poc', 'public_poc'), ('active', 'observed_in_wild'), ('none', 'none_reported')])
|
|
def test_publication_and_cisa_assessment_are_independent(value, normalized):
|
|
doc = parse('cvelist', record(value), 'https://www.cve.org/')
|
|
issue, = doc.issues
|
|
assert issue.facts['exploitation_evidence'] == [
|
|
{'publisher': 'Maintainer', 'catalog': 'Exploit-DB', 'status': 'public_poc'},
|
|
{'publisher': 'CISA-ADP', 'assessment': 'SSVC', 'date': DATE, 'status': normalized}]
|
|
assert [(r['type'], r['url']) for r in issue.refs] == [
|
|
('advisory_pdf','https://support.example.org/advisory.pdf'),
|
|
('fix_patch','https://github.com/example/pkg/commit/' + 'a'*40 + '.patch')]
|
|
assert 'exploit-db.com/' not in doc.model_dump_json()
|
|
|
|
|
|
@pytest.mark.parametrize(('org','subject'), [('other', CVE), (CISA, 'CVE-2024-25523')])
|
|
def test_no_cisa_attribution_for_unrelated_assessment(org, subject):
|
|
issue, = parse('cvelist', record('active', org, subject), 'https://www.cve.org/').issues
|
|
assert all(e['status'] != 'observed_in_wild' for e in issue.facts['exploitation_evidence'])
|