Skip to content

Hiding

Inline Kernel Function Hooking on Linux: Traces, Checks

How Linux rootkits overwrite the first instructions of kernel functions to divert them, as Reptile's KHOOK and Syslogk do, and how to find the patched code.

Goal
Hiding
Layer
Kernel
Platforms
Linux
ATT&CK
T1014
Also known as
Inline hooking, Function prologue patching, KHOOK
Checked by
Linux kernel

Overview

Inline hooking rewrites the first instructions of a kernel function so that they jump to the rootkit's code. Every caller of that function, from any path, now runs the rootkit first. The rootkit's version usually calls the original through a small stub, a trampoline, and edits the result. Elastic describes it as writing "a jump instruction at the start (prologue) of a kernel function", says Reptile uses it extensively and Suterusu for some hooks, and calls the method fragile: it depends on the kernel version and compiler and can crash the system.

This page is about the method. The target is often the file system: when the patched function is filldir or tcp4_seq_show, the effect is described in VFS and /proc hooking. The other ways to divert a kernel function are replacing a pointer in the system call table and registering with the kernel's own ftrace and kprobes. On Windows, see kernel hooks on Windows.

What sets inline hooks apart for a responder: they bypass the kernel's tracing interfaces, so enabled_functions and kprobes/list stay clean, and they change kernel code, which only memory shows.

How it works

StepWhat the rootkit doesWhat it means for a responder
Find the functionLooks up its address: KHOOK walks the symbol table with kallsyms_on_each_symbol; Syslogk reads /proc/kallsyms (ASEC)Lookup imports or strings in the module. kallsyms_on_each_symbol was unexported in Linux 5.7, like kallsyms_lookup_name (commit)
Make the code writableKernel code is read-only. ASEC says Syslogk clears the write-protect bit in CR0 and makes the page table entry writable; Avast describes set_addr_rw and set_addr_ro helpersSince Linux 5.3 the kernel's own CR0 routine warns CR0 WP bit went missing!? when it sees WP cleared
Overwrite the startThe first bytes become a jump. ASEC describes Syslogk's as a register load of the rootkit function's address followed by a push and a return.The function no longer starts as the kernel image says; the jump lands in module memory
Keep the original callableKHOOK "provides a trampoline to call the original function safely" (Elastic)An extra executable stub in the module
Switch atomicallyKHOOK writes its hooks under stop_machine (source)Nothing visible

The kernel also patches its own code at run time: static keys use "jump label patching", and ftrace rewrites function entries (static keys, ftrace). Kernel code in memory therefore never matches the vmlinux file byte for byte, and checks look for jumps out of kernel code rather than any difference.

Elastic notes that KHOOK is "commonly limited to x86 and fails on kernel 5.x+", and that lockdown, Secure Boot or W^X protections "can block it".

How families use it

FamilyWhat it patchesSource
ReptileKHOOK inline hooks on filldir, filldir64, fillonedir, __d_lookup and vfs_statx (files); next_tgid, find_task_by_vpid and sys_kill (processes); tcp4_seq_show and udp4_seq_show (connections); vfs_read (tagged text); ip_rcv (the magic-packet trigger). KHOOK is also published on its own as a "Linux Kernel hooking engine (x86)"Repository, KHOOK, Elastic
SyslogkASEC's 2026 sample inline-hooks proc_root_readdir (processes) and tcp4_seq_show (TCP sockets); its file hiding is a pointer swap. Avast's 2022 analysis says hooks were placed with udis86ASEC, Avast
DrovorubNSA and FBI say the module hooks kernel functions "either by patching functions directly, or by overwriting function pointers", without saying which hook uses which. A researcher writing without a sample "highly doubt[s]" direct patching and guesses ftrace (Xcellerator). Treat inline patching as possible, not confirmedNSA and FBI

Outside the catalogue, Sandfly describes the rootkit from the 2025 "APT Down" leak as "based on the khook library" (Sandfly).

Traces it leaves

WhereTraceNotes
MemoryKernel functions whose first instructions jump outside kernel code, usually into a moduleThe proof
MemoryTrampolines and the hooking module, often hidden from the module list
Module fileImports of kallsyms_on_each_symbol or kallsyms_lookup_name; strings such as /proc/kallsyms and the names of patched functionsReptile's default install keeps the module encrypted inside its loader; see loading a kernel module from memory
kern.log, journalTaint lines naming the module; CR0 WP bit went missing!?; oopses after a failed patchThe absence of the warning proves nothing
Live hostListings, /proc and /proc/net/tcp disagreeing with direct lookups and outside capturesSame checks as VFS and /proc hooking
Tracing filesNothingInline hooks do not register with ftrace or kprobes

