arango-cve-processor 1.2.5__tar.gz → 1.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/.github/workflows/run-tests.yml +1 -1
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/PKG-INFO +1 -1
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/__main__.py +11 -5
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/config.py +7 -6
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/base_manager.py +16 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cpe_match.py +4 -1
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_epss.py +50 -73
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_kev.py +11 -12
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_kev_vulncheck.py +2 -5
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/cpe.py +50 -16
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/cpe_db.py +15 -9
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/epss.py +17 -12
- arango_cve_processor-1.2.7/arango_cve_processor/tools/retriever.py +71 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/utils.py +9 -5
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/README.md +5 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cpematch.md +4 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-attack.md +2 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-capec.md +2 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-cwe.md +2 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-epss.md +18 -1
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-kev.md +18 -3
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/cve-vulncheck-kev.md +20 -5
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/pyproject.toml +1 -1
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_base.py +8 -7
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cpematch.py +10 -5
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_attack.py +2 -18
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_capec.py +3 -3
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_cwe.py +2 -2
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_epss.py +14 -25
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_kev_cisa.py +16 -9
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/managers/test_cve_kev_vulncheck.py +13 -9
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/tools/test_cpe.py +72 -4
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/tools/test_utils.py +1 -1
- arango_cve_processor-1.2.5/arango_cve_processor/tools/retriever.py +0 -62
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/.env.example +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/.env.markdown +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/.github/workflows/create-release.yml +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/.gitignore +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/LICENSE +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/README.md +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/__init__.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/__init__.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_attack.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_capec.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_cwe.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/__init__.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/docs/arango_cve_processor.png +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/requirements.txt +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/NOTES.md +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/README.md +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/__init__.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/attack-enterprise-objects.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/base_cves.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/base_cves_update_1.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/base_cves_update_2.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/capec-objects.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/cves.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/files/cwe-objects.json +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/requirements.txt +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/tests.env +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/cli/test_main.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/conftest.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/tools/test_epss.py +0 -0
- {arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/tests/unit/utils.py +0 -0
|
@@ -61,7 +61,7 @@ jobs:
|
|
|
61
61
|
- name: Run tests
|
|
62
62
|
id: run_tests
|
|
63
63
|
run: |
|
|
64
|
-
pytest --cov=arango_cve_processor --cov-branch --cov-report=xml --junitxml=junit.xml -o junit_family=legacy tests/unit
|
|
64
|
+
pytest --cov=arango_cve_processor --cov-branch --cov-report=xml --junitxml=junit.xml -o junit_family=legacy tests/unit -v
|
|
65
65
|
|
|
66
66
|
- name: Upload coverage reports to Codecov
|
|
67
67
|
id: upload_unit_test_coverage
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: arango_cve_processor
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.7
|
|
4
4
|
Summary: A small python script that enriches Vulnerability STIX Objects with other intel
|
|
5
5
|
Project-URL: Homepage, https://github.com/muchdogesec/arango_cve_processor
|
|
6
6
|
Project-URL: Issues, https://github.com/muchdogesec/arango_cve_processor/issues
|
|
@@ -101,7 +101,11 @@ def parse_arguments():
|
|
|
101
101
|
for mode in RELATION_MANAGERS.values():
|
|
102
102
|
p = subparser.add_parser(mode.relationship_note, description=mode.DESCRIPTION)
|
|
103
103
|
for k, action in actions.items():
|
|
104
|
-
if k in ["created_min", "modified_min"] and mode in [
|
|
104
|
+
if k in ["created_min", "modified_min"] and mode in [
|
|
105
|
+
CpeMatchUpdateManager,
|
|
106
|
+
CISAKevManager,
|
|
107
|
+
VulnCheckKevManager,
|
|
108
|
+
]:
|
|
105
109
|
continue
|
|
106
110
|
p._add_action(action)
|
|
107
111
|
|
|
@@ -120,7 +124,7 @@ def parse_arguments():
|
|
|
120
124
|
required=False,
|
|
121
125
|
help="Date to end backfilling epss at, only applies to `cve-epss-backfill` mode",
|
|
122
126
|
)
|
|
123
|
-
|
|
127
|
+
|
|
124
128
|
if mode == CpeMatchUpdateManager:
|
|
125
129
|
p.add_argument(
|
|
126
130
|
"--updated_after",
|
|
@@ -149,9 +153,11 @@ def run_all(database=None, modes: list[str] = None, **kwargs):
|
|
|
149
153
|
|
|
150
154
|
import_default_objects(
|
|
151
155
|
processor,
|
|
152
|
-
default_objects=tuple(
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
default_objects=tuple(
|
|
157
|
+
itertools.chain(
|
|
158
|
+
*[RELATION_MANAGERS[mode].default_objects for mode in modes]
|
|
159
|
+
)
|
|
160
|
+
),
|
|
155
161
|
)
|
|
156
162
|
manager_klasses = sorted(
|
|
157
163
|
[RELATION_MANAGERS[mode] for mode in modes],
|
|
@@ -16,16 +16,17 @@ ARANGODB_PASSWORD = os.getenv("ARANGODB_PASSWORD")
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
namespace = UUID("152ecfe1-5015-522b-97e4-86b60c57036d")
|
|
19
|
-
|
|
19
|
+
MARKING_DEF_URL = "https://github.com/muchdogesec/stix4doge/raw/main/objects/marking-definition/arango_cve_processor.json" # this is arango_cve_processor marking-definition
|
|
20
|
+
IDENTITY_URL = "https://github.com/muchdogesec/stix4doge/raw/main/objects/identity/dogesec.json" # this is dogesec identity
|
|
20
21
|
DEFAULT_OBJECT_URL = [
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
MARKING_DEF_URL,
|
|
23
|
+
IDENTITY_URL,
|
|
23
24
|
]
|
|
24
25
|
|
|
25
|
-
OBJECT_MARKING_REFS=[
|
|
26
|
+
OBJECT_MARKING_REFS = [
|
|
26
27
|
"marking-definition--94868c89-83c2-464b-929b-a1a8aa3c8487",
|
|
27
|
-
"marking-definition--152ecfe1-5015-522b-97e4-86b60c57036d"
|
|
28
|
+
"marking-definition--152ecfe1-5015-522b-97e4-86b60c57036d",
|
|
28
29
|
]
|
|
29
|
-
IDENTITY_REF = "identity--
|
|
30
|
+
IDENTITY_REF = "identity--9779a2db-f98c-5f4b-8d08-8ee04e02dbb5"
|
|
30
31
|
|
|
31
32
|
EPSS_API_ENDPOINT = "https://api.first.org/data/v1/epss"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from datetime import UTC, datetime
|
|
1
2
|
import itertools
|
|
2
3
|
import logging
|
|
3
4
|
from types import SimpleNamespace
|
|
@@ -10,6 +11,7 @@ from stix2arango.services.arangodb_service import ArangoDBService
|
|
|
10
11
|
|
|
11
12
|
from arango_cve_processor.tools import utils
|
|
12
13
|
from arango_cve_processor.tools.utils import (
|
|
14
|
+
chunked_tqdm,
|
|
13
15
|
generate_md5,
|
|
14
16
|
genrate_relationship_id,
|
|
15
17
|
get_embedded_refs,
|
|
@@ -62,6 +64,8 @@ class STIXRelationManager:
|
|
|
62
64
|
self.kwargs = kwargs
|
|
63
65
|
self.ignore_embedded_relationships_smo = ignore_embedded_relationships_smo
|
|
64
66
|
self.ignore_embedded_relationships_sro = ignore_embedded_relationships_sro
|
|
67
|
+
self.update_objects = []
|
|
68
|
+
|
|
65
69
|
|
|
66
70
|
@property
|
|
67
71
|
def collection(self):
|
|
@@ -93,6 +97,18 @@ class STIXRelationManager:
|
|
|
93
97
|
)
|
|
94
98
|
|
|
95
99
|
def upload_vertex_data(self, objects):
|
|
100
|
+
if self.update_objects:
|
|
101
|
+
modified_at = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
102
|
+
for obj in self.update_objects:
|
|
103
|
+
obj.update(_record_modified=modified_at)
|
|
104
|
+
|
|
105
|
+
logging.info("updating %d existing reports", len(self.update_objects))
|
|
106
|
+
for batch in chunked_tqdm(self.update_objects, n=10_000, description='update existing objects'):
|
|
107
|
+
self.arango.db.collection(self.vertex_collection).update_many(
|
|
108
|
+
batch
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
self.update_objects.clear()
|
|
96
112
|
logging.info("uploading %d vertices", len(objects))
|
|
97
113
|
for obj in objects:
|
|
98
114
|
obj["_arango_cve_processor_note"] = self.relationship_note
|
{arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cpe_match.py
RENAMED
|
@@ -41,6 +41,7 @@ class CpeMatchUpdateManager(STIXRelationManager, relationship_note="cpematch"):
|
|
|
41
41
|
if isinstance(self.updated_after, (datetime, date)):
|
|
42
42
|
self.updated_after = self.updated_after.isoformat()
|
|
43
43
|
self.ignore_embedded_relationships = True
|
|
44
|
+
self.updated_before = datetime.now(UTC).isoformat()
|
|
44
45
|
|
|
45
46
|
def get_updated_cpematches(self):
|
|
46
47
|
total_results = math.inf
|
|
@@ -49,7 +50,7 @@ class CpeMatchUpdateManager(STIXRelationManager, relationship_note="cpematch"):
|
|
|
49
50
|
if self.updated_after:
|
|
50
51
|
query.update(
|
|
51
52
|
lastModStartDate=self.updated_after,
|
|
52
|
-
lastModEndDate=
|
|
53
|
+
lastModEndDate=self.updated_before,
|
|
53
54
|
)
|
|
54
55
|
|
|
55
56
|
iterator = tqdm(total=1, desc="retrieve cpematch from nvd")
|
|
@@ -129,8 +130,10 @@ class CpeMatchUpdateManager(STIXRelationManager, relationship_note="cpematch"):
|
|
|
129
130
|
objects = cpe.parse_objects_for_criteria(match_data)
|
|
130
131
|
grouping_object = objects[0]
|
|
131
132
|
relationships = cpe.relate_indicator(grouping_object, indicator)
|
|
133
|
+
deprecations = cpe.parse_deprecations(objects[1:])
|
|
132
134
|
for r in relationships:
|
|
133
135
|
r['_from'] = indicator['_id']
|
|
134
136
|
retval.extend(objects)
|
|
135
137
|
retval.extend(relationships)
|
|
138
|
+
retval.extend(deprecations)
|
|
136
139
|
return stix2python(retval)
|
{arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_epss.py
RENAMED
|
@@ -19,87 +19,69 @@ class _CveEpssWorker(STIXRelationManager, relationship_note="cve-epss", register
|
|
|
19
19
|
default_objects = [
|
|
20
20
|
"https://raw.githubusercontent.com/muchdogesec/stix2extensions/refs/heads/main/extension-definitions/properties/report-epss-scoring.json"
|
|
21
21
|
]
|
|
22
|
+
CHUNK_SIZE = 20_000
|
|
22
23
|
|
|
23
24
|
def __init__(self, *args, **kwargs) -> None:
|
|
24
25
|
super().__init__(*args, **kwargs)
|
|
25
|
-
self.update_objects = []
|
|
26
26
|
self.epss_date = EPSSManager.datenow()
|
|
27
27
|
|
|
28
|
+
def process(self, **kwargs):
|
|
29
|
+
self.epss_data_source = EPSSManager.get_epss_data(self.epss_date)
|
|
30
|
+
if self.cve_ids:
|
|
31
|
+
self.cve_ids = list(set(self.epss_data_source).intersection(self.cve_ids))
|
|
32
|
+
else:
|
|
33
|
+
self.cve_ids = list(self.epss_data_source)
|
|
34
|
+
return super().process(**kwargs)
|
|
35
|
+
|
|
36
|
+
def get_objects_from_db(self, query, **binds):
|
|
37
|
+
return self.arango.execute_raw_query(
|
|
38
|
+
query,
|
|
39
|
+
bind_vars={
|
|
40
|
+
"@collection": self.collection,
|
|
41
|
+
**binds,
|
|
42
|
+
},
|
|
43
|
+
memory_limit=100 * 1024**2,
|
|
44
|
+
)
|
|
45
|
+
|
|
28
46
|
def get_object_chunks(self, **kwargs):
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
for cve_ids_chunk in chunked_tqdm(
|
|
48
|
+
self.cve_ids, self.CHUNK_SIZE, "get-cve-and-existing-epss-reports"
|
|
49
|
+
):
|
|
50
|
+
reports_query = """
|
|
31
51
|
FOR doc IN @@collection OPTIONS {indexHint: "acvep_search", forceIndexHint: true}
|
|
32
52
|
FILTER doc._arango_cve_processor_note == @relationship_note
|
|
33
53
|
FILTER doc.name IN @cve_ids AND doc._is_latest == TRUE
|
|
34
54
|
LET cve_name = doc.external_references[0].external_id
|
|
35
55
|
RETURN [cve_name, KEEP(doc, '_key', 'x_epss', '_record_created')]
|
|
36
56
|
"""
|
|
37
|
-
|
|
38
|
-
self.get_objects_from_db(
|
|
39
|
-
query,
|
|
40
|
-
limit,
|
|
41
|
-
dict(
|
|
42
|
-
relationship_note=self.relationship_note,
|
|
43
|
-
cve_ids=[f"EPSS Scores: {cve_id}" for cve_id in self.cve_ids],
|
|
44
|
-
),
|
|
45
|
-
)
|
|
46
|
-
)
|
|
47
|
-
cve_query = (
|
|
48
|
-
query
|
|
49
|
-
) = """
|
|
57
|
+
cve_query = """
|
|
50
58
|
FOR doc IN @@collection OPTIONS {indexHint: "acvep_search", forceIndexHint: true}
|
|
51
59
|
FILTER doc.type == 'vulnerability'
|
|
52
60
|
FILTER doc.name IN @cve_ids
|
|
53
61
|
FILTER doc._is_latest == TRUE AND doc.created >= @created_min AND doc.modified >= @modified_min
|
|
54
62
|
RETURN [doc.name, KEEP(doc, 'id', '_record_created', 'created', '_key')]
|
|
55
63
|
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
reports = dict(
|
|
65
|
+
self.get_objects_from_db(
|
|
66
|
+
reports_query,
|
|
67
|
+
relationship_note=self.relationship_note,
|
|
68
|
+
cve_ids=[f"EPSS Scores: {cve_id}" for cve_id in cve_ids_chunk],
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
cves: list[tuple[str, dict]] = self.get_objects_from_db(
|
|
72
|
+
cve_query,
|
|
73
|
+
cve_ids=cve_ids_chunk,
|
|
61
74
|
created_min=self.created_min,
|
|
62
75
|
modified_min=self.modified_min,
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
objects = []
|
|
67
|
-
for cve_name, cve in cves:
|
|
68
|
-
cve.update(name=cve_name, epss=reports.get(cve_name))
|
|
69
|
-
objects.append(cve)
|
|
70
|
-
return [objects]
|
|
71
|
-
|
|
72
|
-
def process(self, **kwargs):
|
|
73
|
-
self.epss_data_source = EPSSManager.get_epss_data(self.epss_date)
|
|
74
|
-
if self.cve_ids:
|
|
75
|
-
self.cve_ids = list(set(self.epss_data_source).intersection(self.cve_ids))
|
|
76
|
-
else:
|
|
77
|
-
self.cve_ids = list(self.epss_data_source)
|
|
78
|
-
return super().process(**kwargs)
|
|
79
|
-
|
|
80
|
-
def get_objects_from_db(self, query, limit, binds={}):
|
|
81
|
-
objects = []
|
|
82
|
-
t0 = time.time()
|
|
83
|
-
for cve_ids_chunk in chunked_tqdm(
|
|
84
|
-
binds.pop("cve_ids", []), limit, "get-cve-and-existing-epss-reports"
|
|
85
|
-
):
|
|
86
|
-
t = time.time()
|
|
87
|
-
ret = self.arango.execute_raw_query(
|
|
88
|
-
query,
|
|
89
|
-
bind_vars={
|
|
90
|
-
"@collection": self.collection,
|
|
91
|
-
"cve_ids": cve_ids_chunk,
|
|
92
|
-
**binds,
|
|
93
|
-
},
|
|
94
|
-
memory_limit=100 * 1024**2,
|
|
95
76
|
)
|
|
96
|
-
objects
|
|
97
|
-
|
|
98
|
-
|
|
77
|
+
objects = []
|
|
78
|
+
for cve_name, cve in cves:
|
|
79
|
+
cve.update(name=cve_name, epss=reports.get(cve_name))
|
|
80
|
+
objects.append(cve)
|
|
81
|
+
yield objects
|
|
99
82
|
|
|
100
83
|
def relate_single(self, cve_object):
|
|
101
84
|
todays_report = parse_cve_epss_report(cve_object, self.epss_date)
|
|
102
|
-
record_modified = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
103
85
|
if not todays_report:
|
|
104
86
|
return []
|
|
105
87
|
if cve_object["epss"]:
|
|
@@ -117,34 +99,29 @@ class _CveEpssWorker(STIXRelationManager, relationship_note="cve-epss", register
|
|
|
117
99
|
{
|
|
118
100
|
**cve_object["epss"],
|
|
119
101
|
"x_epss": all_epss,
|
|
120
|
-
"_record_modified": record_modified,
|
|
121
102
|
"modified": latest_epss["date"] + "T00:00:00.000Z",
|
|
122
103
|
"_arango_cve_processor_note": self.relationship_note,
|
|
123
104
|
},
|
|
124
|
-
|
|
125
|
-
_key=cve_object["_key"],
|
|
126
|
-
_acvep_epss=latest_epss,
|
|
127
|
-
_record_modified=record_modified,
|
|
128
|
-
),
|
|
105
|
+
self.make_opencti_properties(cve_object["_key"], latest_epss),
|
|
129
106
|
]
|
|
130
107
|
)
|
|
131
108
|
return []
|
|
132
109
|
else:
|
|
133
110
|
self.update_objects.append(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
_record_modified=record_modified,
|
|
138
|
-
)
|
|
111
|
+
self.make_opencti_properties(
|
|
112
|
+
cve_object["_key"], todays_report["x_epss"][0]
|
|
113
|
+
),
|
|
139
114
|
)
|
|
140
115
|
return [stix2python(todays_report)]
|
|
141
116
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
117
|
+
@staticmethod
|
|
118
|
+
def make_opencti_properties(key: str, epss: dict):
|
|
119
|
+
return dict(
|
|
120
|
+
_key=key,
|
|
121
|
+
x_opencti_epss_score=epss["epss"],
|
|
122
|
+
x_opencti_epss_percentile=epss["percentile"],
|
|
123
|
+
x_opencti_epss_date=epss["date"],
|
|
146
124
|
)
|
|
147
|
-
return super().upload_vertex_data(objects)
|
|
148
125
|
|
|
149
126
|
|
|
150
127
|
class CveEpssManager(_CveEpssWorker, relationship_note="cve-epss"):
|
{arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/managers/cve_kev.py
RENAMED
|
@@ -70,11 +70,12 @@ class CISAKevManager(STIXRelationManager, relationship_note="cve-kev"):
|
|
|
70
70
|
yield dict(source_name="cisa_note", url=note)
|
|
71
71
|
|
|
72
72
|
def get_dates(self, cve):
|
|
73
|
-
|
|
73
|
+
date_added = cve['kev']["dateAdded"] + 'T00:00:00Z'
|
|
74
|
+
return date_added, date_added
|
|
74
75
|
|
|
75
|
-
def relate_single(self,
|
|
76
|
-
cve_id =
|
|
77
|
-
kev_obj =
|
|
76
|
+
def relate_single(self, vuln_obj):
|
|
77
|
+
cve_id = vuln_obj["name"]
|
|
78
|
+
kev_obj = vuln_obj['kev']
|
|
78
79
|
references = [
|
|
79
80
|
{
|
|
80
81
|
"source_name": "cve",
|
|
@@ -113,32 +114,30 @@ class CISAKevManager(STIXRelationManager, relationship_note="cve-kev"):
|
|
|
113
114
|
cwe_stix_ids.append(cwe["id"])
|
|
114
115
|
references.append(cwe["external_references"][0])
|
|
115
116
|
|
|
116
|
-
exploit_objects = self.parse_exploits(
|
|
117
|
+
exploit_objects = self.parse_exploits(vuln_obj, kev_obj)
|
|
117
118
|
content = self.content_fmt.format(cve_id=cve_id)
|
|
118
|
-
created, modified = self.get_dates(
|
|
119
|
+
created, modified = self.get_dates(vuln_obj)
|
|
119
120
|
report = {
|
|
120
121
|
"type": "report",
|
|
121
122
|
"spec_version": "2.1",
|
|
122
123
|
"id": make_stix_id("report", content),
|
|
123
|
-
"created_by_ref":
|
|
124
|
+
"created_by_ref": config.IDENTITY_REF,
|
|
124
125
|
"created": created,
|
|
125
126
|
"modified": modified,
|
|
126
127
|
"published": created,
|
|
127
128
|
"name": content,
|
|
128
129
|
"description": kev_obj["shortDescription"],
|
|
129
130
|
"object_refs": [
|
|
130
|
-
|
|
131
|
+
vuln_obj["id"],
|
|
131
132
|
*cwe_stix_ids,
|
|
132
133
|
*[exploit["id"] for exploit in exploit_objects],
|
|
133
134
|
],
|
|
134
135
|
"labels": ["kev"],
|
|
135
136
|
"report_types": ["vulnerability"],
|
|
136
137
|
"external_references": references,
|
|
137
|
-
"object_marking_refs":
|
|
138
|
-
"marking-definition--94868c89-83c2-464b-929b-a1a8aa3c8487",
|
|
139
|
-
"marking-definition--152ecfe1-5015-522b-97e4-86b60c57036d",
|
|
140
|
-
],
|
|
138
|
+
"object_marking_refs": config.OBJECT_MARKING_REFS,
|
|
141
139
|
}
|
|
140
|
+
self.update_objects.append(dict(_key=vuln_obj['_key'], x_opencti_cisa_kev=True))
|
|
142
141
|
return [report, *exploit_objects, *cwe_objects]
|
|
143
142
|
|
|
144
143
|
def get_all_kevs(self):
|
|
@@ -81,7 +81,7 @@ class VulnCheckKevManager(CISAKevManager, relationship_note="cve-vulncheck-kev")
|
|
|
81
81
|
"type": "exploit",
|
|
82
82
|
"spec_version": "2.1",
|
|
83
83
|
"id": "exploit--" + str(uuid.uuid5(config.namespace, xdb["xdb_id"])),
|
|
84
|
-
"created_by_ref":
|
|
84
|
+
"created_by_ref": config.IDENTITY_REF,
|
|
85
85
|
"created": xdb["date_added"],
|
|
86
86
|
"modified": xdb["date_added"],
|
|
87
87
|
"name": object["name"],
|
|
@@ -100,10 +100,7 @@ class VulnCheckKevManager(CISAKevManager, relationship_note="cve-vulncheck-kev")
|
|
|
100
100
|
"url": xdb["xdb_url"],
|
|
101
101
|
},
|
|
102
102
|
],
|
|
103
|
-
"object_marking_refs":
|
|
104
|
-
"marking-definition--94868c89-83c2-464b-929b-a1a8aa3c8487",
|
|
105
|
-
"marking-definition--60c0f466-511a-5419-9f7e-4814e696da40",
|
|
106
|
-
],
|
|
103
|
+
"object_marking_refs": config.OBJECT_MARKING_REFS,
|
|
107
104
|
"extensions": {
|
|
108
105
|
"extension-definition--5a047f57-0149-59b6-a079-e2d7c7ac799a": {
|
|
109
106
|
"extension_type": "new-sdo"
|
|
@@ -9,6 +9,7 @@ from arango_cve_processor import config
|
|
|
9
9
|
from arango_cve_processor.tools import utils
|
|
10
10
|
from arango_cve_processor.tools.cpe_db import SwidTitleDB
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
def parse_cpematch_date(d):
|
|
13
14
|
return pytz.utc.localize(datetime.strptime(d, "%Y-%m-%dT%H:%M:%S.%f"))
|
|
14
15
|
|
|
@@ -45,8 +46,10 @@ def parse_objects_for_criteria(match_data: dict):
|
|
|
45
46
|
"object_marking_refs": config.OBJECT_MARKING_REFS,
|
|
46
47
|
}
|
|
47
48
|
if not softwares:
|
|
48
|
-
grouping[
|
|
49
|
-
grouping[
|
|
49
|
+
grouping["object_refs"] = ["software--11111111-1111-4111-8111-111111111111"]
|
|
50
|
+
grouping["description"] = (
|
|
51
|
+
"This grouping contains no CPEs, a null software object has been added in object_refs"
|
|
52
|
+
)
|
|
50
53
|
return [grouping, *softwares]
|
|
51
54
|
|
|
52
55
|
|
|
@@ -59,8 +62,32 @@ def generate_grouping_id(criteria_id):
|
|
|
59
62
|
)
|
|
60
63
|
|
|
61
64
|
|
|
62
|
-
def
|
|
63
|
-
|
|
65
|
+
def parse_deprecations(softwares, add_arango_props=True):
|
|
66
|
+
name_db = SwidTitleDB.get_db()
|
|
67
|
+
objects = []
|
|
68
|
+
for source in softwares:
|
|
69
|
+
cpe = name_db.lookup(source.swid)
|
|
70
|
+
for deprecated in cpe["deprecates"]:
|
|
71
|
+
target = parse_software(deprecated["cpeName"], deprecated["cpeNameId"])
|
|
72
|
+
objects.append(
|
|
73
|
+
utils.create_relationship(
|
|
74
|
+
source,
|
|
75
|
+
target.id,
|
|
76
|
+
relationship_type="related-to",
|
|
77
|
+
description=f"{source.cpe} deprecates {target.cpe}",
|
|
78
|
+
add_arango_props=add_arango_props,
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
objects.append(target)
|
|
82
|
+
return objects
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def parse_softwares(cpematches):
|
|
86
|
+
softwares = []
|
|
87
|
+
for cpename, swid in cpematches:
|
|
88
|
+
s = parse_software(cpename, swid)
|
|
89
|
+
softwares.append(s)
|
|
90
|
+
return softwares
|
|
64
91
|
|
|
65
92
|
|
|
66
93
|
def relate_indicator(grouping: Grouping, indicator):
|
|
@@ -132,21 +159,28 @@ def cpe_name_as_dict(cpe_name: str) -> dict[str, str]:
|
|
|
132
159
|
)
|
|
133
160
|
|
|
134
161
|
|
|
162
|
+
def make_software_id(cpename, swid):
|
|
163
|
+
return "software--" + str(
|
|
164
|
+
uuid.uuid5(
|
|
165
|
+
config.namespace,
|
|
166
|
+
f"{cpename}+{swid}",
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
135
171
|
def parse_software(cpename, swid):
|
|
136
172
|
cpe_struct = cpe_name_as_dict(cpename)
|
|
137
173
|
name_db = SwidTitleDB.get_db()
|
|
138
174
|
cpe = name_db.lookup(swid)
|
|
175
|
+
stix_id = make_software_id(cpename, swid)
|
|
176
|
+
created = parse_cpematch_date(cpe["created"])
|
|
177
|
+
modified = parse_cpematch_date(cpe["modified"])
|
|
178
|
+
|
|
139
179
|
return Software(
|
|
140
|
-
id=
|
|
141
|
-
+ str(
|
|
142
|
-
uuid.uuid5(
|
|
143
|
-
config.namespace,
|
|
144
|
-
f"{cpename}+{swid}",
|
|
145
|
-
)
|
|
146
|
-
),
|
|
180
|
+
id=stix_id,
|
|
147
181
|
x_cpe_struct=cpe_struct,
|
|
148
182
|
cpe=cpename,
|
|
149
|
-
name=cpe.get(
|
|
183
|
+
name=cpe.get("title", cpename),
|
|
150
184
|
swid=swid,
|
|
151
185
|
version=cpe_struct["version"],
|
|
152
186
|
vendor=cpe_struct["vendor"],
|
|
@@ -155,9 +189,9 @@ def parse_software(cpename, swid):
|
|
|
155
189
|
"extension_type": "toplevel-property-extension"
|
|
156
190
|
}
|
|
157
191
|
},
|
|
158
|
-
object_marking_refs=
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
192
|
+
object_marking_refs=config.OBJECT_MARKING_REFS,
|
|
193
|
+
x_revoked=cpe["deprecated"],
|
|
194
|
+
x_created=created,
|
|
195
|
+
x_modified=modified,
|
|
162
196
|
allow_custom=True,
|
|
163
197
|
)
|
{arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/cpe_db.py
RENAMED
|
@@ -20,7 +20,7 @@ class SwidTitleDB:
|
|
|
20
20
|
_date = None
|
|
21
21
|
_class_db = None
|
|
22
22
|
|
|
23
|
-
def __init__(self, zip_path):
|
|
23
|
+
def __init__(self, zip_path=""):
|
|
24
24
|
self.db_path = tempfile.mktemp(prefix="acvep-swid-cpe_", suffix=".sqlite")
|
|
25
25
|
self.conn = None
|
|
26
26
|
zip_file = zip_path or self._download_zip()
|
|
@@ -32,7 +32,7 @@ class SwidTitleDB:
|
|
|
32
32
|
def get_db(cls):
|
|
33
33
|
today = datetime.now(UTC).date()
|
|
34
34
|
if cls._date != today:
|
|
35
|
-
cls._class_db = SwidTitleDB(
|
|
35
|
+
cls._class_db = SwidTitleDB()
|
|
36
36
|
cls._date = today
|
|
37
37
|
return cls._class_db
|
|
38
38
|
|
|
@@ -50,19 +50,20 @@ class SwidTitleDB:
|
|
|
50
50
|
title TEXT,
|
|
51
51
|
deprecated INTEGER,
|
|
52
52
|
created TEXT,
|
|
53
|
-
modified TEXT
|
|
53
|
+
modified TEXT,
|
|
54
|
+
deprecates TEXT
|
|
54
55
|
)
|
|
55
56
|
"""
|
|
56
57
|
)
|
|
57
58
|
self.conn.commit()
|
|
58
59
|
|
|
59
|
-
def _insert_cpe_title(self, swid, title, deprecated, created, modified):
|
|
60
|
+
def _insert_cpe_title(self, swid, title, deprecated, created, modified, deprecates):
|
|
60
61
|
self.cur.execute(
|
|
61
62
|
"""
|
|
62
|
-
INSERT OR REPLACE INTO cpe_titles (swid, title, deprecated, created, modified)
|
|
63
|
-
VALUES (?, ?, ?, ?, ?)
|
|
63
|
+
INSERT OR REPLACE INTO cpe_titles (swid, title, deprecated, created, modified, deprecates)
|
|
64
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
64
65
|
""",
|
|
65
|
-
(swid, title, int(deprecated), created, modified),
|
|
66
|
+
(swid, title, int(deprecated), created, modified, json.dumps(deprecates)),
|
|
66
67
|
)
|
|
67
68
|
|
|
68
69
|
def _extract_swid_titles_to_sqlite(self, zip_file):
|
|
@@ -95,19 +96,24 @@ class SwidTitleDB:
|
|
|
95
96
|
cpe.get("deprecated", False),
|
|
96
97
|
cpe.get("created", ""),
|
|
97
98
|
cpe.get("lastModified", ""),
|
|
99
|
+
cpe.get("deprecates", []),
|
|
98
100
|
)
|
|
99
101
|
logging.info(f"wrote {count} entries to db")
|
|
100
102
|
self.conn.commit()
|
|
101
103
|
|
|
102
104
|
def lookup(self, swid):
|
|
103
105
|
self.cur.execute(
|
|
104
|
-
"SELECT title, deprecated, created, modified FROM cpe_titles WHERE swid=?",
|
|
106
|
+
"SELECT title, deprecated, created, modified, deprecates FROM cpe_titles WHERE swid=?",
|
|
105
107
|
(swid,),
|
|
106
108
|
)
|
|
107
109
|
row = self.cur.fetchone()
|
|
108
110
|
if row:
|
|
109
111
|
return dict(
|
|
110
|
-
title=row[0],
|
|
112
|
+
title=row[0],
|
|
113
|
+
deprecated=bool(row[1]),
|
|
114
|
+
created=row[2],
|
|
115
|
+
modified=row[3],
|
|
116
|
+
deprecates=json.loads(row[4]),
|
|
111
117
|
)
|
|
112
118
|
|
|
113
119
|
def __del__(self):
|
{arango_cve_processor-1.2.5 → arango_cve_processor-1.2.7}/arango_cve_processor/tools/epss.py
RENAMED
|
@@ -9,6 +9,8 @@ from pytz import timezone
|
|
|
9
9
|
from functools import lru_cache
|
|
10
10
|
|
|
11
11
|
logging.basicConfig(level=logging.INFO)
|
|
12
|
+
|
|
13
|
+
|
|
12
14
|
@dataclass
|
|
13
15
|
class EPSS:
|
|
14
16
|
cve: str = ""
|
|
@@ -16,6 +18,7 @@ class EPSS:
|
|
|
16
18
|
score: float = 0
|
|
17
19
|
percentile: float = 0
|
|
18
20
|
|
|
21
|
+
|
|
19
22
|
class EPSSManager:
|
|
20
23
|
_epss_data: dict[date, dict[str, EPSS]] = {}
|
|
21
24
|
keep_old_data = False
|
|
@@ -27,21 +30,21 @@ class EPSSManager:
|
|
|
27
30
|
return cls._epss_data
|
|
28
31
|
|
|
29
32
|
@classmethod
|
|
30
|
-
def get_epss_data(cls, d: date|datetime=None):
|
|
33
|
+
def get_epss_data(cls, d: date | datetime = None):
|
|
31
34
|
if not d:
|
|
32
35
|
d = cls.datenow()
|
|
33
36
|
if isinstance(d, datetime):
|
|
34
37
|
d = d.date()
|
|
35
38
|
return cls._get_epss_date(d)
|
|
36
|
-
|
|
39
|
+
|
|
37
40
|
@classmethod
|
|
38
41
|
@lru_cache(maxsize=30)
|
|
39
42
|
def _get_epss_date(cls, d: date):
|
|
40
43
|
if d in cls._epss_data:
|
|
41
44
|
return cls._epss_data[d]
|
|
42
|
-
d_str = d.strftime(
|
|
45
|
+
d_str = d.strftime("%Y-%m-%d")
|
|
43
46
|
url = "https://epss.cyentia.com/epss_scores-{}.csv.gz".format(d_str)
|
|
44
|
-
logging.info(f
|
|
47
|
+
logging.info(f"retrieving epss from {url}")
|
|
45
48
|
resp = requests.get(url)
|
|
46
49
|
csv_data = gzip.decompress(resp.content).decode()
|
|
47
50
|
if not cls.keep_old_data:
|
|
@@ -50,15 +53,17 @@ class EPSSManager:
|
|
|
50
53
|
logging.info(f"Got {len(cls._epss_data[d])} EPSS data for {d_str}")
|
|
51
54
|
|
|
52
55
|
return cls._epss_data[d]
|
|
53
|
-
|
|
56
|
+
|
|
54
57
|
@staticmethod
|
|
55
58
|
def parse_csv(csv_data, date_str):
|
|
56
|
-
data = csv.DictReader(io.StringIO(csv_data), ["cve","epss","percentile"])
|
|
59
|
+
data = csv.DictReader(io.StringIO(csv_data), ["cve", "epss", "percentile"])
|
|
57
60
|
for d in data:
|
|
58
|
-
cve_name = d[
|
|
59
|
-
if not cve_name.startswith(
|
|
61
|
+
cve_name = d["cve"]
|
|
62
|
+
if not cve_name.startswith("CVE-"):
|
|
60
63
|
continue
|
|
61
|
-
yield cve_name, dict(
|
|
64
|
+
yield cve_name, dict(
|
|
65
|
+
date=date_str, epss=float(d["epss"]), percentile=float(d["percentile"])
|
|
66
|
+
)
|
|
62
67
|
|
|
63
68
|
@classmethod
|
|
64
69
|
def get_data_for_cve(cls, cve, date=None):
|
|
@@ -69,8 +74,8 @@ class EPSSManager:
|
|
|
69
74
|
except:
|
|
70
75
|
return cls.get_data_for_cve(cve, date - timedelta(days=1))
|
|
71
76
|
return data.get(cve)
|
|
72
|
-
|
|
77
|
+
|
|
73
78
|
@classmethod
|
|
74
79
|
def datenow(cls):
|
|
75
|
-
resp = requests.get(
|
|
76
|
-
return datetime.strptime(resp.json()[
|
|
80
|
+
resp = requests.get("https://api.first.org/data/v1/epss?limit=1")
|
|
81
|
+
return datetime.strptime(resp.json()["data"][0]["date"], "%Y-%m-%d").date()
|