ld.so.preload and Userland Rootkits: Offline and Live Checks
How Linux userland rootkits use /etc/ld.so.preload and LD_PRELOAD, why ls, cat and ldd on the host can lie, and how to check a system offline and live.
TL;DR.
- The mechanism.
/etc/ld.so.preloadnames libraries that the dynamic linker loads into every dynamically linked program, before libc. A library listed there can replacereaddir,fopen,statorpam_authenticateand decide what everyls,ps,cat,netstatandlddon the host reports. That includes, for some rootkits, whether the preload file itself exists. - Offline. Read the file and the library from a disk image on a clean machine. Check the library's exported functions, owner and times.
- Live. Use statically linked tools from trusted media, started as a static shell, and read
/proc/<pid>/maps.
Never run ldd on a suspect binary.
How preloading works
The dynamic linker (ld.so) handles preload requests in a fixed order, per ld.so(8):
- the
LD_PRELOADenvironment variable; - the
--preloadoption, whenld.sois run directly; /etc/ld.so.preload, a whitespace-separated list of shared objects.
| Route | Reach | Where it is set |
|---|---|---|
/etc/ld.so.preload | Every dynamically linked program started after the change, set-user-ID programs included | One file, root only |
LD_PRELOAD | Processes that inherit the variable | /etc/environment, shell startup files, systemd Environment=, ~/.ssh/environment, a wrapper script |
A directory in /etc/ld.so.conf.d/ | Programs that resolve a library name to a planted copy | ldconfig cache rebuild |
Limits of the mechanism:
- Set-user-ID programs. In secure-execution mode,
LD_PRELOADentries containing a slash are ignored. Only set-user-ID libraries from standard directories load. - Static binaries. Statically linked programs ignore all three routes.
- Running processes. A process started before the change does not get the library.
Linux Persistence's LD_PRELOAD page covers the persistence side in detail. Linux Forensics' ld.so.preload artifact page covers the evidence.
Who uses it
| Family | Library and route | What it hides or does |
|---|---|---|
| libprocesshider | /usr/local/lib/libprocesshider.so in /etc/ld.so.preload; TeamTNT used /usr/local/lib/systemhealt.so | One process name, from /proc listings |
| Hildegard (TeamTNT) | /etc/ld.so.preload with x86_64.so and xmrig.so (Unit 42) | Processes named tmate, xmrig, ziggy |
| Azazel | /lib/libselinux.so in /etc/ld.so.preload (default) | Files, processes, ports, logins, its own preload file; PAM backdoor |
| Winnti for Linux | libxselinux.so, a modified Azazel (MITRE) | The main backdoor's activity |
| Symbiote | Loaded into every process through LD_PRELOAD (Intezer) | Files, processes, connections, its own ldd line; steals SSH credentials |
| MEDUSA (UNC3886) | An open-source LD_PRELOAD rootkit (Mandiant) | Logs credentials from local and remote logins |
| PUMAKIT | Kitsune, LD_PRELOAD=/lib64/libs.so beside a kernel module (Elastic) | Userland part of a two-layer rootkit |
Legitimate uses exist but are rare. The Snoopy command logger's enable step adds libsnoopy.so to /etc/ld.so.preload (Snoopy docs). Memory allocators and profilers are normally preloaded per process through the variable, not system-wide.
Why ls, cat and ldd on the host may lie
Every dynamically linked tool you run on an infected host contains the rootkit:
-
ls,find,ps,top. They read directories throughreaddir. libprocesshider drops/proc/<pid>entries; Azazel and Symbiote drop files on their lists. -
cat,stat,test -e. They go throughopen,fopenand thestatfamily. Azazel hides any path containingld.so.preload, socat /etc/ld.so.preloadreports that the file does not exist. -
netstat,ss. They read/proc/net/tcpthroughfopenor walk/procfor owners; Symbiote filters the former. -
tcpdump. Symbiote hooks libpcap and attaches its own BPF filter ahead of yours. -
Your shell. Expanding
/proc/[0-9]*or*.sousesreaddirinside bash. -
ldd. It runs the dynamic linker withLD_TRACE_LOADED_OBJECTS=1(ldd(1)), so the preloaded library is loaded first:- Symbiote's
execvehook removes its own line when it sees that variable; - Azazel renames
/etc/ld.so.preloadto/etc/.ld.so.preloadwhilelddorunhideruns, then renames it back.
The manual also warns that
lddmay execute the program it inspects. - Symbiote's
What does not lie:
- Statically linked programs. They never run the dynamic linker.
- The kernel. A userland rootkit cannot change what the kernel returns to a program that does not carry it:
/proc/<pid>/mapsread by a static tool, the bytes on the block device read by a clean system, a capture taken on another machine.
That stops being true if a kernel rootkit is present too.
Offline checks
From an image mounted read-only on a clean machine:
R=/mnt/evidence
ls -la --time-style=full-iso "$R"/etc/ld.so.preload "$R"/etc/.ld.so.preload 2>&1
cat "$R"/etc/ld.so.preload
cat "$R"/etc/ld.so.conf "$R"/etc/ld.so.conf.d/*.conf
ldconfig -p -C "$R"/etc/ld.so.cache | grep -v -E '=> /(usr/)?lib(64|/x86_64-linux-gnu|/aarch64-linux-gnu)?/[^/]+$' | head # cached libraries outside the usual folders
grep -rn 'LD_PRELOAD\|LD_AUDIT\|LD_LIBRARY_PATH' "$R"/etc/environment "$R"/etc/profile "$R"/etc/profile.d "$R"/etc/bash.bashrc \
"$R"/etc/systemd "$R"/root/.[a-z]* "$R"/home/*/.[a-z]* "$R"/home/*/.ssh/environment 2>/dev/null
grep -rn 'env_keep' "$R"/etc/sudoers "$R"/etc/sudoers.d 2>/dev/null
For each library named in the preload file or an LD_PRELOAD setting:
L="$R/usr/local/lib/libexample.so" # the path from the file, inside the image
file "$L"
readelf --dyn-syms -W "$L" | awk '$7 != "UND" && $4 == "FUNC" {print $8}' | sort | head -60 # functions it defines
readelf -d "$L" | grep -E 'NEEDED|SONAME'
strings -a -n 5 "$L" | head -80
grep -l "$(basename "$L")" "$R"/var/lib/dpkg/info/*.list 2>/dev/null || echo "no dpkg package lists it"
debugfs -R "stat ${L#"$R"}" /dev/loop0p1 2>/dev/null | grep -E 'crtime|ctime|mtime' # ext4 birth time, read from the image device
What to look for:
- libc names in the exports. A library that defines
readdir,readdir64,fopen,opendir, thestatfamily,execve,accept,pam_authenticateorpcap_loopis replacing them. Ordinary libraries do not define libc's functions. - Where it lives. Outside the distribution's library folders, or under a name imitating a system library (Azazel's default
/lib/libselinux.sobeside the reallibselinux.so.1). - Who owns it. No package owns it.
- Strings. Libprocesshider's hidden name is in plain text; Azazel encodes its strings.
- Times. The library's birth time and the preload file's change time are the best estimate of when hiding started. Azazel's rename trick resets the preload file's change time each time
lddruns.
ldconfig -C reads the image's cache instead of the analysis machine's. debugfs gives the ext4 birth time; on XFS use xfs_db. Replace /dev/loop0p1 with the image's partition device.
Live checks
Bring a statically linked toolkit on read-only media and start its shell first:
/media/ir/busybox sh # everything below runs inside the static shell
/media/ir/busybox cat /etc/ld.so.preload
/media/ir/busybox ls -la /etc/ld.so.preload /etc/.ld.so.preload
/media/ir/busybox grep -h '\.so' /proc/[0-9]*/maps | /media/ir/busybox awk '{print $6}' | /media/ir/busybox sort | /media/ir/busybox uniq -c | /media/ir/busybox sort -rn | /media/ir/busybox head -40
/media/ir/busybox grep -l 'LD_PRELOAD' /proc/[0-9]*/environ
/media/ir/busybox grep -l '(deleted)' /proc/[0-9]*/maps # libraries deleted from disk but still mapped
- Library counts. The
mapscount lists each mapped library and how many processes map it. With system-wide preloading, one unfamiliar library appears in almost every process, next to libc and the dynamic linker. - Preload variables.
LD_PRELOADin anenvironfile shows a per-process preload, such as Kitsune's. - Two views. Compare the static tool's output with the host's own
cat /etc/ld.so.preloadandps. A difference is strong evidence of an active rootkit. - Reading the device. On ext4,
debugfs -R 'cat /etc/ld.so.preload' /dev/sda1reads the file from the block device rather than through libc.debugfsis dynamically linked, so prefer a static build. - Capture memory if the host matters. Volatility 3's
linux.proc.Maps,linux.envarsandlinux.library_listshow the same evidence from the image (memory forensics).
A collection taken on the live host by a normal, dynamically linked script reads the file system through the rootkit. If the archive lacks /etc/ld.so.preload, that may be the rootkit's doing. Collect with static tools, or image the disk.
What offline checks cannot prove
- A preload set for one service through a unit file or a wrapper leaves no trace in
/etc/ld.so.preload. You have to find the setting. - A library deleted after loading stays in running processes until they restart, and only memory or a live
mapsread shows it. - Hooks without preloading. A trojanised libc or a replaced
pam_unix.sohooks without any preload file. Compare system libraries with their packages. - A kernel rootkit underneath defeats static tools and live reads alike. See checking kernel modules offline.
- Intent. A library's exports show what it can intercept, not what it did. That needs reverse engineering or memory.
What an offline rootkit check can prove puts this in context with the other layers.
With the checker
The rootkits.dev checker reads etc/ld.so.preload, the libraries it names and other shared objects in an image or a collection. It flags:
- each entry of the file, as "Library preloaded into every program";
- an entry outside the packaged library folders (
/lib,/usr/lib,/lib64,/usr/lib64and their multiarch subfolders), as "Preloaded library outside the system library folders", with whether a dpkg package owns it; - a library that defines libc's directory-listing or file-access functions, as "Library replaces libc directory and file functions", with the function names as evidence, whether or not a preload entry names it. Process, network and authentication names are listed in the detail sheet without a finding of their own;
- an entry whose library is missing from the collection, as "Preloaded library not read" (the same finding covers a library in a system folder larger than 256 KiB, which the checker skips).
The fin-jump-01 sample host shows a synthetic example: its /etc/ld.so.preload, written at 10:08:47 UTC on 2026-09-14, names /usr/local/lib/libraplmon.so.1, written seven seconds earlier, which exports readdir, readdir64, fopen and fopen64. The sample walk-through reads it. The checker does not read LD_PRELOAD settings in environment or unit files, or /proc/<pid>/maps. It cannot tell whether a live collection was filtered.
Cleaning up
- Preserve the preload file, the library, their times and a static-tool view of running processes. Capture memory if you can.
- Remove the preload line, or the file if nothing legitimate uses it, then the library. Restart services or reboot so no process keeps it mapped.
- Find what was hidden (miners, shells, credential logs) and how the intruder got root.
- Rebuild when you cannot account for everything root did. Rotate every credential that passed through PAM, SSH or
sudoon the host while the library was loaded. - Alert on future writes and renames of
/etc/ld.so.preloadand/etc/ld.so.conf.d/.
Frequently asked questions
Is /etc/ld.so.preload ever legitimate?
Rarely. It is absent on default Debian, Ubuntu and RHEL installs. Some tools use it on purpose, such as the Snoopy command logger, whose enable command adds libsnoopy.so to it. Any entry should name a library that a package owns and that someone on the team can explain.
Why does ldd not show the rootkit library?
ldd runs the dynamic linker with LD_TRACE_LOADED_OBJECTS=1, so the preloaded library is already inside ldd's own process and the program it inspects. Symbiote removes itself from the output when it sees that variable, and Azazel moves /etc/ld.so.preload aside while ldd or unhide runs. ldd can also execute the program it inspects. Use readelf or objdump, preferably on a clean machine.
Does a static busybox see past a preload rootkit?
Yes, for userland rootkits: a statically linked program never runs the dynamic linker, so /etc/ld.so.preload does not apply to it. Start a static shell first, because your normal shell expands globs through the hooked readdir. A static tool does not help against a kernel rootkit, which filters the system calls themselves.
If I delete /etc/ld.so.preload, is the host clean?
New programs stop loading the library at once, but processes already running keep it mapped until they restart. What the library hid (a miner, a backdoor, a credential log) is still there, and an intruder who could write the file had root. Preserve evidence first, then decide whether to rebuild.