blint 2.1.2__tar.gz → 2.1.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 (37) hide show
  1. {blint-2.1.2 → blint-2.1.3}/PKG-INFO +1 -1
  2. {blint-2.1.2 → blint-2.1.3}/blint/android.py +1 -7
  3. {blint-2.1.2 → blint-2.1.3}/blint/binary.py +61 -50
  4. {blint-2.1.2 → blint-2.1.3}/blint/sbom.py +40 -0
  5. {blint-2.1.2 → blint-2.1.3}/pyproject.toml +1 -1
  6. {blint-2.1.2 → blint-2.1.3}/LICENSE +0 -0
  7. {blint-2.1.2 → blint-2.1.3}/README.md +0 -0
  8. {blint-2.1.2 → blint-2.1.3}/blint/__init__.py +0 -0
  9. {blint-2.1.2 → blint-2.1.3}/blint/analysis.py +0 -0
  10. {blint-2.1.2 → blint-2.1.3}/blint/checks.py +0 -0
  11. {blint-2.1.2 → blint-2.1.3}/blint/cli.py +0 -0
  12. {blint-2.1.2 → blint-2.1.3}/blint/config.py +0 -0
  13. {blint-2.1.2 → blint-2.1.3}/blint/cyclonedx/README.md +0 -0
  14. {blint-2.1.2 → blint-2.1.3}/blint/cyclonedx/__init__.py +0 -0
  15. {blint-2.1.2 → blint-2.1.3}/blint/cyclonedx/spdx.py +0 -0
  16. {blint-2.1.2 → blint-2.1.3}/blint/cyclonedx/spec.py +0 -0
  17. {blint-2.1.2 → blint-2.1.3}/blint/data/__init__.py +0 -0
  18. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/__init__.py +0 -0
  19. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_entries_generic.yml +0 -0
  20. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_entries_pe.yml +0 -0
  21. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_exe_go.yml +0 -0
  22. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_imports_pe.yml +0 -0
  23. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_methods_generic.yml +0 -0
  24. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_methods_mips.yml +0 -0
  25. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_monero_generic.yml +0 -0
  26. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_monero_go.yml +0 -0
  27. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_monero_rust +0 -0
  28. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_monero_rust.yml +0 -0
  29. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_rootkits_win.yml +0 -0
  30. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
  31. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_symbols_generic.yml +0 -0
  32. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_symbols_hooka.yml +0 -0
  33. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_symbols_macho.yml +0 -0
  34. {blint-2.1.2 → blint-2.1.3}/blint/data/annotations/review_symbols_rust.yml +0 -0
  35. {blint-2.1.2 → blint-2.1.3}/blint/data/rules.yml +0 -0
  36. {blint-2.1.2 → blint-2.1.3}/blint/logger.py +0 -0
  37. {blint-2.1.2 → blint-2.1.3}/blint/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blint
3
- Version: 2.1.2
3
+ Version: 2.1.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
@@ -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"
@@ -3,6 +3,8 @@ import codecs
3
3
  import contextlib
4
4
  import json
5
5
  import sys
6
+ from typing import Tuple
7
+ import zlib
6
8
 
7
9
  import lief
8
10
 
@@ -217,24 +219,6 @@ def parse_strings(parsed_obj):
217
219
  return strings_list
218
220
 
219
221
 
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
222
  def parse_symbols(symbols):
