Linux : Installer et Configurer une passerelle SMTP Anti Virus/Anti Spam sous Ubuntu

Un article de Wiki.Yakakliker.org.

Installer et Configurer une passerelle SMTP Anti Virus/Anti Spam sous Ubuntu

Après de longues et fastidieuses recherches afin de trouver une procédure me permettant d'installer et configurer une passerelle SMTP sous linux, je me suis rendu compte (peut-être ai-je mal cherché ...) qu'il n'existait pas grand chose.

J'apporte donc ma pierre à l'édifice (petite .... la pierre). Cette procédure n'a aucune prétention, je ne suis pas un «Maître» sous Linux, juste un passionné, comme beaucoup avec la ferme volonté de démocratiser un système.

Il s'agit d'une tentative d'adaptation d'une procédure pour Debian.

Je tiens avant tout à remercier :

http://www200.pair.com/mecham/spam

Il s'agit de la procédure originelle (en anglais malheureusement) qui m'a servie de base à la mise en place de la passerelle. Je vous conseille de la lire, elle est géniale ...(et elle permettra certainement de debugger ma procédure ...)

http://forum.ubuntu.fr.org/

Forum où l'on trouve réponse à beaucoup de nos questions

Je tiens aussi à m'excuser d'avance pour toutes les erreurs qu'il va certainement y avoir dans cette procédure.(dues à une certaine incompétence je pense ... mais j'me soigne ....)

N'hésitez pas à me remonter mes erreurs, vos observations et vos modifications sur mon site : http://www.yakakliker.org .

Si vous vous sentez le courage d'améliorer cette doc, n'hésitez surtout pas, « l'union fait la force ... »


Bref, en Avant ...


1)Distrib Utilisée : Ubuntu edge 6.10 Serveur

Elle est disponible à cette adresse : ftp://releases.ubuntu.com/releases/edgy/

Il s'agit de booter sur le CD, passer le language en Francais (F2), puis : Installer sur le disque dur

Nom de machine : SRV01 (A vous de choisir ...)

Methode de partitionnement : Effacer et utiliser tout le disque IDE1 maître (hda) Les puristes crieront au blasphème... je sais, mais un problème à la fois non ?

Appliquez les changements ...

Paramétrage de l'horloge ...

Nom d'utilisateur + mot de passe ....

Sélection des logiciels : J'ai choisit d'installer LAMP server afin de pouvoir installer Webmin ensuite. Ca n'est pas indispensable, certains diront même très certainement déconseillé, à vous de voir ...

Reboot ...


2)Installation de l'interface graphique de base

2ème blasphème (et oui, je les collectionne ...) l'interface graphique : Ô Linuxien du Dimanche entends-je murmurer ! Et bien oui, je l'affirme haut et fort : « La Souris est Belle ! La Souris est grande ! Reine est la Souris ! » n'en déplaise aux puristes, je n'ai pas encore réussit à m'en passer.

Donc, après cette mise au point : Allons y ...

Loggez vous

PARAMETRAGES DES SOURCES

Tapez sur votre triste écran noir :

sudo vi /etc/apt/sources.list

Supprimez le # devant :

deb http://fr.archive.ubuntu.com/ubuntu/ edgy universe deb-src http://fr.archive.ubuntu.com/ubuntu/ edgy universe

deb http://fr.archive.ubuntu.com/ubuntu/ edgy-backports main restricted universe multiverse deb-src http://fr.archive.ubuntu.com/ubuntu/ edgy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu edgy-security main restricted deb-src http://security.ubuntu.com/ubuntu edgy-security main restricted


Rajoutez un # devant deb cdrom:[Ubuntu-Server .........


sudo apt-get update

sudo apt-get install gdm gnome-core xfonts-base xserver-xorg

sudo reboot


Une erreur due au thème apparaît mais il ne faut pas s'inquiéter, en modifiant la fenêtre de connexion tout rentrera dans l'ordre.

