Protection contre le spam

De wikilivois
Aller à la navigationAller à la recherche
La version imprimable n’est plus prise en charge et peut comporter des erreurs de génération. Veuillez mettre à jour les signets de votre navigateur et utiliser à la place la fonction d’impression par défaut de celui-ci.

http://www.gentoo.org/doc/fr/mailfilter-guide.xml

Le filtrage sous postfix est expliqué à la page: http://www.postfix.org/CONTENT_INSPECTION_README.html

La méthode proposée ici est appelée "content filter" ou "after queue".

Amavisd-new

http://www.ijs.si/software/amavisd/

Amavisd-new est présenté dans http://www.linuxjournal.com/article/7427

Package Gentoo: amavisd-new

Configuration

#mkdir –p /var/amavis/quarantine/
#chown amavis.amavis /var/amavis/ -R
#chown root:amavis /etc/amavisd.conf
#chmod 640 /etc/amavisd.conf

/etc/amavisd.conf (à lire)

<licode file=/etc/amavisd.conf> mydomain=’’ $QUARANTINEDIR = '/var/amavis/quarantine'; </licode>

Lancer amavis en mode debug

#/usr/sbin/amavisd debug

Remarque : Les explications suivantes reprennent le fichier README.postfix livré avec amavisd-new.

1. Tester la connexion sur le port 10024

#telnet 127.0.0.1 10024

2. master.cf Ajouter les 2 entrées suivantes (y si postfix chrooté sinon n):

<licode file=/etc/postfix/master.cf> smtp-amavis unix - - y/n - 2 smtp

   -o smtp_data_done_timeout=1200
   -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - y/n - - smtpd

   -o content_filter=
   -o local_recipient_maps=
   -o relay_recipient_maps=
   -o smtpd_restriction_classes=
   -o smtpd_client_restrictions=
   -o smtpd_helo_restrictions=
   -o smtpd_sender_restrictions=
   -o smtpd_recipient_restrictions=permit_mynetworks,reject
   -o mynetworks=127.0.0.0/8
   -o strict_rfc821_envelopes=yes
   -o smtpd_error_sleep_time=0
   -o smtpd_soft_error_limit=1001
   -o smtpd_hard_error_limit=1000

</licode>

Attention: La ligne smtp-amavis précise qu'au maximum 2 processus de ce type peuvent tourner en même temps. Ce paramètre est ajustable mais doit être inférieur (ou égal?) à la variable $max_servers= dans amavisd.conf.

Remarque: Il est possible de rejeter les spams en amont avec la méthode Before-Queue(proxy) au lieu de la méthode filter. Toutefois ce n'est pas recommendé pour les serveurs à trafic important car le nombre de connexion est limité au nombre d'instances d'amavis.

L’option essentielle est '-o content_filter=' .

3. Test du fonctionnement d’amavis

#postfix reload

Test de la connexion

#telnet 127.0.0.1 10025 

