Linux LKM rootkit
Diamorphine LKM Rootkit: Traces and Offline Checks
Diamorphine is an open-source Linux kernel module rootkit used by cryptomining crews. Its traces, how to check a host offline and live, and how to recover.
- Kind
- Linux LKM rootkit · Kernel layer
- Platforms
- Linux
- First seen
- 2013
- Status
- In the wild
- Checked by
- Linux kernel
Overview
Diamorphine is a public, open-source loadable kernel module (LKM) rootkit for Linux. Its repository was created in November 2013 and is still maintained. The README claims support for kernels from 2.6 onwards on x86, x86_64 and ARM64. The source is public and small, and the reports below show intruders compiling it on the host they control.
Reported uses:
- TeamTNT, 2021. Aqua Security described a campaign it attributes to TeamTNT on a few dozen hosts. The script carried the unmodified source, built
diamorphine.koand loaded it withinsmod. If the build failed, it fell back to replacingps,topandpstreewith filtering versions. - 2024, attributed to TeamTNT with moderate confidence. Group-IB found the same unmodified source unpacked under
/var/tmp, compiled and loaded withinsmod. Group-IB says it "cannot definitively confirm" TeamTNT is behind the activity. - A modified variant, 2024. Gen Digital (Avast) analysed a build found in March 2024. It imitates the Netfilter module
x_tables, adds a control device namedxx_tablesand runs commands on receipt of crafted network packets. Avast does not attribute it.
Elastic Security Labs describes Diamorphine as a syscall-table hooker that "remains functional on many distributions" (part 1).
How it loads and hides
Loading. Diamorphine has no persistence of its own. Something must load the .ko at every boot:
- a script started by cron, as in Aqua's case;
- a line in
/etc/modules-load.d/or/etc/modules; - a systemd unit or rc script running
insmod.
Loading a module needs root or CAP_SYS_MODULE. On a kernel that enforces module signatures, an unsigned build is refused. Otherwise it loads and taints the kernel.
Hiding. In the public source, the module finds the kernel's sys_call_table by name, through kallsyms_lookup_name. On kernels where that function is no longer exported (5.7 and later), it reaches it through a kprobe. On x86 it clears the write-protect bit in CR0 and replaces three entries:
getdentsandgetdents64, to drop directory entries;kill, to receive commands.
| Default behaviour (public source) | Effect |
|---|---|
| Module invisible as soon as it loads | It unlinks itself from the kernel's module list, so lsmod and /proc/modules do not show it |
| Signal 31 sent to a PID | Hides or shows that process in /proc listings |
| Signal 63 sent to any PID | Makes the module visible or invisible again |
| Signal 64 sent to any PID | Gives root to the calling user |
Names starting with diamorphine_secret | Files and directories left out of listings; still reachable by full path |
The hiding is a filter on listings only. A hidden file can still be opened by its path, and a hidden process can still be reached through /proc/<pid>/.
In the public source, hiding removes the module from the module list but leaves its directory under /sys/module/. A module in /sys/module but missing from /proc/modules is therefore a strong sign. Variants can change any of these defaults: the prefix, the signal numbers, the module name, and whether sysfs is cleaned too.
Traces on disk
| Location | What | Source |
|---|---|---|
diamorphine.c, diamorphine.h and Makefile in a working folder; Group-IB saw a folder under /var/tmp | Source unpacked on the host | Group-IB, Aqua |
diamorphine.ko beside it, with kbuild leftovers (*.o, *.mod.c, Module.symvers, modules.order) | The module built on the host | Group-IB, Aqua, kbuild |
dia.tar.gz in the dropper script | The archived source | Aqua |
A cron job running a loader script (cronb.sh in Aqua's case) | Reload at every run | Aqua |
Kernel headers and compilers installed shortly before (/var/log/dpkg.log, /var/log/apt/history.log) | Prerequisites for the build | Inference from the build step |
Files whose names start with diamorphine_secret | Hidden by the default build | Repository |
/var/log/kern.log, /var/log/messages, the journal | loading out-of-tree module taints kernel and module verification failed lines naming the module | Linux kernel |
A .ko whose .modinfo says name=diamorphine and description=LKM rootkit | Unmodified build | Repository |
A .ko posing as x_tables, built for 5.19.17 | Gen Digital's variant | Gen Digital |
The kernel prints each of the two taint warnings only for the first such module after a boot. A host running another out-of-tree module (VirtualBox, ZFS, a vendor agent) may therefore have logged that module's name instead. Gen Digital publishes hashes and a YARA rule for its variant in the avast/ioc repository. Copy them from there rather than from secondary write-ups.
How to check a host
Live, with caution. A loaded kernel rootkit controls what every program on the host sees, statically linked tools included. Use live output for cross-checks, not as proof of a clean host.
cat /proc/sys/kernel/tainted # non-zero: something tainted the kernel since boot
grep -h '(' /proc/modules # loaded modules carrying taint letters
dmesg | grep -iE 'taint|module verification'
for m in /sys/module/*; do [ -e "$m/initstate" ] && ! grep -q "^${m##*/} " /proc/modules && echo "only in sysfs: ${m##*/}"; done
unhide brute proc # PIDs that answer but are missing from listings
- Taint bit 12 (
O, out-of-tree) and bit 13 (E, unsigned) are listed in the kernel's tainted kernels documentation. - The sysfs loop prints modules that sysfs still knows but the module list no longer shows, which is exactly what the public build leaves.
- Elastic's detection article recommends auditing
init_moduleandfinit_modulerather than watching forinsmod. It also flags unusual high-numbered signals such as Diamorphine's. - Capture memory before anything that changes state. See memory acquisition.
Offline, from an image or a collection.
R=/mnt/evidence
find "$R" -xdev \( -name '*.ko' -o -name '*.ko.zst' -o -name '*.ko.xz' \) -newer "$R/etc/hostname" -printf '%T+ %p\n'
find "$R" -xdev -name 'diamorphine*' 2>/dev/null
modinfo /path/to/suspect.ko # name, description, vermagic, signer if any
tail -c 28 /path/to/suspect.ko # "~Module signature appended~" when signed
nm -u /path/to/suspect.ko | grep -E 'kallsyms|kprobe|creds'
strings -n 6 /path/to/suspect.ko | grep -E 'sys_call_table|kallsyms_lookup_name|getdents'
zgrep -hE 'taint|module verification' "$R"/var/log/kern.log* "$R"/var/log/messages* 2>/dev/null
grep -rhvE '^\s*([#;]|$)' "$R"/etc/modules-load.d "$R"/etc/modules 2>/dev/null
grep -rn 'insmod\|modprobe' "$R"/etc/cron* "$R"/var/spool/cron "$R"/etc/systemd/system "$R"/etc/rc.local 2>/dev/null
Read the files from an image mounted read-only on a clean analysis machine. On the suspect host itself, the rootkit filters the directory listing. Check which package owns each module you cannot explain: see checking Linux kernel modules offline. The kernel modules artifact page on Linux Forensics covers the configuration files in detail.
What the checker looks for
The linuxkernel module reads the module tree under lib/modules/, the load configuration, ld.so.preload, the kernel logs (kern.log, messages) and the collect script's _live/ outputs. For Diamorphine it can show:
- A module file under
lib/modules/that stands out, if the built.kowas copied there:- "Unsigned module among signed modules", when most of the host's other modules carry a signature;
- "Module unknown to the kernel build and to every package":
modules.orderdoes not list it and no dpkg package owns it.modules.depmay list it, becausedepmodindexes whatever is in the tree when it runs; if it does not, a separate low finding, "Module not indexed by depmod", says so; - "Out-of-tree module inside the kernel's own folder", for a module under
kernel/without theintreetag; - from its imports and strings: "Looks up the system call table" for the
sys_call_tablestring, and "Resolves unexported kernel symbols" forregister_kprobewith the stringkallsyms_lookup_name, or an import ofkallsyms_lookup_nameon kernels before 5.7. "Names kernel functions that rootkits hook" appears only when the build carries names such as__x64_sys_getdents64as strings.
- A load line in
/etc/modulesormodules-load.dnaming such a module: "Boot configuration loads a flagged module". - The taint messages in
kern.logormessages: "Kernel log: out-of-tree module loaded" and "Kernel log: unsigned module loaded", which name the first such module of each boot. - A module hidden from
/proc/modules. With_live/outputs, "Loaded module missing from /proc/modules" for a module that still has a/sys/moduleentry, which is what the public build leaves, and "Kernel tainted by an out-of-tree or unsigned module" from the saved taint value.
None of these findings names a family: the same evidence fits other LKM rootkits, so read them as Diamorphine-style, not as an attribution. The sample host fin-jump-01 shows all of them for a synthetic module, as the sample walk-through describes.
What it does not see:
- a
.kokept outside the module tree, such as a build folder under/var/tmp; - cron jobs and scripts that run
insmod; - the journal: it reads
kern.logandmessages, not/var/log/journal; - a module that existed only in memory.
Search those by hand, as shown above.
Removal and recovery
- Preserve first. Capture memory (AVML or LiME), then image the disk. A reboot unloads the module and destroys what only memory holds: the hidden process list and any changes the rootkit made.
- Work from the image. Find the loader (cron job, unit, load configuration line), the
.ko, the source folder and whatever the rootkit hid: miners, scanners, backdoors. Prefixes and hidden PIDs tell you what to look for. - Do not trust in-place cleaning. Code ran in the kernel, and signal 64 gave root to any user who knew it. Removing the files and rebooting may stop the rootkit, but it does not restore trust in the host. Rebuild it from known-good media.
- Rotate secrets. Rotate every credential, key and token that was on the host or used from it. On container hosts, include cloud and registry credentials: AT&T Alien Labs reported TeamTNT stealing credentials as well as mining.
- Prevent the next load.
- Enforce module signatures: Secure Boot with lockdown, or
module.sig_enforce=1(see the kernel's module signing documentation). - Set
kernel.modules_disabled=1after boot on servers that never load modules later. - Audit
init_moduleandfinit_module.
- Enforce module signatures: Secure Boot with lockdown, or
See also Reptile, which adds a userland loader and port-knocking backdoor, and libprocesshider, the userland tool used by the same crews.
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-09-18Storm clouds on the horizon: Resurgence of TeamTNT?Group-IB
- 2024-06-18New Diamorphine rootkit variant seen undetected in the wildGen Digital (Avast)
- 2021-08-26Advanced Persistent Threat Techniques Used in Container AttacksAqua Security
- 2013-11-06Diamorphine source repositoryGitHub
See also
Related families
- ReptileLinux LKM rootkit
- KoviDLinux LKM rootkit
- PUMAKITLinux LKM rootkit
- libprocesshiderLinux user-land rootkit