CHKRootkit installation : Différence entre versions
De wikiGite
|  (→Sur CentOS) | |||
| (13 révisions intermédiaires par 2 utilisateurs non affichées) | |||
| Ligne 6 : | Ligne 6 : | ||
|   mv /etc/chkrootkit.conf /etc/chkrootkit |   mv /etc/chkrootkit.conf /etc/chkrootkit | ||
| − | + | Créer /etc/chkrootkit/chkrootkit.conf (cf [[#chkrootkit.conf|chkrootkit.conf]]) | |
| Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR DEBIAN : | Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple POUR DEBIAN : | ||
| Ligne 14 : | Ligne 14 : | ||
|   eth0: PACKET SNIFFER(/usr/sbin/snort |   eth0: PACKET SNIFFER(/usr/sbin/snort | ||
| − | Editer / | + | Editer /opt/systools/chkrootkit.sh (cf [[#chkrootkit.sh|chkrootkit.sh]]) | 
| '''Pour finir''' | '''Pour finir''' | ||
| 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=epel | ||
| + |  mkdir /etc/chkrootkit | ||
| + | <!-- | ||
| = 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 26 : | Ligne 31 : | ||
|   wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz |   wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz | ||
|   tar -xvzf chkrootkit.tar.gz |   tar -xvzf chkrootkit.tar.gz | ||
| − |   cd chkrootkit-0. | + |   cd chkrootkit-0.49/ | 
|   make sense |   make sense | ||
| 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 : | ||
|   Warning: '/' is not an ordinary file |   Warning: '/' is not an ordinary file | ||
| Ligne 64 : | Ligne 67 : | ||
|   redirectUrl: /base/vsite/vsiteList.php |   redirectUrl: /base/vsite/vsiteList.php | ||
| − | + | '''NOTE''' : on peut ajouter une tache cron.daily pour éviter des faux-positifs dans /tmp. Exemple :<br> | |
| − | + | /opt/before-chkrootkit.sh (chmod 700 et créer un lien dans /etc/cron.daily): | |
| − | |||
| − | '''NOTE''' :  | ||
| − | /etc/cron.daily | ||
|   #!/bin/bash |   #!/bin/bash | ||
| − |   #  | + |   # 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 80 : | Ligne 79 : | ||
|   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 === | |
| − | + | Créer /opt/chkrootkit.sh, pour qu'il ressemble à ça : | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | === chkrootkit === | ||
| − | |||
|   #!/bin/bash |   #!/bin/bash | ||
| − | |||
|   CHKROOTKIT=/usr/sbin/chkrootkit |   CHKROOTKIT=/usr/sbin/chkrootkit | ||
| − | + |   CONF=/etc/chkrootkit/chkrootkit.conf | |
| − | + |   EXCLUDE=/etc/chkrootkit/chkrootkit.exclude | |
|   MAIL=$(which mail) |   MAIL=$(which mail) | ||
|   LOG_DIR=/var/cache/chkrootkit |   LOG_DIR=/var/cache/chkrootkit | ||
| Ligne 101 : | Ligne 93 : | ||
|   fi |   fi | ||
| − |   if [ -f $ | + |   if [ -f $CONF ]; then | 
| − |       . $ | + |       . $CONF | 
|   fi |   fi | ||
| Ligne 122 : | Ligne 114 : | ||
|      cat $LOG_DIR/log.alert | grep -v "$LINE" > $LOG_DIR/log.a2 |      cat $LOG_DIR/log.alert | grep -v "$LINE" > $LOG_DIR/log.a2 | ||
|      mv $LOG_DIR/log.a2 $LOG_DIR/log.alert |      mv $LOG_DIR/log.a2 $LOG_DIR/log.alert | ||
| − |   done <  | + |   done < $EXCLUDE | 
|   # If some alerts stay in file, we cry |   # If some alerts stay in file, we cry | ||
|   if [ -s $LOG_DIR/log.alert ] |   if [ -s $LOG_DIR/log.alert ] | ||
| Ligne 131 : | Ligne 123 : | ||
|   fi |   fi | ||
| Ne pas oublier | Ne pas oublier | ||
| − |   chmod 700 /etc/cron.daily/chkrootkit | + |   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 === | === chkrootkit.conf === | ||
| − | Editer /etc/chkrootkit/chkrootkit.conf, modifier : | + | Editer /etc/chkrootkit/chkrootkit.conf, modifier (Attention au mail de l'admin !): | 
|   RUN_DAILY="true" |   RUN_DAILY="true" | ||
|   RUN_DAILY_OPTS="-q" # -q=quiet mode |   RUN_DAILY_OPTS="-q" # -q=quiet mode | ||
|   DIFF_MODE="true" # garde un /var/cache/chkrootkit/log.old pour comparer la prochaine fois |   DIFF_MODE="true" # garde un /var/cache/chkrootkit/log.old pour comparer la prochaine fois | ||
| − | |||
|   REPORT_MAIL=<mail_admin>@example.net |   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.<br> | ||
| + | (/var/cache/chkrootkit/log.old contient tous les messages, log.alert doit être vide si exclude.list est ok) | ||
Version actuelle datée du 13 août 2013 à 16:29
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)

