Getting into the kernel
Loading a Linux Kernel Module from Memory: Traces, Checks
How Linux rootkit loaders hand the kernel a decrypted module from memory so no .ko file reaches disk, what the kernel still records, and how to check a host.
- Goal
- Getting into the kernel
- Layer
- Kernel
- Platforms
- Linux
- Also known as
- Fileless module loading, In-memory LKM loading
- Checked by
- Linux kernel
Overview
The usual way to load a Linux kernel module is insmod or modprobe. Both open a .ko file and hand it to the kernel. The kernel also accepts a module as a block of memory: init_module() "loads an ELF image into kernel space", and its first argument "points to a buffer containing the binary image to be loaded" (init_module(2)). A loader can carry the module encrypted inside itself, decrypt it in its own memory and pass the buffer. No .ko file ever exists on disk.
Elastic's taxonomy lists the routes rootkit droppers use: writing a .ko and running insmod or modprobe, calling init_module() or finit_module() directly, and loading in memory via ptrace or memfd_create, "often avoiding disk artifacts". The aim is to stay out of sight of tools that watch insmod or scan module folders.
It is a loading technique, not a bypass. A module from a buffer goes through the same kernel path as one from a file: the same signature check, version check, taint flags and log lines. What is missing is the file.
How it works
| Route | What the kernel receives | What is on disk | Example |
|---|---|---|---|
insmod or modprobe | A file, through finit_module() | The .ko | Diamorphine |
Loader calls init_module() | An ELF image from the loader's own memory | The loader, with the module encrypted inside | Reptile's loader |
| Chain-loading inside the kernel | A first module decrypts a second and loads it from kernel code | Nothing more | Reptile's kmatryoshka |
| Anonymous memory file | A file descriptor from memfd_create, through finit_module() | Nothing | Named by Elastic as a general route |
The kernel runs its signature check on every load, wherever the image came from (module_sig_check in load_module, kernel source). It prints the same loading out-of-tree module taints kernel and module verification failed lines, and the module appears in /proc/modules and /sys/module unless it hides itself. modinfo and the module folders know nothing about it.
How families use it
| Family | How it loads | Source |
|---|---|---|
| Reptile | The default install's reptile loader "directly invokes the init_module syscall with an in-memory decrypted kernel blob". That first module, kmatryoshka, "acts as an in-kernel chainloader that decrypts and loads another hidden LKM using a direct function pointer to sys_init_module, located via kallsyms_on_each_symbol()". In the public source, the chain-loader returns error 37 so that it never stays loaded; the loader treats that error as success. The inner rootkit then unlinks itself from the module list. UNC3886 kept an encrypted kernel component under /lib/modules/<release>/kernel/drivers/<keyword>/<keyword>, without a .ko name, started by /usr/bin/<keyword> | Elastic, 2026, repository, Mandiant |
| PUMAKIT | "All necessary files are embedded as ELF binaries within the dropper", which runs its stages from memfd_create files. The loader, running as /memfd:wpn (deleted), "will, if all conditions are met, load the LKM rootkit". Elastic does not say which system call it uses, or whether puma.ko ever touches disk. The kernel still logged module verification failed | Elastic, 2024 |
Elastic sums up the effect of Reptile's design: "This further obscures the loading mechanism from userland visibility", and insmod never runs (Elastic, 2026).
Traces it leaves
| Where | Trace | Notes |
|---|---|---|
/proc/modules | A loaded module that no file on disk explains | Absent when the module also hides |
/sys/module/<name>/ | An entry with initstate that /proc/modules lacks | When the module unlinks itself but keeps its sysfs entry, as Reptile's public source does |
kern.log, messages, journal | Taint lines naming the module | Printed for buffer loads too, once per boot |
| Audit log | init_module or finit_module from a program that is not kmod; with such a rule, a KERN_MODULE record naming the module (Linux 4.11 and later) | Needs the rules below; Reptile's public loader shows a call that fails with error 37 |
| Processes | A loader running from /memfd:… (deleted) | PUMAKIT, live only |
| Disk | The loader, with high-entropy data; persistence that starts it; files without .ko under the module tree (UNC3886) | The dependable offline trace |
| Memory | The module itself | The only copy |
How to check a host
Live, as root.
cat /proc/sys/kernel/tainted
while read -r name _; do modinfo -n "$name" >/dev/null 2>&1 || echo "loaded, no file known: $name"; done < /proc/modules
for m in /sys/module/*; do [ -e "$m/initstate" ] && ! grep -q "^${m##*/} " /proc/modules && echo "only in sysfs: ${m##*/}"; done
ls -l /proc/[0-9]*/exe 2>/dev/null | grep -E 'memfd:|\(deleted\)'
ausearch -m KERN_MODULE -i 2>/dev/null | tail -n 20
ausearch -sc init_module -i 2>/dev/null | tail -n 20
modinfo -nprints the file a module name resolves to. A loaded module it cannot resolve came from another path, a deleted file or memory.- Elastic recommends auditing the system calls, not the tools: "Effective detection should therefore focus on tracing these syscalls directly". Its rules are
-a always,exit -F arch=b64 -S finit_module -S init_moduleand the same forb32. Look at which program made each call.
Memory. Capture memory before rebooting: it may hold the only copy of the module. Volatility 3's linux.malware.hidden_modules finds unlinked modules, and linux.module_extract "recreates an ELF file" from a module in memory, for analysis.
Offline, from an image.
R=/mnt/evidence
find "$R"/lib/modules "$R"/usr/lib/modules -type f ! -name '*.ko*' ! -name 'modules.*' 2>/dev/null
zgrep -hE 'taint|module verification' "$R"/var/log/kern.log* "$R"/var/log/messages* 2>/dev/null
ausearch -if "$R"/var/log/audit -m KERN_MODULE -i 2>/dev/null
ausearch -if "$R"/var/log/audit -sc init_module -i 2>/dev/null
grep -rnE 'RUN\+?=' "$R"/etc/udev/rules.d "$R"/lib/udev/rules.d 2>/dev/null
A module name in the logs or the audit trail that matches no file in the image points to a memory load or a deleted file. Then look for the loader: unowned executables in system folders, and the udev rules, units, rc scripts and cron jobs that start them. Checking Linux kernel modules offline covers the module tree itself.
What the checker looks for
The linuxkernel module compares the collect script's _live/proc_modules with the collected module tree of the running kernel:
- "Loaded module with no file on disk" for a module that
/proc/moduleslists but that has no file in that tree and is not built in. It fires only when the tree looks complete: its files cover at least 90% of the entries inmodules.dep. Its text names three explanations:insmodfrom another path (for example/tmpor/dev/shm), a file deleted after loading, or a load straight from memory. The checker cannot tell them apart. - It does not fire for a module that also hides from
/proc/modules, which Reptile's does. For that case, "Loaded module missing from /proc/modules" fires when/sys/modulestill lists the module, as Reptile's public source leaves it. - "Kernel log: out-of-tree module loaded", "Kernel log: unsigned module loaded" and "Kernel tainted by an out-of-tree or unsigned module" apply to memory loads as to any other.
It does not read the loader, the audit log or memfd processes. It reads only .ko, .ko.zst, .ko.xz and .ko.gz files under the module tree, so an encrypted blob without that extension, as in UNC3886's case, is not examined.
Mitigation and recovery
- Enforce module signatures. Because the check runs on every load,
module.sig_enforce=1or kernel lockdown refuses an unsigned module from memory exactly as from a file (module signing). - Close module loading with
kernel.modules_disabled=1after boot where possible (sysctl documentation). - Pin module origins. Where the LoadPin security module is built in and enforcing, it refuses the buffer interface outright ("old-api-denied") and files from outside the pinned file system (LoadPin, source).
- Audit both system calls and ship the records off the host.
Recovery. Capture memory first, then image the disk; extract the module from memory if no file exists. Find the loader and what starts it, rebuild from known-good media, and rotate credentials.
Sources
Primary public reports, newest first.
- 2026-04-02Hooked on Linux: Rootkit Detection EngineeringElastic Security Labs
- 2026-03-05Hooked on Linux: Rootkit Taxonomy, Hooking Techniques and TradecraftElastic Security Labs
- 2024-12-12Declawing PUMAKITElastic Security Labs
- 2024-06-18Cloaked and Covert: Uncovering UNC3886 Espionage OperationsGoogle Cloud (Mandiant)
- 2017-10-22Reptile source repositoryGitHub