feat(llvm): 加固 SD 签名与内购交易关键分支
This commit is contained in:
@@ -688,6 +688,9 @@
|
||||
{ "id": "swift_injection_det_ibr", "path_contains": "RDInjectionDetector.swift" },
|
||||
{ "id": "swift_jailbreak_det_ibr", "path_contains": "RDJailbreakDetector.swift" },
|
||||
{ "id": "swift_sd_signer_ibr", "path_contains": "RDSDAuthV32Signer.swift" },
|
||||
{ "id": "swift_sd_request_format_ibr", "path_contains": "RDRequestParamsFormat.swift" },
|
||||
{ "id": "swift_sd_private_key_manager_ibr", "path_contains": "RDSDPrivateKeyManager.swift" },
|
||||
{ "id": "swift_iap_transaction_gate_ibr", "path_contains": "RDIAPPurchaseManager.swift", "function_contains": "RDIAPTransactionGate" },
|
||||
{ "id": "swift_iap_handler_ibr", "path_contains": "RDIAPHandler.swift" },
|
||||
{ "id": "objc_iap_verify_handler_ibr", "path_contains": "STSIAPVerifyHandler.m" },
|
||||
{ "id": "objc_pay_ext_ibr", "path_contains": "STSBaseViewController+STSPayExtension.m" },
|
||||
@@ -696,6 +699,11 @@
|
||||
{ "id": "vendor_pdf_trial_ibr", "path_contains": "Vendor/RDPDFReaderView/Sources/RDPDFReaderTrial.swift" },
|
||||
{ "id": "vendor_epub_core_ibr", "path_contains": "Vendor/RDEpubReaderView/EPUBCore/" }
|
||||
],
|
||||
"required_indirect_branch_sources": [
|
||||
"RDRequestParamsFormat.swift",
|
||||
"RDSDPrivateKeyManager.swift",
|
||||
"RDIAPPurchaseManager.swift"
|
||||
],
|
||||
"string_encrypt_stack_targets": [
|
||||
{ "id": "c_rd_sd_keybox_sstr", "path_contains": "RDSDKeyBox.c" },
|
||||
{ "id": "c_rd_epub_keybox_sstr", "path_contains": "RDEpubKeyBox.c" },
|
||||
|
||||
@@ -177,9 +177,20 @@ int main(void) {
|
||||
exe1, dwarf1, audit_wrapper, require_topology=''
|
||||
)
|
||||
self.assertEqual(star_res['failed_count'], 0)
|
||||
ibr_res = verify_macho_indirect_branches.verify_binary_indirect_branches(exe1, dwarf1, audit_wrapper)
|
||||
ibr_res = verify_macho_indirect_branches.verify_binary_indirect_branches(
|
||||
exe1, dwarf1, audit_wrapper, required_sources=[src_c.name]
|
||||
)
|
||||
self.assertEqual(ibr_res['failed_count'], 0)
|
||||
self.assertGreaterEqual(ibr_res['verified_ibr_count'], 2)
|
||||
self.assertEqual(ibr_res['required_sources_verified'], {src_c.name: ibr_res['verified_ibr_count']})
|
||||
audit_with_unlinked = {'module_audits': [
|
||||
*audit_wrapper['module_audits'],
|
||||
{'source_path': 'required.c', 'indirect_branches_functions': ['unlinked_func']},
|
||||
]}
|
||||
with self.assertRaisesRegex(AssertionError, r'required\.c'):
|
||||
verify_macho_indirect_branches.verify_binary_indirect_branches(
|
||||
exe1, dwarf1, audit_with_unlinked, required_sources=['required.c']
|
||||
)
|
||||
nm_exe = subprocess.check_output(['xcrun', 'nm', str(exe1)], text=True)
|
||||
self.assertNotIn('dead_unused_helper', nm_exe)
|
||||
|
||||
|
||||
@@ -964,7 +964,8 @@ def build_ipa(scheme: str, output_dir: Path, seed: str, expected_binaries: int,
|
||||
)
|
||||
assert icall_gate['gate_passed'], f"IndirectCallGate failed: {icall_gate['violations']}"
|
||||
ibr_gate = verify_macho_indirect_branches.verify_binary_indirect_branches(
|
||||
main_bin, dwarf_bin, obf_audit
|
||||
main_bin, dwarf_bin, obf_audit,
|
||||
required_sources=policy.get('required_indirect_branch_sources') or (),
|
||||
)
|
||||
print(
|
||||
f"[IndirectBranchGate] verified={ibr_gate['verified_ibr_count']}/{ibr_gate['linked_checked_count']} "
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify that every indirect-branch obfuscated function emits ARM64 `br xN` instructions in Mach-O."""
|
||||
import argparse
|
||||
from collections import Counter
|
||||
from collections.abc import Iterable
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import json
|
||||
from pathlib import Path
|
||||
@@ -37,6 +39,7 @@ def verify_binary_indirect_branches(
|
||||
obf_audit: dict,
|
||||
*,
|
||||
fail_on_missing: bool = False,
|
||||
required_sources: Iterable[str] = (),
|
||||
) -> dict:
|
||||
"""Disassemble every audited IBR function in main_bin and require >=1 `br xN`."""
|
||||
ranges_map = parse_dwarf_text_ranges(dwarf_bin)
|
||||
@@ -86,7 +89,10 @@ def verify_binary_indirect_branches(
|
||||
**range_results[0],
|
||||
})
|
||||
|
||||
verified_per_source = Counter(item['source'] for item in verified)
|
||||
required_source_counts = {source: verified_per_source[source] for source in required_sources}
|
||||
summary = {
|
||||
'required_sources_verified': required_source_counts,
|
||||
'total_audited': len(verified) + len(failed) + (0 if fail_on_missing else len(dead_stripped)),
|
||||
'linked_checked_count': len(verified) + len(failed),
|
||||
'verified_ibr_count': len(verified),
|
||||
@@ -100,6 +106,9 @@ def verify_binary_indirect_branches(
|
||||
raise AssertionError(
|
||||
f'[IndirectBranchGate] {len(failed)} function(s) failed br xN check:\n{preview}'
|
||||
)
|
||||
missing_sources = [source for source, count in required_source_counts.items() if not count]
|
||||
if missing_sources:
|
||||
raise AssertionError('[IndirectBranchGate] 缺少已链接的间接分支保护: ' + ', '.join(missing_sources))
|
||||
return summary
|
||||
|
||||
|
||||
|
||||
@@ -375,6 +375,12 @@ def audit_ipa(
|
||||
raise ValueError(f'IPA 静态卫生门禁失败: {failed_keys}')
|
||||
|
||||
policy = _load_policy(policy_path)
|
||||
required_ibr_sources = policy.get('required_indirect_branch_sources') or ()
|
||||
if archive_path and required_ibr_sources and not skip_macho_gates:
|
||||
if not Path(archive_path).is_dir():
|
||||
raise ValueError(f'核心间接分支门禁缺少 xcarchive: {archive_path}')
|
||||
if not audit_json_path or not Path(audit_json_path).is_file():
|
||||
raise ValueError('核心间接分支门禁缺少本次构建的 LLVM 审计日志')
|
||||
obf_audit = None
|
||||
if audit_json_path and Path(audit_json_path).is_file():
|
||||
obf_audit = json.loads(Path(audit_json_path).read_text(encoding='utf-8'))
|
||||
@@ -415,7 +421,7 @@ def audit_ipa(
|
||||
raise ValueError('StarCFGGate verified_star_count 为 0')
|
||||
|
||||
ibr_gate = verify_macho_indirect_branches.verify_binary_indirect_branches(
|
||||
main_bin, dwarf_bin, obf_audit
|
||||
main_bin, dwarf_bin, obf_audit, required_sources=required_ibr_sources
|
||||
)
|
||||
report['indirect_branch_gate'] = ibr_gate
|
||||
if policy.get('indirect_branch_targets') and ibr_gate['verified_ibr_count'] <= 0:
|
||||
|
||||
Reference in New Issue
Block a user