Site icon GetPageSpeed

Sane use of rkhunter in CentOS 7

Linux Command Line

Linux Command Line

rkhunter is the last thing you should use

If there is a rootkit in your system, it has all the privileges in the system. These include complete hiding from any tool like rkhunter. The rkhunter is only useful as detection for lazy rootkits, that is, authored by lazy hackers 🙂 Or, as a supplementary tool for checking validity of a few base system programs it monitors, against RPM database. Which might be only useful to detect corrupted hard drives..

With all this in mind, proceed.

The problem of broken/unfinished rkhunter workflow

So you’ve installed rkhunter and let its cron run every day? Only to nag you with false positive every time you update a package via yum.

E.g. rkhunter output after updating system via yum upgrade:

Warning: The file properties have changed:
        File: /usr/bin/pgrep
        Current inode: 470397    Stored inode: 34965
Warning: The file properties have changed:
        File: /usr/bin/pkill

But why?

With PKGMGR=RPM in /etc/rkhunter.conf you tell rkhunter the source of information about genuine, unmodified system programs. RPM database is being consulted only when you run --propupd. But not when you run --check!

So rkhunter does not do any magic check against RPM database after every yum update.

How can we make things better?

If we install packages from a YUM repository, we already assume that the repository is giving us genuine and secure packages. So in general, having rkhunter trust yum installed/updated packages automatically is a good idea to reduce false positives.

rkhunter + yum updates setup

yum -y install yum-plugin-post-transaction-actions
echo '*:any:echo $name >> /var/lib/rkhunter/updated.txt' > /etc/yum/post-actions/rkhunter.action

Create file /etc/cron.daily/0rkhunter:

#!/bin/bash

if [[ -f /var/lib/rkhunter/updated.txt ]] ; then
    while read in; do /usr/bin/rkhunter --propupdate "$in" > /dev/null; done < /var/lib/rkhunter/updated.txt
    rm -rf /var/lib/rkhunter/updated.txt
fi

Setup permissions:

chmod 0755 /etc/cron.daily/0rkhunter

So what we do is:

We could directly run /usr/bin/rkhunter --propupdate package-name in the yum hook, but I chose the flat file approach so that every yum transaction would not be slowed down.

You may think that between the time a package is installed and the 0rkhunter cron run, which enables trust of its files, our lazy hacker would be able to replace the package’s files manually and the change will be undetected. No, their manual changes would still be reported by rkhunter later on. Imagine the following to happen:

So manual changes to files managed by RPM will be alerted later anyway.

We let rkhunter only nag us when someone manually replaces system files (not via RPM repositories). The convenience of less nagging comes with sort of lessened security.

Potentially a hacker would be able to configure a yum repository in the system and install malicious packages. These changes would not be flagged by rkhunter anymore. But come to think of it:

So trusting yum updates by rkhunter seems like a sane use of it.

Bonus tip. Know your tool

The rkhunter utility does not check file properties of every system file or package you have. It only checks files which are more often replaced by rootkits, the list of which is coded in /bin/rkhunter script source itself under PROP_FILE_LIST.

So if you are to run rkhunter --propupd artbitrary-package-name, you may get:

File or package name is not in the “rkhunter.dat” file: php-pecl-igbinary

or

Warning: The file exists on the system, but it is not present in the rkhunter.dat file

Sources:

Exit mobile version