Kernel Modules and Extensions

From enterprise
Jump to: navigation, search
Kernel Modules and Extensions
Technique
ID T1215
Tactic Persistence
Platform Linux, macOS
Permissions Required root
Data Sources System calls, Process Monitoring, Process command-line parameters
Contributors Jeremy Galloway, Red Canary

Loadable Kernel Modules (or 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.1 When used maliciously, Loadable Kernel Modules (LKMs) can be a type of kernel-mode Rootkit that run with the highest operating system privilege (Ring 0).2 Adversaries can use loadable kernel modules to covertly persist on a system and evade defenses. Examples have been found in the wild and there are some open source projects.3456

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.7

Kernel extensions, also called kext, are used for macOS to load functionality onto a system similar to LKMs for Linux. They are loaded and unloaded through kextload and kextunload commands. Several examples have been found where this can be used.89 Examples have been found in the wild.10

Mitigation

Common tools for detecting Linux rootkits include: rkhunter11, chrootkit12, although rootkits may be designed to evade certain detection tools.

LKMs and Kernel extensions require root level permissions to be installed. Limit access to the root account and prevent users from loading kernel modules and extensions through proper privilege separation and limiting Privilege Escalation opportunities.

Application whitelisting and software restriction tools, such as SELinux, can also aide in restricting kernel module loading.13

Detection

LKMs are typically loaded into /lib/modules and have had the extension .ko ("kernel object") since version 2.6 of the Linux kernel.14

Many LKMs require Linux headers (specific to the target kernel) in order to compile properly.  These are typically obtained through the operating systems package manager and installed like a normal package.

Adversaries will likely run these commands on the target system before loading a malicious module in order to ensure that it is properly compiled.7

On Ubuntu and Debian based systems this can be accomplished by running: apt-get install linux-headers-$(uname -r)

On RHEL and CentOS based systems this can be accomplished by running: yum install kernel-devel-$(uname -r)

Loading, unloading, and manipulating modules on Linux systems can be detected by monitoring for the following commands:modprobe insmod lsmod rmmod modinfo15

For macOS, monitor for execution of kextload commands and correlate with other unknown or suspicious activity.

References