-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extractors/oracle.py: add extractor for Oracle Critical Patch Updates
The descriptions are autogenerated by Oracle and need to be edited manually, but that is still quicker than having to copy and paste everything by hand.
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
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
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,77 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
import click | ||
import json | ||
import re | ||
import requests | ||
from lxml import etree | ||
|
||
|
||
def parse_severity(cvss): | ||
base_score = re.search("Base Score ([0-9]+\.[0-9])", cvss) | ||
if base_score is None: | ||
return "Unknown" | ||
else: | ||
base_score = float(base_score.group(1)) | ||
|
||
if base_score < 4.0: | ||
return "Low" | ||
elif base_score < 7.0: | ||
return "Medium" | ||
elif base_score < 9.0: | ||
return "High" | ||
else: | ||
return "Critical" | ||
|
||
|
||
def parse_vector(cvss): | ||
vector = re.search("/AV:([NALP])/", cvss) | ||
if vector is None: | ||
return "Unknown" | ||
else: | ||
vector = vector.group(1) | ||
|
||
if vector in ["L", "P"]: | ||
return "Local" | ||
else: | ||
return "Remote" | ||
|
||
|
||
@click.command() | ||
@click.argument("url", nargs=-1) | ||
@click.option( | ||
"--output", | ||
type=click.File("w"), | ||
default=click.get_text_stream("stdout"), | ||
help="Output file with CVEs in JSON format (defaults to stdout)", | ||
) | ||
def oracle(url, output): | ||
"""Extract CVEs for Oracle from their Critical Patch Updates (CPUs)""" | ||
cves = [] | ||
|
||
for advisory_url in url: | ||
advisory = requests.get(advisory_url).content | ||
advisory = etree.fromstring(advisory, etree.HTMLParser()) | ||
|
||
cve_ids = advisory.xpath('//a[starts-with(@id, "CVE-")]/text()') | ||
|
||
cves += [ | ||
{ | ||
"name": cve, | ||
"type": "Unknown", | ||
"severity": parse_severity( | ||
cvss := advisory.xpath( | ||
f'string((//a[@id="{cve}"])[1]/parent::td/following-sibling::td/text()[contains(., "CVSS 3.1")])' | ||
) | ||
), | ||
"vector": parse_vector(cvss), | ||
"description": advisory.xpath( | ||
f'string((//a[@id="{cve}"])[1]/parent::td/following-sibling::td/text()[1])' | ||
), | ||
"references": [f"{advisory_url}#{cve}"], | ||
"notes": None, | ||
} | ||
for cve in cve_ids | ||
] | ||
|
||
output.write(json.dumps(cves, indent=2, ensure_ascii=False)) |