blint 2.2.2__tar.gz → 2.2.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.
Files changed (36) hide show
  1. {blint-2.2.2 → blint-2.2.3}/PKG-INFO +1 -1
  2. {blint-2.2.2 → blint-2.2.3}/blint/analysis.py +76 -66
  3. {blint-2.2.2 → blint-2.2.3}/blint/binary.py +20 -3
  4. {blint-2.2.2 → blint-2.2.3}/pyproject.toml +1 -1
  5. {blint-2.2.2 → blint-2.2.3}/LICENSE +0 -0
  6. {blint-2.2.2 → blint-2.2.3}/README.md +0 -0
  7. {blint-2.2.2 → blint-2.2.3}/blint/__init__.py +0 -0
  8. {blint-2.2.2 → blint-2.2.3}/blint/android.py +0 -0
  9. {blint-2.2.2 → blint-2.2.3}/blint/checks.py +0 -0
  10. {blint-2.2.2 → blint-2.2.3}/blint/cli.py +0 -0
  11. {blint-2.2.2 → blint-2.2.3}/blint/config.py +0 -0
  12. {blint-2.2.2 → blint-2.2.3}/blint/cyclonedx/README.md +0 -0
  13. {blint-2.2.2 → blint-2.2.3}/blint/cyclonedx/__init__.py +0 -0
  14. {blint-2.2.2 → blint-2.2.3}/blint/cyclonedx/spdx.py +0 -0
  15. {blint-2.2.2 → blint-2.2.3}/blint/cyclonedx/spec.py +0 -0
  16. {blint-2.2.2 → blint-2.2.3}/blint/data/__init__.py +0 -0
  17. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/__init__.py +0 -0
  18. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_entries_generic.yml +0 -0
  19. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_entries_pe.yml +0 -0
  20. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_exe_go.yml +0 -0
  21. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_imports_pe.yml +0 -0
  22. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_methods_generic.yml +0 -0
  23. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_methods_mips.yml +0 -0
  24. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_monero_generic.yml +0 -0
  25. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_monero_go.yml +0 -0
  26. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_monero_rust.yml +0 -0
  27. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_rootkits_win.yml +0 -0
  28. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
  29. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_symbols_generic.yml +0 -0
  30. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_symbols_hooka.yml +0 -0
  31. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_symbols_macho.yml +0 -0
  32. {blint-2.2.2 → blint-2.2.3}/blint/data/annotations/review_symbols_rust.yml +0 -0
  33. {blint-2.2.2 → blint-2.2.3}/blint/data/rules.yml +0 -0
  34. {blint-2.2.2 → blint-2.2.3}/blint/logger.py +0 -0
  35. {blint-2.2.2 → blint-2.2.3}/blint/sbom.py +0 -0
  36. {blint-2.2.2 → blint-2.2.3}/blint/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blint
3
- Version: 2.2.2
3
+ Version: 2.2.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
@@ -15,15 +15,23 @@ from rich.progress import Progress
15
15
  from rich.terminal_theme import MONOKAI
16
16
 
17
17
  from blint.binary import parse
18
+
18
19
  # pylint: disable-next=unused-import
19
- from blint.checks import (check_nx, check_pie,
20
- check_relro, check_canary, check_rpath,
21
- check_virtual_size, check_authenticode,
22
- check_dll_characteristics, check_codesign,
23
- check_trust_info)
20
+ from blint.checks import (
21
+ check_nx,
22
+ check_pie,
23
+ check_relro,
24
+ check_canary,
25
+ check_rpath,
26
+ check_virtual_size,
27
+ check_authenticode,
28
+ check_dll_characteristics,
29
+ check_codesign,
30
+ check_trust_info,
31
+ )
24
32
  from blint.config import FIRST_STAGE_WORDS, PII_WORDS, get_int_from_env
25
33
  from blint.logger import LOG, console
26
- from blint.utils import (create_findings_table, is_fuzzable_name, print_findings_table)
34
+ from blint.utils import create_findings_table, is_fuzzable_name, print_findings_table
27
35
 
28
36
  try:
29
37
  import importlib.resources # pylint: disable=ungrouped-imports
@@ -37,16 +45,12 @@ if HAVE_RESOURCE_READER:
37
45
  with contextlib.suppress(NameError, FileNotFoundError):
38
46
  review_files = (
39
47
  resource.name
40
- for resource in importlib.resources.files(
41
- "blint.data.annotations"
42
- ).iterdir()
48
+ for resource in importlib.resources.files("blint.data.annotations").iterdir()
43
49
  if resource.is_file() and resource.name.endswith(".yml")
44
50
  )
45
51
  if not review_files:
46
52
  review_methods_dir = Path(__file__).parent / "data" / "annotations"
