A prototype for the paper KextFuzz: Fuzzing macOS Kernel EXTensions on Apple Silicon via Exploiting Mitigations [USENIX Security 2023]. The code was tested on Apple Silicon macOS 11.5.2. Thanks for your attention.
- Apple Silicon Devices / Virtual Machine with macOS 11
- capstone & keystone
The ./rewrite
directory contains the code to do kext instrumentation and entitlement patch.
Step 1. Get a patched kext.
Note: edit ./rewrite/config.json
to specify the patch target and strategy.
Instrumentation and Entitlement patching are enabled by default.
$ pip install -r requirements.txt
$ cd rewrite
$ python bin_rewrite.py config.json
The patched kext will be saved in the ./rewrite/output
directory by default.
Step 2. Build helper.kext.
Build the ./rewrite/helper
in XCode to get helper.kext
Note: The helper kext should implement 1) the fake entitlement checker and 2) the profiling function which will be instrumented into the kext.
The helper.kext in the repository is an example of the helper kext. Please customize your own profiling functions with reference to ./rewrite/helper/helper.cpp
.
Step 3. Build macOS kernel collection. reference
$ kmutil inspect -V release --no-header | grep -v "SEPHiber" | awk '{print " -b "$1; }' > kext_list
$ echo "kextfuzz.example.helper" >> kext_list
# build kernel collection with patched kext and helper kext
$ mkdir Extensions
$ sudo cp -r ./output/* ./Extensions/
$ kmutil create -a arm64e -z -V release -n boot -B /path/to/your.kc -k /System/Library/kernels -r ./Extensions -r /System/Library/DriverExtensions -x $(cat kext_list)"
Step 4. Install the patched kernel collection.
- Boot into recovery mode & open terminal.
- Enter
csrutil disable
to disable System Integrity Protection. - Enter
bputil -a
to disable boot args restriction. - Reboot to apply above settings.
- Boot into recovery mode & open terminal.
- Install kernel collection:
kmutil configure-boot -v /Volumes/your-volume -c /path/to/your.kc
.
- View loaded kexts:
kextstat
- Load a kext:
kextload /path/to/kext
- View Mach-O binary symbols:
nm /path/to/bin
- View kernel log:
log stream --predicate "sender=='xxx'"
Play the video with sound :)