Skip to content

Commit b76210e

Browse files
author
Prabhu Subramanian
committed
Improved package type detection
1 parent d22ce30 commit b76210e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="appthreat-vulnerability-db",
8-
version="1.6.3",
8+
version="1.6.4",
99
author="Team AppThreat",
1010
author_email="[email protected]",
1111
description="AppThreat's vulnerability database and package search library with a built-in file based storage. CVE, GitHub, npm are the primary sources of vulnerabilities.",

vdb/cli.py

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def print_results(results):
110110
for res in results:
111111
vuln_occ_dict = res.to_dict()
112112
id = vuln_occ_dict.get("id")
113+
package_type = vuln_occ_dict.get("type")
113114
if id not in added_list:
114115
package_issue = res.package_issue
115116
full_pkg = package_issue.affected_location.package
@@ -118,6 +119,8 @@ def print_results(results):
118119
package_issue.affected_location.vendor,
119120
package_issue.affected_location.package,
120121
)
122+
if package_type and package_type != "*":
123+
full_pkg = package_type + ":" + full_pkg
121124
table.append(
122125
[
123126
id,

vdb/lib/__init__.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@
77
# Known application package types
88
KNOWN_PKG_TYPES = ["composer", "maven", "npm", "nuget", "pypi", "rubygems", "golang"]
99

10+
# Maps variations of string to package types
11+
PKG_TYPES_MAP = {
12+
"composer": ["php", "laravel", "wordpress", "joomla"],
13+
"maven": ["jenkins", "java", "kotlin", "groovy"],
14+
"npm": ["javascript", "node.js", "nodejs"],
15+
"nuget": [".net_framework", "csharp", ".net_core"],
16+
"pypi": ["python"],
17+
"rubygems": ["ruby"],
18+
"golang": ["go"],
19+
}
20+
1021
# CPE Regex
1122
CPE_REGEX = re.compile(
1223
"cpe:?:[^:]+:[^:]+:(?P<vendor>[^:]+):(?P<package>[^:]+):(?P<version>[^:]+)?"
1324
)
1425

26+
# CPE Full Regex including unused parameters
27+
CPE_FULL_REGEX = re.compile(
28+
"cpe:?:[^:]+:[^:]+:(?P<vendor>[^:]+):(?P<package>[^:]+):(?P<version>[^:]+):(?P<update>[^:]+):(?P<edition>[^:]+):(?P<lang>[^:]+):(?P<sw_edition>[^:]+):(?P<target_sw>[^:]+):(?P<target_hw>[^:]+):(?P<other>[^:]+)"
29+
)
30+
1531

1632
class VulnerabilitySource(metaclass=ABCMeta):
1733
@classmethod
@@ -191,15 +207,31 @@ def get_type(cpe_uri, package_type):
191207
if package_type in KNOWN_PKG_TYPES:
192208
return package_type
193209
parts = CPE_REGEX.match(cpe_uri)
210+
# cpe:2.3:a:netaddr_project:netaddr:*:*:*:*:*:ruby:*:*
211+
all_parts = CPE_FULL_REGEX.match(cpe_uri)
194212
if parts:
195213
type = parts.group("vendor")
196214
if type in KNOWN_PKG_TYPES:
197215
return type
216+
elif all_parts and (
217+
(all_parts.group("target_sw") and all_parts.group("target_sw") != "*")
218+
or (
219+
all_parts.group("sw_edition")
220+
and all_parts.group("sw_edition") != "*"
221+
)
222+
):
223+
for vk, vv in PKG_TYPES_MAP.items():
224+
target_sw = all_parts.group("target_sw")
225+
sw_edition = all_parts.group("sw_edition")
226+
if target_sw == vk or sw_edition == vk:
227+
return vk
228+
if target_sw in vv or sw_edition in vv:
229+
return vk
230+
return type
198231
else:
199232
# Unknown type. Just pass-through for now
200233
return type
201-
else:
202-
return None
234+
return None
203235

204236
@staticmethod
205237
def from_dict(detail):

0 commit comments

Comments
 (0)