Outils personnels

CHKRootkit installation : Différence entre versions

De wikiGite

Ligne 21 : Ligne 21 :
 
(/var/cache/chkrootkit/log.old contient tous les messages, log.alert doit être vide si exclude.list est ok)
 
(/var/cache/chkrootkit/log.old contient tous les messages, log.alert doit être vide si exclude.list est ok)
  
 +
= Sur CentOS =
 +
<span style="color:green">Procédure validée</span>
 +
yum install chkrootkit --enablerepo=rpmforge
 +
 +
<!--
 
= Sur CentOS4/BQ =
 
= Sur CentOS4/BQ =
 
<span style="color:green">Procédure validée</span>
 
<span style="color:green">Procédure validée</span>
Ligne 52 : Ligne 57 :
 
  mkdir /etc/chkrootkit
 
  mkdir /etc/chkrootkit
 
  cd /etc/chkrootkit
 
  cd /etc/chkrootkit
 +
-->
  
 
Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR CENTOS :
 
Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR CENTOS :
Ligne 62 : Ligne 68 :
 
  redirectUrl: /base/vsite/vsiteList.php
 
  redirectUrl: /base/vsite/vsiteList.php
  
'''NOTE''' : pour '''E-photo''', ajouter une tache cron.daily pour éviter des faux-positifs dans /tmp<br>
+
'''NOTE''' : on peut ajouter une tache cron.daily pour éviter des faux-positifs dans /tmp. Exemple :<br>
/opt/systools/before-chkrootkit.sh (chmod 700 et créer un lien dans /etc/cron.daily):
+
/opt/before-chkrootkit.sh (chmod 700 et créer un lien dans /etc/cron.daily):
 
  #!/bin/bash
 
  #!/bin/bash
  # 05/2008 faux-positifs sur fichiers /tmp/php_writeexcel*
+
  # faux-positifs sur fichiers /tmp/php_writeexcel*
 
  find /tmp -name "php_writeexcel*" -ctime +1 -exec rm {} \;
 
  find /tmp -name "php_writeexcel*" -ctime +1 -exec rm {} \;
  
 +
<!--
 
= Sur CentOS5/BlueOnyx =
 
= Sur CentOS5/BlueOnyx =
 
Erreur à la compilation :
 
Erreur à la compilation :
Ligne 73 : Ligne 80 :
 
  chkwtmp.c:95: warning: incompatible implicit declaration of built-in function ‘exit’
 
  chkwtmp.c:95: warning: incompatible implicit declaration of built-in function ‘exit’
 
mais chkrootkit fonctionne quand même
 
mais chkrootkit fonctionne quand même
 +
-->
  
 
=== chkrootkit.sh ===
 
=== chkrootkit.sh ===
Créer /opt/systools/chkrootkit.sh, pour qu'il ressemble à ça :
+
Créer /opt/chkrootkit.sh, pour qu'il ressemble à ça :
 
  #!/bin/bash
 
  #!/bin/bash
 
   
 
   

Version du 7 août 2013 à 13:25

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=rpmforge


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
CF=/etc/chkrootkit/chkrootkit.conf
EXCLUDEF=/etc/chkrootkit/exclude.list
MAIL=$(which mail)
LOG_DIR=/var/cache/chkrootkit

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

if [ -f $CF ]; then
    . $CF
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 < /etc/chkrootkit/exclude.list
# 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)