CHKRootkit installation
De wikiGite
Sommaire
Sur DEBIAN
apt-get install chkrootkit
Créer /etc/chkrootkit et y déplacer /etc/chkrootkit.conf
Editer /etc/cron.daily/chkrootkit, pour qu'il ressemble à ça :
Editer /etc/chkrootkit/chkrootkit.conf, modifier :
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
et y ajouter
REPORT_MAIL=fsoyer@systea.net
Et enfin créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple :
The following suspicious files and directories were found: /lib/init/rw/.ramfs INFECTED (PORTS: 465) eth0: PACKET SNIFFER(/usr/sbin/snort
Sur CentOS/BQ
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz tar -xvzf chkrootkit.tar.gz cd chkrootkit-0.48/ make sense
Si gcc non trouvé :
yum install gcc
Editer /usr/sbin/chkrootkit
Ajouter entre "unalias dirname > /dev/null 2>&1" et "# Workaround for recent GNU coreutils" :
cd /usr/lib/chkrootkit
Puis :
cp chkrootkit /usr/sbin mkdir /usr/lib/chkrootkit cp chkdirs /usr/lib/chkrootkit cp ifpromisc /usr/lib/chkrootkit cp chkwtmp /usr/lib/chkrootkit cp chklastlog /usr/lib/chkrootkit cp chkutmp /usr/lib/chkrootkit cp check_wtmpx /usr/lib/chkrootkit cp chkproc /usr/lib/chkrootkit cp strings-static /usr/lib/chkrootkit mkdir /var/cache/chkrootkit mkdir /etc/chkrootkit cd /etc/chkrootkit
Créer /etc/chkrootkit/chkrootkit.conf : --idem
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=fsoyer@systea.net
Créer /etc/chkrootkit/exclude.list et y ajouter les phrases à exclure du mail d'alerte, exemple : 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
Editer /etc/cron.daily/chkrootkit, pour qu'il ressemble à ça :
X
- !/bin/bash
CHKROOTKIT=/usr/sbin/chkrootkit CF=/etc/chkrootkit/chkrootkit.conf EXCLUDEF=/etc/chkrootkit/exclude.list MAIL=/bin/mail LOG_DIR=/var/cache/chkrootkit
if [ ! -x $CHKROOTKIT ]; then
exit 0
fi
if [ -f $CF ]; then
. $CF
fi
- 05/2008 faux-positifs sur fichiers /tmp/php_writeexcel*
find /tmp -name "php_writeexcel*" -ctime +1 -exec rm {} \;
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
# write the cat output to the same file seems to not 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
chmod 700 /etc/cron.daily/chkrootkit
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)
#!/bin/bash CHKROOTKIT=/usr/sbin/chkrootkit CF=/etc/chkrootkit/chkrootkit.conf EXCLUDEF=/etc/chkrootkit/exclude.list MAIL=/usr/bin/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