blint 2.0.1__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.
Files changed (38) hide show
  1. blint-2.0.3/LICENSE +21 -0
  2. {blint-2.0.1 → blint-2.0.3}/PKG-INFO +9 -3
  3. {blint-2.0.1 → blint-2.0.3}/README.md +6 -0
  4. {blint-2.0.1 → blint-2.0.3}/blint/analysis.py +18 -9
  5. {blint-2.0.1 → blint-2.0.3}/blint/android.py +10 -1
  6. {blint-2.0.1 → blint-2.0.3}/blint/binary.py +69 -3
  7. {blint-2.0.1 → blint-2.0.3}/blint/cli.py +10 -5
  8. {blint-2.0.1 → blint-2.0.3}/blint/sbom.py +112 -27
  9. {blint-2.0.1 → blint-2.0.3}/blint/utils.py +6 -1
  10. {blint-2.0.1 → blint-2.0.3}/pyproject.toml +2 -2
  11. blint-2.0.1/LICENSE +0 -201
  12. {blint-2.0.1 → blint-2.0.3}/blint/__init__.py +0 -0
  13. {blint-2.0.1 → blint-2.0.3}/blint/checks.py +0 -0
  14. {blint-2.0.1 → blint-2.0.3}/blint/config.py +0 -0
  15. {blint-2.0.1 → blint-2.0.3}/blint/cyclonedx/README.md +0 -0
  16. {blint-2.0.1 → blint-2.0.3}/blint/cyclonedx/__init__.py +0 -0
  17. {blint-2.0.1 → blint-2.0.3}/blint/cyclonedx/spdx.py +0 -0
  18. {blint-2.0.1 → blint-2.0.3}/blint/cyclonedx/spec.py +0 -0
  19. {blint-2.0.1 → blint-2.0.3}/blint/data/__init__.py +0 -0
  20. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/__init__.py +0 -0
  21. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_entries_generic.yml +0 -0
  22. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_entries_pe.yml +0 -0
  23. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_exe_go.yml +0 -0
  24. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_imports_pe.yml +0 -0
  25. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_methods_generic.yml +0 -0
  26. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_methods_mips.yml +0 -0
  27. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_monero_generic.yml +0 -0
  28. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_monero_go.yml +0 -0
  29. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_monero_rust +0 -0
  30. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_monero_rust.yml +0 -0
  31. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_rootkits_win.yml +0 -0
  32. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
  33. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_symbols_generic.yml +0 -0
  34. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_symbols_hooka.yml +0 -0
  35. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_symbols_macho.yml +0 -0
  36. {blint-2.0.1 → blint-2.0.3}/blint/data/annotations/review_symbols_rust.yml +0 -0
  37. {blint-2.0.1 → blint-2.0.3}/blint/data/rules.yml +0 -0
  38. {blint-2.0.1 → blint-2.0.3}/blint/logger.py +0 -0
blint-2.0.3/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) OWASP Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blint
3
- Version: 2.0.1
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
- License: Apache-2.0
6
+ License: MIT
7
7
  Keywords: linter,binary,security,sast
8
8
  Author: Prabhu Subramanian
9
9
  Author-email: prabhu@appthreat.com
@@ -11,7 +11,7 @@ Requires-Python: >=3.10,<3.13
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Intended Audience :: System Administrators
14
- Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: License :: OSI Approved :: MIT License
15
15
  Classifier: Operating System :: OS Independent
16
16
  Classifier: Programming Language :: Python :: 3
17
17
  Classifier: Programming Language :: Python :: 3.10
@@ -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, indent=True
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, indent=True)
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, indent=True
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
- html_file = Path(reports_dir) / "blint-output.html"
347
- console.save_html(html_file, theme=MONOKAI)
348
- LOG.info(f"HTML report written to {html_file}")
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, indent=True)
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")
@@ -143,6 +143,11 @@ def collect_version_files_metadata(app_file, app_temp_dir):
143
143
  group, name = parse_file_name(file_name, group)
144
144
  with open(vf, encoding="utf-8") as fp:
145
145
  version_data = fp.read().strip()
146
+ # Sometimes the version data could be dynamic. Eg:
147
+ # task ':lifecycle:lifecycle-viewmodel:writeVersionFile' property 'version'"
148
+ # These can be treated as dynamic
149
+ if version_data and version_data.startswith("task"):
150
+ version_data = "dynamic"
146
151
  if name and version_data:
147
152
  component = create_version_component(app_file, group, name, rel_path, version_data)
148
153
  file_components.append(component)
@@ -167,6 +172,10 @@ def create_version_component(app_file, group, name, rel_path, version_data):
167
172
  purl = f"pkg:maven/{group}/{name}@{version_data}"
168
173
  else:
169
174
  purl = f"pkg:maven/{name}@{version_data}"
