amfi_detect.py: Use enum

This commit is contained in:
Mykola Grymalyuk
2023-02-09 18:09:02 -07:00
parent e83e260db7
commit c5eb52ac5e
2 changed files with 33 additions and 32 deletions
+12 -11
View File
@@ -6,19 +6,20 @@
# - 0x3 used in 11.0.1 dyld source: # - 0x3 used in 11.0.1 dyld source:
# - https://github.com/apple-oss-distributions/dyld/blob/5c9192436bb195e7a8fe61f22a229ee3d30d8222/testing/test-cases/kernel-hello-world.dtest/main.c#L2 # - https://github.com/apple-oss-distributions/dyld/blob/5c9192436bb195e7a8fe61f22a229ee3d30d8222/testing/test-cases/kernel-hello-world.dtest/main.c#L2
class apple_mobile_file_integrity: import enum
class AppleMobileFileIntegrity(enum.IntEnum):
# Names set are solely for readability # Names set are solely for readability
# Internal names are unknown # Internal names are unknown
amfi_values = { AMFI_ALLOW_TASK_FOR_PID: int = 0x1 # Allow Task for PID (alt. amfi_unrestrict_task_for_pid=0x1)
"AMFI_ALLOW_TASK_FOR_PID": False, # 0x1 - Allow Task for PID (alt. amfi_unrestrict_task_for_pid=0x1) AMFI_ALLOW_INVALID_SIGNATURE: int = 0x2 # Reduce sig enforcement (alt. amfi_allow_any_signature=0x1)
"AMFI_ALLOW_INVALID_SIGNATURE": False, # 0x2 - Reduce sig enforcement (alt. amfi_allow_any_signature=0x1) AMFI_LV_ENFORCE_THIRD_PARTY: int = 0x4 # Don't mark external binaries as platform binaries
"AMFI_LV_ENFORCE_THIRD_PARTY": False, # 0x4 - Don't mark external binaries as platform binaries AMFI_UNKNOWN_1: int = 0x8
"AMFI_UNKNOWN_1": False, # 0x8 AMFI_UNKNOWN_2: int = 0x10
"AMFI_UNKNOWN_2": False, # 0x10 AMFI_UNKNOWN_3: int = 0x20
"AMFI_UNKNOWN_3": False, # 0x20 AMFI_UNKNOWN_4: int = 0x40
"AMFI_UNKNOWN_4": False, # 0x40 AMFI_ALLOW_EVERYTHING: int = 0x80 # Disable sig enforcement and Library Validation (alt. amfi_get_out_of_my_way=0x1)
"AMFI_ALLOW_EVERYTHING": False, # 0x80 - Disable sig enforcement and Library Validation (alt. amfi_get_out_of_my_way=0x1)
},
# Internally within AMFI.kext, Apple references 0x2 and 0x80 as both 'Disable signature enforcement' # Internally within AMFI.kext, Apple references 0x2 and 0x80 as both 'Disable signature enforcement'
# However 0x80 is a higher privilege than 0x2, and breaks TCC support in OS (ex. Camera, Microphone, etc prompts) # However 0x80 is a higher privilege than 0x2, and breaks TCC support in OS (ex. Camera, Microphone, etc prompts)
+21 -21
View File
@@ -3,6 +3,7 @@
import enum import enum
from resources import utilities from resources import utilities
from data import amfi_data
class AmfiConfigDetectLevel(enum.IntEnum): class AmfiConfigDetectLevel(enum.IntEnum):
@@ -67,32 +68,31 @@ class AmfiConfigurationDetection:
amfi_value = 0 amfi_value = 0
for arg in self.boot_args: for arg in self.boot_args:
if arg.startswith("amfi="): if not arg.startswith("amfi"):
try: continue
amfi_value = arg.split("=") try:
if len(amfi_value) != 2: amfi_value = arg.split("=")
return if len(amfi_value) != 2:
amfi_value = amfi_value[1]
if amfi_value.startswith("0x"):
amfi_value = int(amfi_value, 16)
else:
amfi_value = int(amfi_value)
except:
return return
break amfi_value = amfi_value[1]
if amfi_value.startswith("0x"):
amfi_value = int(amfi_value, 16)
else:
amfi_value = int(amfi_value)
except:
return
break
if amfi_value == 0: if amfi_value == 0:
return return
if amfi_value & 0x1: self.AMFI_ALLOW_TASK_FOR_PID: bool = amfi_value & amfi_data.AppleMobileFileIntegrity.AMFI_ALLOW_TASK_FOR_PID
self.AMFI_ALLOW_TASK_FOR_PID = True self.AMFI_ALLOW_INVALID_SIGNATURE: bool = amfi_value & amfi_data.AppleMobileFileIntegrity.AMFI_ALLOW_INVALID_SIGNATURE
if amfi_value & 0x2: self.AMFI_LV_ENFORCE_THIRD_PARTY: bool = amfi_value & amfi_data.AppleMobileFileIntegrity.AMFI_LV_ENFORCE_THIRD_PARTY
self.AMFI_ALLOW_INVALID_SIGNATURE = True
if amfi_value & 0x4: if amfi_value & amfi_data.AppleMobileFileIntegrity.AMFI_ALLOW_EVERYTHING:
self.AMFI_LV_ENFORCE_THIRD_PARTY = True self.AMFI_ALLOW_EVERYTHING = True
if amfi_value & 0x80: self.SKIP_LIBRARY_VALIDATION = True
self.AMFI_ALLOW_EVERYTHING = True
self.SKIP_LIBRARY_VALIDATION = True
self.AMFI_ALLOW_INVALID_SIGNATURE = True self.AMFI_ALLOW_INVALID_SIGNATURE = True