239
223
  """
240
224
  Parse symbols from a list of symbols.
@@ -260,24 +244,23 @@ def parse_symbols(symbols):
260
244
  symbol_name = symbol.demangled_name
261
245
  if isinstance(symbol_name, lief.lief_errors):
262
246
  symbol_name = symbol.name
263
- if not ignorable_symbol(symbol_name):
264
- exe_type = guess_exe_type(symbol_name)
265
- symbols_list.append(
266
- {
267
- "name": symbol_name,
268
- "type": str(symbol.type).rsplit(".", maxsplit=1)[-1],
269
- "value": symbol.value,
270
- "visibility": str(symbol.visibility).rsplit(".", maxsplit=1)[-1],
271
- "binding": str(symbol.binding).rsplit(".", maxsplit=1)[-1],
272
- "is_imported": is_imported,
273
- "is_exported": is_exported,
274
- "information": symbol.information,
275
- "is_function": symbol.is_function,
276
- "is_static": symbol.is_static,
277
- "is_variable": symbol.is_variable,
278
- "version": str(symbol_version),
279
- }
280
- )
247
+ exe_type = guess_exe_type(symbol_name)
248
+ symbols_list.append(
249
+ {
250
+ "name": symbol_name,
251
+ "type": str(symbol.type).rsplit(".", maxsplit=1)[-1],
252
+ "value": symbol.value,
253
+ "visibility": str(symbol.visibility).rsplit(".", maxsplit=1)[-1],
254
+ "binding": str(symbol.binding).rsplit(".", maxsplit=1)[-1],
255
+ "is_imported": is_imported,
256
+ "is_exported": is_exported,
257
+ "information": symbol.information,
258
+ "is_function": symbol.is_function,
259
+ "is_static": symbol.is_static,
260
+ "is_variable": symbol.is_variable,
261
+ "version": str(symbol_version),
262
+ }
263
+ )
281
264
  except (AttributeError, IndexError, TypeError):
282
265
  continue
283
266
  return symbols_list, exe_type
@@ -656,19 +639,18 @@ def parse_macho_symbols(symbols):
656
639
  if not symbol_name or isinstance(symbol_name, lief.lief_errors):
657
640
  symbol_name = symbol.name
658
641
  symbol_name = symbol_name.replace("..", "::")
659
- if not ignorable_symbol(symbol_name):
660
- if not exe_type:
661
- exe_type = guess_exe_type(symbol_name)
662
- symbols_list.append(
663
- {
664
- "name": (f"{libname}::{symbol_name}" if libname else symbol_name),
665
- "short_name": symbol_name,
666
- "type": symbol.type,
667
- "num_sections": symbol.numberof_sections,
668
- "description": symbol.description,
669
- "value": symbol_value,
670
- }
671
- )
642
+ if not exe_type:
643
+ exe_type = guess_exe_type(symbol_name)
644
+ symbols_list.append(
645
+ {
646
+ "name": (f"{libname}::{symbol_name}" if libname else symbol_name),
647
+ "short_name": symbol_name,
648
+ "type": symbol.type,
649
+ "num_sections": symbol.numberof_sections,
650
+ "description": symbol.description,
651
+ "value": symbol_value,
652
+ }
653
+ )
672
654
  except (AttributeError, TypeError):
673
655
  continue
674
656
  return symbols_list, exe_type
@@ -761,6 +743,7 @@ def add_elf_metadata(exe_file, metadata, parsed_obj):
761
743
  metadata["ctor_functions"] = parse_functions(parsed_obj.ctor_functions)
762
744
  metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
763
745
  metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
746
+ metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
764
747
 
765
748
  return metadata
766
749
 
@@ -930,7 +913,7 @@ def parse_overlay(parsed_obj: lief.Binary) -> dict[str, dict]:
930
913
  return deps
931
914
 
932
915
 
933
- def parse_go_buildinfo(parsed_obj: lief.Binary) -> (dict[str, dict[str, str]], dict[str, str]):
916
+ def parse_go_buildinfo(parsed_obj: lief.Binary) -> Tuple[dict[str, dict[str, str]], dict[str, str]]:
934
917
  """
935
918
  Parse the go build info section to extract go dependencies
936
919
  Args:
@@ -983,6 +966,32 @@ def parse_go_buildinfo(parsed_obj: lief.Binary) -> (dict[str, dict[str, str]], d
983
966
  return deps, formulation
984
967
 
985
968
 
969
+ def parse_rust_buildinfo(parsed_obj: lief.Binary) -> list:
970
+ """
971
+ Parse the rust build info section of binaries that are cargo-auditable to extract rust dependencies
972
+ Args:
973
+ parsed_obj (lief.Binary): The parsed object representing the binary.
974
+
975
+ Returns:
976
+ list: List representing the dependencies.
977
+ """
978
+ deps = []
979
+
980
+ try:
981
+ audit_data_section = next(filter(lambda section: section.name == ".dep-v0", parsed_obj.sections), None)
982
+ if audit_data_section is not None and audit_data_section.content:
983
+ json_string = zlib.decompress(audit_data_section.content)
984
+ audit_data = json.loads(json_string)
985
+
986
+ if audit_data and audit_data["packages"]:
987
+ packages = audit_data["packages"]
988
+ deps = [x for x in packages if 'root' not in x]
989
+ except json.JSONDecodeError:
990
+ pass
991
+
992
+ return deps
993
+
994
+
986
995
  def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
987
996
  """Adds PE metadata to the given metadata dictionary.
988
997
 
@@ -1035,6 +1044,7 @@ def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
1035
1044
  metadata["is_dotnet"] = True
1036
1045
  metadata["dotnet_dependencies"] = parse_overlay(parsed_obj)
1037
1046
  metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
1047
+ metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
1038
1048
  tls = parsed_obj.tls
1039
1049
  if tls and tls.sizeof_zero_fill:
1040
1050
  metadata["tls_address_index"] = tls.addressof_index
@@ -1196,6 +1206,7 @@ def add_mach0_metadata(exe_file, metadata, parsed_obj):
1196
1206
  metadata = add_mach0_functions(metadata, parsed_obj)
1197
1207
  metadata = add_mach0_signature(exe_file, metadata, parsed_obj)
1198
1208
  metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)
1209
+ metadata["rust_dependencies"] = parse_rust_buildinfo(parsed_obj)
1199
1210
  return metadata
1200
1211
 
1201
1212
 
@@ -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:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "blint"
3
- version = "2.1.2"
3
+ version = "2.1.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