Hacktricks-skills macos-kext-analysis
How to analyze macOS kernel extensions (Kexts), extract and inspect kernelcaches, enumerate loaded kexts, debug kernel panics, and identify kernel-level security issues. Use this skill whenever the user mentions kernel extensions, kexts, kernelcache, macOS kernel debugging, KDK, kmutil, kextstat, kernel vulnerabilities, SIP bypass, or any macOS kernel-level security analysis. Make sure to use this skill for any macOS security research, kernel extension management, or kernel debugging tasks.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-extensions/SKILL.MDmacOS Kernel Extension Analysis
A skill for analyzing macOS kernel extensions, extracting kernelcaches, debugging kernel panics, and identifying kernel-level security issues.
When to Use This Skill
Use this skill when the user needs to:
- Enumerate or manage loaded kernel extensions on macOS
- Extract and analyze kernelcaches from IPSW or local systems
- Debug kernel panics or attach to running kernel extensions
- Research kernel extension vulnerabilities or SIP bypasses
- Work with KDK (Kernel Debug Kit) for kernel debugging
- Analyze macOS kernel security configurations
Core Concepts
Kernel Extensions (Kexts)
Kernel extensions are packages with
.kext extension loaded directly into macOS kernel space. Key facts:
- Deprecated: Most legacy KPIs deprecated in macOS Catalina (10.15)
- System Extensions: Apple introduced DriverKit/System Extensions running in user-space
- Big Sur+: Third-party kexts with deprecated KPIs require Reduced Security mode
- Apple Silicon: Requires Recovery → Startup Security Utility → Reduced Security
Kernelcache
Pre-compiled, pre-linked XNU kernel with drivers and kexts:
- Stored compressed, decompressed at boot
- Faster boot time, modules prelinked
- Once loaded, XNU cannot load new KEXTs
- Located in
/System/Volumes/Preboot/*/boot/*/System/Library/Caches/com.apple.kernelcaches/kernelcache
Enumeration & Management
List Loaded Kexts
# Modern tool (preferred) sudo kmutil showloaded --sort # Third-party only sudo kmutil showloaded --collection aux # Deprecated but still works kextstat
Unload a Kext
sudo kmutil unload -b com.example.mykext
Inspect Kernel Collections
# List fileset entries in boot KC kmutil inspect -B /System/Library/KernelCollections/BootKernelExtensions.kc --show-fileset-entries # Check undefined symbols before loading kmutil libraries -p /Library/Extensions/FancyUSB.kext --undef-symbols
Kernelcache Extraction
Find Local Kernelcache
find / -name "kernelcache" 2>/dev/null
Extract from IPSW
# Install ipsw tool brew install blacktop/tap/ipsw # Extract kernelcache from IPSW ipsw extract --kernel /path/to/firmware.ipsw -o out/ # If IMG4 payload, extract it ipsw img4 im4p extract out/Firmware/kernelcache*.im4p -o kcache.raw
Decompress IMG4 Format
# Using img4tool img4tool -e kernelcache.release.iphone14 -o kernelcache.release.iphone14.e # Using pyimg4 pyimg4 im4p extract -i kernelcache.release.iphone14 -o kernelcache.release.iphone14.e # Using disarm (direct on IMG4) disarm -L kernelcache.release.v57
Extract Kexts from Kernelcache
# List all extensions kextex -l kernelcache.release.iphone14.e # Extract specific kext kextex -e com.apple.security.sandbox kernelcache.release.iphone14.e # Extract all kextex_all kernelcache.release.iphone14.e
Check for Symbols
nm -a kernelcache.release.iphone14.e | wc -l nm -a ~/Downloads/Sandbox.kext/Contents/MacOS/Sandbox | wc -l
Symbolicate with Disarm
# Extract filesets disarm -e filesets kernelcache.release.d23 # Analyze with matchers cd /tmp/extracted JMATCHERS=xnu.matchers disarm --analyze kernel.rebuilt
Debugging
One-Shot Panic Analysis
# Create symbolication bundle for latest panic sudo kdpwrit dump latest.kcdata kmutil analyze-panic latest.kcdata -o ~/panic_report.txt
Live Remote Debugging
- Download KDK matching target build
- Connect target and host via USB-C/Thunderbolt
- On target:
sudo nvram boot-args="debug=0x100 kdp_match_name=macbook-target" reboot - On host:
lldb (lldb) kdp-remote "udp://macbook-target" (lldb) bt
Attach LLDB to Loaded Kext
# Get load address ADDR=$(kmutil showloaded --bundle-identifier com.example.driver | awk '{print $4}') # Attach sudo lldb -n kernel_task -o "target modules load --file /Library/Extensions/Example.kext/Contents/MacOS/Example --slide $ADDR"
Security Analysis
Check Entitled Daemons
codesign -dvv /path/to/binary | grep entitlements
Look for:
- can execute post-install scriptscom.apple.rootless.install
- can load kextscom.apple.private.security.kext-management
Monitor Kext Loading
# Alert on writes to Extensions directory # Monitor kmutil load/create invocations # Endpoint Security: ES_EVENT_TYPE_NOTIFY_KEXTLOAD
Known Vulnerabilities
| CVE | Summary |
|---|---|
| CVE-2024-44243 | storagekitd logic flaw allowed unsigned kext loading, bypassing SIP |
| CVE-2021-30892 | Shrootless - entitled daemon abuse to disable SIP and load kexts |
Resources
Download Sources
- KernelDebugKit: https://github.com/dortania/KdkSupportPkg/releases
- Firmware with symbols: https://theapplewiki.com/wiki/Firmware/Mac/14.x
- IPSW archives: https://ipsw.me/, https://www.theiphonewiki.com/
Tools
- img4tool: https://github.com/tihmstar/img4tool
- pyimg4: https://github.com/m1stadev/PyIMG4
- disarm: https://newandroidbook.com/tools/disarm.html
- aeota: https://github.com/dhinakg/aeota (decrypts AEA containers)
Workflow Patterns
Pattern 1: Analyze Loaded Kexts
- Run
to enumeratekmutil showloaded --sort - Identify third-party kexts with
--collection aux - Check for unsigned or suspicious kexts
- Inspect with
for symbol dependencieskmutil inspect
Pattern 2: Extract and Analyze Kernelcache
- Download IPSW or find local kernelcache
- Extract kernelcache from IPSW using
ipsw extract - Decompress IMG4 format with
orimg4toolpyimg4 - Check for symbols with
nm -a - Extract specific kexts with
kextex - Symbolicate with
if neededdisarm
Pattern 3: Debug Kernel Panic
- Capture panic with
kdpwrit dump - Analyze with
kmutil analyze-panic - For live debugging, set up KDP with matching KDK
- Attach LLDB and get backtrace
Pattern 4: Security Assessment
- Check SIP status and kext loading permissions
- Enumerate entitled daemons
- Monitor for
invocationskmutil load - Check for known vulnerability patterns
- Review
for unauthorized kexts/Library/Extensions