La souris est enfin de retour ...


PARAMETRAGES DU COMPTE ROOT


Lancez une fenêtre terminal :

Nous allons maintenant activer le compte Root dans le terminal :

sudo passwd root

Il vous demandera 2 fois le nouveau mot de passe root


3)Installation de Webmin

Téléchargez le package webmin correspondant à ubuntu (.deb) à cette adresse : http://www.webmin.com/download.html

su

(Dorenavant, tout se fera sous le compte root-su-, si vous refermez le terminal pensez à lancer cette commande ...)

apt-get install libnet-ssleay-perl libauthen-pam-perl libio-pty-perl libmd5-perl

cd Desktop


(En toute logique, votre fichier a été téléchargé sur le bureau)


dpkg --install webmin_(numero_de_version_webmin)


Petit test :

Lancez Firefox : https://srv01:10000

login : root

mot de passe : votre mot de passe root

Normalement, votre interface webmin doit s'ouvrir.

Allez dans : Networking/Network Configuration pour les paramétrages IP de votre carte réseau.


4)PARAMETRAGES DE LA PASSERELLE SMTP


Nous allons maintenant nous appuyer sur la doc de http://www200.pair.com/mecham/spam... pour la suite

Editez le fichier Preferences :

vi /etc/apt/preferences

Copiez y ceci :


Package: *

Pin: release a=stable

Pin-Priority: 600


Package: *

Pin: release a=testing

Pin-Priority: 450


Package: *

Pin: release a=unstable

Pin-Priority: 400


Package: *

Pin: release a=edgy-backports

Pin-Priority: 350


Une longue série de commandes :

echo 'APT::Cache-Limit "25165824";' >> /etc/apt/apt.conf

apt-get update

apt-get remove ipchains lpr nfs-common portmap pidentd pcmcia-cs pppoe pppoeconf ppp pppconfig

apt-get install cramfsprogs

cd /usr/local/src

wget http://www200.pair.com/mecham/initrd-tools_0.1.84.1_all.deb

dpkg -i initrd-tools_0.1.84.1_all.deb

echo "initrd-tools hold" | dpkg --set-selections

apt-get -t testing install gcc-3.3

cd /usr/bin

wget http://www200.pair.com/mecham/debian/lsconfig

chmod +x /usr/bin/lsconfig

lsconfig

cp -r /etc/init.d /etc/init.d-original

/etc/init.d/lpd stop

update-rc.d -f lpd remove

/etc/init.d/nfs-common stop

update-rc.d -f nfs-common remove

/etc/init.d/portmap stop

update-rc.d -f portmap remove

/etc/init.d/pcmcia stop

update-rc.d -f pcmcia remove

/etc/init.d/ppp stop

update-rc.d -f ppp remove

/etc/init.d/exim4 stop

update-rc.d -f exim4 remove

update-rc.d -f ntpdate remove

update-inetd --disable time

update-inetd --disable daytime

update-inetd --disable echo

update-inetd --disable chargen

update-inetd --disable ident

update-inetd --disable discard

update-inetd --enable ident

/etc/init.d/networking restart

apt-get install ntp-simple ntp-server

/etc/init.d/ntp-server stop

ntpdate clock.fmt.he.net

ntpdate ntp1.tummy.com

/etc/init.d/ntp-server start

apt-get -t sarge-backports install libcompress-zlib-perl

apt-get install arc arj autoconf automake1.7 bzip2 cabextract db4.3-util libarchive-tar-perl libarchive-zip-perl libauthen-sasl-perl libberkeleydb-perl libconvert-binhex-perl libconvert-tnef-perl libconvert-uulib-perl libdb4.3-dev libdbd-mysql-perl libdbi-perl libdigest-hmac-perl libdigest-sha1-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libio-multiplex-perl libio-socket-ssl-perl libio-string-perl unrar libdigest-nilsimsa-perl libmail-audit-perl

