CHKRootkit installation : Différence entre versions
De wikiGite
| Ligne 1 : | Ligne 1 : | ||
| + | __TOC__ | ||
= Sur DEBIAN = | = Sur DEBIAN = | ||
apt-get install chkrootkit | apt-get install chkrootkit | ||
Créer /etc/chkrootkit et y déplacer /etc/chkrootkit.conf | 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<br> | ||
| + | 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 : | 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 | #!/bin/bash | ||
| Ligne 21 : | Ligne 137 : | ||
if [ "$RUN_DAILY" = "true" ]; then | if [ "$RUN_DAILY" = "true" ]; then | ||
if [ "$DIFF_MODE" = "true" ]; then | if [ "$DIFF_MODE" = "true" ]; then | ||
| − | $CHKROOTKIT $RUN_DAILY_OPTS > | + | $CHKROOTKIT $RUN_DAILY_OPTS > $LOG_DIR/log.old 2>&1 |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
else | else | ||
$CHKROOTKIT $RUN_DAILY_OPTS | $CHKROOTKIT $RUN_DAILY_OPTS | ||
| Ligne 37 : | Ligne 148 : | ||
while read LINE | while read LINE | ||
do | do | ||
| − | cat $LOG_DIR/log.alert | grep -v "$LINE" > $LOG_DIR/log.alert | + | # 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 | done < /etc/chkrootkit/exclude.list | ||
# If some alerts stay in file, we cry | # If some alerts stay in file, we cry | ||
| Ligne 46 : | Ligne 160 : | ||
) | $MAIL -s 'chkrootkit Daily Run' $REPORT_MAIL | ) | $MAIL -s 'chkrootkit Daily Run' $REPORT_MAIL | ||
fi | fi | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Version du 30 septembre 2008 à 10:22
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