175
+ confidence = 1.0
176
+ # Adjust the confidence based on the version data
177
+ if version_data in ("latest", "dynamic"):
178
+ confidence = 0.2
170
179
  component = Component(
171
180
  type=Type.library,
172
181
  group=group,
@@ -174,7 +183,7 @@ def create_version_component(app_file, group, name, rel_path, version_data):
174
183
  version=version_data,
175
184
  purl=purl,
176
185
  scope=Scope.required,
177
- evidence=create_component_evidence(rel_path, 1.0),
186
+ evidence=create_component_evidence(rel_path, confidence),
178
187
  properties=[
179
188
  Property(name="internal:srcFile", value=rel_path),
180
189
  Property(name="internal:appFile", value=app_file),
@@ -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 add_pe_metadata(exe_file, metadata, parsed_obj):
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
- path = src[0]
123
- result = path.split("\n")
124
- result.pop()
125
- return result
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:
@@ -57,7 +60,7 @@ def default_metadata(src_dirs):
57
60
  metadata = Metadata()
58
61
  metadata.timestamp = datetime.now()
59
62
  metadata.component = default_parent(src_dirs)
60
- metadata.tools = [
63
+ metadata.tools = (
61
64
  Tools(
62
65
  components=[
63
66
  Component(
@@ -71,7 +74,7 @@ def default_metadata(src_dirs):
71
74
  )
72
75
  ]
73
76
  )
74
- ]
77
+ )
75
78
  metadata.lifecycles = [Lifecycles(phase=Phase.post_build)]
76
79
  return metadata
77
80
 
@@ -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,37 +294,57 @@ 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
294
307
  # If this is unsuccessful then store the information as a property
295
308
  lib_components += components_from_symbols_version(symbols_version)
296
- if not lib_components:
309
+ if not lib_components and symbols_version:
297
310
  parent_component.properties += [
298
311
  Property(
299
312
  name="internal:symbols_version",
300
313
  value=", ".join([f["name"] for f in symbols_version]),
301
314
  )
302
315
  ]
303
- parent_component.properties += [
304
- Property(
305
- name="internal:functions",
306
- value=SYMBOL_DELIMITER.join(
307
- [f["name"] for f in metadata.get("functions", []) if not f["name"].startswith("__")]),
308
- ),
309
- Property(
310
- name="internal:symtab_symbols",
311
- value=SYMBOL_DELIMITER.join([f["name"] for f in metadata.get("symtab_symbols", [])]),
312
- ),
313
- Property(
314
- name="internal:imports",
315
- value=SYMBOL_DELIMITER.join([f["name"] for f in metadata.get("imports", [])]),
316
- ),
317
- Property(
318
- name="internal:dynamic_symbols",
319
- value=SYMBOL_DELIMITER.join([f["name"] for f in metadata.get("dynamic_symbols", [])]),
320
- ),
321
- ]
316
+ internal_functions = [f["name"] for f in metadata.get("functions", []) if not f["name"].startswith("__")]
317
+ if internal_functions:
318
+ parent_component.properties += [
319
+ Property(
320
+ name="internal:functions",
321
+ value=SYMBOL_DELIMITER.join(internal_functions),
322
+ )
323
+ ]
324
+ symtab_symbols = [f["name"] for f in metadata.get("symtab_symbols", [])]
325
+ if symtab_symbols:
326
+ parent_component.properties += [
327
+ Property(
328
+ name="internal:symtab_symbols",
329
+ value=SYMBOL_DELIMITER.join(symtab_symbols),
330
+ )
331
+ ]
332
+ all_imports = [f["name"] for f in metadata.get("imports", [])]
333
+ if all_imports:
334
+ parent_component.properties += [
335
+ Property(
336
+ name="internal:imports",
337
+ value=SYMBOL_DELIMITER.join(all_imports),
338
+ )
339
+ ]
340
+ dynamic_symbols = [f["name"] for f in metadata.get("dynamic_symbols", [])]
341
+ if dynamic_symbols:
342
+ parent_component.properties += [
343
+ Property(
344
+ name="internal:dynamic_symbols",
345
+ value=SYMBOL_DELIMITER.join(dynamic_symbols),
346
+ )
347
+ ]
322
348
  if not sbom.metadata.component.components:
323
349
  sbom.metadata.component.components = []
324
350
  sbom.metadata.component.components.append(parent_component)
@@ -330,6 +356,10 @@ def process_exe_file(
330
356
  for entry in metadata["dynamic_entries"]:
331
357
  comp = create_dynamic_component(entry, exe)
332
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
333
363
  if lib_components:
334
364
  components += lib_components
335
365
  track_dependency(dependencies_dict, parent_component, lib_components)
@@ -381,10 +411,11 @@ def create_dynamic_component(entry: Dict, exe: str) -> Component:
381
411
  Returns:
382
412
  Component: The created dynamic component object.
383
413
  """
384
- purl = f"pkg:file/{entry['name']}"
414
+ name = entry.get("name", "").removeprefix("$ORIGIN/")
415
+ purl = f"pkg:file/{name}"
385
416
  comp = Component(
386
417
  type=Type.library,
387
- name=entry["name"],
418
+ name=name,
388
419
  purl=purl,
389
420
  evidence=create_component_evidence(exe, 0.5),
390
421
  properties=[
@@ -428,6 +459,60 @@ def process_android_file(
428
459
  return components
429
460
 
430
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
+
431
516
  def track_dependency(
432
517
  dependencies_dict: dict, parent_component: Component, app_components: list[Component]
433
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()
@@ -1,9 +1,9 @@
1
1
  [tool.poetry]
2
2
  name = "blint"
3
- version = "2.0.1"
3
+ version = "2.0.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
- license = "Apache-2.0"
6
+ license = "MIT"
7
7
  readme = "README.md"
8
8
  homepage = "https://github.com/OWASP-dep-scan/blint"
9
9
  repository = "https://github.com/OWASP-dep-scan/blint"
blint-2.0.1/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "{}"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright {yyyy} {name of copyright owner}
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
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