Skip to content

Commit fe1e94c

Browse files
ziadhanyTG1999
authored andcommitted
Add pathlib and glob
Fix docstring style Add the License, add a Git Importer to fireeye Remove print logs Add docstring , add test for parse_advisory_data. Add Fireeye importer Reference: #487 Signed-off-by: ziadhany <[email protected]>
1 parent 07985b0 commit fe1e94c

File tree

7 files changed

+397
-0
lines changed

7 files changed

+397
-0
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from vulnerabilities.importers import debian_oval
1616
from vulnerabilities.importers import elixir_security
1717
from vulnerabilities.importers import gentoo
18+
from vulnerabilities.importers import fireeye
1819
from vulnerabilities.importers import github
1920
from vulnerabilities.importers import gitlab
2021
from vulnerabilities.importers import istio
@@ -61,6 +62,7 @@
6162
apache_tomcat.ApacheTomcatImporter,
6263
xen.XenImporter,
6364
ubuntu_usn.UbuntuUSNImporter,
65+
fireeye.FireyeImporter,
6466
]
6567

6668
IMPORTERS_REGISTRY = {x.qualified_name: x for x in IMPORTERS_REGISTRY}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 re
10+
from pathlib import Path
11+
from typing import Iterable
12+
13+
from vulnerabilities.importer import AdvisoryData
14+
from vulnerabilities.importer import GitImporter
15+
from vulnerabilities.importer import Reference
16+
from vulnerabilities.utils import build_description
17+
from vulnerabilities.utils import dedupe
18+
19+
20+
class FireyeImporter(GitImporter):
21+
spdx_license_expression = "CC-BY-SA-4.0 AND MIT"
22+
license_url = "https://github.com/mandiant/Vulnerability-Disclosures/blob/master/README.md"
23+
24+
def __init__(self):
25+
super().__init__(repo_url="git+https://github.com/mandiant/Vulnerability-Disclosures")
26+
27+
def advisory_data(self) -> Iterable[AdvisoryData]:
28+
self.clone()
29+
files = filter(
30+
lambda p: p.suffix in [".md", ".MD"], Path(self.vcs_response.dest_dir).glob("**/*")
31+
)
32+
for file in files:
33+
if Path(file).stem == "README":
34+
continue
35+
with open(file, encoding="ISO-8859-1") as f:
36+
yield parse_advisory_data(f.read())
37+
38+
39+
def parse_advisory_data(raw_data) -> AdvisoryData:
40+
"""
41+
Parse a fireeye advisory repo and return an AdvisoryData or None.
42+
These files are in Markdown format.
43+
"""
44+
raw_data = raw_data.replace("\n\n", "\n")
45+
md_list = raw_data.split("\n")
46+
md_dict = md_list_to_dict(md_list)
47+
48+
database_id = md_list[0][1::]
49+
summary = md_dict.get(database_id[1::]) or []
50+
description = md_dict.get("## Description") or []
51+
impact = md_dict.get("## Impact") # not used but can be used to get severity
52+
exploit_ability = md_dict.get("## Exploitability") # not used
53+
cve_ref = md_dict.get("## CVE Reference") or []
54+
tech_details = md_dict.get("## Technical Details") # not used
55+
resolution = md_dict.get("## Resolution") # not used
56+
disc_credits = md_dict.get("## Discovery Credits") # not used
57+
disc_timeline = md_dict.get("## Disclosure Timeline") # not used
58+
references = md_dict.get("## References") or []
59+
60+
return AdvisoryData(
61+
aliases=get_aliases(database_id, cve_ref),
62+
summary=build_description(" ".join(summary), " ".join(description)),
63+
references=get_references(references),
64+
)
65+
66+
67+
def get_references(references):
68+
"""
69+
Return a list of Reference from a list of URL reference in md format
70+
>>> get_references(["- http://1-4a.com/cgi-bin/alienform/af.cgi"])
71+
[Reference(reference_id='', url='http://1-4a.com/cgi-bin/alienform/af.cgi', severities=[])]
72+
>>> get_references(["- [Mitre CVE-2021-42712](https://www.cve.org/CVERecord?id=CVE-2021-42712)"])
73+
[Reference(reference_id='', url='https://www.cve.org/CVERecord?id=CVE-2021-42712', severities=[])]
74+
"""
75+
urls = []
76+
for ref in references:
77+
if ref.startswith("- "):
78+
urls.append(matcher_url(ref[2::]))
79+
else:
80+
urls.append(matcher_url(ref))
81+
82+
return [Reference(url=url) for url in urls if url]
83+
84+
85+
def matcher_url(ref) -> str:
86+
"""
87+
Returns URL of the reference markup from reference url in Markdown format
88+
"""
89+
markup_regex = "\[([^\[]+)]\(\s*(http[s]?://.+)\s*\)"
90+
matched_markup = re.findall(markup_regex, ref)
91+
if matched_markup:
92+
return matched_markup[0][1]
93+
else:
94+
return ref
95+
96+
97+
def get_aliases(database_id, cve_ref) -> []:
98+
"""
99+
Returns a List of Aliases from a database_id and a list of CVEs
100+
>>> get_aliases("MNDT-2021-0012",["CVE-2021-44207"])
101+
['CVE-2021-44207', 'MNDT-2021-0012']
102+
"""
103+
cve_ref.append(database_id)
104+
return dedupe(cve_ref)
105+
106+
107+
def md_list_to_dict(md_list):
108+
"""
109+
Returns a dictionary of md_list from a list of a md file splited by \n
110+
>>> md_list_to_dict(["# Header","hello" , "hello again" ,"# Header2"])
111+
{'# Header': ['hello', 'hello again'], '# Header2': []}
112+
"""
113+
md_dict = {}
114+
md_key = ""
115+
for md_line in md_list:
116+
if md_line.startswith("#"):
117+
md_dict[md_line] = []
118+
md_key = md_line
119+
else:
120+
md_dict[md_key].append(md_line)
121+
return md_dict
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# FEYE-2019-0002
2+
## Description
3+
GPU-Z.sys, part of the GPU-Z package from TechPowerUp, exposes the wrmsr instruction to user-mode callers without properly validating the target Model Specific Register (MSR). This can result in arbitrary unsigned code being executed in Ring 0.
4+
5+
## Impact
6+
High - Arbitrary Ring 0 code execution
7+
8+
## Exploitability
9+
Medium/Low - Driver must be loaded or attacker will require admin rights. Newer versions require admin callers.
10+
11+
## CVE Reference
12+
CVE-2019-7245
13+
14+
## Technical Details
15+
IOCTL 0x8000644C in the GPU-Z driver instructs the binary to modify a Model Specific Register (MSR) on the target system. These registers control a wide variety of system functionality and can be used to monitor CPU temperature, track branches in code, tweak voltages, etc. MSRs are also responsible for setting the kernel mode function responsible for handling system calls.
16+
17+
The driver does not appropriately filter access to MSRs, allowing an attacker to overwrite the system call handler and run unsigned code in Ring 0. Allowing access to any of the following MSRs can result in arbitrary Ring 0 code being executed:
18+
19+
* 0xC0000081
20+
* 0xC0000082
21+
* 0xC0000083
22+
* 0x174
23+
* 0x175
24+
* 0x176
25+
26+
For exploitation details see the INFILTRATE presentation in the references.
27+
28+
## Resolution
29+
This issue is fixed in v2.23.0: [https://www.techpowerup.com/257995/techpowerup-releases-gpu-z-v2-23-0](https://www.techpowerup.com/257995/techpowerup-releases-gpu-z-v2-23-0)
30+
31+
## Discovery Credits
32+
Ryan Warns
33+
34+
## Disclosure Timeline
35+
- 2 February 2019 - Contacted vendor
36+
- 2 February 2019 - Vendor response, confirmation of issue
37+
- 25 July 2019 - Vendor confirmed fix
38+
- 6 August 2019 - Fixed version released
39+
40+
## References
41+
[Exploitation Details](https://downloads.immunityinc.com/infiltrate2019-slidepacks/ryan-warns-timothy-harrison-device-driver-debauchery-msr-madness/MSR_Madness_v2.9_INFILTRATE.pptx)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"aliases": [
3+
"CVE-2019-7245 ", " FEYE-2019-0002"
4+
],
5+
"summary": "GPU-Z.sys, part of the GPU-Z package from TechPowerUp, exposes the wrmsr instruction to user-mode callers without properly validating the target Model Specific Register (MSR). This can result in arbitrary unsigned code being executed in Ring 0.",
6+
"affected_packages": [],
7+
"references": [],
8+
"date_published":""
9+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# FEYE-2020-0020
2+
## Description
3+
4+
Digi International's ConnectPort X2e is susceptible to a local privilege escalation vulnerable to the privileged user `root`.
5+
6+
## Impact
7+
High - An attacker with remote network access to a X2e could remotely compromise the device. This could be used to install malware, modify system behavior, or stage a more serious attack.
8+
9+
## Exploitability
10+
Medium - An attacker would need to read and write files as the system user python. On production devices, this can be accomplished remotely by establishing an SSH connection or access via a TTY.
11+
12+
## CVE Reference
13+
CVE-2020-12878
14+
15+
## Technical Details
16+
The ConnectPort X2e performed filesystem actions as the privileged system user root on files controllable by the less-privileged user python. A malicious attacker could use this to escalate privileges from the local user `python` user to `root`.
17+
18+
Mandiant determined that the user `root` executed the file `/etc/init.d/S50dropbear.sh` during normal system boot. The shell script performed a `chown` on the directory `/WEB/python/.ssh/`, which was writable as the user `python`.
19+
20+
To exploit this, Mandiant used Linux symbolic links to force the system to set the ownership of the directory `/etc/init.d/` to `python:python`. Mandiant could then create a malicious `init` script in the `/etc/init.d/` directory that would be executed by `root` on future system boots.
21+
22+
## Resolution
23+
Digi International has fixed the reported vulnerability in [version 3.2.30.6](https://ftp1.digi.com/support/firmware/93001304_D.pdf) (May 2020) of the ConnectPort X2e software.
24+
25+
## Discovery Credits
26+
- Jake Valletta, FireEye Mandiant
27+
- Sam Sabetan, FireEye Mandiant
28+
29+
## Disclosure Timeline
30+
31+
- 13 February 2020 - Issue reported to vendor
32+
- 11 March 2020 - Issue confirmed by Digi International
33+
- 14 May 2020 - CVE reserved with MITRE
34+
- May 2020 - Digi Releases Patch
35+
- 17 February 2021 - FireEye Mandiant advisory published
36+
37+
## References
38+
39+
- https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-12878
40+
- https://www.fireeye.com/blog/threat-research/2021/02/solarcity-exploitation-of-x2e-iot-device-part-one.html
41+
- https://www.fireeye.com/blog/threat-research/2021/02/solarcity-exploitation-of-x2e-iot-device-part-two.html
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"aliases": ["CVE-2020-12878", " FEYE-2020-0020"],
3+
"summary": "Digi International's ConnectPort X2e is susceptible to a local privilege escalation vulnerable to the privileged user `root`.",
4+
"affected_packages": [],
5+
"references": [
6+
{
7+
"reference_id": "", "url": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-12878", "severities": []},
8+
{
9+
"reference_id": "", "url": "https://www.fireeye.com/blog/threat-research/2021/02/solarcity-exploitation-of-x2e-iot-device-part-one.html", "severities": []},
10+
{
11+
"reference_id": "", "url": "https://www.fireeye.com/blog/threat-research/2021/02/solarcity-exploitation-of-x2e-iot-device-part-two.html", "severities": []}],
12+
"date_published":""
13+
}

0 commit comments

Comments
 (0)