47
- review_files = [
48
- p.as_posix() for p in Path(review_methods_dir).rglob("*.yml")
49
- ]
53
+ review_files = [p.as_posix() for p in Path(review_methods_dir).rglob("*.yml")]
50
54
 
51
55
  rules_dict = {}
52
56
  review_exe_dict = defaultdict(list)
@@ -56,16 +60,18 @@ review_imports_dict = defaultdict(list)
56
60
  review_entries_dict = defaultdict(list)
57
61
  review_rules_cache = {
58
62
  "PII_READ": {
63
+ "id": "PII_READ",
59
64
  "title": "Detect PII Read Operations",
60
65
  "summary": "Can Retrieve Sensitive PII data",
61
66
  "description": "Contains logic to retrieve sensitive data such as names, email, passwords etc.",
62
- "patterns": PII_WORDS
67
+ "patterns": PII_WORDS,
63
68
  },
64
69
  "LOADER_SYMBOLS": {
70
+ "id": "LOADER_SYMBOLS",
65
71
  "title": "Detect Initial Loader",
66
72
  "summary": "Behaves like a loader",
67
73
  "description": "The binary behaves like a loader by downloading and executing additional payloads.",
68
- "patterns": FIRST_STAGE_WORDS
74
+ "patterns": FIRST_STAGE_WORDS,
69
75
  },
70
76
  }
71
77
 
@@ -84,11 +90,7 @@ def get_resource(package, resource):
84
90
  # If we're in the context of a module, we could also use
85
91
  # ``__loader__.get_resource_reader(__name__).open_resource(resource)``.
86
92
  # We use open_binary() because it is simple.
87
- return (
88
- importlib.resources.files(package)
89
- .joinpath(resource)
90
- .open("r", encoding="utf-8")
91
- )
93
+ return importlib.resources.files(package).joinpath(resource).open("r", encoding="utf-8")
92
94
 
93
95
  # Fall back to __file__.
94
96
 
@@ -318,7 +320,7 @@ def json_serializer(obj):
318
320
  """JSON serializer to help serialize problematic types such as bytes"""
319
321
  if isinstance(obj, bytes):
320
322
  try:
321
- return obj.decode('utf-8')
323
+ return obj.decode("utf-8")
322
324
  except UnicodeDecodeError:
323
325
  return ""
324
326
 
@@ -346,23 +348,26 @@ def report(src_dir, reports_dir, findings, reviews, files, fuzzables):
346
348
  print_findings_table(findings, files)
347
349
  findings_file = Path(reports_dir) / "findings.json"
348
350
  LOG.info(f"Findings written to {findings_file}")
349
- output = orjson.dumps({**common_metadata, "findings": findings}, default=json_serializer).decode("utf-8",
350
- "ignore")
351
+ output = orjson.dumps(
352
+ {**common_metadata, "findings": findings}, default=json_serializer
353
+ ).decode("utf-8", "ignore")
351
354
  with open(findings_file, mode="w", encoding="utf-8") as ffp:
352
355
  ffp.write(output)
353
356
  if reviews:
354
357
  print_reviews_table(reviews, files)
355
358
  reviews_file = Path(reports_dir) / "reviews.json"
356
359
  LOG.info(f"Review written to {reviews_file}")
357
- output = orjson.dumps({**common_metadata, "reviews": reviews}, default=json_serializer).decode("utf-8",
358
- "ignore")
360
+ output = orjson.dumps(
361
+ {**common_metadata, "reviews": reviews}, default=json_serializer
362
+ ).decode("utf-8", "ignore")
359
363
  with open(reviews_file, mode="w", encoding="utf-8") as rfp:
360
364
  rfp.write(output)
361
365
  if fuzzables:
362
366
  fuzzables_file = Path(reports_dir) / "fuzzables.json"
363
367
  LOG.info(f"Fuzzables data written to {fuzzables_file}")
364
- output = orjson.dumps({**common_metadata, "fuzzables": fuzzables}, default=json_serializer).decode("utf-8",
365
- "ignore")
368
+ output = orjson.dumps(
369
+ {**common_metadata, "fuzzables": fuzzables}, default=json_serializer
370
+ ).decode("utf-8", "ignore")
366
371
  with open(fuzzables_file, mode="w", encoding="utf-8") as rfp:
367
372
  rfp.write(output)
368
373
  else:
@@ -385,8 +390,11 @@ class AnalysisRunner:
385
390
  self.reviews = []
386
391
  self.fuzzables = []
387
392
  self.progress = Progress(
388
- transient=True, redirect_stderr=True,
389
- redirect_stdout=True, refresh_per_second=1, )
393
+ transient=True,
394
+ redirect_stderr=True,
395
+ redirect_stdout=True,
396
+ refresh_per_second=1,
397
+ )
390
398
  self.task = None
