Skip to content

At boot

Kernel Extensions: macOS Persistence via Kexts

How kexts in /Library/Extensions load at boot on macOS, what approval and Reduced Security require, and how to find and remove a planted kernel extension.

MITRE ATT&CK
T1547.006
Tactics
Persistence, Privilege escalation, Defense evasion
Runs
At boot
Set up by
root
Locations
  • /Library/Extensions/*.kext
  • /Library/StagedExtensions/**/*.kext
  • /var/db/SystemPolicyConfiguration/KextPolicy

How it works

A kernel extension (kext) is a bundle, Name.kext, whose Contents/Info.plist describes it (CFBundleIdentifier, OSBundleLibraries, IOKitPersonalities) and whose Contents/MacOS binary is linked into the kernel. Once loaded it runs with full kernel privileges: it can hide files and processes, intercept system calls or read any memory. A kext loads when one of its IOKit personalities matches (a personality on IOResources matches at every boot) or when software asks for it, so a kext that matches at boot is persistence by itself.

Apple has tightened kext loading release after release:

ReleaseChange
OS X 10.9–10.10Third-party kexts belong in /Library/Extensions; Yosemite enforces kext signing with a Developer ID certificate Apple grants on request
OS X 10.11 El CapitanSystem Integrity Protection (SIP) locks /System/Library/Extensions
macOS 10.13 High SierraUser-approved kext loading: a new kext waits for approval in Security & Privacy
macOS 10.14.5New and updated kexts must be notarized by Apple
macOS 10.15 CatalinaSystem extensions arrive as the replacement for most kexts
macOS 11 Big SurKernel collections: approved third-party kexts are staged in /Library/StagedExtensions and linked into an auxiliary kernel collection that loads after a restart; kmutil replaces kextload, kextunload and kextstat
Apple silicon (macOS 11 and later)Third-party kexts also require Reduced Security set in recoveryOS, with "Allow user management of kernel extensions from identified developers" turned on

Approval is recorded per developer team in /var/db/SystemPolicyConfiguration/KextPolicy, a SQLite database whose kext_policy table lists team IDs, bundle IDs and whether they are allowed. MDM can pre-approve team IDs, but on Apple silicon the Mac must still be in Reduced Security. On macOS 27, kextload and kextunload are no longer installed and kextstat only prints a note and runs kmutil showloaded.

The point for a responder: on a current Mac, a third-party kext is rare and costly to install. It needs root, a kext-signing certificate (or a Mac with its security lowered), an administrator's approval and a restart. Every one you find should map to a known product.

Where it lives

