blint 2.1.2__tar.gz → 2.1.4__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.1.2 → blint-2.1.4}/PKG-INFO +4 -2
- {blint-2.1.2 → blint-2.1.4}/README.md +1 -1
- {blint-2.1.2 → blint-2.1.4}/blint/analysis.py +16 -12
- {blint-2.1.2 → blint-2.1.4}/blint/android.py +1 -7
- {blint-2.1.2 → blint-2.1.4}/blint/binary.py +97 -57
- {blint-2.1.2 → blint-2.1.4}/blint/config.py +0 -14
- {blint-2.1.2 → blint-2.1.4}/blint/sbom.py +40 -0
- {blint-2.1.2 → blint-2.1.4}/blint/utils.py +1 -0
- {blint-2.1.2 → blint-2.1.4}/pyproject.toml +5 -3
- {blint-2.1.2 → blint-2.1.4}/LICENSE +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/__init__.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/checks.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/cli.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/cyclonedx/README.md +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/cyclonedx/__init__.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/cyclonedx/spdx.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/cyclonedx/spec.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/__init__.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/__init__.py +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_entries_generic.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_entries_pe.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_exe_go.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_imports_pe.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_methods_generic.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_methods_mips.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_monero_generic.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_monero_go.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_monero_rust +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_monero_rust.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_rootkits_win.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_symbols_generic.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_symbols_hooka.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_symbols_macho.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/annotations/review_symbols_rust.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/data/rules.yml +0 -0
- {blint-2.1.2 → blint-2.1.4}/blint/logger.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: blint
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
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
|
|
@@ -22,8 +22,10 @@ Classifier: Topic :: Utilities
|
|
|
22
22
|
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
23
23
|
Requires-Dist: defusedxml (>=0.7.1,<0.8.0)
|
|
24
24
|
Requires-Dist: lief (>=0.14.0,<0.15.0)
|
|
25
|
+
Requires-Dist: orjson (>=3.10.1,<4.0.0)
|
|
25
26
|
Requires-Dist: pydantic[email] (>=2.6.0,<3.0.0)
|
|
26
27
|
Requires-Dist: rich (>=13.7.0,<14.0.0)
|
|
28
|
+
Requires-Dist: symbolic (==10.2.1)
|
|
27
29
|
Project-URL: CI, https://github.com/AppThreat/blint/actions
|
|
28
30
|
Project-URL: Repository, https://github.com/OWASP-dep-scan/blint
|
|
29
31
|
Description-Content-Type: text/markdown
|
|
@@ -176,7 +178,7 @@ sbom command generates CycloneDX json.
|
|
|
176
178
|
|
|
177
179
|
## References
|
|
178
180
|
|
|
179
|
-
- [lief examples](https://github.com/lief-project/LIEF/tree/master/examples
|
|
181
|
+
- [lief examples](https://github.com/lief-project/LIEF/tree/master/examples)
|
|
180
182
|
- [checksec](https://github.com/Wenzel/checksec.py)
|
|
181
183
|
|
|
182
184
|
## Discord support
|
|
@@ -146,7 +146,7 @@ sbom command generates CycloneDX json.
|
|
|
146
146
|
|
|
147
147
|
## References
|
|
148
148
|
|
|
149
|
-
- [lief examples](https://github.com/lief-project/LIEF/tree/master/examples
|
|
149
|
+
- [lief examples](https://github.com/lief-project/LIEF/tree/master/examples)
|
|
150
150
|
- [checksec](https://github.com/Wenzel/checksec.py)
|
|
151
151
|
|
|
152
152
|
## Discord support
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import contextlib
|
|
2
2
|
import importlib # noqa
|
|
3
|
-
import json
|
|
4
3
|
import os
|
|
5
4
|
import re
|
|
6
5
|
import sys
|
|
@@ -10,12 +9,14 @@ from datetime import datetime
|
|
|
10
9
|
from itertools import islice
|
|
11
10
|
from pathlib import Path
|
|
12
11
|
|
|
12
|
+
import orjson
|
|
13
13
|
import yaml
|
|
14
14
|
from rich.progress import Progress
|
|
15
15
|
from rich.terminal_theme import MONOKAI
|
|
16
16
|
|
|
17
17
|
from blint.binary import parse
|
|
18
|
-
|
|
18
|
+
# pylint: disable-next=unused-import
|
|
19
|
+
from blint.checks import (check_nx, check_pie,
|
|
19
20
|
check_relro, check_canary, check_rpath,
|
|
20
21
|
check_virtual_size, check_authenticode,
|
|
21
22
|
check_dll_characteristics, check_codesign,
|
|
@@ -300,6 +301,7 @@ def print_reviews_table(reviews, files):
|
|
|
300
301
|
|
|
301
302
|
|
|
302
303
|
def json_serializer(obj):
|
|
304
|
+
"""JSON serializer to help serialize problematic types such as bytes"""
|
|
303
305
|
if isinstance(obj, bytes):
|
|
304
306
|
return obj.decode('utf-8')
|
|
305
307
|
|
|
@@ -327,23 +329,25 @@ def report(src_dir, reports_dir, findings, reviews, files, fuzzables):
|
|
|
327
329
|
print_findings_table(findings, files)
|
|
328
330
|
findings_file = Path(reports_dir) / "findings.json"
|
|
329
331
|
LOG.info(f"Findings written to {findings_file}")
|
|
332
|
+
output = orjson.dumps({**common_metadata, "findings": findings}, default=json_serializer).decode("utf-8",
|
|
333
|
+
"ignore")
|
|
330
334
|
with open(findings_file, mode="w", encoding="utf-8") as ffp:
|
|
331
|
-
|
|
332
|
-
{**common_metadata, "findings": findings}, ffp, default=json_serializer
|
|
333
|
-
)
|
|
335
|
+
ffp.write(output)
|
|
334
336
|
if reviews:
|
|
335
337
|
print_reviews_table(reviews, files)
|
|
336
338
|
reviews_file = Path(reports_dir) / "reviews.json"
|
|
337
339
|
LOG.info(f"Review written to {reviews_file}")
|
|
340
|
+
output = orjson.dumps({**common_metadata, "reviews": reviews}, default=json_serializer).decode("utf-8",
|
|
341
|
+
"ignore")
|
|
338
342
|
with open(reviews_file, mode="w", encoding="utf-8") as rfp:
|
|
339
|
-
|
|
343
|
+
rfp.write(output)
|
|
340
344
|
if fuzzables:
|
|
341
345
|
fuzzables_file = Path(reports_dir) / "fuzzables.json"
|
|
342
346
|
LOG.info(f"Fuzzables data written to {fuzzables_file}")
|
|
347
|
+
output = orjson.dumps({**common_metadata, "fuzzables": fuzzables}, default=json_serializer).decode("utf-8",
|
|
348
|
+
"ignore")
|
|
343
349
|
with open(fuzzables_file, mode="w", encoding="utf-8") as rfp:
|
|
344
|
-
|
|
345
|
-
{**common_metadata, "fuzzables": fuzzables}, rfp, default=json_serializer
|
|
346
|
-
)
|
|
350
|
+
rfp.write(output)
|
|
347
351
|
else:
|
|
348
352
|
LOG.debug("No suggestion available for fuzzing")
|
|
349
353
|
|
|
@@ -412,8 +416,9 @@ class AnalysisRunner:
|
|
|
412
416
|
metadata_file = (Path(reports_dir) / f"{os.path.basename(exe_name)}"
|
|
413
417
|
f"-metadata.json")
|
|
414
418
|
LOG.debug(f"Metadata written to {metadata_file}")
|
|
419
|
+
output = orjson.dumps(metadata, default=json_serializer).decode("utf-8", "ignore")
|
|
415
420
|
with open(metadata_file, mode="w", encoding="utf-8") as ffp:
|
|
416
|
-
|
|
421
|
+
ffp.write(output)
|
|
417
422
|
self.progress.update(
|
|
418
423
|
self.task,
|
|
419
424
|
description=f"Checking [bold]{f}[/bold] against rules")
|
|
@@ -639,8 +644,7 @@ class ReviewRunner:
|
|
|
639
644
|
if found_pattern[apattern] > EVIDENCE_LIMIT or found_cid[cid] > EVIDENCE_LIMIT:
|
|
640
645
|
continue
|
|
641
646
|
for afun in functions_list:
|
|
642
|
-
if
|
|
643
|
-
found_function.get(afun.lower())):
|
|
647
|
+
if apattern.lower() in afun.lower() and not found_function.get(afun.lower()):
|
|
644
648
|
result = {"pattern": apattern, "function": afun, }
|
|
645
649
|
results[cid].append(result)
|
|
646
650
|
found_cid[cid] += 1
|
|
@@ -18,13 +18,7 @@ from blint.utils import check_command, create_component_evidence, find_files, un
|
|
|
18
18
|
|
|
19
19
|
ANDROID_HOME = os.getenv("ANDROID_HOME")
|
|
20
20
|
APKANALYZER_CMD = os.getenv("APKANALYZER_CMD")
|
|
21
|
-
if (
|
|
22
|
-
not APKANALYZER_CMD
|
|
23
|
-
and ANDROID_HOME
|
|
24
|
-
and (
|
|
25
|
-
os.path.exists(os.path.join(ANDROID_HOME, "cmdline-tools", "latest", "bin", "apkanalyzer"))
|
|
26
|
-
)
|
|
27
|
-
):
|
|
21
|
+
if not APKANALYZER_CMD and ANDROID_HOME and os.path.exists(os.path.join(ANDROID_HOME, "cmdline-tools", "latest", "bin", "apkanalyzer")):
|
|
28
22
|
APKANALYZER_CMD = os.path.join(ANDROID_HOME, "cmdline-tools", "latest", "bin", "apkanalyzer")
|
|
29
23
|
elif check_command("apkanalyzer"):
|
|
30
24
|
APKANALYZER_CMD = "apkanalyzer"
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
# pylint: disable=too-many-lines,consider-using-f-string
|
|
2
2
|
import codecs
|
|
3
3
|
import contextlib
|
|
4
|
-
import json
|
|
5
4
|
import sys
|
|
5
|
+
from typing import Tuple
|
|
6
|
+
import zlib
|
|
7
|
+
import orjson
|
|
6
8
|
|
|
7
9
|
import lief
|
|
8
10
|
|
|
9
11
|
from blint.logger import DEBUG, LOG
|
|
10
12
|
from blint.utils import calculate_entropy, check_secret, cleanup_dict_lief_errors, decode_base64
|
|
11
13
|
|
|
14
|
+
SYMBOLIC_FOUND = True
|
|
15
|
+
try:
|
|
16
|
+
from symbolic._lowlevel import ffi, lib
|
|
17
|
+
from symbolic.utils import encode_str, decode_str, rustcall
|
|
18
|
+
except OSError:
|
|
19
|
+
SYMBOLIC_FOUND = False
|
|
20
|
+
|
|
12
21
|
MIN_ENTROPY = 0.39
|
|
13
22
|
MIN_LENGTH = 80
|
|
14
23
|
|
|
@@ -19,6 +28,21 @@ if LOG.level != DEBUG:
|
|
|
19
28
|
ADDRESS_FMT = "0x{:<10x}"
|
|
20
29
|
|
|
21
30
|
|
|
31
|
+
def demangle_symbolic_name(symbol, lang=None, no_args=False):
|
|
32
|
+
"""Demangles a symbol."""
|
|
33
|
+
if not SYMBOLIC_FOUND:
|
|
34
|
+
return symbol
|
|
35
|
+
try:
|
|
36
|
+
func = lib.symbolic_demangle_no_args if no_args else lib.symbolic_demangle
|
|
37
|
+
lang_str = encode_str(lang) if lang else ffi.NULL
|
|
38
|
+
|
|
39
|
+
demangled = rustcall(func, encode_str(symbol), lang_str)
|
|
40
|
+
demangled_symbol = decode_str(demangled, free=True)
|
|
41
|
+
return demangled_symbol.strip()
|
|
42
|
+
except AttributeError:
|
|
43
|
+
return symbol
|
|
44
|
+
|
|
45
|
+
|
|
22
46
|
def is_shared_library(parsed_obj):
|
|
23
47
|
"""
|
|
24
48
|
Checks if the given parsed binary object represents a shared library.
|
|
@@ -217,24 +241,6 @@ def parse_strings(parsed_obj):
|
|
|
217
241
|
return strings_list
|
|
218
242
|
|
|
219
243
|
|
|
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
|
-
"""
|
|
230
|
-
if not symbol_name:
|
|
231
|
-
return True
|
|
232
|
-
for pref in ("_$f", "$f64.", "__"):
|
|
233
|
-
if symbol_name.startswith(pref):
|
|
234
|
-
return True
|
|
235
|
-
return False
|
|
236
|
-
|
|
237
|
-
|
|
238
244
|
def parse_symbols(symbols):
|
|
239
245
|
"""
|
|
240
246
|
Parse symbols from a list of symbols.
|
|
@@ -259,25 +265,26 @@ def parse_symbols(symbols):
|
|
|
259
265
|
is_exported = True
|
|
260
266
|
symbol_name = symbol.demangled_name
|
|
261
267
|
if isinstance(symbol_name, lief.lief_errors):
|
|
262
|
-
symbol_name = symbol.name
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
268
|
+
symbol_name = demangle_symbolic_name(symbol.name)
|
|
269
|
+
else:
|
|
270
|
+
symbol_name = demangle_symbolic_name(symbol_name)
|
|
271
|
+
exe_type = guess_exe_type(symbol_name)
|
|
272
|
+
symbols_list.append(
|
|
273
|
+
{
|
|
274
|
+
"name": symbol_name,
|
|
275
|
+
"type": str(symbol.type).rsplit(".", maxsplit=1)[-1],
|
|
276
|
+
"value": symbol.value,
|
|
277
|
+
"visibility": str(symbol.visibility).rsplit(".", maxsplit=1)[-1],
|
|
278
|
+
"binding": str(symbol.binding).rsplit(".", maxsplit=1)[-1],
|
|
279
|
+
"is_imported": is_imported,
|
|
280
|
+
"is_exported": is_exported,
|
|
281
|
+
"information": symbol.information,
|
|
282
|
+
"is_function": symbol.is_function,
|
|
283
|
+
"is_static": symbol.is_static,
|
|
284
|
+
"is_variable": symbol.is_variable,
|
|
285
|
+
"version": str(symbol_version),
|
|
286
|
+
}
|
|
287
|
+
)
|
|
281
288
|
except (AttributeError, IndexError, TypeError):
|
|
282
289
|
continue
|
|
283
290
|
return symbols_list, exe_type
|
|
@@ -514,12 +521,14 @@ def parse_pe_symbols(symbols):
|
|
|
514
521
|
symbols_list = []
|
|
515
522
|
exe_type = ""
|
|
516
523
|
for symbol in symbols:
|
|
524
|
+
if not symbol:
|
|
525
|
+
continue
|
|
517
526
|
try:
|
|
518
527
|
if symbol.section_number <= 0:
|
|
519
528
|
section_nb_str = str(lief.PE.SYMBOL_SECTION_NUMBER(symbol.section_number)).rsplit(
|
|
520
529
|
".", maxsplit=1
|
|
521
530
|
)[-1]
|
|
522
|
-
elif symbol.section.name:
|
|
531
|
+
elif symbol.section and symbol.section.name:
|
|
523
532
|
section_nb_str = symbol.section.name
|
|
524
533
|
else:
|
|
525
534
|
section_nb_str = "section<{:d}>".format(symbol.section_number)
|
|
@@ -542,6 +551,8 @@ def parse_pe_symbols(symbols):
|
|
|
542
551
|
)
|
|
543
552
|
except (IndexError, AttributeError, ValueError) as e:
|
|
544
553
|
LOG.debug(f"Caught {type(e)}: {e} while parsing {symbol}.")
|
|
554
|
+
except RuntimeError:
|
|
555
|
+
pass
|
|
545
556
|
return symbols_list, exe_type
|
|
546
557
|
|
|
547
558
|
|
|
@@ -654,21 +665,21 @@ def parse_macho_symbols(symbols):
|
|
|
654
665
|
)
|
|
655
666
|
symbol_name = symbol.demangled_name
|
|
656
667
|
if not symbol_name or isinstance(symbol_name, lief.lief_errors):
|
|
657
|
-
symbol_name = symbol.name
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
668
|
+
symbol_name = demangle_symbolic_name(symbol.name)
|
|
669
|
+
else:
|
|
670
|
+
symbol_name = demangle_symbolic_name(symbol_name)
|
|
671
|
+
if not exe_type:
|
|
672
|
+
exe_type = guess_exe_type(symbol_name)
|
|
673
|
+
symbols_list.append(
|
|
674
|
+
{
|
|
675
|
+
"name": (f"{libname}::{symbol_name}" if libname else symbol_name),
|
|
676
|
+
"short_name": symbol_name,
|
|
677
|
+
"type": symbol.type,
|
|
678
|
+
"num_sections": symbol.numberof_sections,
|
|
679
|
+
"description": symbol.description,
|
|
680
|
+
"value": symbol_value,
|
|
681
|
+
}
|
|
682
|
+
)
|
|
672
683
|
except (AttributeError, TypeError):
|
|
673
684
|
continue
|
|
674
685
|
return symbols_list, exe_type
|
|
@@ -761,6 +772,7 @@ def add_elf_metadata(exe_file, metadata, parsed_obj):
|
|
|
761
772
|
metadata["ctor_functions"] = parse_functions(parsed_obj.ctor_functions)
|
|
762
773
|
metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
|
|
763
774
|
metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
|
|
775
|
+
metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
|
|
764
776
|
|
|
765
777
|
return metadata
|
|
766
778
|
|
|
@@ -924,13 +936,13 @@ def parse_overlay(parsed_obj: lief.Binary) -> dict[str, dict]:
|
|
|
924
936
|
try:
|
|
925
937
|
# deps should have runtimeTarget, compilationOptions, targets, and libraries
|
|
926
938
|
# Use libraries to construct BOM components and targets for the dependency tree
|
|
927
|
-
deps =
|
|
928
|
-
except
|
|
939
|
+
deps = orjson.loads(overlay_str)
|
|
940
|
+
except orjson.JSONDecodeError:
|
|
929
941
|
pass
|
|
930
942
|
return deps
|
|
931
943
|
|
|
932
944
|
|
|
933
|
-
def parse_go_buildinfo(parsed_obj: lief.Binary) ->
|
|
945
|
+
def parse_go_buildinfo(parsed_obj: lief.Binary) -> Tuple[dict[str, dict[str, str]], dict[str, str]]:
|
|
934
946
|
"""
|
|
935
947
|
Parse the go build info section to extract go dependencies
|
|
936
948
|
Args:
|
|
@@ -983,6 +995,32 @@ def parse_go_buildinfo(parsed_obj: lief.Binary) -> (dict[str, dict[str, str]], d
|
|
|
983
995
|
return deps, formulation
|
|
984
996
|
|
|
985
997
|
|
|
998
|
+
def parse_rust_buildinfo(parsed_obj: lief.Binary) -> list:
|
|
999
|
+
"""
|
|
1000
|
+
Parse the rust build info section of binaries that are cargo-auditable to extract rust dependencies
|
|
1001
|
+
Args:
|
|
1002
|
+
parsed_obj (lief.Binary): The parsed object representing the binary.
|
|
1003
|
+
|
|
1004
|
+
Returns:
|
|
1005
|
+
list: List representing the dependencies.
|
|
1006
|
+
"""
|
|
1007
|
+
deps = []
|
|
1008
|
+
|
|
1009
|
+
try:
|
|
1010
|
+
audit_data_section = next(filter(lambda section: section.name == ".dep-v0", parsed_obj.sections), None)
|
|
1011
|
+
if audit_data_section is not None and audit_data_section.content:
|
|
1012
|
+
json_string = zlib.decompress(audit_data_section.content)
|
|
1013
|
+
audit_data = orjson.loads(json_string)
|
|
1014
|
+
|
|
1015
|
+
if audit_data and audit_data["packages"]:
|
|
1016
|
+
packages = audit_data["packages"]
|
|
1017
|
+
deps = [x for x in packages if 'root' not in x]
|
|
1018
|
+
except orjson.JSONDecodeError:
|
|
1019
|
+
pass
|
|
1020
|
+
|
|
1021
|
+
return deps
|
|
1022
|
+
|
|
1023
|
+
|
|
986
1024
|
def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
|
|
987
1025
|
"""Adds PE metadata to the given metadata dictionary.
|
|
988
1026
|
|
|
@@ -1035,6 +1073,7 @@ def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
|
|
|
1035
1073
|
metadata["is_dotnet"] = True
|
|
1036
1074
|
metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
|
|
1037
1075
|
metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
|
|
1076
|
+
metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
|
|
1038
1077
|
tls = parsed_obj.tls
|
|
1039
1078
|
if tls and tls.sizeof_zero_fill:
|
|
1040
1079
|
metadata["tls_address_index"] = tls.addressof_index
|
|
@@ -1196,6 +1235,7 @@ def add_mach0_metadata(exe_file, metadata, parsed_obj):
|
|
|
1196
1235
|
metadata = add_mach0_functions(metadata, parsed_obj)
|
|
1197
1236
|
metadata = add_mach0_signature(exe_file, metadata, parsed_obj)
|
|
1198
1237
|
metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
|
|
1238
|
+
metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
|
|
1199
1239
|
return metadata
|
|
1200
1240
|
|
|
1201
1241
|
|
|
@@ -37,20 +37,6 @@ ignore_files = [
|
|
|
37
37
|
".tar",
|
|
38
38
|
".log",
|
|
39
39
|
".tmp",
|
|
40
|
-
".gif",
|
|
41
|
-
".png",
|
|
42
|
-
".jpg",
|
|
43
|
-
".webp",
|
|
44
|
-
".webm",
|
|
45
|
-
".icns",
|
|
46
|
-
".pcm",
|
|
47
|
-
".wav",
|
|
48
|
-
".mp3",
|
|
49
|
-
".pdf",
|
|
50
|
-
".doc",
|
|
51
|
-
".docx",
|
|
52
|
-
".xls",
|
|
53
|
-
".xlsx",
|
|
54
40
|
".d.ts",
|
|
55
41
|
".min.js",
|
|
56
42
|
".min.css",
|
|
@@ -393,6 +393,10 @@ def process_exe_file(
|
|
|
393
393
|
value=str(v).strip(),
|
|
394
394
|
)
|
|
395
395
|
)
|
|
396
|
+
# Convert rust dependencies
|
|
397
|
+
if metadata.get("rust_dependencies"):
|
|
398
|
+
rust_components = process_rust_dependencies(metadata.get("rust_dependencies"), dependencies_dict)
|
|
399
|
+
lib_components += rust_components
|
|
396
400
|
if lib_components:
|
|
397
401
|
components += lib_components
|
|
398
402
|
track_dependency(dependencies_dict, parent_component, lib_components)
|
|
@@ -583,6 +587,42 @@ def process_go_dependencies(go_deps: dict[str, str]) -> list[Component]:
|
|
|
583
587
|
return components
|
|
584
588
|
|
|
585
589
|
|
|
590
|
+
def process_rust_dependencies(rust_deps: list, dependencies_dict: dict[str, set]) -> list[Component]:
|
|
591
|
+
"""
|
|
592
|
+
Process the rust dependencies metadata extracted for binary overlays
|
|
593
|
+
|
|
594
|
+
Args:
|
|
595
|
+
rust_deps (list): dependencies metadata
|
|
596
|
+
|
|
597
|
+
Returns:
|
|
598
|
+
list: New component list
|
|
599
|
+
"""
|
|
600
|
+
components = []
|
|
601
|
+
idx_to_purl = {}
|
|
602
|
+
for idx, dep in enumerate(rust_deps):
|
|
603
|
+
idx_to_purl[idx] = f"""pkg:cargo/{dep["name"]}@{dep["version"]}"""
|
|
604
|
+
for dependency in rust_deps:
|
|
605
|
+
purl = f"""pkg:cargo/{dependency["name"]}@{dependency["version"]}"""
|
|
606
|
+
purl_qualifer = f"""?repository={dependency.get("source")}""" if dependency.get("source", "") != "crates.io" else ""
|
|
607
|
+
comp = Component(
|
|
608
|
+
type=Type.library,
|
|
609
|
+
name=dependency["name"],
|
|
610
|
+
version=dependency["version"],
|
|
611
|
+
purl=f"{purl}{purl_qualifer}",
|
|
612
|
+
scope=Scope.required,
|
|
613
|
+
evidence=create_component_evidence(dependency["name"], 0.8)
|
|
614
|
+
)
|
|
615
|
+
comp.bom_ref = RefType(purl)
|
|
616
|
+
components.append(comp)
|
|
617
|
+
if not dependencies_dict.get(purl):
|
|
618
|
+
dependencies_dict[purl] = set()
|
|
619
|
+
# Recover the dependency tree
|
|
620
|
+
if dependency.get("dependencies"):
|
|
621
|
+
for adep in dependency.get("dependencies"):
|
|
622
|
+
dependencies_dict[purl].add(idx_to_purl[adep])
|
|
623
|
+
return components
|
|
624
|
+
|
|
625
|
+
|
|
586
626
|
def track_dependency(
|
|
587
627
|
dependencies_dict: dict[str, set], parent_component: Component, app_components: list[Component]
|
|
588
628
|
) -> None:
|
|
@@ -505,5 +505,6 @@ def create_component_evidence(method_value: str, confidence: float) -> Component
|
|
|
505
505
|
|
|
506
506
|
|
|
507
507
|
def camel_to_snake(name: str) -> str:
|
|
508
|
+
"""Convert camelCase to snake_case"""
|
|
508
509
|
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
|
509
510
|
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "blint"
|
|
3
|
-
version = "2.1.
|
|
3
|
+
version = "2.1.4"
|
|
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"
|
|
@@ -34,6 +34,8 @@ rich = "^13.7.0"
|
|
|
34
34
|
PyYAML = "^6.0.1"
|
|
35
35
|
defusedxml = "^0.7.1"
|
|
36
36
|
pydantic = {version = "^2.6.0", extras = ["email"]}
|
|
37
|
+
orjson = "^3.10.1"
|
|
38
|
+
symbolic = "10.2.1"
|
|
37
39
|
|
|
38
40
|
[tool.poetry.group.dev.dependencies]
|
|
39
41
|
pytest = "^8.0.0"
|
|
@@ -54,8 +56,8 @@ build-backend = "poetry.core.masonry.api"
|
|
|
54
56
|
addopts = "--verbose --cov-append --cov-report term --cov blint"
|
|
55
57
|
|
|
56
58
|
[tool.pylint]
|
|
57
|
-
generated-members = ["lief"]
|
|
58
|
-
ignore-paths = ["blint/cyclonedx/*"]
|
|
59
|
+
generated-members = ["lief", "orjson"]
|
|
60
|
+
ignore-paths = ["blint/cyclonedx/*", "tests/*"]
|
|
59
61
|
# Let's not fuss about long strings
|
|
60
62
|
ignore-long-lines = "[r|f]\""
|
|
61
63
|
disable = ["missing-module-docstring", "logging-fstring-interpolation"]
|
|
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
|