-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prabhu Subramanian <[email protected]>
- Loading branch information
Showing
9 changed files
with
148 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from typing import Any | ||
|
||
import apsw | ||
import orjson | ||
|
||
from vdb.lib import KNOWN_PKG_TYPES, db6 | ||
from vdb.lib.cve_model import CVE, CVE1 | ||
|
||
|
||
def get_cve_data(db_conn, index_hits: list[dict, Any]): | ||
"""Get CVE data for the index results | ||
Args: | ||
db_conn: DB Connection or None to create a new one | ||
index_hits: Hits from one of the search methods | ||
search_str: Original search string used | ||
Returns: | ||
generator: generator for CVE data with original source data as a pydantic model | ||
""" | ||
if not db_conn: | ||
db_conn, _ = db6.get(read_only=True) | ||
for ahit in index_hits: | ||
results: apsw.Cursor = db_conn.execute( | ||
"SELECT cve_id, type, namespace, name, json_object('source', source_data) FROM cve_data WHERE cve_id = ? AND type = ? ORDER BY cve_id DESC;", | ||
(ahit[0], ahit[1]), | ||
) | ||
for res in results: | ||
yield { | ||
"cve_id": res[0], | ||
"type": res[1], | ||
"namespace": res[2], | ||
"name": res[3], | ||
"purl_prefix": ahit[-1], | ||
"source_data": ( | ||
CVE( | ||
root=CVE1.model_validate( | ||
orjson.loads(res[4])["source"], strict=False | ||
) | ||
) | ||
if res[4] | ||
else None | ||
) | ||
} | ||
|
||
|
||
def get_unmapped_namespaces() -> list: | ||
"""Get a list of namespaces without a precise purl prefix""" | ||
db_conn, index_conn = db6.get(read_only=True) | ||
raw_hits = index_conn.execute(f"""select distinct cve_id, type, namespace, name, purl_prefix from cve_index where type not in ({', '.join([f"'{p}'" for p in KNOWN_PKG_TYPES])})""") | ||
for ahit in raw_hits: | ||
data_list_gen = get_cve_data(db_conn, [ahit]) | ||
for data_list in data_list_gen: | ||
source_data: CVE1 = data_list["source_data"].root | ||
affected = source_data.containers.cna.affected.root | ||
cpes = [", ".join([b.root for b in a.cpes]) for a in affected] | ||
references = source_data.containers.cna.references.root | ||
ref_urls = [str(a.url.root) for a in references] | ||
print(data_list["cve_id"], data_list["type"], data_list["namespace"], data_list["name"], data_list["purl_prefix"], cpes, ref_urls) | ||
|
||
|
||
if __name__ == "__main__": | ||
get_unmapped_namespaces() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.