Simuler l’envoi d’un mail puis l’envoi d’une signature du virus EICAR (récupérable sur http://www.eicar.org/anti_virus_test_file.htm)

#telnet 127.0.0.1 10024
     Trying 127.0.0.1...
     Connected to 127.0.0.1.
     Escape character is '^]'.
     220 [127.0.0.1] ESMTP amavisd-new service ready
-->  MAIL FROM:<test@example.com>
     250 2.1.0 Sender test@example.com OK
-->  RCPT TO:<postmaster>
     250 2.1.5 Recipient postmaster OK
-->  DATA
     354 End data with <CR><LF>.<CR><LF>
-->  Subject: test1
-->
-->  test1
-->  .

***  250 2.6.0 Ok, id=31859-01, from MTA: 250 Ok: queued as 90B7F16F

-->  MAIL FROM:<test@example.com>
     250 2.1.0 Sender test@example.com OK
-->  RCPT TO:<postmaster>
     250 2.1.5 Recipient postmaster OK
-->  DATA
     354 End data with <CR><LF>.<CR><LF>
-->  Subject: test2 - virus test pattern
-->
-->  X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
-->  .

Les réponses dépendent de la configuration des variables $final_virus_destiny and *virus_lovers* dans amavisd.conf:

***  550 5.7.1 Message content rejected, id=16968-01 - VIRUS: EICAR-AV-Test
***  250 2.5.0 Ok, but 1 BOUNCE
***  250 2.7.1 Ok, discarded, id=16984-01 - VIRUS: EICAR-AV-Test
***  250 2.6.0 Ok, id=17041-01, from MTA: 250 Ok: queued as 3F1841A5F5

4. Configurer Postfix pour qu’il envoie tous les mails reçus à amavisd-new

<licode file=/etc/postfix/main.cf> content_filter=smtp-amavis:[127.0.0.1]:10024 </licode>

5. Lancer amavis au démarrage

#rc-update add amavisd default

White/Black/Soft listing

Décommenter la ligne suivante dans amavisd.conf:

<licode file=/etc/amavisd.conf>

  1. read_hash("/var/amavis/sender_scores_sitewide"),

</licode>

et éditer sender_scores_sitewide:

<licode file=/var/amavis/sender_scores_sitewide> (Whitelist all emails from the specific email address) postmaster@example.net -3.0 (Whitelist all emails from the example.net excluding subdomains) .example.net 1.0 </licode>

Remarque: il serait possible d'établir la liste dans le fichier de configuration de spamassassin mais cette méthode permet de tenir à jour un fichier dédié.

Filtrage bayésien et autoapprentissage

Configuration

Créer le compte mail spamtrap (avec Phamm par exemple) Rediriger les spams vers spamtrap@livois.com avec amavis

<licode file=/etc/amavisd.conf> $spam_quarantine_to = "spamtrap\@$mydomain"; </licode>

Remarque: Aucune $spam_quarantine_method ne doit être définie.

Avec l'aide d'un client mail (ex: thunderbird), créer les dossiers

  • ham
  • spam
  • redeliver

L'administrateur abonné à la boîte spamtrap déplaçe les mails dans le dossier qui correspond leur correspond (ham ou spam). L'utilisation de sa-learn sur la boîte spamtrap permet de faire apprendre à amavis ce qui estdu spam ou non (ham).

#chgrp amavis /home/vmail/livois.com/spamtrap/ -R
#chmod g+rwx /home/vmail/livois.com/spamtrap/ -R


<licode file=/etc/crontab> 0 * * * * amavis /usr/bin/sa-learn --spam /home/vmail/livois.com/spamtrap/.spam/{cur,new} > /dev/null 2>&1 0 * * * * amavis /usr/bin/sa-learn --ham /home/vmail/livois.com/spamtrap/.ham/{cur,new} > /dev/null 2>&1 </licode>

Aller plus loin

Le principe

http://en.wikipedia.org/wiki/Bayesian_spam_filtering

De la complexité de voir la liste des mots appris

http://search.cpan.org/dist/Mail-SpamAssassin/sa-learn.raw

http://www.mail-archive.com/users@spamassassin.apache.org/msg03635.html

https://issues.apache.org/SpamAssassin/show_bug.cgi?id=3331

SA 3.0.x does not store bayes tokens in plain-text, it stores the SHA1 hashes of them. Since the tokens are hashed, it's impossible to derive what words they represent, so sa-learn --dump prints the hashes.

Spamassassin

http://spamassassin.apache.org/full/3.2.x/dist/doc/Mail_SpamAssassin_Conf.html

http://spamassassin.apache.org/full/3.2.x/dist/doc/

http://ezine.daemonnews.org/200309/postfix-spamassassin.html

http://wiki.apache.org/spamassassin/SingleUserUnixInstall

Package Gentoo: spamassassin

Configuration de base

http://spamassassin.apache.org/full/3.2.x/dist/doc/Mail_SpamAssassin_Conf.html

amavisd.conf

Des explications sont données dans le fichier amavisd.conf. A noter les trois niveaux d'action sur le spam qui peuvent être changés par les utilisateurs (cf § sur la quarantaine):

  • $sa_tag_level_dflt: niveau à partir duquel un en-tête est ajouté
  • $sa_tag2_level_dflt: niveau à partir duqel le sujet est modifié
  • $sa_kill_level_dflt: niveau à partir duqel le mail est mis en quarantaine ou supprimé

<licode file=/etc/amavisd.conf>

  1. SpamAssassin settings
  1. $sa_local_tests_only is passed to Mail::SpamAssassin::new as a value
  2. of the option local_tests_only. See Mail::SpamAssassin man page.
  3. If set to 1, no tests that require internet access will be performed.

$sa_local_tests_only = 0; # (default: false)

  1. $sa_auto_whitelist = 1; # turn on AWL (default: false)

$sa_mail_body_size_limit = 200*1024; # don't waste time on SA if mail is larger

                           # (less than 1% of spam is > 64k)
                           # default: undef, no limitations
  1. default values, customarily used in the @spam_*_level_maps as the last entry

$sa_tag_level_deflt = 2.0; # add spam info headers if at, or above that level;

                           # undef is interpreted as lower than any spam level

$sa_tag2_level_deflt = 5.0; # add 'spam detected' headers at that level $sa_kill_level_deflt = $sa_tag2_level_deflt; # triggers spam evasive actions

                           # at or above that level: bounce/reject/drop,
                           # quarantine, and adding mail address extension

$sa_dsn_cutoff_level = 10; # spam level beyond which a DSN is not sent,

                           # effectively turning D_BOUNCE into D_DISCARD;
                           # undef disables this feature and is a default;

</licode>

local.cf

<licode file=/etc/mail/spamassassin/local.cf>

  1. Enable the Bayes system

use_bayes 1

  1. Mail using languages used in these country codes will not be marked
  2. as being possibly spam in a foreign language.

ok_languages en fr

  1. Mail using locales used in these country codes will not be marked
  2. as being possibly spam in a foreign language.

ok_locales fr

  1. Use a sensible bayes path

bayes_path /var/amavis/.spamassassin/bayes </licode>

Remarque : Avec spamassassin 3.1, il faut activer le plugin TextCat (language guesser) dans v310.pre. pour utiliser la directive ok_languages. Ce paramètre peut être configuré par utilisateur.

http://spamassassin.apache.org/full/3.2.x/dist/doc/Mail_SpamAssassin_Plugin_AutoLearnThreshold.html

  • bayes_auto_learn_threshold_nonspam n.nn (default: 0.1)

The score threshold below which a mail has to score, to be fed into SpamAssassin's learning systems automatically as a non-spam message.

  • bayes_auto_learn_threshold_spam n.nn (default: 12.0)

The score threshold above which a mail has to score, to be fed into SpamAssassin's learning systems automatically as a spam message.

<licode file=/etc/mail/spamassassin/local.cf>

  1. Enable the Bayes system

use_bayes 1 bayes_auto_learn 1 bayes_auto_learn_threshold_nonspam 1 bayes_auto_learn_threshold_spam 14.00

  1. Enable all network checks

skip_rbl_checks 0 </licode>

Attention: il n'est pas nécessaire de lancer spamd (cf amavisd.conf)

Le fichier de scores

Remarque : les scores de spamassassin sont définis dans le fichier /usr/share/spamassassin/50_scores.cf.
Les points sont attribués pour 4 catégories: local, net, with bayes, with bayes+net http://spamassassin.apache.org/tests_3_2_x.html

Test d'amavis:

#amavisd debug-sa

Les scores peuvent être changés par l'administrateur dans le fichier local.cf <licode file=/etc/mail/spamassassin/local.cf> score SYMBOLIC_TEST_NAME n.nn [ n.nn n.nn n.nn ] </licode>

Exemple: <licode file=/etc/mail/spamassassin/local.cf> score SUBJ_ILLEGAL_CHARS 0.1 #accents dans le sujet score BAD_ENC_HEADER 0.1 #accents dans le sujet </licode>

Les plugins

http://spamassassin.apache.org/full/3.2.x/doc/

Le fichier de plugins sont:

  • /etc/mail/spamassassin/init.pre (RelayCountry, URIDNSBL,Hashcash, SPF)
  • /etc/mail/spamassassin/v310.pre (DCC,Pyzor,Razor2,Spamcop,Antivirus,AWL,AutoLearnThreshold,Texcat,AccessDB,WhiteListSubject,MIMEHeader,ReplaceTags)
  • /etc/mail/spamassassin/v312.pre (DKIM)
  • /etc/mail/spamassassin/v320.pre (Check,HTTPSMismatch,URIDetail,VBounce,Rule2XSBody,ASN,ImageInfo)

URIBL_SBL

http://www.surbl.org/

http://www.spamhaus.org

http://uribl.com/

This works by analysing message text and HTML for URLs, extracting the domain names from those, querying their NS records in DNS, resolving the hostnames used therein, and querying various DNS blocklists for those IP addresses. This is quite effective.

In addition to checking the IPs of the connecting servers against the SBL, you can significantly boost your spam catch rate by also scanning the email body of any mails that get past SBL/XBL looking for host names of URLs (web sites) advertised in spams, and checking the IPs of those hosts, and their names servers, against the SBL. This is because the SBL lists the IPs of spammers' websites in addition to their mail servers. This feature ("URIBL_SBL") is available in SpamAssassin 3.0.

<licode file=25_uribl.cf>

    1. SBL

uridnsbl URIBL_SBL sbl.spamhaus.org. TXT body URIBL_SBL eval:check_uridnsbl('URIBL_SBL') describe URIBL_SBL Contains an URL listed in the SBL blocklist tflags URIBL_SBL net

  1. reuse URIBL_SBL

... </licode>

SPF

cf §dédié

Razor / Pyzor / DCC

Le principe de Razor/Pyzor/DCC est de centraliser des checksums des mails que les serveurs mails leur envoie. Si le checksum correspond à un nombre élevé de mail, il y a de forte chances que le mail soit du spam.

Ouvrir les flux sur votre pare-feu En plus d'accepter le trafic usuel de courrier, certaines applications nécessitent une autorisation d'accès au réseau que vous devez mettre en place au niveau de votre pare-feu pour qu'elles puissent communiquer avec les serveurs.

Application Protocole Port
DCC UDP 6277
Razor (ping sortant) TCP 7
Razor TCP 2703
Pyzor TCP 24441

Razor utilise les pings pour trouver quels serveurs sont les plus proches.

razor2

http://razor.sourceforge.net/docs/

http://spamassassin.apache.org/full/3.2.x/dist/doc/Mail_SpamAssassin_Plugin_Razor2.html

Razor2 est un réseau collaboratif et distribué d'identification de spam.

Package Gentoo: razor

#su - amavis
#razor-admin -create
#razor-admin -register -user=admin@livois.com

Le fichier identité se créé sous /var/amavis/.razor/identity-admin@livois.com

Le fichier de configuration de razor est /var/amavis/.razor/razor-agent.conf

(Man razor-agent.conf pour comprendre la configuration - noter la directive min_cf qui correspond en quelque sorte au niveau de spam accepté.

Razor retourne une « spam confidence value » entre 0 et 100. Pour être considéré comme spam, la valeur retournée doit être supérieure ou égale à min_cf. min_cf peut être une valeur absolue, par exemple 80 ou fonction de ac, « average confidence » affiché par Razor. min_cf peut être mis à ac + 10.)

Pour activer razor, décommenter la ligne de plugin dans v310.pre. En effet razor est désactivé par défaut car la licence n'est pas gratuite :

« Use of the SpamNet service by Razor-agent-enabled software will remain free for personal use, subject to capacity constraints that Cloudmark may enforce against intensive users of the service as it sees fit.

Distribution or use of the system in commercial embedded software solutions is not free. All such access must be licensed by Cloudmark.

Organizations interested in working with Razor or with Cloudmark's next-generation SpamNet client technologies should contact Cloudmark at partners@cloudmark.com »

<licode file=/etc/mail/spamassassin/v310.pre>

  1. Razor2 - perform Razor2 message checks.
  2. Razor2 is disabled here because it is not available for unlimited free
  3. use. It is currently free for personal use, subject to capacity
  4. constraints. See the Cloudmark SpamNet Service Policy for more details.

loadplugin Mail::SpamAssassin::Plugin::Razor2 </licode>

Activer razor dans local.cf:

<licode file=/etc/spamassassin/local.cf> use_razor2 1 razor_timeout 5 # defaut </licode>

pyzor

http://pyzor.sourceforge.net/

http://spamassassin.apache.org/full/3.1.x/dist/doc/Mail_SpamAssassin_Plugin_Pyzor.html

Pyzor est sous licence GPL et est activé par défaut pour spamasassin.

Package Gentoo: pyzor

<licode file=/etc/spamassassin/local.cf> use_pyzor 1 pyzor_timeout 5 #defaut pyzor_max 5 #defaut </licode>

L'attribut pyzor_max définit le nombre de checksum rapportés au serveur pyzor avant que spamasassin ne considère le retour de pyzor comme positif.

DCC Distributed Checksum Clearinghouse

http://www.rhyolite.com/anti-spam/dcc/

http://spamassassin.apache.org/full/3.2.x/dist/doc/Mail_SpamAssassin_Plugin_DCC.html

http://wiki.apache.org/spamassassin/SingleUserUnixInstall

DCC est souvent désactivé par défaut car sa licence est restrictive. Voici des conditions d'utilisations telles qu'expliquées sur le site:

« The Distributed Checksum Clearinghouse source carries a license that is free to organizations that do not sell filtering devices or services except to their own users and that participate in the global DCC network. (I.e. ISPs that use the DCC to filter mail for their own users are intended to be covered in the free license.) You also can't call it your own or blame anyone for using it. »

« Sellers of products or services including the DCC must provide DCC servers of their own or contracted from others. For example, Commtouch operates DCC servers for its licensees. »

Spamasassin peut utiliser dcc et affecter un score au mail en fonction durésultat.

Package Gentoo: dcc

Activer le plugin spamassassin (désactivé par défaut)

<licode file=/etc/mail/spamassassin/v310.pre>

  1. DCC is disabled here because it is not open source. See the DCC
  2. license for more details.

loadplugin Mail::SpamAssassin::Plugin::DCC </licode>

La commande suivante permet de vérifier que le plugin est bien activé :

#zcat /usr/share/doc/amavisd-new-<version>/sample-nonspam.txt.gz | spamassassin -D   


<licode file=/etc/mail/spamassassin/local.cf> use_dcc 1 #utilise dcc dcc_timeout 5 #timeout par défaut dcc_body_max 10000 #nombre de checksum qui doivent être rapportés au dcc_fuz1_max 10000 #serveur DCC avant que spamasassin les considère dcc_fuz2_max 10000 #comme spam (defaut: 999999) </licode>

Configuration du firewall

Allow outgoing packets to distant UDP port 6277 and incoming packets from distant UDP port 6277. If `dccproc` fails or the command `cdcc info` says no DCC servers are answering, you may need to adjust your firewall.

Remarque: par défaut, spamasassin utilise dccproc, il est possible d'utiliser DCC en tant que démon, ce qui est plus efficace mais nécessite davantage de mémoire.

Test de dccproc:

#dccproc -C -i /home/vmail/livois.com/spamtrap/.spam/cur/1132184113.M149300P12737V0000000000000303I000AB6F1_4.gw.livois.com\,S\=10179\:2\,S
X-DCC-NIET-Metrics: gw.livois.com 1080; env_From=2 Body=2 Fuz1=2 Fuz2=2                           
		reported: 1               checksum  server
             	env_From: 1bf85f2c eb261f2f effb1e08 d79c3ea6       1
                 From: ab363612 48b72f70 6a2cbef8 bf671bda
               	Message-ID: 1c8c150f 86b472af ad0efe22 be87b8b8
                 Received: 37526031 ea6524b7 1395736d 50a4479d
                 Body: ee4264ff 2af020c2 817c8b23 799ce2b2       1
                 Fuz1: cafc108f 90817b72 f3ebc845 1bf933b3       1
                 Fuz2: a1ce1b18 4e6808dc fe6430c0 4f2ce20d       1

DKIM

http://dkim.org/

  • What does DKIM do ?
The responsible organization adds a digital signature to the message, associating it with a domain name of that organization. Typically, signing will be done by an service agent within the authority of the message originator's Administrative Management Domain (ADMD). Signing might be performed by any of the functional components, in that environment, including: Mail User Agent (MUA), or Mail Submission Agent (MSA), Internet Boundary MTA. DKIM permits signing to be performed by authorized third-parties.


http://spamassassin.apache.org/full/3.2.x/doc/Mail_SpamAssassin_Plugin_DKIM.html

Package Gentoo: dev-perl/Mail-DKIM ~x86 dev-perl/Mail-DomainKeys

<licode file=/etc/mail/spamassassin/v312.pre> loadplugin Mail::SpamAssassin::Plugin::DKIM </licode>

<licode file=25_dkim.cf> header DKIM_SIGNED eval:check_dkim_signed() header DKIM_VERIFIED eval:check_dkim_verified() header DKIM_POLICY_TESTING eval:check_dkim_testing() header DKIM_POLICY_SIGNSOME eval:check_dkim_signsome() header DKIM_POLICY_SIGNALL eval:check_dkim_signall()

tflags DKIM_SIGNED net nice tflags DKIM_VERIFIED net nice tflags DKIM_POLICY_SIGNSOME net nice tflags DKIM_POLICY_SIGNALL net nice tflags DKIM_POLICY_TESTING net nice

describe DKIM_SIGNED Domain Keys Identified Mail: message has a signature describe DKIM_VERIFIED Domain Keys Identified Mail: signature passes verification describe DKIM_POLICY_SIGNSOME Domain Keys Identified Mail: policy says domain signs some mails describe DKIM_POLICY_SIGNALL Domain Keys Identified Mail: policy says domain signs all mails describe DKIM_POLICY_TESTING Domain Keys Identified Mail: policy says domain is testing DK </licode>

<licode file=60_whitelist_dkim.cf> header USER_IN_DKIM_WHITELIST eval:check_for_dkim_whitelist_from() describe USER_IN_DKIM_WHITELIST From: address is in the user's DKIM whitelist tflags USER_IN_DKIM_WHITELIST userconf nice noautolearn net

header USER_IN_DEF_DKIM_WL eval:check_for_def_dkim_whitelist_from() describe USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list tflags USER_IN_DEF_DKIM_WL userconf nice noautolearn net

meta ENV_AND_HDR_DKIM_MATCH (USER_IN_DEF_DKIM_WL && __ENV_AND_HDR_FROM_MATCH) describe ENV_AND_HDR_DKIM_MATCH Env and Hdr From used in default DKIM WL Match tflags ENV_AND_HDR_DKIM_MATCH userconf nice noautolearn net </licode>

Détecter les images avec fuzzyocr

http://fuzzyocr.own-hero.net/wiki

Package Gentoo: fuzzyocr

Mise à jour automatique des règles spamassassin (sa-update)

http://www.rulesemporium.com/

http://wiki.apache.org/spamassassin/CustomRulesets

http://wiki.apache.org/spamassassin/RuleUpdates

Installation

http://wiki.apache.org/spamassassin/SareChannels

http://www.rulesemporium.com/rules.htm

#wget http://daryl.dostech.ca/sa-update/sare/GPG.KEY
#sa-update --import GPG.KEY

Pour la mise à jour automatique, il faut choisir entre la réalisation d'un fichier personnel ou l'utilisation du fichier d'openprotect.

  • Fichier de configuration personnel

Ecrire le fichier de configuration en fonction de ses besoins. Les règles et leur explications sont disponibles sur http://www.rulesemporium.com/rules.htm. <licode file=sare-sa-update-channels.txt> updates.spamassassin.org 72_sare_redirect_post3.0.0.cf.sare.sa-update.dostech.net 70_sare_evilnum0.cf.sare.sa-update.dostech.net 70_sare_bayes_poison_nxm.cf.sare.sa-update.dostech.net 70_sare_html0.cf.sare.sa-update.dostech.net 70_sare_html_eng.cf.sare.sa-update.dostech.net 70_sare_header0.cf.sare.sa-update.dostech.net 70_sare_header_eng.cf.sare.sa-update.dostech.net 70_sare_specific.cf.sare.sa-update.dostech.net 70_sare_adult.cf.sare.sa-update.dostech.net 72_sare_bml_post25x.cf.sare.sa-update.dostech.net 99_sare_fraud_post25x.cf.sare.sa-update.dostech.net 70_sare_spoof.cf.sare.sa-update.dostech.net 70_sare_random.cf.sare.sa-update.dostech.net 70_sare_oem.cf.sare.sa-update.dostech.net 70_sare_genlsubj0.cf.sare.sa-update.dostech.net 70_sare_genlsubj_eng.cf.sare.sa-update.dostech.net 70_sare_unsub.cf.sare.sa-update.dostech.net 70_sare_uri0.cf.sare.sa-update.dostech.net 70_sare_obfu0.cf.sare.sa-update.dostech.net 70_sare_stocks.cf.sare.sa-update.dostech.net </licode>

#sa-update --channelfile /path/to/sare-sa-update-channels.txt --gpgkey 856AA88A -D
  • utiliser les règles d'openprotect

http://saupdates.openprotect.com/

Extrait du site d'openprotect:

SARE provides several rules, some which have versions from 0-4, 0 being the one that catches most spam, while not blocking any ham. Versions 1-4 which are new rules, which don't yet hit lots of spam but blocks too many ham, are not present in this channel. We have included all the 0 rules and other single version rules, and this has been tested on our servers to give the highest spam catching rate, while having low FP(False Positives) and have less memory consumption too.

importer la clé GPG

#gpg --keyserver pgp.mit.edu --recv-keys BDE9DC10
#gpg --armor -o pub.gpg --export BDE9DC10 
#sa-update --import pub.gpg
#sa-update --allowplugins --allowplugins --gpgkey D1C035168C1EBC08464946DA258CDB3ABDE9DC10 --channel saupdates.openprotect.com --channel updates.spamassassin.org -D

Remarque: L'option --allowplugins ne doit être utilisée qu'à partir la version 3.2 de spamassassin

  • vérifier les changements
#spamassin --lint -D

cron

<licode file=/etc/cron.daily/rulesdujour>

  1. !/bin/sh

echo "rulesdujour"

  1. mode "fichier perso"
  2. sa-update --channelfile /etc/spamassassin/sare-sa-update-channels.txt --gpgkey 856AA88A -D
  1. mode "openprotect"

sa-update --gpgkey D1C035168C1EBC08464946DA258CDB3ABDE9DC10 --channel saupdates.openprotect.com --channel updates.spamassassin.org

/etc/init.d/amavisd stop /etc/init.d/amavisd zap /etc/init.d/amavisd start

/etc/init.d/spamd stop /etc/init.d/spamd zap /etc/init.d/spamd start </licode>

Libération de la quarantaine

Package Gentoo: smtptools, tmpwatch

Les spams bloqués ont été envoyés à la boîte spamtrap@livois.com.

L'administrateur abonné à cette boîte au lettre peut décider de renvoyer le mail à l'utilisateur en copiant le mail dans le dossier redeliver. Pour cela, le script redeliver.pl est lancé régulièrement afin de scanner le dossier et renvoyer le courrier via smtpblast du package smtptools. Tmpwatch est utilisé pour faire le ménage dans les répertoires de quarantaine.

redeliver.pl

Le script redeliver.pl peut être téléchargé sur http://home.coming.dk/files/redeliver.pl.

#wget http://home.coming.dk/files/redeliver.pl
#mv redeliver.pl /opt/script/

Remplacer la ligne de smtpclient par my $redelivercmd = "smtpblast -i $ARGV[0] -r 127.0.0.1 -p 10025 -f $from -t $to";

<licode file=/opt/script/redeliver.pl>

  1. !/usr/bin/perl -w
  2. modifié à partir de la version de Jens Hilligsoe <gentoo@hilli.dk>

use strict; if(!($#ARGV == 0)) {

       die "Usage:\n$0 maildir_mail\n";

}

my $mail = $ARGV[0]; my $to = ""; my $from = ""; sub prunefile ( $ );

  1. Récupère les champs To et From

open (MAIL, $mail) or die "Could not open $mail: $?\n"; while(<MAIL>) {

   if(($to eq "") || ($from eq "")) {
       chop;
       (my $key, my $value) = split (/:/);
       if($key eq "X-Envelope-To") {
           $to = $value;
           $to =~ s/[\<\>,]//g; # Supprime "<", ">" and ","
           $to =~ s/^\s+|\s+$//g; # Supprime les espaces avant et après
       }
       if($key eq "X-Envelope-From") {
           $from = $value;
           $from =~ s/[\<\>,]//g;
           $from =~ s/^\s+|\s+$//g;
           if($from eq "") {
               $from = "postmaster";
           }
       }
   }

}

if($to eq "") {

   prunefile($ARGV[0]); # Supprimez-le simplement s'il est vide

} else {

   #my $redelivercmd = "cat $ARGV[0] | smtpclient -F -S 127.0.0.1 -P 10025 -f $from $to";
   my $redelivercmd = "smtpblast -i $ARGV[0] -r 127.0.0.1 -p 10025 -f $from -t $to";
   unless (system($redelivercmd) == 0 ) {
       die "Unable to redeliver: $?";
   }
   #prunefile($ARGV[0]); # Clean up

}

sub prunefile ( $ ) {

   my ($file) = @_;
   unless (unlink $file) {
       die "Unable to remove mail: $?";
   }

} </licode>

crontab

Editer la crontab pour renvoyer les messages une fois qu'ils ont été mis dans le dossier redeliver et nettoyer les répertoires de la quarantaine avec tmpwatch.


<licode file=/etc/crontab> 0 * * * * root find /home/vmail/livois.com/spamtrap/.redeliver/cur/ -type f -name "[0-9]*" -exec /opt/script/redeliver.pl {} \;

  1. Garder les mails à virus et les fichiers banned pendant une semaine (24*7 heures)

15 0 * * * root /usr/sbin/tmpwatch -c -f -d --quiet 168 -t /var/amavis/quarantine/ </licode>

Remarque: Il existe d'autres interfaces / méthodes pour gérer la mise en quarantaine:

  • Squirrelmail + le plugin amavisnewSQL
  • Maia mailguard (sans doute le plus abouti)
  • SAM Horde
  • ... (cf page d'amavisd-new)

SPF - Sender Policy Framework

http://www.openspf.org/index.html

Fonctionnement du SPF

SPF lutte contre l'usurpation d'adresses e-mail. L'idée est de définir dans le DNS la liste des serveurs autorisés à envoyer des mails pour un domaine. Les serveurs SMTP vérifient si le serveur emetteur de l'e-mail correspond à la politique du domaine de l'e-mail emetteur.

Par exemple, si quelquun@livois.com envoie un mail a ami@exemple.com, le serveur exemple.com peut vérifier que l'e-mail est bien parti d'un serveur livois.com.

Attention : Mettre en place le SPF siginifie que tous les utilisateurs du domaine doivent envoyer leurs mails par des serveurs smtp de la liste SPF. Un moyen est de mettre en place des serveurs SMTP accessibles à tous les utilisateurs avec une authentification SASL.

Spamassassin a un plugin SPF.

SPF est très décrié car il cassse les fonctionnalités du protocole SMTP. Il n'est plus posssible d'utiliser la redirection d'adresse. L'efficcacité de SPF dans la lutte contre le SPAM est remise en cause. http://www.infoworld.com/article/04/08/31/HNspammerstudy_1.html

Configuration de spamassassin

La bibliothèque perl Mail::SPF::Query est requise:

Package Gentoo: dev-perl/Mail-SPF-Query

<licode file=/etc/spamassassin/init.pre>

  1. SPF - perform SPF verification.

loadplugin Mail::SpamAssassin::Plugin::SPF </licode>

La fichier spamassassin de scores SPF par défaut est le suivant: <licode file=/usr/share/spamassassin/50_scores.cf>

  1. SPF
  2. Note that the benefit for a valid SPF record is deliberately minimal; it's
  3. likely that more spammers would quickly move to setting valid SPF records
  4. otherwise. The penalties for an *incorrect* record, however, are large.  ;)

ifplugin Mail::SpamAssassin::Plugin::SPF score SPF_PASS -0.001score SPF_HELO_PASS -0.001

  1. <gen:mutable>

score SPF_FAIL 0 1.333 0 1.142 score SPF_HELO_FAIL 0 score SPF_HELO_NEUTRAL 0 score SPF_HELO_SOFTFAIL 0 2.078 0 2.432 score SPF_NEUTRAL 0 1.379 0 1.069 score SPF_SOFTFAIL 0 1.470 0 1.384

  1. </gen:mutable>

endif # Mail::SpamAssassin::Plugin::SPF </licode>

Configuration d'une polique SPF

Configuration du DNS

http://new.openspf.org/SPF_Record_Syntax

<licode file=livois.com.zone> livois.com. IN TXT "v=spf1 mx ip4:82.226.44.52 ~all" mail IN TXT "v=spf1 a -all" www IN TXT "v=spf1 a -all" </licode>

~ indique que la politique est en test. Un mail provenant d'un serveur non listé dans la politique sera considéré comme "softfail".

Remarque : When a mail server sends a bounce message, it uses a null MAIL FROM: <>, and a HELO address that's supposed to be its own name. SPF will still operate, but in "degraded mode" by using the HELO domain name instead. Because this wizard can't tell which name your mail server uses in its HELO command, it lists all possible names, so there may be multiple lines shown below. If you know which hostname your mail server uses in its HELO command, you should pick out the appropriate entries and ignore the rest.

So this should also appear in DNS. You may or may not be in charge of the DNS for these entries; if you are, add them.

<licode file=livois.com.zone> mail.livois.com. IN TXT "v=spf1 a -all" mail.rollernet.us. IN TXT "v=spf1 a -all" mail2.rollernet.us. IN TXT "v=spf1 a -all" www.livois.com. IN TXT "v=spf1 a -all" </licode>

Vérification de l'implémentation

# host -t txt livois.com
livois.com descriptive text "v=spf1 mx ip4:82.226.44.52 include:free.fr ~all"

Le site http://www.dnsreport.com/ vérifie plusieurs paramètres dont la présence de règles spf.

Le site http://www.kitterman.com/spf/validate.html vérifie la validité des règles spf.

Copyright

© 2006-2009 Christophe de Livois

Tête de GNU Vous avez l'autorisation de copier, distribuer et/ou modifier ce document suivant les termes de la GNU Free Documentation License, Version 1.2 ou n'importe quelle version ultérieure publiée par la Free Software Foundation; sans section invariante, sans page de garde, sans entête et sans page finale. Pour plus d'informations consulter le site de l'APRIL.