blint 2.3.0__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {blint-2.3.0 → blint-2.3.1}/PKG-INFO +11 -6
- {blint-2.3.0 → blint-2.3.1}/README.md +8 -4
- {blint-2.3.0 → blint-2.3.1}/blint/android.py +19 -15
- {blint-2.3.0 → blint-2.3.1}/blint/cli.py +11 -4
- {blint-2.3.0 → blint-2.3.1}/blint/sbom.py +78 -16
- {blint-2.3.0 → blint-2.3.1}/blint/utils.py +11 -1
- {blint-2.3.0 → blint-2.3.1}/pyproject.toml +4 -3
- {blint-2.3.0 → blint-2.3.1}/LICENSE +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/__init__.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/analysis.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/binary.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/checks.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/config.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/cyclonedx/README.md +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/cyclonedx/__init__.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/cyclonedx/spdx.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/cyclonedx/spec.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/__init__.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/__init__.py +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_entries_generic.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_entries_pe.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_exe_go.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_imports_pe.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_methods_generic.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_methods_mips.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_monero_generic.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_monero_go.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_monero_rust.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_rootkits_win.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_symbols_generic.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_symbols_hooka.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_symbols_macho.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/annotations/review_symbols_rust.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/data/rules.yml +0 -0
- {blint-2.3.0 → blint-2.3.1}/blint/logger.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: blint
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.1
|
|
4
4
|
Summary: Linter and SBOM generator for binary files.
|
|
5
5
|
Home-page: https://github.com/OWASP-dep-scan/blint
|
|
6
6
|
License: MIT
|
|
7
7
|
Keywords: linter,binary,security,sast
|
|
8
8
|
Author: Prabhu Subramanian
|
|
9
9
|
Author-email: prabhu@appthreat.com
|
|
10
|
-
Requires-Python: >=3.10,<3.
|
|
10
|
+
Requires-Python: >=3.10,<3.14
|
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: Intended Audience :: System Administrators
|
|
@@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Classifier: Topic :: Security
|
|
21
22
|
Classifier: Topic :: Utilities
|
|
22
23
|
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
@@ -102,17 +103,21 @@ sub-commands:
|
|
|
102
103
|
### SBOM sub-command
|
|
103
104
|
|
|
104
105
|
```shell
|
|
105
|
-
usage: blint sbom [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o SBOM_OUTPUT] [--deep]
|
|
106
|
+
usage: blint sbom [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o SBOM_OUTPUT] [--deep] [--stdout] [--exports-prefix EXPORTS_PREFIX [EXPORTS_PREFIX ...]]
|
|
107
|
+
[--bom-src SRC_DIR_BOMS [SRC_DIR_BOMS ...]]
|
|
106
108
|
|
|
107
109
|
options:
|
|
108
110
|
-h, --help show this help message and exit
|
|
109
111
|
-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...], --src SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]
|
|
110
112
|
Source directories, container images or binary files. Defaults to current directory.
|
|
111
113
|
-o SBOM_OUTPUT, --output-file SBOM_OUTPUT
|
|
112
|
-
SBOM output file. Defaults to bom.json in current directory.
|
|
113
|
-
--deep Enable deep mode to collect more used symbols and modules aggressively. Slow
|
|
114
|
-
operation.
|
|
114
|
+
SBOM output file. Defaults to bom-post-build.cdx.json in current directory.
|
|
115
|
+
--deep Enable deep mode to collect more used symbols and modules aggressively. Slow operation.
|
|
115
116
|
--stdout Print the SBOM to stdout instead of a file.
|
|
117
|
+
--exports-prefix EXPORTS_PREFIX [EXPORTS_PREFIX ...]
|
|
118
|
+
prefixes for the exports to be included in the SBOM.
|
|
119
|
+
--bom-src SRC_DIR_BOMS [SRC_DIR_BOMS ...]
|
|
120
|
+
Directories containing pre-build and build BOMs. Use to improve the precision.
|
|
116
121
|
```
|
|
117
122
|
|
|
118
123
|
To test any binary, including default commands
|
|
@@ -69,17 +69,21 @@ sub-commands:
|
|
|
69
69
|
### SBOM sub-command
|
|
70
70
|
|
|
71
71
|
```shell
|
|
72
|
-
usage: blint sbom [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o SBOM_OUTPUT] [--deep]
|
|
72
|
+
usage: blint sbom [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o SBOM_OUTPUT] [--deep] [--stdout] [--exports-prefix EXPORTS_PREFIX [EXPORTS_PREFIX ...]]
|
|
73
|
+
[--bom-src SRC_DIR_BOMS [SRC_DIR_BOMS ...]]
|
|
73
74
|
|
|
74
75
|
options:
|
|
75
76
|
-h, --help show this help message and exit
|
|
76
77
|
-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...], --src SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]
|
|
77
78
|
Source directories, container images or binary files. Defaults to current directory.
|
|
78
79
|
-o SBOM_OUTPUT, --output-file SBOM_OUTPUT
|
|
79
|
-
SBOM output file. Defaults to bom.json in current directory.
|
|
80
|
-
--deep Enable deep mode to collect more used symbols and modules aggressively. Slow
|
|
81
|
-
operation.
|
|
80
|
+
SBOM output file. Defaults to bom-post-build.cdx.json in current directory.
|
|
81
|
+
--deep Enable deep mode to collect more used symbols and modules aggressively. Slow operation.
|
|
82
82
|
--stdout Print the SBOM to stdout instead of a file.
|
|
83
|
+
--exports-prefix EXPORTS_PREFIX [EXPORTS_PREFIX ...]
|
|
84
|
+
prefixes for the exports to be included in the SBOM.
|
|
85
|
+
--bom-src SRC_DIR_BOMS [SRC_DIR_BOMS ...]
|
|
86
|
+
Directories containing pre-build and build BOMs. Use to improve the precision.
|
|
83
87
|
```
|
|
84
88
|
|
|
85
89
|
To test any binary, including default commands
|
|
@@ -106,12 +106,11 @@ def strip_apk_data(data):
|
|
|
106
106
|
Returns:
|
|
107
107
|
str: The stripped data.
|
|
108
108
|
"""
|
|
109
|
+
parts = data.split("\n")
|
|
109
110
|
if "JAVA_TOOL_OPTIONS" in data:
|
|
110
|
-
parts = data.split("\n")
|
|
111
111
|
if parts and len(parts) > 0:
|
|
112
112
|
parts.pop(0)
|
|
113
|
-
|
|
114
|
-
return ""
|
|
113
|
+
return "\n".join(parts)
|
|
115
114
|
|
|
116
115
|
|
|
117
116
|
def collect_version_files_metadata(app_file, app_temp_dir):
|
|
@@ -162,13 +161,14 @@ def create_version_component(app_file, group, name, rel_path, version_data):
|
|
|
162
161
|
Returns:
|
|
163
162
|
Component: A Component object with the provided metadata.
|
|
164
163
|
"""
|
|
164
|
+
confidence = 1.0
|
|
165
165
|
if group:
|
|
166
|
-
purl = f"pkg:maven/{group}/{name}@{version_data}"
|
|
166
|
+
purl = f"pkg:maven/{group}/{name}@{version_data}?type=jar"
|
|
167
167
|
else:
|
|
168
|
-
purl = f"pkg:maven/{name}@{version_data}"
|
|
169
|
-
|
|
168
|
+
purl = f"pkg:maven/{name}@{version_data}?type=jar"
|
|
169
|
+
confidence = 0.2
|
|
170
170
|
# Adjust the confidence based on the version data
|
|
171
|
-
if version_data in ("latest", "dynamic"):
|
|
171
|
+
if not version_data or version_data in ("latest", "dynamic"):
|
|
172
172
|
confidence = 0.2
|
|
173
173
|
component = Component(
|
|
174
174
|
type=Type.library,
|
|
@@ -261,7 +261,9 @@ def parse_so_file(app_file, app_temp_dir, sof):
|
|
|
261
261
|
for f in so_metadata.get("functions", [])
|
|
262
262
|
if f.get("name") and not f.get("name").startswith("_")
|
|
263
263
|
]
|
|
264
|
-
purl = f"pkg:
|
|
264
|
+
purl = f"pkg:android/{name}"
|
|
265
|
+
if version:
|
|
266
|
+
purl = f"{purl}@{version}"
|
|
265
267
|
if arch:
|
|
266
268
|
purl = f"{purl}?arch={arch}"
|
|
267
269
|
component = Component(
|
|
@@ -282,16 +284,16 @@ def parse_so_file(app_file, app_temp_dir, sof):
|
|
|
282
284
|
return component
|
|
283
285
|
|
|
284
286
|
|
|
285
|
-
def get_so_version(so_metadata_notes):
|
|
287
|
+
def get_so_version(so_metadata_notes) -> str | None:
|
|
286
288
|
"""Returns the version of the shared object (SO) file.
|
|
287
289
|
|
|
288
290
|
Args:
|
|
289
291
|
so_metadata_notes: The metadata notes of the SO file.
|
|
290
292
|
|
|
291
293
|
Returns:
|
|
292
|
-
str: The version of the SO file.
|
|
294
|
+
str | None: The version of the SO file or None.
|
|
293
295
|
"""
|
|
294
|
-
version =
|
|
296
|
+
version = None
|
|
295
297
|
for anote in so_metadata_notes:
|
|
296
298
|
if anote.get("version"):
|
|
297
299
|
version = anote.get("version")
|
|
@@ -323,7 +325,7 @@ def collect_dex_files_metadata(app_file, parent_component, app_temp_dir):
|
|
|
323
325
|
rel_path = os.path.relpath(adex, app_temp_dir)
|
|
324
326
|
group = parent_component.group if parent_component and parent_component.group else ""
|
|
325
327
|
version = (
|
|
326
|
-
parent_component.version if parent_component and parent_component.version else
|
|
328
|
+
parent_component.version if parent_component and parent_component.version else None
|
|
327
329
|
)
|
|
328
330
|
component = create_dex_component(app_file, dex_metadata, group, name, rel_path, version)
|
|
329
331
|
file_components.append(component)
|
|
@@ -340,12 +342,14 @@ def create_dex_component(app_file, dex_metadata, group, name, rel_path, version)
|
|
|
340
342
|
group (str): The group of the component.
|
|
341
343
|
name (LiteralString | bytes): The name of the component.
|
|
342
344
|
rel_path (str | LiteralString |bytes): The relative path.
|
|
343
|
-
version (str): The version of the component.
|
|
345
|
+
version (str | None): The version of the component.
|
|
344
346
|
|
|
345
347
|
Returns:
|
|
346
348
|
Component: A Component object representing the DEX file with metadata.
|
|
347
349
|
"""
|
|
348
|
-
purl = f"pkg:
|
|
350
|
+
purl = f"pkg:android/{name}"
|
|
351
|
+
if version:
|
|
352
|
+
purl = f"{purl}@{version}"
|
|
349
353
|
comp = Component(
|
|
350
354
|
type=Type.file,
|
|
351
355
|
group=group,
|
|
@@ -414,7 +418,7 @@ def parse_apk_summary(data):
|
|
|
414
418
|
if data and (parts := data.strip().split("\n")[-1].split("\t")):
|
|
415
419
|
name = parts[0]
|
|
416
420
|
version = parts[-1]
|
|
417
|
-
purl = f"pkg:
|
|
421
|
+
purl = f"pkg:android/{name}@{version}"
|
|
418
422
|
component = Component(type=Type.application, name=name, version=version, purl=purl)
|
|
419
423
|
component.bom_ref = RefType(purl)
|
|
420
424
|
return component
|
|
@@ -95,7 +95,7 @@ def build_args():
|
|
|
95
95
|
"-o",
|
|
96
96
|
"--output-file",
|
|
97
97
|
dest="sbom_output",
|
|
98
|
-
help="SBOM output file. Defaults to bom.json in current directory.",
|
|
98
|
+
help="SBOM output file. Defaults to bom-post-build.cdx.json in current directory.",
|
|
99
99
|
)
|
|
100
100
|
sbom_parser.add_argument(
|
|
101
101
|
"--deep",
|
|
@@ -120,6 +120,13 @@ def build_args():
|
|
|
120
120
|
dest="exports_prefix",
|
|
121
121
|
help="prefixes for the exports to be included in the SBOM.",
|
|
122
122
|
)
|
|
123
|
+
sbom_parser.add_argument(
|
|
124
|
+
"--bom-src",
|
|
125
|
+
dest="src_dir_boms",
|
|
126
|
+
action="extend",
|
|
127
|
+
nargs="+",
|
|
128
|
+
help="Directories containing pre-build and build BOMs. Use to improve the precision.",
|
|
129
|
+
)
|
|
123
130
|
return parser.parse_args()
|
|
124
131
|
|
|
125
132
|
|
|
@@ -186,13 +193,13 @@ def main():
|
|
|
186
193
|
if args.sbom_output:
|
|
187
194
|
sbom_output = args.sbom_output
|
|
188
195
|
if os.path.isdir(sbom_output):
|
|
189
|
-
sbom_output = os.path.join(sbom_output, "bom.json")
|
|
196
|
+
sbom_output = os.path.join(sbom_output, "bom-post-build.cdx.json")
|
|
190
197
|
else:
|
|
191
|
-
sbom_output = os.path.join(os.getcwd(), "bom.json")
|
|
198
|
+
sbom_output = os.path.join(os.getcwd(), "bom-post-build.cdx.json")
|
|
192
199
|
sbom_output_dir = os.path.dirname(sbom_output)
|
|
193
200
|
if sbom_output_dir and not os.path.exists(sbom_output_dir):
|
|
194
201
|
os.makedirs(sbom_output_dir)
|
|
195
|
-
generate(src_dirs, sbom_output, args.deep_mode, args.exports_prefix)
|
|
202
|
+
generate(src_dirs, sbom_output, args.deep_mode, args.exports_prefix, args.src_dir_boms)
|
|
196
203
|
# Default case
|
|
197
204
|
else:
|
|
198
205
|
if reports_dir and not os.path.exists(reports_dir):
|
|
@@ -6,6 +6,7 @@ import uuid
|
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
from typing import Any, Dict
|
|
8
8
|
|
|
9
|
+
import orjson
|
|
9
10
|
from rich.progress import Progress
|
|
10
11
|
|
|
11
12
|
from blint.android import collect_app_metadata
|
|
@@ -31,17 +32,19 @@ from blint.utils import (
|
|
|
31
32
|
camel_to_snake,
|
|
32
33
|
create_component_evidence,
|
|
33
34
|
find_android_files,
|
|
35
|
+
find_bom_files,
|
|
34
36
|
gen_file_list,
|
|
35
37
|
get_version,
|
|
36
38
|
)
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
def default_parent(src_dirs: list[str]) -> Component:
|
|
41
|
+
def default_parent(src_dirs: list[str], symbols_purl_map: dict = None) -> Component:
|
|
40
42
|
"""
|
|
41
43
|
Creates a default parent Component object for the given source directories.
|
|
42
44
|
|
|
43
45
|
Args:
|
|
44
46
|
src_dirs (list[str]): A list of source directories.
|
|
47
|
+
symbols_purl_map (dict): containing symbol name as the key and purl as the value
|
|
45
48
|
|
|
46
49
|
Returns:
|
|
47
50
|
Component: A Component object representing the default parent.
|
|
@@ -49,11 +52,21 @@ def default_parent(src_dirs: list[str]) -> Component:
|
|
|
49
52
|
if not src_dirs:
|
|
50
53
|
raise ValueError("No source directories provided")
|
|
51
54
|
name = os.path.basename(src_dirs[0])
|
|
55
|
+
version = None
|
|
52
56
|
# Extract the name from the .rlib files
|
|
53
57
|
if name.endswith(".rlib"):
|
|
54
58
|
name = name.split("-")[0].removeprefix("lib")
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
pkg_type = "nuget" if name.endswith(".dll") else "generic"
|
|
60
|
+
if pkg_type == "nuget":
|
|
61
|
+
name = name.replace(".dll", "")
|
|
62
|
+
purl = f"pkg:{pkg_type}/{name}"
|
|
63
|
+
pkg_type = Type.application
|
|
64
|
+
if symbols_purl_map and symbols_purl_map.get(purl):
|
|
65
|
+
purl = symbols_purl_map.get(purl)
|
|
66
|
+
pkg_type = Type.library
|
|
67
|
+
if "@" in purl:
|
|
68
|
+
version = purl.split("@")[-1]
|
|
69
|
+
component = Component(type=pkg_type, name=name, version=version, purl=purl)
|
|
57
70
|
component.bom_ref = RefType(purl)
|
|
58
71
|
return component
|
|
59
72
|
|
|
@@ -88,7 +101,7 @@ def default_metadata(src_dirs):
|
|
|
88
101
|
return metadata
|
|
89
102
|
|
|
90
103
|
|
|
91
|
-
def generate(src_dirs: list[str], output_file: str, deep_mode: bool, export_prefixes: list[str]) -> bool:
|
|
104
|
+
def generate(src_dirs: list[str], output_file: str, deep_mode: bool, export_prefixes: list[str], src_dir_boms: list[str]) -> bool:
|
|
92
105
|
"""
|
|
93
106
|
Generates an SBOM for the given source directories.
|
|
94
107
|
|
|
@@ -96,10 +109,14 @@ def generate(src_dirs: list[str], output_file: str, deep_mode: bool, export_pref
|
|
|
96
109
|
src_dirs (list): A list of source directories.
|
|
97
110
|
output_file (str): The path to the output file.
|
|
98
111
|
deep_mode (bool): Flag indicating whether to perform deep analysis.
|
|
99
|
-
|
|
112
|
+
export_prefixes (list): Prefixes to determine exported symbols.
|
|
113
|
+
src_dir_boms (list): Directory containing pre-build and build sboms.
|
|
100
114
|
Returns:
|
|
101
115
|
bool: True if the SBOM generation is successful, False otherwise.
|
|
102
116
|
"""
|
|
117
|
+
symbols_purl_map = {}
|
|
118
|
+
if src_dir_boms:
|
|
119
|
+
symbols_purl_map = populate_purl_lookup(src_dir_boms)
|
|
103
120
|
android_files = []
|
|
104
121
|
components = []
|
|
105
122
|
dependencies = []
|
|
@@ -131,7 +148,7 @@ def generate(src_dirs: list[str], output_file: str, deep_mode: bool, export_pref
|
|
|
131
148
|
)
|
|
132
149
|
for exe in exe_files:
|
|
133
150
|
progress.update(task, description=f"Processing [bold]{exe}[/bold]", advance=1)
|
|
134
|
-
components += process_exe_file(dependencies_dict, deep_mode, exe, sbom, export_prefixes)
|
|
151
|
+
components += process_exe_file(dependencies_dict, deep_mode, exe, sbom, export_prefixes, symbols_purl_map)
|
|
135
152
|
if android_files:
|
|
136
153
|
task = progress.add_task(
|
|
137
154
|
f"[green] Parsing {len(android_files)} android apps",
|
|
@@ -143,7 +160,7 @@ def generate(src_dirs: list[str], output_file: str, deep_mode: bool, export_pref
|
|
|
143
160
|
components += process_android_file(dependencies_dict, deep_mode, f, sbom)
|
|
144
161
|
if dependencies_dict:
|
|
145
162
|
dependencies += [{"ref": k, "dependsOn": list(v)} for k, v in dependencies_dict.items()]
|
|
146
|
-
return create_sbom(components, dependencies, output_file, sbom, deep_mode)
|
|
163
|
+
return create_sbom(components, dependencies, output_file, sbom, deep_mode, symbols_purl_map)
|
|
147
164
|
|
|
148
165
|
|
|
149
166
|
def create_sbom(
|
|
@@ -152,6 +169,7 @@ def create_sbom(
|
|
|
152
169
|
output_file: str,
|
|
153
170
|
sbom: CycloneDX,
|
|
154
171
|
deep_mode: bool,
|
|
172
|
+
symbols_purl_map: dict
|
|
155
173
|
) -> bool:
|
|
156
174
|
"""
|
|
157
175
|
Creates a Software Bill of Materials (SBOM) with the provided components,
|
|
@@ -163,6 +181,7 @@ def create_sbom(
|
|
|
163
181
|
output_file (str): The path to the output file.
|
|
164
182
|
sbom: The SBOM object representing the SBOM.
|
|
165
183
|
deep_mode (bool): Flag indicating whether to perform deep analysis.
|
|
184
|
+
symbols_purl_map (dict): containing symbol name as the key and purl as the value
|
|
166
185
|
|
|
167
186
|
Returns:
|
|
168
187
|
bool: True if the SBOM generation is successful, False otherwise.
|
|
@@ -187,7 +206,7 @@ def create_sbom(
|
|
|
187
206
|
sbom.dependencies = dependencies
|
|
188
207
|
if isinstance(output_file, str):
|
|
189
208
|
LOG.debug(
|
|
190
|
-
f"SBOM includes {len(components)} components and {len(dependencies)} dependencies",
|
|
209
|
+
f"SBOM includes {len(sbom.components)} components and {len(sbom.dependencies)} dependencies",
|
|
191
210
|
)
|
|
192
211
|
with open(output_file, mode="w", encoding="utf-8") as fp:
|
|
193
212
|
fp.write(
|
|
@@ -224,7 +243,8 @@ def components_from_symbols_version(symbols_version: list[dict]) -> list[Compone
|
|
|
224
243
|
for symbol in symbols_version:
|
|
225
244
|
group = ""
|
|
226
245
|
name = symbol["name"]
|
|
227
|
-
version =
|
|
246
|
+
version = None
|
|
247
|
+
pkg_type = "nuget" if name.endswith(".dll") else "generic"
|
|
228
248
|
if "_" in name:
|
|
229
249
|
tmp_a = name.split("_")
|
|
230
250
|
if len(tmp_a) == 2:
|
|
@@ -233,9 +253,13 @@ def components_from_symbols_version(symbols_version: list[dict]) -> list[Compone
|
|
|
233
253
|
if name.startswith("glib"):
|
|
234
254
|
name = name.removeprefix("g")
|
|
235
255
|
group = "gnu"
|
|
256
|
+
if pkg_type == "nuget":
|
|
257
|
+
name = name.replace(".dll", "")
|
|
236
258
|
purl = (
|
|
237
|
-
f"pkg:
|
|
259
|
+
f"pkg:{pkg_type}/{group}/{name}" if group else f"pkg:{pkg_type}/{name}"
|
|
238
260
|
)
|
|
261
|
+
if version:
|
|
262
|
+
purl = f"{purl}@{version}"
|
|
239
263
|
if symbol.get("hash"):
|
|
240
264
|
purl = f"{purl}?hash={symbol.get('hash')}"
|
|
241
265
|
comp = Component(
|
|
@@ -267,6 +291,7 @@ def process_exe_file(
|
|
|
267
291
|
exe: str,
|
|
268
292
|
sbom: CycloneDX,
|
|
269
293
|
export_prefixes: list[str] = None,
|
|
294
|
+
symbols_purl_map: dict = None,
|
|
270
295
|
) -> list[Component]:
|
|
271
296
|
"""
|
|
272
297
|
Processes an executable file, extracts metadata, and generates a Software Bill of Materials.
|
|
@@ -276,13 +301,15 @@ def process_exe_file(
|
|
|
276
301
|
deep_mode: A flag indicating whether to include deep analysis of the executable.
|
|
277
302
|
exe: The path to the executable file.
|
|
278
303
|
sbom: The CycloneDX SBOM object.
|
|
304
|
+
export_prefixes (list): Prefixes to determine exported symbols.
|
|
305
|
+
symbols_purl_map (dict): containing symbol name as the key and purl as the value
|
|
279
306
|
|
|
280
307
|
Returns:
|
|
281
308
|
list[Component]: The updated list of components.
|
|
282
309
|
|
|
283
310
|
"""
|
|
284
311
|
metadata: Dict[str, Any] = parse(exe)
|
|
285
|
-
parent_component: Component = default_parent([exe])
|
|
312
|
+
parent_component: Component = default_parent([exe], symbols_purl_map)
|
|
286
313
|
parent_component.properties = []
|
|
287
314
|
lib_components: list[Component] = []
|
|
288
315
|
for prop in (
|
|
@@ -424,7 +451,12 @@ def process_exe_file(
|
|
|
424
451
|
)
|
|
425
452
|
if not sbom.metadata.component.components:
|
|
426
453
|
sbom.metadata.component.components = []
|
|
427
|
-
|
|
454
|
+
# Automatically promote application dependencies to the parent
|
|
455
|
+
if parent_component.type == Type.application:
|
|
456
|
+
_add_to_parent_component(sbom.metadata.component.components, parent_component)
|
|
457
|
+
# Library dependencies such as .dll could be moved to lib_components
|
|
458
|
+
elif parent_component.type == Type.library:
|
|
459
|
+
lib_components.append(parent_component)
|
|
428
460
|
if metadata.get("libraries"):
|
|
429
461
|
for entry in metadata.get("libraries"):
|
|
430
462
|
comp = create_library_component(entry, exe)
|
|
@@ -459,7 +491,6 @@ def process_exe_file(
|
|
|
459
491
|
lib_components += rust_components
|
|
460
492
|
if lib_components:
|
|
461
493
|
track_dependency(dependencies_dict, parent_component, lib_components)
|
|
462
|
-
|
|
463
494
|
return lib_components
|
|
464
495
|
|
|
465
496
|
|
|
@@ -718,9 +749,11 @@ def track_dependency(
|
|
|
718
749
|
for acomp in app_components:
|
|
719
750
|
if not dependencies_dict.get(acomp.bom_ref.model_dump(mode="python")):
|
|
720
751
|
dependencies_dict[acomp.bom_ref.model_dump(mode="python")] = set()
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
752
|
+
# Prevent self loops
|
|
753
|
+
if parent_component.bom_ref.model_dump(mode="python") != acomp.bom_ref.model_dump(mode="python"):
|
|
754
|
+
dependencies_dict[parent_component.bom_ref.model_dump(mode="python")].add(
|
|
755
|
+
acomp.bom_ref.model_dump(mode="python")
|
|
756
|
+
)
|
|
724
757
|
else:
|
|
725
758
|
for acomp in app_components:
|
|
726
759
|
if not dependencies_dict.get(acomp.bom_ref.model_dump(mode="python")):
|
|
@@ -742,3 +775,32 @@ def trim_components(components: list[Component]) -> list[Component]:
|
|
|
742
775
|
if not added_dict.get(comp.bom_ref.model_dump(mode="python")):
|
|
743
776
|
added_dict[comp.bom_ref.model_dump(mode="python")] = comp
|
|
744
777
|
return [added_dict[k] for k in sorted(added_dict.keys())]
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def populate_purl_lookup(src_dir_boms: list[str]):
|
|
781
|
+
"""
|
|
782
|
+
Create a purl lookup cache by parsing the various BOMs in the given source directory.
|
|
783
|
+
|
|
784
|
+
Args:
|
|
785
|
+
src_dir_boms (list): Directory containing pre-build and build sboms.
|
|
786
|
+
|
|
787
|
+
Returns:
|
|
788
|
+
dict: containing symbol name as the key and purl as the value
|
|
789
|
+
"""
|
|
790
|
+
symbols_purl_map = {}
|
|
791
|
+
for adir in src_dir_boms:
|
|
792
|
+
if files := find_bom_files(adir):
|
|
793
|
+
for f in files:
|
|
794
|
+
with open(f) as fp:
|
|
795
|
+
try:
|
|
796
|
+
bom_obj = orjson.loads(fp.read())
|
|
797
|
+
# Ignore non-compatible bom files
|
|
798
|
+
if not bom_obj or not bom_obj.get("metadata", {}).get("lifecycles") or not bom_obj.get("components"):
|
|
799
|
+
continue
|
|
800
|
+
for comp in bom_obj["components"]:
|
|
801
|
+
# For nuget, store the unversioned purl as a lookup key
|
|
802
|
+
if comp and comp["purl"].startswith("pkg:nuget") and "@" in comp["purl"]:
|
|
803
|
+
symbols_purl_map[comp["purl"].split("@")[0]] = comp["purl"]
|
|
804
|
+
except orjson.JSONDecodeError:
|
|
805
|
+
pass
|
|
806
|
+
return symbols_purl_map
|
|
@@ -31,7 +31,6 @@ CHARSET = string.digits + string.ascii_letters + r"""!&@"""
|
|
|
31
31
|
# Known files compressed with ar
|
|
32
32
|
KNOWN_AR_EXTNS = (".a", ".rlib", ".lib")
|
|
33
33
|
|
|
34
|
-
|
|
35
34
|
def is_base64(s):
|
|
36
35
|
"""
|
|
37
36
|
Checks if the given string is a valid Base64 encoded string.
|
|
@@ -276,6 +275,17 @@ def find_android_files(path):
|
|
|
276
275
|
return find_files(path, app_extns)
|
|
277
276
|
|
|
278
277
|
|
|
278
|
+
def find_bom_files(path):
|
|
279
|
+
"""
|
|
280
|
+
Method to find BOM files
|
|
281
|
+
|
|
282
|
+
:param path: Project directory
|
|
283
|
+
:return: List of bom files
|
|
284
|
+
"""
|
|
285
|
+
app_extns = ["bom.json", ".cdx.json"]
|
|
286
|
+
return find_files(path, app_extns)
|
|
287
|
+
|
|
288
|
+
|
|
279
289
|
def find_files(path, extns):
|
|
280
290
|
"""
|
|
281
291
|
Method to find files matching an extension
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "blint"
|
|
3
|
-
version = "2.3.
|
|
3
|
+
version = "2.3.1"
|
|
4
4
|
description = "Linter and SBOM generator for binary files."
|
|
5
5
|
authors = ["Prabhu Subramanian <prabhu@appthreat.com>", "Caroline Russell <caroline@appthreat.dev>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -17,6 +17,7 @@ classifiers = [
|
|
|
17
17
|
"Programming Language :: Python :: 3.10",
|
|
18
18
|
"Programming Language :: Python :: 3.11",
|
|
19
19
|
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
20
21
|
"Operating System :: OS Independent",
|
|
21
22
|
]
|
|
22
23
|
include = ["blint/data/*.yml"]
|
|
@@ -28,8 +29,8 @@ include = ["blint/data/*.yml"]
|
|
|
28
29
|
blint = 'blint.cli:main'
|
|
29
30
|
|
|
30
31
|
[tool.poetry.dependencies]
|
|
31
|
-
python = ">=3.10,<3.
|
|
32
|
-
lief = "
|
|
32
|
+
python = ">=3.10,<3.14"
|
|
33
|
+
lief = "~0.15.1"
|
|
33
34
|
rich = "^13.7.1"
|
|
34
35
|
PyYAML = "^6.0.1"
|
|
35
36
|
defusedxml = "^0.7.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|