391
399
  self.reviewer = None
392
400
 
@@ -410,7 +418,9 @@ class AnalysisRunner:
410
418
  with self.progress:
411
419
  self.task = self.progress.add_task(
412
420
  f"[green] BLinting {len(files)} binaries",
413
- total=len(files), start=True, )
421
+ total=len(files),
422
+ start=True,
423
+ )
414
424
  for f in files:
415
425
  self._process_files(f, reports_dir, no_reviews, suggest_fuzzables)
416
426
  return self.findings, self.reviews, self.fuzzables
@@ -425,20 +435,16 @@ class AnalysisRunner:
425
435
  suggest_fuzzables (bool): Whether to suggest fuzzable targets or not.
426
436
 
427
437
  """
428
- self.progress.update(
429
- self.task, description=f"Processing [bold]{f}[/bold]")
438
+ self.progress.update(self.task, description=f"Processing [bold]{f}[/bold]")
430
439
  metadata = parse(f)
431
440
  exe_name = metadata.get("name", "")
432
441
  # Store raw metadata
433
- metadata_file = (Path(reports_dir) / f"{os.path.basename(exe_name)}"
434
- f"-metadata.json")
442
+ metadata_file = Path(reports_dir) / f"{os.path.basename(exe_name)}" f"-metadata.json"
435
443
  LOG.debug(f"Metadata written to {metadata_file}")
436
444
  output = orjson.dumps(metadata, default=json_serializer).decode("utf-8", "ignore")
437
445
  with open(metadata_file, mode="w", encoding="utf-8") as ffp:
438
446
  ffp.write(output)
439
- self.progress.update(
440
- self.task,
441
- description=f"Checking [bold]{f}[/bold] against rules")
447
+ self.progress.update(self.task, description=f"Checking [bold]{f}[/bold] against rules")
442
448
  if finding := run_checks(f, metadata):
443
449
  self.findings += finding
444
450
  # Perform symbol reviews
@@ -457,8 +463,7 @@ class AnalysisRunner:
457
463
 
458
464
  def do_review(self, exe_name, f, metadata):
459
465
  """Performs a review of the given file."""
460
- self.progress.update(
461
- self.task, description="Checking methods against review rules")
466
+ self.progress.update(self.task, description="Checking methods against review rules")
462
467
  self.reviewer = ReviewRunner()
463
468
  self.reviewer.run_review(metadata)
464
469
  if self.reviewer.results:
@@ -498,11 +503,11 @@ class ReviewRunner:
498
503
  self._gen_review_lists(exe_type)
499
504
  # Check if reviews are available for this exe type
500
505
  if (
501
- self.review_methods_list
502
- or self.review_exe_list
503
- or self.review_symbols_list
504
- or self.review_imports_list
505
- or self.review_entries_list
506
+ self.review_methods_list
507
+ or self.review_exe_list
508
+ or self.review_symbols_list
509
+ or self.review_imports_list
510
+ or self.review_entries_list
506
511
  ):
507
512
  return self._review_lists(metadata)
508
513
  return self._review_loader_symbols(metadata)
@@ -552,9 +557,11 @@ class ReviewRunner:
552
557
  Returns:
553
558
  dict: The results of the review.
554
559
  """
555
- entries_list = [f.get("name", "") for f in
556
- metadata.get("dynamic_entries", []) if
557
- f.get("tag") == "NEEDED"]
560
+ entries_list = [
561
+ f.get("name", "")
562
+ for f in metadata.get("dynamic_entries", [])
563
+ if f.get("tag") == "NEEDED"
564
+ ]
558
565
  LOG.debug(f"Reviewing {len(entries_list)} dynamic entries")
559
566
  self.run_review_methods_symbols(self.review_entries_list, entries_list)
560
567
 
@@ -597,14 +604,11 @@ class ReviewRunner:
597
604
  Args:
598
605
  metadata (dict): The metadata to review.
599
606
  """
600
- symbols_list = [f.get("name", "") for f in
601
- metadata.get("dynamic_symbols", [])]
602
- symbols_list += [f.get("name", "") for f in
603
- metadata.get("symtab_symbols", [])]
607
+ symbols_list = [f.get("name", "") for f in metadata.get("dynamic_symbols", [])]
608
+ symbols_list += [f.get("name", "") for f in metadata.get("symtab_symbols", [])]
604
609
  LOG.debug(f"Reviewing {len(symbols_list)} symbols")
605
610
  if self.review_symbols_list:
606
- self.run_review_methods_symbols(
607
- self.review_symbols_list, symbols_list)
611
+ self.run_review_methods_symbols(self.review_symbols_list, symbols_list)
608
612
  if self.review_exe_list:
609
613
  self.run_review_methods_symbols(self.review_exe_list, symbols_list)
610
614
 
@@ -616,22 +620,19 @@ class ReviewRunner:
616
620
  Args:
617
621
  metadata (dict): The metadata to review.
618
622
  """