PathWhatWho can write it
/System/Library/Extensions/*.kextApple's kextsNobody: sealed system volume
/Library/Extensions/*.kextThird-party kexts (macOS ships the folder empty)root
/Library/StagedExtensions/…Validated copies macOS stages before building the auxiliary collection (Big Sur and later)macOS only (SIP)
/Applications/*.app/Contents/Library/Extensions/*.kextKexts shipped inside an app and loaded from thereWhoever can write the app
/Library/KernelCollections/Auxiliary kernel collection built by kmutil (where present)macOS
/var/db/SystemPolicyConfiguration/KextPolicyApproval databasemacOS only

How attackers use it

Malicious kexts are uncommon on current macOS precisely because of the hurdles above, so the realistic patterns all involve either a real certificate or a weakened Mac.

A boot-time implant on a weakened Mac. On a Mac where SIP was turned off or the security mode lowered (labs, developer machines, a compromised admin who rebooted into recoveryOS), the checks that stop unsigned code are gone. A kext with a personality on IOResources loads at every boot:

<key>CFBundleIdentifier</key>
<string>com.example.netmon</string>
<key>IOKitPersonalities</key>
<dict>
  <key>netmon</key>
  <dict>
    <key>CFBundleIdentifier</key><string>com.example.netmon</string>
    <key>IOClass</key><string>NetMon</string>
    <key>IOProviderClass</key><string>IOResources</string>
    <key>IOMatchCategory</key><string>NetMon</string>
  </dict>
</dict>
cp -R NetMon.kext /Library/Extensions/
kmutil load -p /Library/Extensions/NetMon.kext   # prompts for approval, then a restart

A signed but vulnerable kext. Instead of signing their own, attackers can install a legitimate, approved kext with a known bug and exploit it for kernel code. If the vendor's team ID was approved before, the approval prompt may not appear again.

Disguise. The bundle takes a com.apple. identifier or the name of a security or driver vendor, sits inside a plausible app bundle, or is left behind after the product it came with was removed. A kext that fails to load still sits on disk and shows intent.

Most products have moved to system extensions, which run in user space. A kext is often loaded or babysat by a LaunchDaemon, so check those too.

How to check a host

On a live Mac:

kmutil showloaded --list-only | grep -v com.apple            # third-party kexts loaded now
ls -leO@ /Library/Extensions /Library/StagedExtensions
kmutil print-diagnostics -p /Library/Extensions/NetMon.kext  # why it would or would not load
codesign -dv --verbose=4 /Library/Extensions/NetMon.kext      # signer, team ID, timestamp
pkgutil --file-info /Library/Extensions/NetMon.kext/Contents/Info.plist
csrutil status
system_profiler SPiBridgeDataType                            # Apple silicon: Secure Boot, Allow All Kernel Extensions
kmutil log show --last 7d                                     # kernelmanagerd, kmutil and kcgend logs
sudo sqlite3 /var/db/SystemPolicyConfiguration/KextPolicy 'SELECT * FROM kext_policy'

KextPolicy may need Terminal to have Full Disk Access. Map each third-party kext to a product, a team ID in the approval table and an installer receipt; a loaded kext with no bundle on disk, or a team ID nobody recognises, is a finding. Hash the binary in Contents/MacOS and compare with the vendor's release.

Offline, the collection command archives /Library/Extensions, binaries included. Add /Library/StagedExtensions and the KextPolicy database if you need them (both need root, and Terminal may need Full Disk Access). Compare bundles with installer receipts, check signatures on an analysis Mac, and set file times against the install history. macOS Persistence does the bundle and receipt part offline.

What macOS Persistence flags

The tool reads the Contents/Info.plist of every kext under /Library/Extensions and /Library/StagedExtensions, including kexts nested in another kext's PlugIns, and reports one entry per kext with its bundle identifier, version, executable name and whether it is a staged copy.

  • Imitates an Apple label (high): the bundle identifier starts with com.apple.; Apple's kexts live in /System/Library/Extensions.
  • Runs from a hidden folder (medium): a component of the bundle path starts with a dot.
  • Not installed by any package (medium): installer receipts are in the collection and none lists the kext's Info.plist in /Library/Extensions. Copies in /Library/StagedExtensions are made by macOS rather than an installer, so they are not flagged; check the original's receipt instead. Kexts under /System/Library/Extensions, when a disk export includes them, are Apple's and shown as information.
  • Differs from package package (medium): a receipt lists the Info.plist but its checksum no longer matches.
  • Changed date (low): the Info.plist was modified in the 7 days before the newest file in the collection.

There is no flag for simply being a third-party kext: a clean, packaged kext from a known vendor shows as an entry without flags.

Limits: the tool reads files, not kernel state, so it cannot tell whether a kext is approved, loaded or in the auxiliary collection. It does not read the kext binary, verify signatures or team IDs, or read KextPolicy. It does not look in app bundles, and /Library/StagedExtensions is read only if you add it to the collection.

Cleaning up

  1. Preserve: copy the bundle with ditto (keeps times and extended attributes), hash its binary, save kmutil showloaded and codesign output, and copy KextPolicy and the unified log for the period.
  2. Stop it from loading again: sudo kmutil unload -b com.example.netmon. On macOS 11 and later the kext stays active until the next restart, because the new collection only takes effect then.
  3. Remove the bundle from /Library/Extensions (and the app that carried it), along with any LaunchDaemon or installer leftovers that reload it. Restart and confirm with kmutil showloaded that it is gone.
  4. If the Mac's security was lowered for this kext, return it to Full Security in Startup Security Utility and turn SIP back on, and remove any MDM kext approval for that team ID.
  5. Code ran in the kernel: treat the Mac's credentials, keys and tokens as exposed, and prefer a clean reinstall of macOS for anything you cannot fully explain.

References

See also

On Mac Forensics

The artifacts behind this technique, in the Mac Forensics reference: