Skip to content

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.ko and loaded it with insmod. If the build failed, it fell back to replacing ps, top and pstree with filtering versions.
  • 2024, attributed to TeamTNT with moderate confidence. Group-IB found the same unmodified source unpacked under /var/tmp, compiled and loaded with insmod. 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 named xx_tables and 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:

  • getdents and getdents64, to drop directory entries;
  • kill, to receive commands.
Default behaviour (public source)Effect
Module invisible as soon as it loadsIt unlinks itself from the kernel's module list, so lsmod and /proc/modules do not show it
Signal 31 sent to a PIDHides or shows that process in /proc listings
Signal 63 sent to any PIDMakes the module visible or invisible again
Signal 64 sent to any PIDGives root to the calling user
Names starting with diamorphine_secretFiles 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

LocationWhatSource
diamorphine.c, diamorphine.h and Makefile in a working folder; Group-IB saw a folder under /var/tmpSource unpacked on the hostGroup-IB, Aqua
diamorphine.ko beside it, with kbuild leftovers (*.o, *.mod.c, Module.symvers, modules.order)The module built on the hostGroup-IB, Aqua, kbuild
dia.tar.gz in the dropper scriptThe archived sourceAqua
A cron job running a loader script (cronb.sh in Aqua's case)Reload at every runAqua
Kernel headers and compilers installed shortly before (/var/log/dpkg.log, /var/log/apt/history.log)Prerequisites for the buildInference from the build step
Files whose names start with diamorphine_secretHidden by the default buildRepository
/var/log/kern.log, /var/log/messages, the journalloading out-of-tree module taints kernel and module verification failed lines naming the moduleLinux kernel
A .ko whose .modinfo says name=diamorphine and description=LKM rootkitUnmodified buildRepository
A .ko posing as x_tables, built for 5.19.17Gen Digital's variantGen 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_module and finit_module rather than watching for insmod. 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 .ko was 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.order does not list it and no dpkg package owns it. modules.dep may list it, because depmod indexes 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 the intree tag;
    • from its imports and strings: "Looks up the system call table" for the sys_call_table string, and "Resolves unexported kernel symbols" for register_kprobe with the string kallsyms_lookup_name, or an import of kallsyms_lookup_name on kernels before 5.7. "Names kernel functions that rootkits hook" appears only when the build carries names such as __x64_sys_getdents64 as strings.
  • A load line in /etc/modules or modules-load.d naming such a module: "Boot configuration loads a flagged module".
  • The taint messages in kern.log or messages: "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/module entry, 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 .ko kept outside the module tree, such as a build folder under /var/tmp;
  • cron jobs and scripts that run insmod;
  • the journal: it reads kern.log and messages, not /var/log/journal;
  • a module that existed only in memory.

Search those by hand, as shown above.

Removal and recovery

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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=1 after boot on servers that never load modules later.
    • Audit init_module and finit_module.

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.

  1. 2026-04-02Hooked on Linux: Rootkit Detection EngineeringElastic Security Labs
  2. 2026-03-05Hooked on Linux: Rootkit Taxonomy, Hooking Techniques and TradecraftElastic Security Labs
  3. 2024-09-18Storm clouds on the horizon: Resurgence of TeamTNT?Group-IB
  4. 2024-06-18New Diamorphine rootkit variant seen undetected in the wildGen Digital (Avast)
  5. 2021-08-26Advanced Persistent Threat Techniques Used in Container AttacksAqua Security
  6. 2013-11-06Diamorphine source repositoryGitHub

See also