Securus Journal 43.65°N, 79.38°W

Checking a Linux host for rootkits with chkrootkit

What a rootkit attacks, how chkrootkit looks for the known ones, why its results need a second opinion, and how to run it on a schedule.

Contents

In his Turing Award lecture, published in 1984 as “Reflections on Trusting Trust,” Ken Thompson described a C compiler altered to slip a back door into login whenever it compiled it, and to copy the alteration into any new compiler it built. The source code of both would be clean and the back door would remain. “You can’t trust code that you did not totally create yourself,” he concluded.

A rootkit is a practical cousin of that idea. It does nothing to get an attacker in; its job is to keep one hidden afterwards. Early Unix kits replaced the tools an administrator would look with, so that ls, ps and netstat stopped showing the intruder’s files, processes and connections. Later kits moved into the kernel as loadable modules, where they could filter what every program was told. In 2005 Mark Russinovich found one on his own Windows machine and traced it to the copy protection on a Sony BMG music CD.

The attack is on the instruments, and anything that checks for a rootkit has to be read with that in mind.

What it is

chkrootkit, written by Nelson Murilo and Klaus Steding-Jessen, is a small collection of shell and C programs that look for known signs of rootkit infection on a Linux system. It checks core utilities (ps, ls, ifconfig, netstat) against known patterns of tampering, looks for suspicious modifications in login services, and watches for the kinds of changes a loadable kernel module rootkit would make, such as processes hidden from ps.

It is a quick, lightweight check, well short of a full EDR, and it should run regularly as a baseline.

Installing

On Debian or Ubuntu:

sudo apt update
sudo apt install chkrootkit

No configuration is needed. The default ruleset is what almost everyone uses.

Running a scan

sudo chkrootkit

A clean run produces output like:

Checking 'sshd'... not infected
Checking 'ifconfig'... not infected
Checking 'login'... not infected

When something looks wrong, the output flags it explicitly:

Warning: Possible LKM Trojan installed

That kind of warning is a starting point, not a verdict. chkrootkit has a reputation for false positives, so any hit needs corroboration before the host is treated as compromised. Pair it with rkhunter, with AIDE for file integrity, and with knowledge of what was recently changed on the machine. Some warnings are habitual: a DHCP client holding a raw socket can be reported as a packet sniffer, and a process that exits in the middle of a scan can trip the hidden-process check.

The tools it borrows

Thompson’s problem applies to chkrootkit itself. To do its work it calls ordinary system commands, among them awk, grep, ps and strings, and on a compromised machine those are the very commands a rootkit replaces. Its authors anticipated this. The -p option tells it where to find known-good copies of the commands it uses, for example from read-only media:

sudo chkrootkit -p /mnt/safe/bin

The stronger check runs from outside the suspect system altogether. Boot a rescue image, mount the suspect disk, and point chkrootkit at it with -r, which treats a directory as the root of the system to examine:

sudo chkrootkit -r /mnt

A kernel-level rootkit cannot lie to a kernel that is not running.

Where it fits

This is one tool in a layered host-security setup. It does not replace endpoint protection, it does not catch novel rootkits that match none of its signatures, and it does not give you forensics. What it does give you is a regular, scriptable check that takes seconds to run and flags the obvious cases.

For a homelab or a small fleet that is useful. It is a smoke alarm, and a smoke alarm has never put out a fire.

Running it on a schedule

A weekly cron entry that logs to a dated file:

@weekly root chkrootkit > /var/log/chkrootkit-$(date +\%F).log

The line names the user it runs as, root, so it belongs in a system crontab: /etc/crontab or a file of its own under /etc/cron.d/. A personal crontab edited with crontab -e has no user field and would read root as the command. The \% is escaped because cron treats % as a line separator.

The resulting logs are easy to diff over time, which is more useful than any single scan; the question is rarely “is anything wrong right now?” and more often “what changed since last week?” A rootkit can make a machine look normal on any given day. It is harder for it to make this week look exactly like last week.

Sources

  • Thompson, Ken. “Reflections on Trusting Trust.” Communications of the ACM 27, no. 8 (August 1984): 761 to 763.
  • Russinovich, Mark. “Sony, Rootkits and Digital Rights Management Gone Too Far.” Sysinternals blog, 31 October 2005.
  • Murilo, Nelson, and Klaus Steding-Jessen. chkrootkit README and manual page.