| name | macos-kext-analysis |
| description | 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. |
macOS 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
sudo kmutil showloaded --sort
sudo kmutil showloaded --collection aux
kextstat
Unload a Kext
sudo kmutil unload -b com.example.mykext
Inspect Kernel Collections
kmutil inspect -B /System/Library/KernelCollections/BootKernelExtensions.kc --show-fileset-entries
kmutil libraries -p /Library/Extensions/FancyUSB.kext --undef-symbols
Kernelcache Extraction
Find Local Kernelcache
find / -name "kernelcache" 2>/dev/null
Extract from IPSW
brew install blacktop/tap/ipsw
ipsw extract --kernel /path/to/firmware.ipsw -o out/
ipsw img4 im4p extract out/Firmware/kernelcache*.im4p -o kcache.raw
Decompress IMG4 Format
img4tool -e kernelcache.release.iphone14 -o kernelcache.release.iphone14.e
pyimg4 im4p extract -i kernelcache.release.iphone14 -o kernelcache.release.iphone14.e
disarm -L kernelcache.release.v57
Extract Kexts from Kernelcache
kextex -l kernelcache.release.iphone14.e
kextex -e com.apple.security.sandbox kernelcache.release.iphone14.e
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
disarm -e filesets kernelcache.release.d23
cd /tmp/extracted
JMATCHERS=xnu.matchers disarm --analyze kernel.rebuilt
Debugging
One-Shot Panic Analysis
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
ADDR=$(kmutil showloaded --bundle-identifier com.example.driver | awk '{print $4}')
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:
com.apple.rootless.install - can execute post-install scripts
com.apple.private.security.kext-management - can load kexts
Monitor Kext Loading
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
Tools
Workflow Patterns
Pattern 1: Analyze Loaded Kexts
- Run
kmutil showloaded --sort to enumerate
- Identify third-party kexts with
--collection aux
- Check for unsigned or suspicious kexts
- Inspect with
kmutil inspect for symbol dependencies
Pattern 2: Extract and Analyze Kernelcache
- Download IPSW or find local kernelcache
- Extract kernelcache from IPSW using
ipsw extract
- Decompress IMG4 format with
img4tool or pyimg4
- Check for symbols with
nm -a
- Extract specific kexts with
kextex
- Symbolicate with
disarm if needed
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
kmutil load invocations
- Check for known vulnerability patterns
- Review
/Library/Extensions for unauthorized kexts