Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore suse/suse cvrf. Other performance improvements. #171

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,12 @@ def test_aqua_convert(
db6.clear_all()
aqualatest.store(cve_data)
cve_data_count, cve_index_count = db6.stats()
assert cve_data_count == 1
assert cve_index_count == 1
assert cve_data_count == 4
assert cve_index_count == 4
results_count = len(list(search.search_by_any("CVE-2020-8022")))
assert results_count == 0
results_count = len(list(search.search_by_any("CVE-2021-3618")))
assert results_count == 1
assert results_count == 4

# suse1
cve_data = aqualatest.convert(test_aqua_suse_json1)
Expand Down
2 changes: 1 addition & 1 deletion vdb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def main():
else:
sources = [OSVSource(), GitHubSource()]
# AquaSource also includes NVD
if args.cache_os:
if args.cache_os and not args.only_aqua:
sources.insert(0, AquaSource())
for s in sources:
LOG.info("Refreshing %s", s.__class__.__name__)
Expand Down
114 changes: 62 additions & 52 deletions vdb/lib/aqua.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ def is_supported_source(zfname):
"oval",
"glad",
"mariner",
f"cvrf{os.sep}suse{os.sep}suse",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This removes data belonging suse enterprise version leaving only the opensuse ones, which is probably ok for us.

):
if distro in zfname:
return False
nvd_start_year = config.NVD_START_YEAR
for year in range(1999, nvd_start_year):
if f"CVE-{year}-" in zfname:
return False
for pat in (f"CVE-{year}-", f"{os.sep}{year}{os.sep}", f"ALAS-{year}-", f"ALAS2-{year}-", f"openSUSE-SU-{year}-"):
if pat in zfname:
return False
if zfname.endswith(".json"):
return True
return False
Expand Down Expand Up @@ -616,6 +618,8 @@ def product_ref_to_name_version(product_ref):
def suse_to_vuln(self, cve_data):
"""Suse Linux"""
ret_data = []
tracking_id = cve_data.get("Tracking", {}).get("ID", "")
assigner = "opensuse" if "opensuse" in tracking_id.lower() else "suse"
packages = cve_data.get("ProductTree", {}).get("Relationships", [])
if not packages or not len(packages) > 0:
return ret_data
Expand Down Expand Up @@ -643,64 +647,70 @@ def suse_to_vuln(self, cve_data):
references = orjson.dumps(references, option=orjson.OPT_NAIVE_UTC)
if isinstance(references, bytes):
references = references.decode("utf-8", "ignore")
assigner = "suse"
(
score,
severity,
vector_string,
attack_complexity,
) = get_default_cve_data(severity)
done_pkgs = {}
for pref in packages:
pkg_key = pref.get("ProductReference")
if done_pkgs.get(pkg_key):
product_statuses = avuln.get("ProductStatuses", [])
for aps in product_statuses:
if aps.get("Type") != "Fixed":
continue
pkg_name, version = self.product_ref_to_name_version(pkg_key)
version_start_including = ""
version_end_including = ""
version_start_excluding = ""
version_end_excluding = version
fix_version_end_including = ""
fix_version_start_excluding = ""
fix_version_end_excluding = ""
fix_version_start_including = version
if pkg_name and version:
tdata = config.CVE_TPL % dict(
cve_id=cve_id,
cwe_id=cwe_id,
assigner=assigner,
references=references,
description="",
vectorString=vector_string,
vendor="rpm",
product=f"suse/{pkg_name}",
version="*",
edition="*",
version_start_including=version_start_including,
version_end_including=version_end_including,
version_start_excluding=version_start_excluding,
version_end_excluding=version_end_excluding,
fix_version_start_including=fix_version_start_including,
fix_version_end_including=fix_version_end_including,
fix_version_start_excluding=fix_version_start_excluding,
fix_version_end_excluding=fix_version_end_excluding,
severity=severity,
attackComplexity=attack_complexity,
score=score,
userInteraction="REQUIRED",
exploitabilityScore=score,
publishedDate=published_date,
lastModifiedDate=last_modified_date,
)
try:
vuln = NvdSource.convert_vuln(orjson.loads(tdata))
if vuln is None:
continue
vuln.description = compress_str(description)
ret_data.append(vuln)
done_pkgs[pkg_key] = True
except Exception:
pass
product_ids = aps.get("ProductID")
if not product_ids:
continue
for pkg_key in product_ids:
if done_pkgs.get(pkg_key):
continue
pkg_name, version = self.product_ref_to_name_version(pkg_key)
pkg_name = pkg_name.lower().replace(" ", "-").replace(":", "/")
Copy link
Contributor Author

@prabhu prabhu Jul 15, 2024

Choose a reason for hiding this comment

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

pkg_name will also include edition and product names such as opensuse-tumbleweed. This would help reduce false positives but would require some rewrite in depscan v6.

version_start_including = ""
version_end_including = ""
version_start_excluding = ""
version_end_excluding = version
fix_version_end_including = ""
fix_version_start_excluding = ""
fix_version_end_excluding = ""
fix_version_start_including = version
if pkg_name and version:
tdata = config.CVE_TPL % dict(
cve_id=cve_id,
cwe_id=cwe_id,
assigner=assigner,
references=references,
description="",
vectorString=vector_string,
vendor="rpm",
product=pkg_name,
version="*",
edition="*",
version_start_including=version_start_including,
version_end_including=version_end_including,
version_start_excluding=version_start_excluding,
version_end_excluding=version_end_excluding,
fix_version_start_including=fix_version_start_including,
fix_version_end_including=fix_version_end_including,
fix_version_start_excluding=fix_version_start_excluding,
fix_version_end_excluding=fix_version_end_excluding,
severity=severity,
attackComplexity=attack_complexity,
score=score,
userInteraction="REQUIRED",
exploitabilityScore=score,
publishedDate=published_date,
lastModifiedDate=last_modified_date,
)
try:
vuln = NvdSource.convert_vuln(orjson.loads(tdata))
if vuln is None:
continue
vuln.description = compress_str(description)
ret_data.append(vuln)
done_pkgs[pkg_key] = True
except Exception:
pass
return ret_data

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions vdb/lib/db6.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def ensure_schemas(db_conn_obj: apsw.Connection, index_conn_obj: apsw.Connection
"CREATE TABLE if not exists cve_data(cve_id TEXT NOT NULL, type TEXT NOT NULL, namespace TEXT, name TEXT NOT NULL, source_data BLOB NOT NULL, override_data BLOB, source_data_hash TEXT NOT NULL, purl_prefix TEXT NOT NULL);")
db_conn_obj.pragma("synchronous", "OFF")
db_conn_obj.pragma("journal_mode", "MEMORY")
db_conn_obj.pragma("temp_store", "MEMORY")
index_conn_obj.execute(
"CREATE TABLE if not exists cve_index(cve_id TEXT NOT NULL, type TEXT NOT NULL, namespace TEXT, name TEXT NOT NULL, vers TEXT NOT NULL, purl_prefix TEXT NOT NULL);")
index_conn_obj.pragma("synchronous", "OFF")
index_conn_obj.pragma("journal_mode", "MEMORY")
index_conn_obj.pragma("temp_store", "MEMORY")


def get(db_file: str = config.VDB_BIN_FILE, index_file: str = config.VDB_BIN_INDEX, read_only=False) -> (
Expand Down