blint 2.1.3__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.
Files changed (37) hide show
  1. {blint-2.1.3 → blint-2.1.4}/PKG-INFO +4 -2
  2. {blint-2.1.3 → blint-2.1.4}/README.md +1 -1
  3. {blint-2.1.3 → blint-2.1.4}/blint/analysis.py +16 -12
  4. {blint-2.1.3 → blint-2.1.4}/blint/binary.py +38 -9
  5. {blint-2.1.3 → blint-2.1.4}/blint/config.py +0 -14
  6. {blint-2.1.3 → blint-2.1.4}/blint/utils.py +1 -0
  7. {blint-2.1.3 → blint-2.1.4}/pyproject.toml +5 -3
  8. {blint-2.1.3 → blint-2.1.4}/LICENSE +0 -0
  9. {blint-2.1.3 → blint-2.1.4}/blint/__init__.py +0 -0
  10. {blint-2.1.3 → blint-2.1.4}/blint/android.py +0 -0
  11. {blint-2.1.3 → blint-2.1.4}/blint/checks.py +0 -0
  12. {blint-2.1.3 → blint-2.1.4}/blint/cli.py +0 -0
  13. {blint-2.1.3 → blint-2.1.4}/blint/cyclonedx/README.md +0 -0
  14. {blint-2.1.3 → blint-2.1.4}/blint/cyclonedx/__init__.py +0 -0
  15. {blint-2.1.3 → blint-2.1.4}/blint/cyclonedx/spdx.py +0 -0
  16. {blint-2.1.3 → blint-2.1.4}/blint/cyclonedx/spec.py +0 -0
  17. {blint-2.1.3 → blint-2.1.4}/blint/data/__init__.py +0 -0
  18. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/__init__.py +0 -0
  19. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_entries_generic.yml +0 -0
  20. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_entries_pe.yml +0 -0
  21. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_exe_go.yml +0 -0
  22. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_imports_pe.yml +0 -0
  23. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_methods_generic.yml +0 -0
  24. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_methods_mips.yml +0 -0
  25. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_monero_generic.yml +0 -0
  26. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_monero_go.yml +0 -0
  27. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_monero_rust +0 -0
  28. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_monero_rust.yml +0 -0
  29. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_rootkits_win.yml +0 -0
  30. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
  31. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_symbols_generic.yml +0 -0
  32. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_symbols_hooka.yml +0 -0
  33. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_symbols_macho.yml +0 -0
  34. {blint-2.1.3 → blint-2.1.4}/blint/data/annotations/review_symbols_rust.yml +0 -0
  35. {blint-2.1.3 → blint-2.1.4}/blint/data/rules.yml +0 -0
  36. {blint-2.1.3 → blint-2.1.4}/blint/logger.py +0 -0
  37. {blint-2.1.3 → blint-2.1.4}/blint/sbom.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blint
3
- Version: 2.1.3
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/python)
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/python)
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
- from blint.checks import (check_nx, check_pie, # noqa, pylint: disable=unused-import
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
- json.dump(
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
- json.dump({**common_metadata, "reviews": reviews}, rfp, default=json_serializer)
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
- json.dump(
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
- json.dump(metadata, ffp, default=json_serializer)
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 ((apattern.lower() in afun.lower()) and not
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
@@ -1,16 +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
6
5
  from typing import Tuple
7
6
  import zlib
7
+ import orjson
8
8
 
9
9
  import lief
10
10
 
11
11
  from blint.logger import DEBUG, LOG
12
12
  from blint.utils import calculate_entropy, check_secret, cleanup_dict_lief_errors, decode_base64
13
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
+
14
21
  MIN_ENTROPY = 0.39
15
22
  MIN_LENGTH = 80
16
23
 
@@ -21,6 +28,21 @@ if LOG.level != DEBUG:
21
28
  ADDRESS_FMT = "0x{:<10x}"
22
29
 
23
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
+
24
46
  def is_shared_library(parsed_obj):
25
47
  """
26
48
  Checks if the given parsed binary object represents a shared library.
@@ -243,7 +265,9 @@ def parse_symbols(symbols):
243
265
  is_exported = True
244
266
  symbol_name = symbol.demangled_name
245
267
  if isinstance(symbol_name, lief.lief_errors):
246
- symbol_name = symbol.name
268
+ symbol_name = demangle_symbolic_name(symbol.name)
269
+ else:
270
+ symbol_name = demangle_symbolic_name(symbol_name)
247
271
  exe_type = guess_exe_type(symbol_name)
248
272
  symbols_list.append(
249
273
  {
@@ -497,12 +521,14 @@ def parse_pe_symbols(symbols):
497
521
  symbols_list = []
498
522
  exe_type = ""
499
523
  for symbol in symbols:
524
+ if not symbol:
525
+ continue
500
526
  try:
501
527
  if symbol.section_number <= 0:
502
528
  section_nb_str = str(lief.PE.SYMBOL_SECTION_NUMBER(symbol.section_number)).rsplit(
503
529
  ".", maxsplit=1
504
530
  )[-1]
505
- elif symbol.section.name:
531
+ elif symbol.section and symbol.section.name:
506
532
  section_nb_str = symbol.section.name
507
533
  else:
508
534
  section_nb_str = "section<{:d}>".format(symbol.section_number)
@@ -525,6 +551,8 @@ def parse_pe_symbols(symbols):
525
551
  )
526
552
  except (IndexError, AttributeError, ValueError) as e:
527
553
  LOG.debug(f"Caught {type(e)}: {e} while parsing {symbol}.")
554
+ except RuntimeError:
555
+ pass
528
556
  return symbols_list, exe_type
529
557
 
530
558
 
@@ -637,8 +665,9 @@ def parse_macho_symbols(symbols):
637
665
  )
638
666
  symbol_name = symbol.demangled_name
639
667
  if not symbol_name or isinstance(symbol_name, lief.lief_errors):
640
- symbol_name = symbol.name
641
- symbol_name = symbol_name.replace("..", "::")
668
+ symbol_name = demangle_symbolic_name(symbol.name)
669
+ else:
670
+ symbol_name = demangle_symbolic_name(symbol_name)
642
671
  if not exe_type:
643
672
  exe_type = guess_exe_type(symbol_name)
644
673
  symbols_list.append(
@@ -907,8 +936,8 @@ def parse_overlay(parsed_obj: lief.Binary) -> dict[str, dict]:
907
936
  try:
908
937
  # deps should have runtimeTarget, compilationOptions, targets, and libraries
909
938
  # Use libraries to construct BOM components and targets for the dependency tree
910
- deps = json.loads(overlay_str)
911
- except json.JSONDecodeError:
939
+ deps = orjson.loads(overlay_str)
940
+ except orjson.JSONDecodeError:
912
941
  pass
913
942
  return deps
914
943
 
@@ -981,12 +1010,12 @@ def parse_rust_buildinfo(parsed_obj: lief.Binary) -> list:
981
1010
  audit_data_section = next(filter(lambda section: section.name == ".dep-v0", parsed_obj.sections), None)
982
1011
  if audit_data_section is not None and audit_data_section.content:
983
1012
  json_string = zlib.decompress(audit_data_section.content)
984
- audit_data = json.loads(json_string)
1013
+ audit_data = orjson.loads(json_string)
985
1014
 
986
1015
  if audit_data and audit_data["packages"]:
987
1016
  packages = audit_data["packages"]
988
1017
  deps = [x for x in packages if 'root' not in x]
989
- except json.JSONDecodeError:
1018
+ except orjson.JSONDecodeError:
990
1019
  pass
991
1020
 
992
1021
  return deps
@@ -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",
@@ -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"
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