18 oct 2008

Serveur Dédié Debian Etch 64bit chez OVH – Protection contre les rootkits

GNU/Linux No Comments

Ils existent deux services permettant de détecter d’éventuels rootkits sur votre serveur :

  • chkrootkit
  • rkhunter

Commençons par les installer :

apt-get install chkrootkit rkhunter libmd5-perl

Configuration de RKHunter suivant votre système, ce script modifie des dossier cachés de Débian pour qu’il soit ignorés de rkhunter et modifie la directive du login root suivant la configuration.
Dans notre cas, le login root est interdit :

SSH_ROOT_ALLOWED=0
TEST_ROOT_ALLOWED=$(/bin/grep -i "PermitRootLogin.*yes" /etc/ssh/sshd_config)
if [ -n "$TEST_ROOT_ALLOWED" ]; then
SSH_ROOT_ALLOWED=1
fi
/bin/sed -i -e 's|^[#]*(ALLOWHIDDENDIR=/dev/.udev)$|1|' \ 
-e 's|^[#]*(ALLOWHIDDENDIR=/dev/.static)$|1|' \
-e 's|^[#]*(ALLOWHIDDENDIR=/dev/.initramfs)$|1|' \
-e "s|^[#]*\(ALLOW_SSH_ROOT_USER=\).*$|\1${SSH_ROOT_ALLOWED}|" \ 
/etc/rkhunter.conf

Vous pouvez copiez/collez le bloc directement dans la console.

Vous pouvez ensuite modifier l’email de la tache CRON pour recevoir l’email du rapport rkhunter, en éditant le fichier /etc/default/rkhunter :

# Defaults for rkhunter cron jobs
# sourced by /etc/cron.*/rkhunter
#
# This is a POSIX shell fragment
#
# Set this to the email address where reports and run output should be sent
REPORT_EMAIL="monemail"
 
# Set this to yes to enable rkhunter weekly database updates
CRON_DB_UPDATE="yes"
 
# Set this to yes to enable reports of weekly database updates
DB_UPDATE_EMAIL="yes"
 
# Set this to yes to enable rkhunter daily runs
CRON_DAILY_RUN="yes"

Pour que chkrootkit s’exécute tous les jours la commande suivante :

/bin/sed -i -e 's/RUN_DAILY=.*/RUN_DAILY="true"/' /etc/chkrootkit.conf

Il y a un faux positif, qui devrait être corrigé dans un patch prochain, en attendant, éditez le fichier /usr/sbin/chkrootkit (Ligne 700 environ) :

if [ "${QUIET}" != "t" ]; then printn 
"Searching for suspicious files and dirs, it may take a while... "; fi
files=`${find} ${DIR} -name ".[A-Za-z]*" -o -name "...*" -o -name ".. *"`
dirs=`${find} ${DIR} -type d -name ".*"`
if [ "${files}" = "" -a "${dirs}" = "" ]
then

Modifiez la ligne files par :

files=`${find} ${DIR} \( -name ".[A-Za-z]*" -o -name "...*" -o -name ".. *" \) -and -not -wholename /lib/init/rw/.ramfs`

Pour recevoir un rapport quotidien sur votre email, editez le fichier /etc/crontab et ajoutez les lignes suivantes :

0 3 * * * root `chkrootkit 2>&1 | mail moi@monemail.com -s "Résultats de chkrootkit MONSERVEUR"`
5 3 * * * root `rkhunter -c --cronjob 2>&1 | mail moi@monemail.com -s "Résultats de rkhunter MONSERVEUR"`

Pour le moment, les emails ne sont pas délivrés, ils nous faudra d’abord installé le serveur d’emails.
Mais vous pouvez à tout moment lancer l’un ou l’autre pour voir les rapports :

chkrootkit
rkhunter -c

Prochaine étape installation du serveur mysql. :)

No Responses to “Serveur Dédié Debian Etch 64bit chez OVH – Protection contre les rootkits”

Leave a Reply