[ << ]
[ < ]
[ Home ]
[ > ]
[ >> ]
13. Intrusion Detection
13.a. AIDE (Advanced Intrusion Detection Environment)
AIDE is a Host-Based Intrusion Detection System (HIDS), a free alternative to
Tripwire (if you already know Tripwire you should have no difficulties learning
the configuration file for AIDE). HIDS are used to detect changes to important
system configuration files and binaries, generally by making a unique
cryptographic hash for the files to be checked and storing it in a secure
place. On a regular basis (such as once a day), the stored "known-good" hash is
compared to the one generated from the current copy of each file, to determine
if that file has changed. HIDS are a great way to detect disallowed changes to
your system, but they take a little work to implement properly and make good use
The configuration file is based on regular expressions, macros and rules for
files and directories. We have the following macros:
||If not defined
||Define a variable
||@@define "name" "value"
||Undefine a variable
||if not "hostname"
Endif must be used after any of the above macros except define and undef
These macros become very handy if you have more than one Gentoo box and want to
use AIDE on all of them. But not all machines run the same services or even have
the same users.
Next we have sets of flags to check for on files and directories. These are a
combination of permissions, file properties and cryptographic hashes
||number of links
||check for growing size
||Growing logfile p+u+g+i+n+S
And if AIDE is compiled with mhash support it supports a few other features:
Now you can create you own rules based on the above flags by combining them
Code Listing 1.1: Create a ruleset for AIDE
The last thing we need to create our own configuration file is to see how to add
a rule to a file or directory. To enter a rule, combine the file or directory
name and the rule. AIDE will add all files recursively unless you specify an
||Don't add this file or directory.
||Add this directory, but not recursively.
So lets watch a full blown example:
Code Listing 1.2: /etc/aide/aide.conf
@@define TOPDIR /
@@define AIDEDIR /etc/aide
# The location of the database to be read.
# The location of the database to be written.
# Rule definition
In the above example we specify with some macros where the topdir starts and
where the AIDE directory is. AIDE checks the /etc/aide/aide.db file
when checking for file integrity. But when updating or creating a new file it
stores the information in /etc/aide/aide.db.new. This is done so it
won't automatically overwrite the old db file. The option
report_URL is not yet implemented, but the author's intention was that
it should be able to e-mail or maybe even execute scripts.
The AIDE ebuild now comes with a working default configuration file, a helper
script and a crontab script. The helper script does a number of tasks for you
and provides an interface that is a little more script friendly. To see all
available options, try aide --help. To get started, all that needs to be
done is aide -i and the crontab script should detect the database and
send mails as appropriate every day. We recommend that you review the
/etc/aide/aide.conf file and ensure that the configuration
accurately reflects what is in place on the machine.
Depending on your CPU, disk access speed, and the flags you have set on files,
this can take some time.
Remember to set an alias so you get roots mail. Otherwise you will never know
what AIDE reports.
Now there is some risk inherent with storing the db files locally, since the
attacker will (if they know that AIDE is installed) most certainly try to alter
the db file, update the db file or modify /usr/bin/aide. So you
should create a CD or other media and put on it a copy of the .db file and the
One can find information at the AIDE project page.
Snort is a Network Intrusion Detection System (NIDS). To install and configure
it use the following examples.
Code Listing 2.1: /etc/conf.d/snort
SNORT_OPTS="-q -D -u snort -d -l $LOGDIR -h $NETWORK -c $SNORT_CONF"
Copy /etc/snort/snort.conf.distrib to
Code Listing 2.2: /etc/snort/snort.conf
~# cd /etc/snort && cp snort.conf.distrib snort.conf
You might need to comment out the blacklist and whitelist entries
if no lists are created.
More information is at the Snort web site.
13.c. Detecting malware with chkrootkit
HIDS like AIDE are a great way to detect changes to your system, but it never
hurts to have another line of defence. chkrootkit is a utility that scans
common system files for the presence of rootkits--software designed to hide an
intruder's actions and allow him to retain his access--and scans your system for
likely traces of key loggers and other "malware". While chkrootkit (and
alternatives like rkhunter) are useful tools, both for system
maintenance and for tracking an intruder after an attack has occurred, they
cannot guarantee your system is secure.
The best way to use chkrootkit to detect an intrusion is to run it
routinely from cron. To start, emerge
app-forensics/chkrootkit. chkrootkit can be run from the
command line by the command of the same name, or from cron with an entry
such as this:
Code Listing 3.1: Schedule chkrootkit as a cronjob
0 3 * * * /usr/sbin/chkrootkit
[ << ]
[ < ]
[ Home ]
[ > ]
[ >> ]
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-2.5 license. The Gentoo Name and Logo Usage Guidelines apply.