blint 2.2.1__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.
- {blint-2.2.1 → blint-2.2.3}/PKG-INFO +1 -1
- {blint-2.2.1 → blint-2.2.3}/blint/analysis.py +76 -66
- {blint-2.2.1 → blint-2.2.3}/blint/binary.py +88 -57
- {blint-2.2.1 → blint-2.2.3}/blint/config.py +6 -2
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_exe_go.yml +47 -5
- {blint-2.2.1 → blint-2.2.3}/pyproject.toml +1 -1
- {blint-2.2.1 → blint-2.2.3}/LICENSE +0 -0
- {blint-2.2.1 → blint-2.2.3}/README.md +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/__init__.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/android.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/checks.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/cli.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/cyclonedx/README.md +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/cyclonedx/__init__.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/cyclonedx/spdx.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/cyclonedx/spec.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/__init__.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/__init__.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_entries_generic.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_entries_pe.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_imports_pe.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_methods_generic.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_methods_mips.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_monero_generic.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_monero_go.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_monero_rust.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_rootkits_win.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_symbols_generic.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_symbols_hooka.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_symbols_macho.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/annotations/review_symbols_rust.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/data/rules.yml +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/logger.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/sbom.py +0 -0
- {blint-2.2.1 → blint-2.2.3}/blint/utils.py +0 -0
|
@@ -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 (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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(
|
|
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(
|
|
350
|
-
|
|
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(
|
|
358
|
-
|
|
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(
|
|
365
|
-
|
|
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,
|
|
389
|
-
|
|
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),
|
|
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 =
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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 = [
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
|
|
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 = [
|
|
620
|
-
|
|
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 = {
|
|
662
|
-
|
|
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(
|
|
699
|
-
|
|
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
|
|
@@ -11,7 +11,13 @@ import lief
|
|
|
11
11
|
|
|
12
12
|
from blint.config import FIRST_STAGE_WORDS, PII_WORDS, get_float_from_env, get_int_from_env
|
|
13
13
|
from blint.logger import DEBUG, LOG
|
|
14
|
-
from blint.utils import
|
|
14
|
+
from blint.utils import (
|
|
15
|
+
camel_to_snake,
|
|
16
|
+
calculate_entropy,
|
|
17
|
+
check_secret,
|
|
18
|
+
cleanup_dict_lief_errors,
|
|
19
|
+
decode_base64,
|
|
20
|
+
)
|
|
15
21
|
|
|
16
22
|
SYMBOLIC_FOUND = True
|
|
17
23
|
try:
|
|
@@ -453,7 +459,11 @@ def process_pe_resources(parsed_obj):
|
|
|
453
459
|
"has_manifest": rm.has_manifest,
|
|
454
460
|
"has_string_table": rm.has_string_table,
|
|
455
461
|
"has_version": rm.has_version,
|
|
456
|
-
"manifest": (
|
|
462
|
+
"manifest": (
|
|
463
|
+
rm.manifest.replace("\\xef\\xbb\\xbf", "").removeprefix("\ufeff")
|
|
464
|
+
if rm.has_manifest
|
|
465
|
+
else None
|
|
466
|
+
),
|
|
457
467
|
"version_info": str(rm.version) if rm.has_version else None,
|
|
458
468
|
"html": rm.html if rm.has_html else None,
|
|
459
469
|
}
|
|
@@ -495,7 +505,9 @@ def process_pe_signature(parsed_obj):
|
|
|
495
505
|
"serial_number": signer.serial_number.hex(),
|
|
496
506
|
"issuer": str(signer.issuer),
|
|
497
507
|
"digest_algorithm": str(signer.digest_algorithm).rsplit(".", maxsplit=1)[-1],
|
|
498
|
-
"encryption_algorithm": str(signer.encryption_algorithm).rsplit(
|
|
508
|
+
"encryption_algorithm": str(signer.encryption_algorithm).rsplit(
|
|
509
|
+
".", maxsplit=1
|
|
510
|
+
)[-1],
|
|
499
511
|
"encrypted_digest": signer.encrypted_digest.hex(),
|
|
500
512
|
}
|
|
501
513
|
signers_list.append(signer_obj)
|
|
@@ -535,7 +547,10 @@ def parse_pe_authenticode(parsed_obj):
|
|
|
535
547
|
if "version" in tmp_key:
|
|
536
548
|
tmp_key = "version"
|
|
537
549
|
value = tmp_a[1].strip()
|
|
538
|
-
if value
|
|
550
|
+
if value in (
|
|
551
|
+
"???",
|
|
552
|
+
"???, ???",
|
|
553
|
+
):
|
|
539
554
|
value = "N/A"
|
|
540
555
|
cert_signer_obj[tmp_key] = value
|
|
541
556
|
authenticode["cert_signer"] = cert_signer_obj
|
|
@@ -798,8 +813,7 @@ def add_elf_metadata(exe_file, metadata, parsed_obj):
|
|
|
798
813
|
metadata["symtab_symbols"], exe_type = parse_symbols(symtab_symbols)
|
|
799
814
|
rdata_section = parsed_obj.get_section(".rodata")
|
|
800
815
|
text_section = parsed_obj.get_section(".text")
|
|
801
|
-
|
|
802
|
-
add_elf_rdata_symbols(metadata, rdata_section, text_section)
|
|
816
|
+
add_rdata_symbols(metadata, rdata_section, text_section, parsed_obj.sections)
|
|
803
817
|
if exe_type:
|
|
804
818
|
metadata["exe_type"] = exe_type
|
|
805
819
|
metadata["dynamic_symbols"], exe_type = parse_symbols(parsed_obj.dynamic_symbols)
|
|
@@ -898,8 +912,6 @@ def add_elf_dynamic_entries(dynamic_entries, metadata):
|
|
|
898
912
|
if entry.tag in [
|
|
899
913
|
lief.ELF.DynamicEntry.TAG.SONAME,
|
|
900
914
|
lief.ELF.DynamicEntry.TAG.NEEDED,
|
|
901
|
-
lief.ELF.DynamicEntry.TAG.RUNPATH,
|
|
902
|
-
lief.ELF.DynamicEntry.TAG.RPATH,
|
|
903
915
|
]:
|
|
904
916
|
metadata["dynamic_entries"].append(
|
|
905
917
|
{
|
|
@@ -908,9 +920,28 @@ def add_elf_dynamic_entries(dynamic_entries, metadata):
|
|
|
908
920
|
"value": entry.value,
|
|
909
921
|
}
|
|
910
922
|
)
|
|
911
|
-
# Detect dotnet binary
|
|
912
923
|
if "netcoredeps" in entry.name:
|
|
913
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
|
+
)
|
|
914
945
|
return metadata
|
|
915
946
|
|
|
916
947
|
|
|
@@ -1126,7 +1157,7 @@ def add_pe_metadata(exe_file: str, metadata: dict, parsed_obj: lief.PE.Binary):
|
|
|
1126
1157
|
else:
|
|
1127
1158
|
text_section = section
|
|
1128
1159
|
if rdata_section or text_section:
|
|
1129
|
-
|
|
1160
|
+
add_rdata_symbols(metadata, rdata_section, text_section, parsed_obj.sections)
|
|
1130
1161
|
metadata["exports"] = parse_pe_exports(parsed_obj.get_export())
|
|
1131
1162
|
metadata["functions"] = parse_functions(parsed_obj.functions)
|
|
1132
1163
|
metadata["ctor_functions"] = parse_functions(parsed_obj.ctor_functions)
|
|
@@ -1180,13 +1211,13 @@ def add_pe_header_data(metadata, parsed_obj):
|
|
|
1180
1211
|
metadata["initial_relative_cs"] = dos_header.initial_relative_cs
|
|
1181
1212
|
metadata["address_relocation_table"] = ADDRESS_FMT.format(
|
|
1182
1213
|
dos_header.addressof_relocation_table
|
|
1183
|
-
)
|
|
1214
|
+
).strip()
|
|
1184
1215
|
metadata["overlay_number"] = dos_header.overlay_number
|
|
1185
1216
|
metadata["oem_id"] = dos_header.oem_id
|
|
1186
1217
|
metadata["oem_info"] = dos_header.oem_info
|
|
1187
1218
|
metadata["address_new_exeheader"] = ADDRESS_FMT.format(
|
|
1188
1219
|
dos_header.addressof_new_exeheader
|
|
1189
|
-
)
|
|
1220
|
+
).strip()
|
|
1190
1221
|
metadata["characteristics"] = ", ".join(
|
|
1191
1222
|
[str(chara).rsplit(".", maxsplit=1)[-1] for chara in header.characteristics_list]
|
|
1192
1223
|
)
|
|
@@ -1231,7 +1262,9 @@ def add_pe_optional_headers(metadata, optional_header):
|
|
|
1231
1262
|
metadata["sizeof_code"] = optional_header.sizeof_code
|
|
1232
1263
|
metadata["sizeof_initialized_data"] = optional_header.sizeof_initialized_data
|
|
1233
1264
|
metadata["sizeof_uninitialized_data"] = optional_header.sizeof_uninitialized_data
|
|
1234
|
-
metadata["addressof_entrypoint"] = ADDRESS_FMT.format(
|
|
1265
|
+
metadata["addressof_entrypoint"] = ADDRESS_FMT.format(
|
|
1266
|
+
optional_header.addressof_entrypoint
|
|
1267
|
+
).strip()
|
|
1235
1268
|
metadata["baseof_code"] = optional_header.baseof_code
|
|
1236
1269
|
metadata["baseof_data"] = optional_header.baseof_data
|
|
1237
1270
|
metadata["imagebase"] = optional_header.imagebase
|
|
@@ -1256,13 +1289,14 @@ def add_pe_optional_headers(metadata, optional_header):
|
|
|
1256
1289
|
return metadata
|
|
1257
1290
|
|
|
1258
1291
|
|
|
1259
|
-
def
|
|
1260
|
-
"""Adds
|
|
1292
|
+
def add_rdata_symbols(metadata, rdata_section, text_section, sections):
|
|
1293
|
+
"""Adds rdata symbols to the metadata dictionary.
|
|
1261
1294
|
|
|
1262
1295
|
Args:
|
|
1263
1296
|
metadata: The dictionary to store the metadata.
|
|
1264
|
-
rdata_section: .rdata section of the
|
|
1265
|
-
text_section: .text section of the
|
|
1297
|
+
rdata_section: .rdata section of the binary.
|
|
1298
|
+
text_section: .text section of the binary.
|
|
1299
|
+
sections: All sections for advanced analysis
|
|
1266
1300
|
|
|
1267
1301
|
Returns:
|
|
1268
1302
|
The updated metadata dictionary.
|
|
@@ -1273,32 +1307,50 @@ def add_pe_rdata_symbols(metadata, rdata_section: lief.PE.Section, text_section:
|
|
|
1273
1307
|
first_stage_symbols = []
|
|
1274
1308
|
for pii in PII_WORDS:
|
|
1275
1309
|
for vari in (f"get{pii}", f"get_{pii}", f"get_{camel_to_snake(pii)}", f"Get{pii}"):
|
|
1276
|
-
if (rdata_section and rdata_section.search_all(vari)) or (
|
|
1310
|
+
if (rdata_section and rdata_section.search_all(vari)) or (
|
|
1311
|
+
text_section and text_section.search_all(vari)
|
|
1312
|
+
):
|
|
1277
1313
|
pii_symbols.append(
|
|
1278
|
-
{
|
|
1314
|
+
{
|
|
1315
|
+
"name": vari.lower(),
|
|
1316
|
+
"type": "FUNCTION",
|
|
1317
|
+
"is_function": True,
|
|
1318
|
+
"is_imported": False,
|
|
1319
|
+
}
|
|
1320
|
+
)
|
|
1279
1321
|
continue
|
|
1280
1322
|
for sw in FIRST_STAGE_WORDS:
|
|
1281
|
-
if (rdata_section and rdata_section.search_all(sw)) or (
|
|
1323
|
+
if (rdata_section and rdata_section.search_all(sw)) or (
|
|
1324
|
+
text_section and text_section.search_all(sw)
|
|
1325
|
+
):
|
|
1282
1326
|
first_stage_symbols.append(
|
|
1283
|
-
{"name": sw, "type": "FUNCTION", "is_function": True, "is_imported": True}
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1327
|
+
{"name": sw, "type": "FUNCTION", "is_function": True, "is_imported": True}
|
|
1328
|
+
)
|
|
1329
|
+
# rdata and rodata can be technically anywhere
|
|
1330
|
+
# go binaries could have them under .gopclntab and .gosymtab for example
|
|
1331
|
+
# We attempt to search for symbols in every section.
|
|
1332
|
+
data_sections = []
|
|
1333
|
+
for section in sections:
|
|
1334
|
+
if str(section.name).removeprefix(".").isalnum():
|
|
1335
|
+
data_sections.append(section)
|
|
1336
|
+
for section in data_sections:
|
|
1337
|
+
str_content = (
|
|
1338
|
+
codecs.decode(section.content.tobytes("A"), encoding="utf-8", errors="ignore")
|
|
1339
|
+
if section and section.content
|
|
1340
|
+
else ""
|
|
1341
|
+
)
|
|
1342
|
+
for block in str_content.split(" "):
|
|
1343
|
+
if "runtime." in block or "internal/" in block or re.match(file_extns_from_rdata, block):
|
|
1344
|
+
if ".go" in block:
|
|
1345
|
+
metadata["exe_type"] = "gobinary"
|
|
1346
|
+
for asym in block.split("\x00"):
|
|
1347
|
+
if re.match(file_extns_from_rdata + "$", asym):
|
|
1348
|
+
rdata_symbols.add(asym)
|
|
1293
1349
|
if not metadata["symtab_symbols"]:
|
|
1294
1350
|
metadata["symtab_symbols"] = []
|
|
1295
1351
|
metadata["symtab_symbols"] += [
|
|
1296
|
-
{
|
|
1297
|
-
|
|
1298
|
-
"type": "FILE",
|
|
1299
|
-
"is_function": False,
|
|
1300
|
-
"is_imported": True
|
|
1301
|
-
} for s in sorted(rdata_symbols)
|
|
1352
|
+
{"name": s, "type": "FILE", "is_function": False, "is_imported": True}
|
|
1353
|
+
for s in sorted(rdata_symbols)
|
|
1302
1354
|
]
|
|
1303
1355
|
if pii_symbols:
|
|
1304
1356
|
metadata["pii_symbols"] = pii_symbols
|
|
@@ -1307,27 +1359,6 @@ def add_pe_rdata_symbols(metadata, rdata_section: lief.PE.Section, text_section:
|
|
|
1307
1359
|
return metadata
|
|
1308
1360
|
|
|
1309
1361
|
|
|
1310
|
-
def add_elf_rdata_symbols(metadata, rdata_section: lief.PE.Section, text_section: lief.PE.Section):
|
|
1311
|
-
"""Adds ELF rdata symbols to the metadata dictionary.
|
|
1312
|
-
|
|
1313
|
-
Args:
|
|
1314
|
-
metadata: The dictionary to store the metadata.
|
|
1315
|
-
rdata_section: .data section of the ELF binary.
|
|
1316
|
-
text_section: .text section of the ELF binary.
|
|
1317
|
-
|
|
1318
|
-
Returns:
|
|
1319
|
-
The updated metadata dictionary.
|
|
1320
|
-
"""
|
|
1321
|
-
first_stage_symbols = []
|
|
1322
|
-
for sw in FIRST_STAGE_WORDS:
|
|
1323
|
-
if (rdata_section and rdata_section.search_all(sw)) or (text_section and text_section.search_all(sw)):
|
|
1324
|
-
first_stage_symbols.append(
|
|
1325
|
-
{"name": sw, "type": "FUNCTION", "is_function": True, "is_imported": True})
|
|
1326
|
-
if first_stage_symbols:
|
|
1327
|
-
metadata["first_stage_symbols"] = first_stage_symbols
|
|
1328
|
-
return metadata
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
1362
|
def add_mach0_metadata(exe_file, metadata, parsed_obj):
|
|
1332
1363
|
"""Adds MachO metadata to the given metadata dictionary.
|
|
1333
1364
|
|
|
@@ -1279,7 +1279,8 @@ PII_WORDS = (
|
|
|
1279
1279
|
"Gender",
|
|
1280
1280
|
"Country",
|
|
1281
1281
|
"Email",
|
|
1282
|
-
"
|
|
1282
|
+
"Town",
|
|
1283
|
+
"County",
|
|
1283
1284
|
"PostCode",
|
|
1284
1285
|
"ZipCode",
|
|
1285
1286
|
"SSN",
|
|
@@ -1292,7 +1293,8 @@ PII_WORDS = (
|
|
|
1292
1293
|
"OTP",
|
|
1293
1294
|
"Calendar",
|
|
1294
1295
|
"AgentStatus",
|
|
1295
|
-
"LastLoginTime"
|
|
1296
|
+
"LastLoginTime",
|
|
1297
|
+
"BankAccount"
|
|
1296
1298
|
)
|
|
1297
1299
|
|
|
1298
1300
|
# Some symbols to look for in a first-stage payload
|
|
@@ -1324,6 +1326,8 @@ FIRST_STAGE_WORDS = (
|
|
|
1324
1326
|
"/usr/bin/poweroff",
|
|
1325
1327
|
"/usr/sbin/halt",
|
|
1326
1328
|
"/usr/bin/halt",
|
|
1329
|
+
"/proc/self/auxv",
|
|
1330
|
+
"/sys/kernel/mm/",
|
|
1327
1331
|
"virtualboxemulunit",
|
|
1328
1332
|
"virtualboximportunit",
|
|
1329
1333
|
"virtualboxunit",
|
|
@@ -54,6 +54,7 @@ rules:
|
|
|
54
54
|
- os.CreateTemp
|
|
55
55
|
- os.NewFile
|
|
56
56
|
- os.DirFS
|
|
57
|
+
- golang/src/os/file
|
|
57
58
|
- id: OS_METHODS
|
|
58
59
|
title: OS functions used
|
|
59
60
|
summary: Can Execute OS commands
|
|
@@ -90,6 +91,10 @@ rules:
|
|
|
90
91
|
- os/executable.go
|
|
91
92
|
- os/executable_windows.go
|
|
92
93
|
- os/proc.go
|
|
94
|
+
- golang/src/io/pipe.go
|
|
95
|
+
- golang/src/runtime/cgo
|
|
96
|
+
- golang/src/runtime/fds_unix.go
|
|
97
|
+
- golang/src/runtime/internal/syscall/
|
|
93
98
|
- id: SYSCALL_METHODS
|
|
94
99
|
title: Syscall functions used
|
|
95
100
|
summary: Can perform system-level operations
|
|
@@ -154,6 +159,7 @@ rules:
|
|
|
154
159
|
- syscall/syscall.go
|
|
155
160
|
- syscall/syscall_windows.go
|
|
156
161
|
- syscall/zsyscall_windows.go
|
|
162
|
+
- runtime/mem.go
|
|
157
163
|
- id: WIN_SIGNAL_METHODS
|
|
158
164
|
title: Windows Signal functions used
|
|
159
165
|
summary: Can disable Windows Error Reporting
|
|
@@ -166,6 +172,15 @@ rules:
|
|
|
166
172
|
- runtime/sys_windows_amd64.s
|
|
167
173
|
- runtime/sys_x86.go
|
|
168
174
|
- runtime/syscall_windows.go
|
|
175
|
+
- id: OS_SIGNAL_METHODS
|
|
176
|
+
title: OS Signal module used
|
|
177
|
+
summary: Can trap OS signals
|
|
178
|
+
description: |
|
|
179
|
+
Package signal implements access to incoming signals. The functions in this package allow a program to change the way Go programs handle signals.
|
|
180
|
+
patterns:
|
|
181
|
+
- runtime/signal_amd64.go
|
|
182
|
+
- runtime/signal_linux_amd64.go
|
|
183
|
+
- runtime/signal_unix.go
|
|
169
184
|
- id: NET_METHODS
|
|
170
185
|
title: Net functions used
|
|
171
186
|
summary: Uses Network to send and receive data
|
|
@@ -231,6 +246,7 @@ rules:
|
|
|
231
246
|
- net/net.go
|
|
232
247
|
- net/netip/leaf_alts.go
|
|
233
248
|
- net/netip/netip.go
|
|
249
|
+
- golang/src/net/
|
|
234
250
|
- id: HTTP_METHODS
|
|
235
251
|
title: HTTP server functions used
|
|
236
252
|
summary: Can run an HTTP server
|
|
@@ -267,13 +283,15 @@ rules:
|
|
|
267
283
|
- github.com/gorilla/websocket
|
|
268
284
|
- github.com/gorilla/mux
|
|
269
285
|
- id: MEM_METHODS
|
|
270
|
-
title:
|
|
271
|
-
summary:
|
|
286
|
+
title: Memory module used
|
|
287
|
+
summary: Manipulates System Memory
|
|
272
288
|
description: |
|
|
273
|
-
|
|
289
|
+
Memory module used.
|
|
274
290
|
patterns:
|
|
275
|
-
-
|
|
276
|
-
|
|
291
|
+
- runtime/mem.go
|
|
292
|
+
- runtime/mem_linux.go
|
|
293
|
+
- runtime/memclr_amd64.s
|
|
294
|
+
- runtime/mcheckmark.go
|
|
277
295
|
- id: HTTP_CLIENT_METHODS
|
|
278
296
|
title: HTTP client functions used
|
|
279
297
|
summary: Invokes HTTP service
|
|
@@ -361,6 +379,7 @@ rules:
|
|
|
361
379
|
- zip.CreateRaw
|
|
362
380
|
- archive/tar
|
|
363
381
|
- github.com/ulikunitz/xz
|
|
382
|
+
- golang/src/compress
|
|
364
383
|
- id: GIT_METHODS
|
|
365
384
|
title: Git library used
|
|
366
385
|
summary: Can perform Git Read and Write operations
|
|
@@ -402,6 +421,8 @@ rules:
|
|
|
402
421
|
- crypto/crypto.go
|
|
403
422
|
- crypto/subtle/xor.go
|
|
404
423
|
- crypto/subtle/xor_amd64.s
|
|
424
|
+
- golang.org/x/crypto
|
|
425
|
+
- golang/src/crypto
|
|
405
426
|
- id: SSH_METHODS
|
|
406
427
|
title: ssh library used
|
|
407
428
|
summary: Can perform SSH operations
|
|
@@ -513,3 +534,24 @@ rules:
|
|
|
513
534
|
- x509.internal.macos.SecPolicyCopyProperties
|
|
514
535
|
- x509.internal.macos.SecTrustSettingsCopyCertificates
|
|
515
536
|
- x509.internal.macos.SecTrustSettingsCopyTrustSettings
|
|
537
|
+
- id: MASSCAN_MODULE
|
|
538
|
+
title: Detect Masscan module
|
|
539
|
+
summary: Can Perform port scans
|
|
540
|
+
description: |
|
|
541
|
+
Masscan is an Internet-scale port scanner. It can scan the entire Internet in under 5 minutes, transmitting 10 million packets per second, from a single machine.
|
|
542
|
+
patterns:
|
|
543
|
+
- massTool/mass.go
|
|
544
|
+
- masscan.go
|
|
545
|
+
- masscan.NewScanner
|
|
546
|
+
- masscan.SetParamTargets
|
|
547
|
+
- masscan.SetParamPorts
|
|
548
|
+
- masscan.SetParamWait
|
|
549
|
+
- masscan.Run
|
|
550
|
+
- id: FTP_MODULE
|
|
551
|
+
title: Detect FTP module
|
|
552
|
+
summary: Can Perform FTP operations
|
|
553
|
+
description: |
|
|
554
|
+
Known FTP modules are used.
|
|
555
|
+
patterns:
|
|
556
|
+
- ftp.go
|
|
557
|
+
- github.com/jlaffaye/ftp
|
|
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
|
|
File without changes
|
|
File without changes
|