619
- functions_list = [re.sub(r"[*&()]", "", f.get("name", "")) for f in
620
- metadata.get("functions", [])]
623
+ functions_list = [
624
+ re.sub(r"[*&()]", "", f.get("name", "")) for f in metadata.get("functions", [])
625
+ ]
621
626
  if metadata.get("magic", "").startswith("PE"):
622
- functions_list += [f.get("name", "") for f in
623
- metadata.get("symtab_symbols", [])]
627
+ functions_list += [f.get("name", "") for f in metadata.get("symtab_symbols", [])]
624
628
  # If there are no function but static symbols use that instead
625
629
  if not functions_list and metadata.get("symtab_symbols"):
626
- functions_list = [f.get("name", "") for f in
627
- metadata.get("symtab_symbols", [])]
630
+ functions_list = [f.get("name", "") for f in metadata.get("symtab_symbols", [])]
628
631
  LOG.debug(f"Reviewing {len(functions_list)} functions")
629
632
  if self.review_methods_list:
630
- self.run_review_methods_symbols(
631
- self.review_methods_list, functions_list)
633
+ self.run_review_methods_symbols(self.review_methods_list, functions_list)
632
634
  if self.review_exe_list:
633
- self.run_review_methods_symbols(
634
- self.review_exe_list, functions_list)
635
+ self.run_review_methods_symbols(self.review_exe_list, functions_list)
635
636
 
636
637
  def _gen_review_lists(self, exe_type):
637
638
  """
@@ -658,8 +659,12 @@ class ReviewRunner:
658
659
  if not self.results:
659
660
  return {}
660
661
  for cid, evidence in self.results.items():
661
- aresult = {**review_rules_cache.get(cid), "evidence": evidence,
662
- "filename": f, "exe_name": exe_name, }
662
+ aresult = {
663
+ **review_rules_cache.get(cid),
664
+ "evidence": evidence,
665
+ "filename": f,
666
+ "exe_name": exe_name,
667
+ }
663
668
  del aresult["patterns"]
664
669
  reviews.append(aresult)
665
670
  return reviews
@@ -695,8 +700,13 @@ class ReviewRunner:
695
700
  if found_pattern[apattern] > EVIDENCE_LIMIT or found_cid[cid] > EVIDENCE_LIMIT:
696
701
  continue
697
702
  for afun in functions_list:
698
- if apattern.lower() in afun.lower() and not found_function.get(afun.lower()):
699
- result = {"pattern": apattern, "function": afun, }
703
+ if apattern.lower() in afun.lower() and not found_function.get(
704
+ afun.lower()
705
+ ):
706
+ result = {
707
+ "pattern": apattern,
708
+ "function": afun,
709
+ }
700
710
  results[cid].append(result)
701
711
  found_cid[cid] += 1
702
712
  found_pattern[apattern] += 1
@@ -912,8 +912,6 @@ def add_elf_dynamic_entries(dynamic_entries, metadata):
912
912
  if entry.tag in [
913
913
  lief.ELF.DynamicEntry.TAG.SONAME,
914
914
  lief.ELF.DynamicEntry.TAG.NEEDED,
915
- lief.ELF.DynamicEntry.TAG.RUNPATH,
916
- lief.ELF.DynamicEntry.TAG.RPATH,
917
915
  ]:
918
916
  metadata["dynamic_entries"].append(
919
917
  {
@@ -922,9 +920,28 @@ def add_elf_dynamic_entries(dynamic_entries, metadata):
922
920
  "value": entry.value,
923
921
  }
924
922
  )
925
- # Detect dotnet binary
926
923
  if "netcoredeps" in entry.name:
927
924
  metadata["exe_type"] = "dotnetbinary"
925
+ if entry.tag in [
926
+ lief.ELF.DynamicEntry.TAG.RUNPATH,
927
+ ]:
928
+ metadata["dynamic_entries"].append(
929
+ {
930
+ "name": "runpath",
931
+ "tag": str(entry.tag).rsplit(".", maxsplit=1)[-1],
932
+ "value": entry.runpath,
933
+ }
934
+ )
935
+ if entry.tag in [
936
+ lief.ELF.DynamicEntry.TAG.RPATH,
937
+ ]:
938
+ metadata["dynamic_entries"].append(
939
+ {
940
+ "name": "rpath",
941
+ "tag": str(entry.tag).rsplit(".", maxsplit=1)[-1],
942
+ "value": entry.rpath,
943
+ }
944
+ )
928
945
  return metadata
929
946
 
930
947
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "blint"
3
- version = "2.2.2"
3
+ version = "2.2.3"
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"
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