How to check a host

Live, with caution. The patched functions serve every tool. Look for side effects and capture memory early.

cat /proc/sys/kernel/tainted
dmesg | grep -iE 'taint|module verification|CR0 WP bit|Oops|BUG:'
journalctl -k -b | grep -iE 'taint|module verification|CR0 WP bit'
cat /sys/kernel/tracing/enabled_functions        # clean output does not rule out inline hooks
  • LKRG validates "kernel and modules code and read-only data" at run time and logs violations to the kernel log. It must be loaded before the compromise, and its authors call it "bypassable by design".
  • The VFS and /proc hooking page has the live comparisons for hidden files, PIDs and ports.

Memory. This is where inline hooks show. Volatility 2's linux_check_inline_kernel ("Check for inline kernel hooks") inspects the start of file, /proc and network operation handlers for jumps, register-and-jump and push-and-return sequences that lead outside known code (source). That covers hooks like Syslogk's on proc_root_readdir and tcp4_seq_show. Volatility 2 needs a profile for the exact kernel and is no longer developed, and Volatility 3 has no equivalent plugin. Otherwise, compare function starts in the image with the vmlinux of the same build from the distribution's debug packages, allowing for the kernel's own patching. linux.malware.hidden_modules and linux.module_extract find and dump the module.

Offline, from an image.

R=/mnt/evidence
nm -u /path/to/suspect.ko | grep -E 'kallsyms_on_each_symbol|kallsyms_lookup_name|stop_machine'
strings -a /path/to/suspect.ko | grep -E '/proc/kallsyms|filldir|seq_show|proc_root_readdir|ip_rcv|vfs_read'
zgrep -hE 'taint|module verification|CR0 WP bit' "$R"/var/log/kern.log* "$R"/var/log/messages* 2>/dev/null

stop_machine has many legitimate users; read it only next to the other signs.

What the checker looks for

The linuxkernel module reads module files under lib/modules/ and raises:

  • "Resolves unexported kernel symbols" for an import of kallsyms_on_each_symbol or kallsyms_lookup_name, or a kprobe-based lookup.
  • "Names kernel functions that rootkits hook" for names such as filldir, filldir64, fillonedir, tcp4_seq_show, udp4_seq_show, proc_pid_readdir and __x64_sys_kill. It does not list proc_root_readdir, __d_lookup, vfs_statx, vfs_read or ip_rcv. /proc/kallsyms appears among the notable strings.
  • The usual module, taint log and _live/ findings.

It cannot see patched code, which exists only in memory, and it does not read a module that never reached the module tree as a .ko file.

Mitigation and recovery

  • No module, no patch. Enforce module signatures (module.sig_enforce=1, or kernel lockdown), set kernel.modules_disabled=1 where possible, and audit init_module and finit_module.
  • Keep kernels current. Read-only kernel text and CR0 pinning raise the bar, and Elastic reports that KHOOK fails on 5.x and later kernels.
  • Watch code integrity with LKRG on hosts where a kernel rootkit would be costly.

Recovery. Capture memory first: the patched code and the trampolines exist nowhere else. Do not try to restore the original bytes in place; a patched kernel cannot be shown to be clean. Find what loaded the module, rebuild from known-good media and rotate credentials.

Sources

Primary public reports, newest first.

  1. 2026-09-03Detection and Removal of the Syslogk Rootkit in a Linux EnvironmentAhnLab ASEC
  2. 2026-03-05Hooked on Linux: Rootkit Taxonomy, Hooking Techniques and TradecraftElastic Security Labs
  3. 2025-08-13Leaked Chinese/North Korean Linux Stealth Rootkit AnalysisSandfly Security
  4. 2022-06-13Linux Threat Hunting: 'Syslogk' a kernel rootkit found under development in the wildGen Digital (Avast)
  5. 2020-08-13Russian GRU 85th GTsSS Deploys Previously Undisclosed Drovorub MalwareNSA and FBI
  6. 2018-09-01KHOOK source repositoryGitHub
  7. 2017-10-22Reptile source repositoryGitHub

See also

Families that use it