rkhunter is another nifty program, similar to blockhosts, whose purpose is to scan for rootkits or other malware on your system such as trojans, backdoors, and local exploits. rkhunter differs from blockhosts in that it is a passive program that only reports (potential) problems. It does not provide any active prevention or protection. But what it does do, it does very well. With a typical installation of rkhunter, the following checks are performed:
1. MD5 has comparisons.
2. Default files commonly used by rootkits.
3. Incorrect file placement (moved binaries).
4. Search for suspect strings in LKM and KLD modules.
5. Hidden files.
6. Optional scan within plain text and binary files.
7. Search for old versions of software packages.
rkhunter used to be a part of Fedora Extras, but was taken out of FC6 due to the fact that "in the second quarter of 2006, the founder of Rookit Hunter found out the hard way that maintaining FOSS can be difficult when real-life commitments overrule. Management of the project was taken over by unSpawn, and a project group comprising of developers and testers was formed..." LOL.
This means that we will have to install it from source. Head over to the new RKhunter website:
Click on the SF project page link, followed by the Download Rootkit Hunter link. Download the latest version, which at the time of this writing is rkhunter-1.3.0.tar.gz. Next, create an appropriate directory to install RKhunter under /usr/local/src:
~>
sudo mkdir /usr/local/src/rkhunter
Copy the source tarball to the
directory: ~>
sudo cp ~/Download/rkhunter-1.3.0.tar.gz /usr/local/src/rkhunter/.
Change into the rkhunter
directory: ~>
cd /usr/local/src/rkhunter
and decompress the source: ~>
sudo tar vfzx rkhunter-1.3.0.tar.gz
Once the package has been
decompressed, delete the source file, and change the ownership
of the rkhunter-1.2.9
directory to root: ~>
sudo rm rkhunter-1.3.0.tar.gz
~> sudo chown root.root -R rkhunter-1.3.0
Next, login as root and change
into the rkhunter-1.3.0 directory:~> sudo chown root.root -R rkhunter-1.3.0
~>
su
# cd rkhunter-1.3.0
Next, run the installer script to
install rkhunter:# cd rkhunter-1.3.0
# ./installer.sh --layout /usr/local --install
Logout of root, and
change into the /usr/local/etc
directory to configure rkhunter: #
exit
~> cd /usr/local/etc
We are now ready to edit the /usr/local/etc/rkhunter.conf
file using sudo.
The first thing we need to do is specify the logfile location,
whitelist a few scripts that are a part of a typical installation for
Fedora 8, and add options for allowing a few
hidden directories and a temporary Pulse Audio file in /dev/shm. For example, the following information should
be added/uncommented:~> cd /usr/local/etc
LOGFILE=/var/log/rkhunter/rkhunter.log
SCRIPTWHITELIST=/sbin/ifup
SCRIPTWHITELIST=/sbin/ifdown
SCRIPTWHITELIST=/usr/bin/groups
SCRIPTWHITELIST=/usr/bin/GET
SCRIPTWHITELIST=/usr/bin/ldd
SCRIPTWHITELIST=/usr/bin/whatis
ALLOWHIDDENDIR=/etc/.java
ALLOWHIDDENDIR=/dev/.udev
ALLOWHIDDENFILE=/etc/.java
ALLOWHIDDENFILE=/usr/share/man/man1/..1.gz
ALLOWHIDDENFILE=/etc/.pwd.lock
ALLOWDEVFILE=/dev/shm/pulse-shm-*
XINETD_ALLOWED_SVC=/etc/xinetd.d/rsync
SYSLOG_CONFIG_FILE=/etc/rsyslog.conf
Save and exit. The
logfile is to be placed in /var/log/rkhunter,
so create the directory:SCRIPTWHITELIST=/sbin/ifup
SCRIPTWHITELIST=/sbin/ifdown
SCRIPTWHITELIST=/usr/bin/groups
SCRIPTWHITELIST=/usr/bin/GET
SCRIPTWHITELIST=/usr/bin/ldd
SCRIPTWHITELIST=/usr/bin/whatis
ALLOWHIDDENDIR=/etc/.java
ALLOWHIDDENDIR=/dev/.udev
ALLOWHIDDENFILE=/etc/.java
ALLOWHIDDENFILE=/usr/share/man/man1/..1.gz
ALLOWHIDDENFILE=/etc/.pwd.lock
ALLOWDEVFILE=/dev/shm/pulse-shm-*
XINETD_ALLOWED_SVC=/etc/xinetd.d/rsync
SYSLOG_CONFIG_FILE=/etc/rsyslog.conf
sudo
mkdir /var/log/rkhunter
Next, run rkhunter
using sudo
and check for any updates and update the properties of various commands:
~>
sudo /usr/local/bin/rkhunter --update
~> sudo /usr/local/bin/rkhunger --propupd
Then you can run an initial test scan:~> sudo /usr/local/bin/rkhunger --propupd
~> sudo /usr/local/bin/rkhunter -c
Running rkhunter
manually on a regular basis is tedious, so let's set up a daily scan
report. Create an /etc/cron.daily/rkhunter
file with the following information in it:#!/bin/sh
(/usr/local/bin/rkhunter --versioncheck --nocolors; /usr/local/bin/rkhunter --update --nocolors; /usr/local/bin/rkhunter --cronjob --summary) | /bin/mail -s 'rkhunter Daily Run' root
Make sure that everything fits on a single
line.
Save and exit. Then make the file executable:(/usr/local/bin/rkhunter --versioncheck --nocolors; /usr/local/bin/rkhunter --update --nocolors; /usr/local/bin/rkhunter --cronjob --summary) | /bin/mail -s 'rkhunter Daily Run' root
~>
sudo chmod ugo+x /etc/cron.daily/rkhunter
Next, create an /etc/logrotate.d/rkhunter
file for log rotation with the following information:/var/log/rkhunter/rkhunter.log
{
weekly
notifempty
create 640 root root
}
Save and exit. Now, whenever rkhunter is
run on a daily basis through cron.daily,
a report will be generated and sent to root's
e-mail. A log of the results will also be stored in /var/log/rkhunter/rkhunter.log.
I rarely, if ever, log in as root,
so I find it useful to put a forward in root's home
directory to forward any e-mails sent to root to your
user directory instead. First, login as root:weekly
notifempty
create 640 root root
}
~>
su -
Type in root's
password, and change your directory into root's home
directory:#
cd ~
# pwd
/root
#
Then put a .forward file
in root's
home directory so that it forwards any e-mail sent to root to your
account. This is done by placing an appropriate e-mail address
(where you want it forwarded to) in the /root/.forward
file:# pwd
/root
#
[username]@[domain].[name]
Save and exit,
and log out of root:#
exit
~>
rkhunter
is now setup, and will send you an e-mail report every morning with the
results of the scan. If a problem shows up in the report, it
gives you a starting point to determine whether your system has been
broken into. It is by no means failsafe, as logs can be edited
and deleted, but it does provide another layer of defense against a
potential hacker.~>