apt-get install libio-stringy-perl libio-zlib-perl libldap2 libmail-spf-query-perl libmailtools-perl libmime-perl libnet-dns-perl libnet-ldap-perl libnet-perl libnet-ph-perl libnet-server-perl libnet-snpp-perl libnet-telnet-perl libsocket6-perl libtimedate-perl libtool libunix-syslog-perl liburi-perl libwww-perl lsof lynx lzop make ncftp nomarch pax perl-doc rblcheck unzip unzoo zip zlib1g-dev zoo pyzor razor

apt-get -s upgrade

apt-get upgrade

reboot


INSTALLATION DE POSTFIX ET DE SPAMASSASSIN


(Test afin de voir si Postfix et Spamassassin sont installés)

apt-cache policy postfix spamassassin

Normalement, doit s'afficher :


postfix:

Installé: (aucun)

...

spamassassin:

Installé: (aucun)

(Installation de Spamassassin)


apt-get install spamassassin

(Installation de Postfix)

apt-get install postfix postfix-pcre postfix-mysql postfix-ldap

Postfix Configuration :

Type de configuration : Pas de configuration

(Installation d'Amavis)

adduser --group --system --home /var/lib/amavis --shell /bin/sh amavis

mkdir /var/run/amavis

chown amavis:amavis /var/run/amavis

mkdir /etc/amavis

mkdir /etc/amavis/en_US

mkdir /var/lib/amavis/tmp

mkdir /var/lib/amavis/db

mkdir /var/lib/amavis/var

mkdir /var/lib/amavis/virusmails

chown -R amavis:amavis /var/lib/amavis

chmod -R 750 /var/lib/amavis

cd /etc/amavis

wget http://www200.pair.com/mecham/amavisd/2.4.5/amavisd.conf

wget http://www200.pair.com/mecham/amavisd/2.4.5/amavisd.conf-sample

ln -s /etc/amavis/amavisd.conf /etc/amavisd.conf

cp -r /etc/amavis/en_US /etc/amavis/en_US-backup

cd /etc/amavis/en_US

rm charset

rm template-dsn.txt

rm template-spam-admin.txt

rm template-spam-sender.txt

rm template-virus-admin.txt

rm template-virus-recipient.txt

rm template-virus-sender.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/charset

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-dsn.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-spam-admin.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-spam-sender.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-virus-admin.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-virus-recipient.txt

wget http://www200.pair.com/mecham/amavisd/2.4.5/en_US/template-virus-sender.txt

cd /usr/local/src

wget http://www.ijs.si/software/amavisd/amavisd-new-2.4.5.tar.gz

tar xzvf amavisd-new-2.4.5.tar.gz

cd amavisd-new-2.4.5

test -e /usr/sbin/amavisd-new && cp /usr/sbin/amavisd-new /usr/sbin/amavisd-new-debian

cp amavisd amavisd-new

cp amavisd-new /usr/sbin/amavisd-new

cp amavisd-new /usr/sbin/amavisd-new-2.4.5

cd /etc/init.d

wget http://www200.pair.com/mecham/debian/amavis-init-20030616

mv amavis-init-20030616 amavis

chmod +x amavis

update-rc.d amavis defaults

cd /etc/cron.daily

wget http://www200.pair.com/mecham/crondaily/amavisd-new.txt

mv amavisd-new.txt amavisd-new

chmod +x amavisd-new

cd /etc/cron.d

wget http://www200.pair.com/mecham/crond/amavisd-new.txt

mv amavisd-new.txt amavisd-new

dpkg-statoverride --add amavis amavis 755 /var/lib/amavis

dpkg-statoverride --add amavis amavis 755 /var/lib/amavis/virusmails

dpkg-statoverride --add amavis amavis 755 /var/run/amavis


Configuration de Postfix


apt-get install dpkg-dev

cd /usr/local/src

apt-get source postfix

ls -l

rm postfix*


(le message est normal ...)

ATTENTION : Repondre « n » à la question « overwrite »

cp -i /usr/share/postfix/main.cf.debian /etc/postfix/main.cf

cp -i /usr/local/src/postfix-2.3.3/conf/* /etc/postfix

cp -i /etc/postfix/header_checks /etc/postfix/body_checks

cp -i /etc/postfix/access /etc/postfix/sender_access

MASTER.CF

postfix stop

cd /etc/postfix

mv master.cf master.cf-original

wget http://www200.pair.com/mecham/debian-postfix-2.3-amavisd/master.cf

postconf -e "alias_maps = hash:/etc/aliases"

newaliases

postconf -e "myorigin = mon_domaine.com"

postconf -e "myhostname = srv01.mon_domaine.com"

postconf -e "mynetworks = 127.0.0.0/8, 192.168.x.0/24"

postconf -e "message_size_limit = 10485760"

postconf -e "local_transport = error:no local mail delivery"

postconf -e "mydestination = "

postconf -e "local_recipient_maps = "

postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

vi /etc/postfix/virtual

postmaster postmaster@mon_domaine.com

abuse abuse@mon_domaine.com

postmap /etc/postfix/virtual

postconf -e "relayhost = [smtp.monFai.com]"

postconf -e "relay_recipient_maps = hash:/etc/postfix/relay_recipients"

vi /etc/postfix/relay_recipients


Copiez y votre ou vos domaines ...

@mon_domaine.com OK

@mon_domaine2.com OK

@mon_domaine3.com OK


postmap /etc/postfix/relay_recipients

postconf -e "transport_maps = hash:/etc/postfix/transport"

vi /etc/postfix/transport

mon_domaine.com smtp:[192.168.x.x]

mon_domaine2.com smtp:[192.168.x.x]

mon_domaine3 smtp:[192.168.x.x]


postmap /etc/postfix/transport

postconf -e "relay_domains = mon_domaine.com, mon_domaine2.com, mon_domaine3.com"

postconf -e "recipient_delimiter = "


PARAMETRAGES ANTI SPAM POSTFIX


postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access, reject_non_fqdn_sender, reject_unknown_sender_domain"

postconf -e "smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, reject_unauth_pipelining"

postconf -e "smtpd_data_restrictions = reject_unauth_pipelining"

postconf -e "header_checks = pcre:/etc/postfix/header_checks"

postconf -e "body_checks = pcre:/etc/postfix/body_checks"

postconf -e "content_filter = smtp-amavis:[127.0.0.1]:10024"


Editez :

vi /etc/postfix/sender_access

Copiez y :

#Example sender access map file

makeabuck@mlm.tld 550 No MLM thanks

allspam.tld 550 Spam is not accepted here

badguy.net REJECT

justaspamminfool@allspamallthetime.com REJECT

newsletter-fake-domain.com OK

my-bogus-test-domain.com OK


postmap /etc/postfix/sender_access

postfix start

TEST :

telnet 127.0.0.1 25

Vous devriez avoir:

220 srv01.mon_domaine.com ESMTP Postfix (Debian/GNU

hit [enter] a few times; then type:


quit to exit


CONFIGURER AMAVISD-NEW


cp /etc/amavis/amavisd.conf /etc/amavis/amavisd.conf-2.4.5-original

vi /etc/amavis/amavisd.conf

Enlevez le #

# @bypass_virus_checks_maps = (1);

Verifiez :

$daemon_user = 'amavis';

$daemon_group = 'amavis';


$mydomain = 'mon_domaine.com';

$myhostname = 'srv01.mon_domaine.com';

@local_domains_maps = ( [ ".$mydomain", '.mon_domaine2.com', '.domaine3.com' ] );

$sa_tag_level_deflt = undef;

$sa_tag2_level_deflt = 5.0;

$sa_kill_level_deflt = 8.0;


rajoutez :

$banned_admin = "postmaster\@$mydomain"

modifiez :

$mailfrom_notify_admin = "postmaster\@$mydomain";

$mailfrom_notify_recip = "postmaster\@$mydomain";

$mailfrom_notify_spamadmin = "postmaster\@$mydomain";

enlevez le # :

# $hdrfrom_notify_sender = "amavisd-new <postmaster\@$mydomain>";

Verifiez :

$recipient_delimiter = ;

$final_spam_destiny = D_DISCARD;

$virus_quarantine_to = undef;

$banned_quarantine_to = "banned\@$mydomain";

$bad_header_quarantine_to = "banned\@$mydomain";

$spam_quarantine_to = "spambin\@$mydomain";

$banned_filename_re = new_RE section:


# qr'.\.(exe|vbs|pif|scr|cpl)$'i, # banned extension - basic

# qr'.\.(exe|vbs|pif|scr|cpl|bat|cmd|com)$'i, # banned extension - basic+cmd

qr'.\.(ade|adp|app|bas|bat|chm|cmd|com|cpl|crt|emf|exe|fxp|grp|hlp|hta |

inf|ins|isp|js|jse|lnk|mda|mdb|mde|mdw|mdt|mdz|msc|msi|msp|mst|

ops|pcd|pif|prg|reg|scr|sct|shb|shs|vb|vbe|vbs|

wmf|wsc|wsf|wsh)$'ix, # banned ext - long


FIN

Sauvegarde du fichier amavisd.conf :

cp /etc/amavis/amavisd.conf /etc/amavis/amavisd.conf-20070317


CONFIGURER PYZOR/RAZOR ET SPAMASSASSIN


chmod -R a+rX /usr/share/doc/pyzor /usr/bin/pyzor /usr/bin/pyzord

lancez:

locate pyzor

si vous avez : no such file or directory

lancez :

updatedb

Puis :

chmod -R a+rX /var/lib/python-support/python2.4/pyzor

pyzor discover

su amavis -c 'pyzor discover'

echo "82.94.255.100:24441" > /var/lib/amavis/.pyzor/servers

su amavis -c 'pyzor ping'

cd /root

wget http://www200.pair.com/mecham/spam/sample-spam.txt

spamassassin -D </root/sample-spam.txt

cp -ir /root/.spamassassin /root/.spamassassin-backup

Repondez 'n' to "overwrite?":

cp -ir /root/.spamassassin /var/lib/amavis

rm /root/.spamassassin/user_prefs

ln -s /var/lib/amavis/.spamassassin/user_prefs /root/.spamassassin/user_prefs

cd

rm /etc/razor/razor-agent.conf

razor-admin -create

razor-admin -create

razor-admin -register

vi /root/.razor/razor-agent.conf

Verifiez :

debuglevel = 0

cp -r /root/.razor /var/lib/amavis

chown -R amavis:amavis /var/lib/amavis

vi /etc/spamassassin/local.cf

Copiez :

bayes_path /var/lib/amavis/.spamassassin/bayes

auto_whitelist_path /var/lib/amavis/.spamassassin/auto-whitelist

whitelist_from spambin@example.com

lock_method flock

bayes_auto_learn_threshold_nonspam -0.5

razor_timeout 8


vi /etc/spamassassin/v310.pre

Enlevez le #

#loadplugin Mail::SpamAssassin::Plugin::DCC

sa-update –nogpg

cd /etc/spamassassin


wget http://spamassassin.apache.org/released/GPG-SIGNING-KEY

gpg --import GPG-SIGNING-KEY

sa-update


Tâche planifiée :

crontab -e

05 05 * * * /usr/bin/sa-update && /usr/bin/spamassassin --lint && /etc/init.d/amavis restart

chown -R amavis:amavis /var/lib/amavis

chmod -R 750 /var/lib/amavis

su amavis -c 'sa-learn –sync'



INSTALLATION DE DCC


apt-get install gcc

cd /usr/local/src

wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z

tar xzvf dcc-dccproc.tar.Z

cd dcc-dccproc- [tab][enter]

./configure --with-uid=amavis && make && make install

cd

ln -s /var/dcc/libexec/cron-dccd /usr/bin/cron-dccd

cdcc info


Tâche planifiée :

crontab -e

43 11 * * * /usr/bin/cron-dccd

su amavis -c 'spamassassin -D </root/sample-spam.txt'

vi /etc/spamassassin/local.cf

Inserez :

dcc_home /var/dcc

Editez :

vi /var/dcc/dcc_conf

Vérifiez :

DCCIFD_ENABLE=on

DBCLEAN_LOGDAYS=1

rm -r /var/dcc/log

Editez :

vi /var/dcc/dcc_conf

DCCIFD_LOGDIR="$DCCM_LOGDIR"

cp /var/dcc/libexec/rcDCC /etc/init.d/adcc

update-rc.d adcc defaults

Editez :

vi /etc/init.d/adcc

Enlevez le #

# $DCC_LIBEXEC/start-dccm $DEBUG

mkdir /var/dcc/log

chown -R amavis:amavis /var/dcc

/etc/init.d/adcc start

Petit test :

su amavis -c 'spamassassin -D </root/sample-spam.txt'


Vous devriez voir quelque part : DCCifd: got response:


INSTALLATION DE CLAMAV


apt-get -t sarge install clamav clamav-daemon clamav-freshclam

gpasswd -a clamav amavis

Editez

vi /etc/clamav/freshclam.conf

Vérifiez

NotifyClamd /etc/clamav/clamd.conf

Editez

vi /etc/amavis/amavisd.conf

Ajoutez un #

@bypass_virus_checks_maps = (1); # uncomment to DISABLE anti-virus code

Enlevez le #

['ClamAV-clamd',

\&ask_daemon, ["CONTSCAN {}\n", '/var/run/clamav/clamd.ctl'],

qr/\bOK$/, qr/\bFOUND$/,

qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],


INSTALLATION ADDITIONNELLE DE SIGNATURES ANTI PHISHING


cd /usr/sbin

wget http://www200.pair.com/mecham/spam/scamp.sh

chmod +x scamp.sh

scamp.sh

ls -l /var/lib/clamav

crontab -e

05 */4 * * * /usr/sbin/scamp.sh


WHITELISTING, BLACKLISTING, TWEAKING


cd /etc/spamassassin

wget http://saupdates.openprotect.com/pub.gpg

sa-update --import pub.gpg

sa-update --gpgkey D1C035168C1EBC08464946DA258CDB3ABDE9DC10 --channel saupdates.openprotect.com

spamassassin --lint

/etc/init.d/amavis restart

cd /usr/sbin

wget http://www200.pair.com/mecham/spam/sa-update.sh

chmod +x sa-update.sh


PROBLEME DE RELAY AVEC LES SERVEURS SMTP DES FAI


Certains serveurs smtp des fai (ex Wanadoo) demandent une authentification et par ailleurs (ex Wanadoo) les adresses IP « fixes » qu'ils proposent si chèrement sont reconnues comme des IP dynaiques par les autres serveurs .... D'où obligation de configurer Postfix ....

vi /etc/postfix/sasl_passwd

Rajoutez :

[root@mail postfix]# cat /etc/postfix/sasl_passwd

mail.monfai.org user:motdepasse


chown root:root /etc/postfix/sasl_passwd && chmod 600 /etc/postfix/sasl_passwd

postmap hash:/etc/postfix/sasl_passwd

vi /etc/postfix/main.cf


Rajoutez :


smtp_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_sasl_security_options =


postfix reload


Sources :

http://www200.pair.com/mecham/spam

http://postfix.state-of- mind.de/patrick.koetter/smtpauth/smtp_auth_mailservers.html

http://doc. ubuntu-fr.org/installation/minimale

http://doc.ubuntu-fr.org/webmin

--Franck Parisy 25 novembre 2007 à 16:25 (CET)