Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Adversaries may modify the kernel to automatically execute programs on system boot.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-13 | ✗→✓ | ▲ Improved | 23% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 102% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 48% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 67% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 82% | 0% |
> Sub-technique of: T1547
Adversaries may modify the kernel to automatically execute programs on system boot. Loadable Kernel Modules (LKMs) are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. For example, one type of module is the device driver, which allows the kernel to access hardware connected to the system.
When used maliciously, LKMs can be a type of kernel-mode Rootkit that run with the highest operating system privilege (Ring 0). Common features of LKM based rootkits include: hiding itself, selective hiding of files, processes and network activity, as well as log tampering, providing authenticated backdoors, and enabling root access to non-privileged users.
Kernel extensions, also called kext, are used in macOS to load functionality onto a system similar to LKMs for Linux. Since the kernel is responsible for enforcing security and the kernel extensions run as apart of the kernel, kexts are not governed by macOS security policies. Kexts are loaded and unloaded through <code>kextload</code> and <code>kextunload</code> commands. Kexts need to be signed with a developer ID that is granted privileges by Apple allowing it to sign Kernel extensions. Developers without these privileges may still sign kexts but they will not load unless SIP is disabled. If SIP is enabled, the kext signature is verified before being added to the AuxKC.
Since macOS Catalina 10.15, kernel extensions have been deprecated in favor of System Extensions. However, kexts are still allowed as "Legacy System Extensions" since there is no System Extension for Kernel Programming Interfaces.
Adversaries can use LKMs and kexts to conduct Persistence and/or Privilege Escalation on a system. Examples have been found in the wild, and there are some relevant open source projects as well.
Platforms: macOS, Linux
The following tests are from Atomic Red Team and provide actionable ways to test this technique:
This test uses the insmod command to load a kernel module for Linux.
Supported Platforms: linux Elevation Required: Yes
bashsudo insmod #{module_path}
Dependencies:
This test uses the kextload and kmutil commands to load and unload a MacOS kernel module.
Supported Platforms: macos Elevation Required: Yes
bashset -x sudo kextload #{module_path} kextstat 2>/dev/null | grep SoftRAID sudo kextunload #{module_path} sudo kmutil load -p #{module_path} kextstat 2>/dev/null | grep SoftRAID sudo kmutil unload -p #{module_path}
Dependencies:
This test uses the IOKit API to load a kernel module for macOS. Harcoded to use SoftRAID kext
Supported Platforms: macos Elevation Required: Yes
bashsudo #{exe_path} kextstat 2>/dev/null | grep SoftRAID sudo kextunload /Library/Extensions/SoftRAID.kext
Dependencies:
If Atomic Red Team tests are not applicable, manually verify the technique by:
Limit access to the root account and prevent users from loading kernel modules and extensions through proper privilege separation and limiting Privilege Escalation opportunities.
Use MDM to disable user's ability to install or approve kernel extensions, and ensure all approved kernel extensions are in alignment with policies specified in <code>com.apple.syspolicy.kernel-extension-policy</code>.
Common tools for detecting Linux rootkits include: rkhunter , chrootkit , although rootkits may be designed to evade certain detection tools.
Application control and software restriction tools, such as SELinux, KSPP, grsecurity MODHARDEN, and Linux kernel tuning can aid in restricting kernel module loading.
| Finding | Severity | Impact | | -------------------------------------------------- | -------- | ----------- | | Kernel Modules and Extensions technique applicable | High | Persistence |
| CWE ID | Title | | ------- | ----------------------------- | | CWE-276 | Incorrect Default Permissions |
Other measured skills in the registry, with their headline benchmark lift.