Skip to content

Commit 20a750a

Browse files
committed
add-amazon-linux-advisories-initial-commit
Signed-off-by: ambuj <kulshreshthaak.12@gmail.com>
1 parent d62f377 commit 20a750a

File tree

4 files changed

+382
-0
lines changed

4 files changed

+382
-0
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# VulnerableCode is a trademark of nexB Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7+
# See https://github.com/nexB/vulnerablecode for support or download.
8+
# See https://aboutcode.org for more information about nexB OSS projects.
9+
#
10+
11+
import logging
12+
from datetime import datetime
13+
from typing import Any
14+
from typing import Iterable
15+
from typing import List
16+
from typing import Mapping
17+
from typing import Optional
18+
from urllib.parse import urljoin
19+
20+
import pytz
21+
from bs4 import BeautifulSoup
22+
from packageurl import PackageURL
23+
from univers.version_range import RpmVersionRange
24+
25+
from vulnerabilities.importer import AdvisoryData
26+
from vulnerabilities.importer import AffectedPackage
27+
from vulnerabilities.importer import Importer
28+
from vulnerabilities.importer import Reference
29+
from vulnerabilities.importer import VulnerabilitySeverity
30+
from vulnerabilities.references import WireSharkReference
31+
from vulnerabilities.references import XsaReference
32+
from vulnerabilities.references import ZbxReference
33+
from vulnerabilities.severity_systems import SCORING_SYSTEMS
34+
from vulnerabilities.utils import fetch_response
35+
from vulnerabilities.utils import is_cve
36+
37+
LOGGER = logging.getLogger(__name__)
38+
BASE_URL = "https://alas.aws.amazon.com/"
39+
other_url = "https://explore.alas.aws.amazon.com/{cve_id.json}" # use this in the url in code to get details for the specific cve.
40+
41+
42+
class AmazonLinuxImporter(Importer):
43+
spdx_license_expression = "CC BY 4.0" # check if this is correct
44+
license_url = " " # todo
45+
46+
importer_name = "Amazon Linux Importer"
47+
48+
def advisory_data(self) -> Iterable[AdvisoryData]:
49+
amazon_linux_1_url = BASE_URL + "/index.html"
50+
amazon_linux_2_url = BASE_URL + "/alas2.html"
51+
amazon_linux_2023_url = BASE_URL + "/alas2023.html"
52+
amazonlinux_advisories_pages = [
53+
amazon_linux_1_url,
54+
amazon_linux_2_url,
55+
amazon_linux_2023_url,
56+
]
57+
alas_dict = {}
58+
for amazonlinux_advisories_page in amazonlinux_advisories_pages:
59+
alas_dict.update(fetch_alas_id_and_advisory_links(amazonlinux_advisories_page))
60+
61+
for alas_id, alas_url in alas_dict.items():
62+
# It iterates through alas_dict to get alas ids and alas url
63+
if alas_id and alas_url:
64+
alas_advisory_page_content = fetch_response(alas_url).content
65+
yield process_advisory_data(alas_id, alas_advisory_page_content, alas_url)
66+
67+
68+
def fetch_alas_id_and_advisory_links(page_url: str) -> dict[str, str]:
69+
"""
70+
Return a dictionary where 'ALAS' entries are the keys and
71+
their corresponding advisory page links are the values.
72+
"""
73+
74+
page_response_content = fetch_response(page_url).content
75+
# Parse the HTML content
76+
soup = BeautifulSoup(page_response_content, "html.parser")
77+
alas_dict = {}
78+
79+
if page_url == "https://alas.aws.amazon.com/index.html":
80+
# Find all relevant ALAS links and their IDs
81+
for row in soup.find_all("tr", id=True):
82+
alas_id = row["id"]
83+
link_tag = row.find("a", href=True)
84+
if link_tag:
85+
full_url = "https://alas.aws.amazon.com/" + link_tag["href"]
86+
alas_dict[alas_id] = full_url
87+
88+
elif page_url == "https://alas.aws.amazon.com/alas2.html":
89+
# Find all relevant ALAS links and their IDs
90+
for row in soup.find_all("tr", id=True):
91+
alas_id = row["id"]
92+
link_tag = row.find("a", href=True)
93+
if link_tag:
94+
full_url = "https://alas.aws.amazon.com/AL2" + link_tag["href"]
95+
alas_dict[alas_id] = full_url
96+
97+
else:
98+
# Find all relevant ALAS links and their IDs
99+
for row in soup.find_all("tr", id=True):
100+
alas_id = row["id"]
101+
link_tag = row.find("a", href=True)
102+
if link_tag:
103+
full_url = "https://alas.aws.amazon.com/AL2023/" + link_tag["href"]
104+
alas_dict[alas_id] = full_url
105+
return alas_dict
106+
107+
108+
def process_advisory_data(alas_id, alas_advisory_page_content, alas_url) -> Optional[AdvisoryData]:
109+
110+
soup = BeautifulSoup(alas_advisory_page_content, "html.parser")
111+
aliases = []
112+
aliases.append(alas_id)
113+
114+
# Find the advisory release date
115+
release_date_span = next(
116+
(
117+
span
118+
for span in soup.find_all("span", class_="alas-info")
119+
if "Advisory Release Date:" in span.get_text(strip=True)
120+
),
121+
None,
122+
)
123+
124+
release_date = (
125+
release_date_span.get_text(strip=True).split(":", 1)[1].strip()
126+
if release_date_span
127+
else None
128+
)
129+
date_published = get_date_published(release_date)
130+
131+
# Extract Issue Overview (all points of issue overviews texts)
132+
issue_overview = []
133+
for p in soup.find("div", id="issue_overview").find_all("p"):
134+
issue_overview.append(p.text.strip())
135+
summary = create_summary(issue_overview)
136+
137+
# Extract Affected Packages (list of strings)
138+
processed_affected_packages = []
139+
affected_packages_section = soup.find("div", id="affected_packages")
140+
if affected_packages_section:
141+
affected_packages = affected_packages_section.find_all("p")
142+
affected_packages = [pkg.text.strip() for pkg in affected_packages]
143+
144+
# getting new packages
145+
new_packages_div = soup.find("div", id="new_packages")
146+
147+
# Extract the text elements between <br /> tags within this div
148+
if new_packages_div:
149+
new_packages_list = [
150+
element.strip() for element in new_packages_div.pre.stripped_strings if element.strip()
151+
]
152+
else:
153+
new_packages_list = []
154+
155+
for package in affected_packages:
156+
purl = PackageURL(type="rpm", namespace="alas.aws.amazon", name=package)
157+
# fixed_version = get_fixed_versions(new_packages_list)
158+
processed_affected_packages.append(
159+
AffectedPackage(package=purl, affected_version_range=None, fixed_version=None)
160+
)
161+
162+
cve_list = []
163+
for link in soup.find("div", id="references").find_all("a", href=True):
164+
if "CVE-" in link.text:
165+
cve_list.append((link.text.strip(), "https://alas.aws.amazon.com" + link["href"]))
166+
167+
references: List[Reference] = []
168+
for cve_id, cve_url in cve_list:
169+
cve_json_url = f"https://explore.alas.aws.amazon.com/{cve_id}"
170+
response = fetch_response(cve_json_url)
171+
172+
# Parse the JSON data
173+
cve_info = response.json()
174+
severity_scores = cve_info.get("scores", [])
175+
severity = []
176+
for score in severity_scores:
177+
severity.append(
178+
VulnerabilitySeverity(
179+
system=SCORING_SYSTEMS[score.get("type", "").lower()],
180+
value=score.get("score", ""),
181+
scoring_elements=score.get("vector", ""),
182+
)
183+
)
184+
references.append(Reference(reference_id=cve_id, url=cve_url, severities=severity))
185+
186+
url = alas_url
187+
188+
return AdvisoryData(
189+
aliases=aliases,
190+
date_published=date_published,
191+
summary=summary,
192+
references=references,
193+
affected_packages=processed_affected_packages,
194+
url=url,
195+
)
196+
197+
198+
def get_date_published(release_date_string):
199+
200+
# Parse the date and time
201+
date_part = release_date_string[:16]
202+
time_zone = release_date_string[17:]
203+
204+
# Convert to datetime object (naive)
205+
naive_date = datetime.strptime(date_part, "%Y-%m-%d %H:%M")
206+
207+
# Convert to aware datetime by adding the Pacific time zone
208+
timezone = pytz.timezone("America/Los_Angeles")
209+
date_published = timezone.localize(naive_date)
210+
return date_published
211+
212+
213+
def create_summary(summary_point: List):
214+
summary = ". ".join(summary_point)
215+
216+
# Add a period at the end if the final sentence doesn't end with one
217+
if not summary.endswith("."):
218+
summary += "."
219+
return summary
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import json
10+
import os
11+
from unittest import TestCase
12+
13+
from bs4 import BeautifulSoup
14+
15+
from vulnerabilities.importers.amazon_linux import process_advisory_data
16+
from vulnerabilities.tests import util_tests
17+
18+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
19+
TEST_DATA = os.path.join(BASE_DIR, "test_data/amazon_linux")
20+
21+
22+
class TestAmazonLinuxImporter(TestCase):
23+
def test_process_advisory_data1(self):
24+
with open(
25+
os.path.join(TEST_DATA, "amazon_linux_advisory_test1.html"), "r", encoding="utf-8"
26+
) as file:
27+
html_content = file.read()
28+
result = process_advisory_data(
29+
"ALAS-2024-1943", html_content, "https://test-url.com/ALAS-2024-1943.html"
30+
).to_dict()
31+
# expected_file = os.path.join(TEST_DATA, "github_osv_expected_1.json")
32+
print(f"Output is {result}")
33+
# util_tests.check_results_against_json(result, expected_file)
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
<!doctype html>
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<title>ALAS-2024-1943</title>
7+
<link rel='icon' type='image/x-icon' href='static/favicon.ico' />
8+
<link rel="stylesheet" href="static/bootstrap.min.css" type='text/css' media='print, projection, screen' >
9+
<link rel='stylesheet' href='static/blue_style.css' type='text/css' media='print, projection, screen' />
10+
<link rel='stylesheet' href='static/fontawesome.css' type='text/css' media='print, projection, screen' />
11+
<link rel='stylesheet' href='static/style.css' type='text/css' media='print, projection, screen' />
12+
<script type='text/javascript' src='static/jquery.min.js'></script>
13+
<script type='text/javascript' src='static/jquery.tablesorter.min.js'></script>
14+
<script type="text/javascript" src="static/index.js"></script>
15+
16+
<!--Add constant cookie banner on this page-->
17+
<script type = 'text/javascript'>
18+
var shortbread = AWSCShortbread();
19+
shortbread.checkForCookieConsent();
20+
function customize() {
21+
shortbread.customizeCookies();
22+
}
23+
</script>
24+
25+
<style>
26+
a{text-decoration: none; color: #0073BB}
27+
a:visited{color: #0073BB}
28+
.Site {
29+
display: flex;
30+
display: -webkit-flex; /* Safari */
31+
min-height: 100vh;
32+
flex-direction: column;
33+
}
34+
.Site-content {
35+
flex: 1;
36+
}
37+
</style>
38+
</head>
39+
<body class="Site">
40+
<main class="Site-content">
41+
<div class="container">
42+
<nav class="navbar navbar-fixed-top navbar-inverse" style="background-color: #000000" id="bs-navbar">
43+
<a style="font-size: 20px; color: #FF9900" class="navbar-brand" href="/"><b>Amazon Linux Security Center</b></a>
44+
<ul class="nav navbar-nav navbar-right" style="color: #ff9900">
45+
<li style="background-color: #FF9900;"> <a style="color: #000000" href="/index.html">Amazon Linux 1</a> </li><li style="background-color: #333333;"> <a style="color: #FFFFFF" href="/alas2.html">Amazon Linux 2</a> </li><li style="background-color: #333333;"> <a style="color: #FFFFFF" href="/alas2023.html">Amazon Linux 2023</a> </li><li style="background-color: #333333;"> <a style="color: #FFFFFF" href="/announcements.html">Announcements</a> </li><li style="background-color: #333333;"> <a style="color: #FFFFFF" href="/faqs.html">FAQs</a> </li>
46+
</ul>
47+
</nav>
48+
</div>
49+
<div style='min-height: 523px; margin-top:80px;' class='nine columns content-with-nav' role='main'>
50+
<section>
51+
<div class='title'>
52+
<h1 id='ALAS-2024-1943'>ALAS-2024-1943</h1>
53+
</div>
54+
55+
<div class='text'>
56+
<hr class='mid-pad'>
57+
<span class='alas-info'>
58+
<b>Amazon Linux 1 Security Advisory:</b> ALAS-2024-1943
59+
</span><br />
60+
<span class='alas-info'><b>Advisory Release Date:</b> 2024-07-03 21:01 Pacific</span><br />
61+
<span class='alas-info'><b>Advisory Updated Date:</b> 2024-07-08 17:04 Pacific</span><br />
62+
63+
<div id='severity' class='alas-info'>
64+
<b>Severity:</b>
65+
<span class='date'>
66+
<span class='bulletin-type'>
67+
<i class='fas fa-exclamation-triangle'></i>
68+
</span>
69+
</span>
70+
Important<br />
71+
</div>
72+
73+
<div id='references'>
74+
<b>References:</b>
75+
<a href='/cve/html/CVE-2021-47110.html' target='_blank' rel='noopener noreferrer'>CVE-2021-47110&nbsp;</a>
76+
<br />
77+
<a href="../../faqs.html">FAQs regarding Amazon Linux ALAS/CVE Severity</a>
78+
</div>
79+
80+
<hr class='mid-pad'>
81+
<div id='issue_overview'>
82+
<b>Issue Overview:</b>
83+
<p>In the Linux kernel, the following vulnerability has been resolved:</p><p>x86/kvm: Disable kvmclock on all CPUs on shutdown (CVE-2021-47110)</p>
84+
</div>
85+
86+
<div id='affected_packages' class='alas-info'>
87+
<br />
88+
<b>Affected Packages:</b>
89+
<br />
90+
<p>kernel</p>
91+
</div>
92+
93+
<div id='issue_correction'>
94+
<br />
95+
<b>Issue Correction:</b>
96+
<br />Run <i>yum update kernel</i> to update your system.<br /></div>
97+
<br />
98+
<div id='new_packages'>
99+
<b>New Packages:</b><pre>i686:<br />&nbsp;&nbsp;&nbsp; kernel-debuginfo-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-devel-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-tools-devel-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-headers-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; perf-debuginfo-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-debuginfo-common-i686-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-tools-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; perf-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-4.14.348-187.565.amzn1.i686<br />&nbsp;&nbsp;&nbsp; kernel-tools-debuginfo-4.14.348-187.565.amzn1.i686<br /><br />src:<br />&nbsp;&nbsp;&nbsp; kernel-4.14.348-187.565.amzn1.src<br /><br />x86_64:<br />&nbsp;&nbsp;&nbsp; kernel-devel-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-tools-debuginfo-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-headers-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-tools-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-tools-devel-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-debuginfo-common-x86_64-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; perf-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; kernel-debuginfo-4.14.348-187.565.amzn1.x86_64<br />&nbsp;&nbsp;&nbsp; perf-debuginfo-4.14.348-187.565.amzn1.x86_64<br /><br /></pre></div>
100+
</div>
101+
<div style="flex:1; margin-bottom: 40px;" class="links-container">
102+
<h3 class="section-heading">Additional References</h3>
103+
<p>
104+
Red Hat:&nbsp;<a style="margin-bottom: 40px;" href="https://access.redhat.com/security/cve/CVE-2021-47110" target="_blank" rel="noopener noreferrer">CVE-2021-47110</a></p>
105+
<p>
106+
Mitre:&nbsp;<a style="margin-bottom: 40px;" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-47110" target="_blank" rel="noopener noreferrer">CVE-2021-47110</a></p>
107+
</div>
108+
</section>
109+
</div>
110+
</main>
111+
<footer style="padding-left: 30px; padding-right: 30px;"><p style="color: #687078">
112+
CVE description copyright &#169 2023
113+
<a href="https://cve.mitre.org/about/termsofuse.html" target="_blank" rel="noopener noreferrer">The MITRE Corporation</a>
114+
</p>
115+
<p style="color: #687078">
116+
CVE description copyright &#169 2023 Red Hat, Inc. Per
117+
<a href="https://access.redhat.com/security/data" target="_blank" rel="noopener noreferrer">https://access.redhat.com/security/data</a>,
118+
RedHat's CVE report is licensed under
119+
<a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener noreferrer">CC BY 4.0</a>.
120+
</p>
121+
</footer>
122+
<footer style="padding-left: 30px; padding-right: 30px;"><p>
123+
<a href="https://aws.amazon.com/privacy/" target="_blank" rel="noopener noreferrer">Privacy</a> |
124+
<a href="https://aws.amazon.com/terms/" target="_blank" rel="noopener noreferrer">Site terms apply, and downloading this site or portions of it is permitted</a> |
125+
<a href="#" onclick="customize()">Cookie preferences</a> |
126+
<span style="color: #687078">&#169 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.</span>
127+
</p>
128+
</footer>
129+
</body>
130+
</html>

vulnerabilities/tests/test_data/amazon_linux/amazon_linux_expected1.json

Whitespace-only changes.

0 commit comments

Comments
 (0)