Outils personnels

CHKRootkit installation

De wikiGite

Révision datée du 13 août 2013 à 16:29 par Frank (discussion | contributions) (Sur CentOS)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Sur DEBIAN

Procédure validée

apt-get install chkrootkit
mkdir /etc/chkrootkit
mv /etc/chkrootkit.conf /etc/chkrootkit

Créer /etc/chkrootkit/chkrootkit.conf (cf chkrootkit.conf)

Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR DEBIAN :

The following suspicious files and directories were found:
/lib/init/rw/.ramfs
INFECTED (PORTS:  465)
eth0: PACKET SNIFFER(/usr/sbin/snort

Editer /opt/systools/chkrootkit.sh (cf chkrootkit.sh)

Pour finir

Lancer /etc/cron.daily/chkrootkit pour vérifier qu'il fonctionne et récupérer les messages.
(/var/cache/chkrootkit/log.old contient tous les messages, log.alert doit être vide si exclude.list est ok)

Sur CentOS

Procédure validée

yum install chkrootkit --enablerepo=epel
mkdir /etc/chkrootkit

Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR CENTOS :

Warning: '/' is not an ordinary file
.packlist
The tty of the following user process(es) were not found
in /var/run/utmp
RUID
/sbin/mingetty
redirectUrl: /base/vsite/vsiteList.php

NOTE : on peut ajouter une tache cron.daily pour éviter des faux-positifs dans /tmp. Exemple :
/opt/before-chkrootkit.sh (chmod 700 et créer un lien dans /etc/cron.daily):

#!/bin/bash
# faux-positifs sur fichiers /tmp/php_writeexcel*
find /tmp -name "php_writeexcel*" -ctime +1 -exec rm {} \;

chkrootkit.sh

Créer /opt/chkrootkit.sh, pour qu'il ressemble à ça :

#!/bin/bash
CHKROOTKIT=/usr/sbin/chkrootkit
CONF=/etc/chkrootkit/chkrootkit.conf
EXCLUDE=/etc/chkrootkit/chkrootkit.exclude
MAIL=$(which mail)
LOG_DIR=/var/cache/chkrootkit

if [ ! -x $CHKROOTKIT ]; then
  exit 0
fi

if [ -f $CONF ]; then
    . $CONF
fi

if [ "$RUN_DAILY" = "true" ]; then
    if [ "$DIFF_MODE" = "true" ]; then
        $CHKROOTKIT $RUN_DAILY_OPTS > $LOG_DIR/log.old 2>&1
    else
        $CHKROOTKIT $RUN_DAILY_OPTS
    fi
fi
# Mail alert
# No future for empty lines
cat $LOG_DIR/log.old | grep -v -e '^$' > $LOG_DIR/log.alert
# We drop lines listed in $EXCLUDEF by suppress them line by line
while read LINE
do
   # unlike Debian, writing the cat output to the same file does'nt seem to work on CentOS
   # We use a temporary file a2
   cat $LOG_DIR/log.alert | grep -v "$LINE" > $LOG_DIR/log.a2
   mv $LOG_DIR/log.a2 $LOG_DIR/log.alert
done < $EXCLUDE
# If some alerts stay in file, we cry
if [ -s $LOG_DIR/log.alert ]
then
        (echo "CHKROOTKIT Alert :"
         cat $LOG_DIR/log.alert
        ) | $MAIL -s 'chkrootkit Daily Run' $REPORT_MAIL
fi

Ne pas oublier

chmod 700 /opt/systools/chkrootkit.sh

Créer un lien dans /etc/cron.daily

ln -s /opt/systools/chkrootkit.sh /etc/cron.daily/chkrootkit

chkrootkit.conf

Editer /etc/chkrootkit/chkrootkit.conf, modifier (Attention au mail de l'admin !):

RUN_DAILY="true"
RUN_DAILY_OPTS="-q" # -q=quiet mode
DIFF_MODE="true" # garde un /var/cache/chkrootkit/log.old pour comparer la prochaine fois
REPORT_MAIL=<mail_admin>@example.net

Pour finir

Lancer /etc/cron.daily/chkrootkit pour vérifier qu'il fonctionne et récupérer les messages.
(/var/cache/chkrootkit/log.old contient tous les messages, log.alert doit être vide si exclude.list est ok)