blint 2.0.2__tar.gz → 2.0.3__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.0.2 → blint-2.0.3}/PKG-INFO +7 -1
- {blint-2.0.2 → blint-2.0.3}/README.md +6 -0
- {blint-2.0.2 → blint-2.0.3}/blint/analysis.py +18 -9
- {blint-2.0.2 → blint-2.0.3}/blint/binary.py +69 -3
- {blint-2.0.2 → blint-2.0.3}/blint/cli.py +10 -5
- {blint-2.0.2 → blint-2.0.3}/blint/sbom.py +77 -5
- {blint-2.0.2 → blint-2.0.3}/blint/utils.py +6 -1
- {blint-2.0.2 → blint-2.0.3}/pyproject.toml +1 -1
- {blint-2.0.2 → blint-2.0.3}/LICENSE +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/__init__.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/android.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/checks.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/config.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/cyclonedx/README.md +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/cyclonedx/__init__.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/cyclonedx/spdx.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/cyclonedx/spec.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/__init__.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/__init__.py +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_entries_generic.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_entries_pe.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_exe_go.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_imports_pe.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_methods_generic.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_methods_mips.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_monero_generic.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_monero_go.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_monero_rust +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_monero_rust.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_rootkits_win.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_symbols_generic.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_symbols_hooka.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_symbols_macho.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/annotations/review_symbols_rust.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/data/rules.yml +0 -0
- {blint-2.0.2 → blint-2.0.3}/blint/logger.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: blint
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.3
|
|
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
|
|
@@ -172,3 +172,9 @@ sbom command generates CycloneDX json.
|
|
|
172
172
|
|
|
173
173
|
The developers could be reached via the [discord](https://discord.gg/DCNxzaeUpd) channel.
|
|
174
174
|
|
|
175
|
+
## Sponsorship wishlist
|
|
176
|
+
|
|
177
|
+
If you love blint, you should consider [donating](https://owasp.org/donate?reponame=www-project-dep-scan&title=OWASP+dep-scan) to our project. In addition, consider donating to the below projects which make blint possible.
|
|
178
|
+
|
|
179
|
+
- [LIEF](https://github.com/sponsors/lief-project/)
|
|
180
|
+
|
|
@@ -141,3 +141,9 @@ sbom command generates CycloneDX json.
|
|
|
141
141
|
## Discord support
|
|
142
142
|
|
|
143
143
|
The developers could be reached via the [discord](https://discord.gg/DCNxzaeUpd) channel.
|
|
144
|
+
|
|
145
|
+
## Sponsorship wishlist
|
|
146
|
+
|
|
147
|
+
If you love blint, you should consider [donating](https://owasp.org/donate?reponame=www-project-dep-scan&title=OWASP+dep-scan) to our project. In addition, consider donating to the below projects which make blint possible.
|
|
148
|
+
|
|
149
|
+
- [LIEF](https://github.com/sponsors/lief-project/)
|
|
@@ -15,13 +15,13 @@ from rich.progress import Progress
|
|
|
15
15
|
from rich.terminal_theme import MONOKAI
|
|
16
16
|
|
|
17
17
|
from blint.binary import parse
|
|
18
|
-
from blint.logger import LOG, console
|
|
19
|
-
from blint.utils import (create_findings_table, is_fuzzable_name, print_findings_table, )
|
|
20
18
|
from blint.checks import (check_nx, check_pie, # noqa, pylint: disable=unused-import
|
|
21
19
|
check_relro, check_canary, check_rpath,
|
|
22
20
|
check_virtual_size, check_authenticode,
|
|
23
21
|
check_dll_characteristics, check_codesign,
|
|
24
22
|
check_trust_info)
|
|
23
|
+
from blint.logger import LOG, console
|
|
24
|
+
from blint.utils import (create_findings_table, is_fuzzable_name, print_findings_table)
|
|
25
25
|
|
|
26
26
|
try:
|
|
27
27
|
import importlib.resources # pylint: disable=ungrouped-imports
|
|
@@ -299,6 +299,13 @@ def print_reviews_table(reviews, files):
|
|
|
299
299
|
console.print(table)
|
|
300
300
|
|
|
301
301
|
|
|
302
|
+
def json_serializer(obj):
|
|
303
|
+
if isinstance(obj, bytes):
|
|
304
|
+
return obj.decode('utf-8')
|
|
305
|
+
|
|
306
|
+
return obj
|
|
307
|
+
|
|
308
|
+
|
|
302
309
|
def report(src_dir, reports_dir, findings, reviews, files, fuzzables):
|
|
303
310
|
"""Generates a report based on the analysis results.
|
|
304
311
|
|
|
@@ -322,20 +329,20 @@ def report(src_dir, reports_dir, findings, reviews, files, fuzzables):
|
|
|
322
329
|
LOG.info(f"Findings written to {findings_file}")
|
|
323
330
|
with open(findings_file, mode="w", encoding="utf-8") as ffp:
|
|
324
331
|
json.dump(
|
|
325
|
-
{**common_metadata, "findings": findings}, ffp,
|
|
332
|
+
{**common_metadata, "findings": findings}, ffp, default=json_serializer
|
|
326
333
|
)
|
|
327
334
|
if reviews:
|
|
328
335
|
print_reviews_table(reviews, files)
|
|
329
336
|
reviews_file = Path(reports_dir) / "reviews.json"
|
|
330
337
|
LOG.info(f"Review written to {reviews_file}")
|
|
331
338
|
with open(reviews_file, mode="w", encoding="utf-8") as rfp:
|
|
332
|
-
json.dump({**common_metadata, "reviews": reviews}, rfp,
|
|
339
|
+
json.dump({**common_metadata, "reviews": reviews}, rfp, default=json_serializer)
|
|
333
340
|
if fuzzables:
|
|
334
341
|
fuzzables_file = Path(reports_dir) / "fuzzables.json"
|
|
335
342
|
LOG.info(f"Fuzzables data written to {fuzzables_file}")
|
|
336
343
|
with open(fuzzables_file, mode="w", encoding="utf-8") as rfp:
|
|
337
344
|
json.dump(
|
|
338
|
-
{**common_metadata, "fuzzables": fuzzables}, rfp,
|
|
345
|
+
{**common_metadata, "fuzzables": fuzzables}, rfp, default=json_serializer
|
|
339
346
|
)
|
|
340
347
|
else:
|
|
341
348
|
LOG.debug("No suggestion available for fuzzing")
|
|
@@ -343,13 +350,15 @@ def report(src_dir, reports_dir, findings, reviews, files, fuzzables):
|
|
|
343
350
|
if not findings and not reviews:
|
|
344
351
|
LOG.info(f":white_heavy_check_mark: No issues found in {src_dir}!")
|
|
345
352
|
# Try console output as html
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
353
|
+
else:
|
|
354
|
+
html_file = Path(reports_dir) / "blint-output.html"
|
|
355
|
+
console.save_html(html_file, theme=MONOKAI)
|
|
356
|
+
LOG.info(f"HTML report written to {html_file}")
|
|
349
357
|
|
|
350
358
|
|
|
351
359
|
class AnalysisRunner:
|
|
352
360
|
"""Class to analyze binaries."""
|
|
361
|
+
|
|
353
362
|
def __init__(self):
|
|
354
363
|
self.findings = []
|
|
355
364
|
self.reviews = []
|
|
@@ -404,7 +413,7 @@ class AnalysisRunner:
|
|
|
404
413
|
f"-metadata.json")
|
|
405
414
|
LOG.debug(f"Metadata written to {metadata_file}")
|
|
406
415
|
with open(metadata_file, mode="w", encoding="utf-8") as ffp:
|
|
407
|
-
json.dump(metadata, ffp,
|
|
416
|
+
json.dump(metadata, ffp, default=json_serializer)
|
|
408
417
|
self.progress.update(
|
|
409
418
|
self.task,
|
|
410
419
|
description=f"Checking [bold]{f}[/bold] against rules")
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# pylint: disable=too-many-lines,consider-using-f-string
|
|
2
|
+
import codecs
|
|
2
3
|
import contextlib
|
|
4
|
+
import json
|
|
3
5
|
import sys
|
|
4
6
|
|
|
5
7
|
import lief
|
|
@@ -216,6 +218,15 @@ def parse_strings(parsed_obj):
|
|
|
216
218
|
|
|
217
219
|
|
|
218
220
|
def ignorable_symbol(symbol_name: str | None) -> bool:
|
|
221
|
+
"""
|
|
222
|
+
Determines if a symbol is ignorable.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
symbol_name (str): The name of the symbol to check.
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
bool: True if the symbol is ignorable, False otherwise.
|
|
229
|
+
"""
|
|
219
230
|
if not symbol_name:
|
|
220
231
|
return True
|
|
221
232
|
for pref in ("$f64.", "__"):
|
|
@@ -380,6 +391,13 @@ def process_pe_resources(parsed_obj):
|
|
|
380
391
|
if not rm or isinstance(rm, lief.lief_errors):
|
|
381
392
|
return {}
|
|
382
393
|
resources = {}
|
|
394
|
+
version_metadata = {}
|
|
395
|
+
version_info: lief.PE.ResourceVersion = rm.version if rm.has_version else None
|
|
396
|
+
if version_info and version_info.has_string_file_info:
|
|
397
|
+
string_file_info: lief.PE.ResourceStringFileInfo = version_info.string_file_info
|
|
398
|
+
for lc_item in string_file_info.langcode_items:
|
|
399
|
+
if lc_item.items:
|
|
400
|
+
version_metadata.update(lc_item.items)
|
|
383
401
|
try:
|
|
384
402
|
resources = {
|
|
385
403
|
"has_accelerator": rm.has_accelerator,
|
|
@@ -393,6 +411,8 @@ def process_pe_resources(parsed_obj):
|
|
|
393
411
|
"version_info": str(rm.version) if rm.has_version else None,
|
|
394
412
|
"html": rm.html if rm.has_html else None,
|
|
395
413
|
}
|
|
414
|
+
if version_metadata:
|
|
415
|
+
resources["version_metadata"] = version_metadata
|
|
396
416
|
except (AttributeError, UnicodeError):
|
|
397
417
|
return resources
|
|
398
418
|
return resources
|
|
@@ -737,9 +757,8 @@ def add_elf_metadata(exe_file, metadata, parsed_obj):
|
|
|
737
757
|
if exe_type:
|
|
738
758
|
metadata["exe_type"] = exe_type
|
|
739
759
|
metadata["functions"] = parse_functions(parsed_obj.functions)
|
|
740
|
-
|
|
741
760
|
metadata["ctor_functions"] = parse_functions(parsed_obj.ctor_functions)
|
|
742
|
-
|
|
761
|
+
metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
|
|
743
762
|
return metadata
|
|
744
763
|
|
|
745
764
|
|
|
@@ -875,7 +894,40 @@ def determine_elf_flags(header):
|
|
|
875
894
|
return eflags_str
|
|
876
895
|
|
|
877
896
|
|
|
878
|
-
def
|
|
897
|
+
def parse_overlay(parsed_obj: lief.Binary) -> dict[str, dict]:
|
|
898
|
+
"""
|
|
899
|
+
Parse the overlay section to extract dotnet dependencies
|
|
900
|
+
Args:
|
|
901
|
+
parsed_obj (lief.Binary): The parsed object representing the PE binary.
|
|
902
|
+
|
|
903
|
+
Returns:
|
|
904
|
+
dict: Dict representing the deps.json if available.
|
|
905
|
+
"""
|
|
906
|
+
deps = {}
|
|
907
|
+
if hasattr(parsed_obj, "overlay"):
|
|
908
|
+
overlay = parsed_obj.overlay
|
|
909
|
+
overlay_str = (
|
|
910
|
+
codecs.decode(overlay.tobytes(), encoding="utf-8", errors="backslashreplace")
|
|
911
|
+
.replace("\0", "")
|
|
912
|
+
.replace("\r\n", "")
|
|
913
|
+
.replace("\n", "")
|
|
914
|
+
.replace(" ", "")
|
|
915
|
+
)
|
|
916
|
+
if overlay_str.find('{"runtimeTarget') > -1:
|
|
917
|
+
start_index = overlay_str.find('{"runtimeTarget')
|
|
918
|
+
end_index = overlay_str.rfind("}}}")
|
|
919
|
+
if end_index > -1:
|
|
920
|
+
overlay_str = overlay_str[start_index: end_index + 3]
|
|
921
|
+
try:
|
|
922
|
+
# deps should have runtimeTarget, compilationOptions, targets, and libraries
|
|
923
|
+
# Use libraries to construct BOM components and targets for the dependency tree
|
|
924
|
+
deps = json.loads(overlay_str)
|
|
925
|
+
except json.JSONDecodeError:
|
|
926
|
+
pass
|
|
927
|
+
return deps
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
|
|
879
931
|
"""Adds PE metadata to the given metadata dictionary.
|
|
880
932
|
|
|
881
933
|
Args:
|
|
@@ -911,10 +963,21 @@ def add_pe_metadata(exe_file, metadata, parsed_obj):
|
|
|
911
963
|
metadata["imports"],
|
|
912
964
|
metadata["dynamic_entries"],
|
|
913
965
|
) = parse_pe_imports(parsed_obj.imports)
|
|
966
|
+
# Attempt to detect if this PE is a driver
|
|
967
|
+
if metadata["dynamic_entries"]:
|
|
968
|
+
for e in metadata["dynamic_entries"]:
|
|
969
|
+
if e["name"] == "ntoskrnl.exe":
|
|
970
|
+
metadata["is_driver"] = True
|
|
971
|
+
break
|
|
914
972
|
metadata["exports"] = parse_pe_exports(parsed_obj.get_export())
|
|
915
973
|
metadata["functions"] = parse_functions(parsed_obj.functions)
|
|
916
974
|
metadata["ctor_functions"] = parse_functions(parsed_obj.ctor_functions)
|
|
917
975
|
metadata["exception_functions"] = parse_functions(parsed_obj.exception_functions)
|
|
976
|
+
# Detect if this PE might be dotnet
|
|
977
|
+
for i, dd in enumerate(parsed_obj.data_directories):
|
|
978
|
+
if i == 14 and dd.type.value == lief.PE.DataDirectory.TYPES.CLR_RUNTIME_HEADER.value:
|
|
979
|
+
metadata["is_dotnet"] = True
|
|
980
|
+
metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
|
|
918
981
|
tls = parsed_obj.tls
|
|
919
982
|
if tls and tls.sizeof_zero_fill:
|
|
920
983
|
metadata["tls_address_index"] = tls.addressof_index
|
|
@@ -997,6 +1060,9 @@ def add_pe_optional_headers(metadata, optional_header):
|
|
|
997
1060
|
for chara in optional_header.dll_characteristics_lists
|
|
998
1061
|
]
|
|
999
1062
|
)
|
|
1063
|
+
# Detect if this binary is a driver
|
|
1064
|
+
if "WDM_DRIVER" in metadata["dll_characteristics"]:
|
|
1065
|
+
metadata["is_driver"] = True
|
|
1000
1066
|
metadata["subsystem"] = str(optional_header.subsystem).rsplit(".", maxsplit=1)[-1]
|
|
1001
1067
|
metadata["is_gui"] = metadata["subsystem"] == "WINDOWS_GUI"
|
|
1002
1068
|
metadata["exe_type"] = "PE32" if optional_header.magic == lief.PE.PE_TYPE.PE32 else "PE64"
|
|
@@ -119,10 +119,12 @@ def parse_input(src):
|
|
|
119
119
|
Returns:
|
|
120
120
|
list: A list containing the parsed path.
|
|
121
121
|
"""
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
if isinstance(src, list):
|
|
123
|
+
path = src[0]
|
|
124
|
+
result = path.split("\n")
|
|
125
|
+
result = [res for res in result if os.path.exists(res)]
|
|
126
|
+
return result
|
|
127
|
+
return [src]
|
|
126
128
|
|
|
127
129
|
|
|
128
130
|
def handle_args():
|
|
@@ -165,10 +167,13 @@ def main():
|
|
|
165
167
|
sbom_output = args.sbom_output
|
|
166
168
|
else:
|
|
167
169
|
sbom_output = os.path.join(os.getcwd(), "bom.json")
|
|
170
|
+
sbom_output_dir = os.path.dirname(sbom_output)
|
|
171
|
+
if sbom_output_dir and not os.path.exists(sbom_output_dir):
|
|
172
|
+
os.makedirs(sbom_output_dir)
|
|
168
173
|
generate(src_dirs, sbom_output, args.deep_mode)
|
|
169
174
|
# Default case
|
|
170
175
|
else:
|
|
171
|
-
if not os.path.exists(reports_dir):
|
|
176
|
+
if reports_dir and not os.path.exists(reports_dir):
|
|
172
177
|
os.makedirs(reports_dir)
|
|
173
178
|
files = gen_file_list(src_dirs)
|
|
174
179
|
analyzer = AnalysisRunner()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import base64
|
|
1
2
|
import os
|
|
2
3
|
import uuid
|
|
3
4
|
from datetime import datetime
|
|
@@ -12,6 +13,8 @@ from blint.cyclonedx.spec import (
|
|
|
12
13
|
BomFormat,
|
|
13
14
|
Component,
|
|
14
15
|
CycloneDX,
|
|
16
|
+
Hash,
|
|
17
|
+
HashAlg,
|
|
15
18
|
Lifecycles,
|
|
16
19
|
Metadata,
|
|
17
20
|
Phase,
|
|
@@ -22,7 +25,7 @@ from blint.cyclonedx.spec import (
|
|
|
22
25
|
Type,
|
|
23
26
|
)
|
|
24
27
|
from blint.logger import LOG
|
|
25
|
-
from blint.utils import create_component_evidence, find_android_files, gen_file_list, get_version
|
|
28
|
+
from blint.utils import camel_to_snake, create_component_evidence, find_android_files, gen_file_list, get_version
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
def default_parent(src_dirs: list[str]) -> Component:
|
|
@@ -246,9 +249,9 @@ def process_exe_file(
|
|
|
246
249
|
list[Component]: The updated list of components.
|
|
247
250
|
|
|
248
251
|
"""
|
|
249
|
-
dependencies_dict = {}
|
|
250
|
-
parent_component: Component = default_parent([exe])
|
|
252
|
+
dependencies_dict: dict[str, set] = {}
|
|
251
253
|
metadata: Dict[str, Any] = parse(exe)
|
|
254
|
+
parent_component: Component = default_parent([exe])
|
|
252
255
|
parent_component.properties = []
|
|
253
256
|
lib_components: list[Component] = []
|
|
254
257
|
for prop in (
|
|
@@ -266,12 +269,15 @@ def process_exe_file(
|
|
|
266
269
|
"flags",
|
|
267
270
|
"relro",
|
|
268
271
|
"is_pie",
|
|
272
|
+
"is_reproducible_build",
|
|
269
273
|
"has_nx",
|
|
270
274
|
"static",
|
|
271
275
|
"characteristics",
|
|
272
276
|
"dll_characteristics",
|
|
273
277
|
"subsystem",
|
|
274
278
|
"is_gui",
|
|
279
|
+
"is_driver",
|
|
280
|
+
"is_dotnet",
|
|
275
281
|
"major_linker_version",
|
|
276
282
|
"minor_linker_version",
|
|
277
283
|
"major_operating_system_version",
|
|
@@ -288,6 +294,13 @@ def process_exe_file(
|
|
|
288
294
|
if note.get("version"):
|
|
289
295
|
parent_component.properties.append(
|
|
290
296
|
Property(name=f"internal:{note.get('type')}", value=note.get('version')))
|
|
297
|
+
# For PE binaries, resources could have a dict called version_metadata with interesting properties
|
|
298
|
+
if metadata.get("resources"):
|
|
299
|
+
version_metadata = metadata.get("resources").get("version_metadata")
|
|
300
|
+
if version_metadata and isinstance(version_metadata, dict):
|
|
301
|
+
for vk, vv in version_metadata.items():
|
|
302
|
+
parent_component.properties.append(
|
|
303
|
+
Property(name=f"internal:{camel_to_snake(vk)}", value=vv))
|
|
291
304
|
if deep_mode:
|
|
292
305
|
symbols_version: list[dict] = metadata.get("symbols_version", [])
|
|
293
306
|
# Attempt to detect library components from the symbols version block
|
|
@@ -343,6 +356,10 @@ def process_exe_file(
|
|
|
343
356
|
for entry in metadata["dynamic_entries"]:
|
|
344
357
|
comp = create_dynamic_component(entry, exe)
|
|
345
358
|
lib_components.append(comp)
|
|
359
|
+
# Convert libraries and targets from dotnet binaries
|
|
360
|
+
if metadata.get("dotnet_dependencies"):
|
|
361
|
+
pe_components = process_dotnet_dependencies(metadata.get("dotnet_dependencies"), dependencies_dict)
|
|
362
|
+
lib_components += pe_components
|
|
346
363
|
if lib_components:
|
|
347
364
|
components += lib_components
|
|
348
365
|
track_dependency(dependencies_dict, parent_component, lib_components)
|
|
@@ -394,10 +411,11 @@ def create_dynamic_component(entry: Dict, exe: str) -> Component:
|
|
|
394
411
|
Returns:
|
|
395
412
|
Component: The created dynamic component object.
|
|
396
413
|
"""
|
|
397
|
-
|
|
414
|
+
name = entry.get("name", "").removeprefix("$ORIGIN/")
|
|
415
|
+
purl = f"pkg:file/{name}"
|
|
398
416
|
comp = Component(
|
|
399
417
|
type=Type.library,
|
|
400
|
-
name=
|
|
418
|
+
name=name,
|
|
401
419
|
purl=purl,
|
|
402
420
|
evidence=create_component_evidence(exe, 0.5),
|
|
403
421
|
properties=[
|
|
@@ -441,6 +459,60 @@ def process_android_file(
|
|
|
441
459
|
return components
|
|
442
460
|
|
|
443
461
|
|
|
462
|
+
def process_dotnet_dependencies(dotnet_deps: dict[str, dict], dependencies_dict: dict[str, set]) -> list[Component]:
|
|
463
|
+
"""
|
|
464
|
+
Process the dotnet dependencies metadata extracted for binary overlays
|
|
465
|
+
|
|
466
|
+
Args:
|
|
467
|
+
dotnet_deps (dict[str, dict]): PE dependencies metadata
|
|
468
|
+
dependencies_dict (dict[str, set]): Existing dependencies dictionary
|
|
469
|
+
|
|
470
|
+
Returns:
|
|
471
|
+
list: New component list
|
|
472
|
+
"""
|
|
473
|
+
components = []
|
|
474
|
+
libraries = dotnet_deps.get("libraries", {})
|
|
475
|
+
# k: 'Microsoft.CodeAnalysis.Analyzers/3.3.4'
|
|
476
|
+
# v: {'type': 'package', 'serviceable': True, 'sha512': 'sha512-AxkxcPR+rheX0SmvpLVIGLhOUXAKG56a64kV9VQZ4y9gR9ZmPXnqZvHJnmwLSwzrEP6junUF11vuc+aqo5r68g==', 'path': 'microsoft.codeanalysis.analyzers/3.3.4', 'hashPath': 'microsoft.codeanalysis.analyzers.3.3.4.nupkg.sha512'}
|
|
477
|
+
for k, v in libraries.items():
|
|
478
|
+
tmp_a = k.split("/")
|
|
479
|
+
purl = f"pkg:nuget/{tmp_a[0]}@{tmp_a[1]}"
|
|
480
|
+
hash_content = ""
|
|
481
|
+
try:
|
|
482
|
+
hash_content = str(base64.b64decode(v.get("sha512", "").removeprefix("sha512-"), validate=True), "utf-8")
|
|
483
|
+
except Exception:
|
|
484
|
+
pass
|
|
485
|
+
comp = Component(
|
|
486
|
+
type=Type.application if v.get("type") == "project" else Type.library,
|
|
487
|
+
name=tmp_a[0],
|
|
488
|
+
version=tmp_a[1],
|
|
489
|
+
purl=purl,
|
|
490
|
+
scope=Scope.required,
|
|
491
|
+
properties=[
|
|
492
|
+
Property(name="internal:serviceable", value=str(v.get("serviceable")).lower()),
|
|
493
|
+
Property(name="internal:hash_path", value=v.get("hashPath")),
|
|
494
|
+
],
|
|
495
|
+
)
|
|
496
|
+
if v.get("path"):
|
|
497
|
+
comp.evidence = create_component_evidence(v.get("path"), 1.0),
|
|
498
|
+
if hash_content:
|
|
499
|
+
comp.hashes = [Hash(alg=HashAlg.SHA_512, content=hash_content)],
|
|
500
|
+
comp.bom_ref = RefType(purl)
|
|
501
|
+
components.append(comp)
|
|
502
|
+
targets: dict[str, dict[str, dict]] = dotnet_deps.get("targets", {})
|
|
503
|
+
for tk, tv in targets.items():
|
|
504
|
+
for k, v in tv.items():
|
|
505
|
+
tmp_a = k.split("/")
|
|
506
|
+
purl = f"pkg:nuget/{tmp_a[0]}@{tmp_a[1]}"
|
|
507
|
+
depends_on = []
|
|
508
|
+
for adep_name, adep_version in v.get("dependencies", {}).items():
|
|
509
|
+
depends_on.append(f"pkg:nuget/{adep_name}@{adep_version}")
|
|
510
|
+
if not dependencies_dict.get(purl):
|
|
511
|
+
dependencies_dict[purl] = set()
|
|
512
|
+
dependencies_dict[purl].update(depends_on)
|
|
513
|
+
return components
|
|
514
|
+
|
|
515
|
+
|
|
444
516
|
def track_dependency(
|
|
445
517
|
dependencies_dict: dict, parent_component: Component, app_components: list[Component]
|
|
446
518
|
) -> None:
|
|
@@ -13,6 +13,7 @@ import lief
|
|
|
13
13
|
from defusedxml.ElementTree import fromstring
|
|
14
14
|
from rich import box
|
|
15
15
|
from rich.table import Table
|
|
16
|
+
|
|
16
17
|
from blint.config import (
|
|
17
18
|
ignore_directories,
|
|
18
19
|
ignore_files,
|
|
@@ -21,7 +22,6 @@ from blint.config import (
|
|
|
21
22
|
secrets_regex
|
|
22
23
|
)
|
|
23
24
|
from blint.cyclonedx.spec import ComponentEvidence, FieldModel, Identity, Method, Technique
|
|
24
|
-
|
|
25
25
|
from blint.logger import console, LOG
|
|
26
26
|
|
|
27
27
|
CHARSET = string.digits + string.ascii_letters + r"""!&@"""
|
|
@@ -502,3 +502,8 @@ def create_component_evidence(method_value: str, confidence: float) -> Component
|
|
|
502
502
|
],
|
|
503
503
|
)
|
|
504
504
|
)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def camel_to_snake(name: str) -> str:
|
|
508
|
+
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
|
509
|
+
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()
|
|
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
|