SpamAssassin ist ein bewährter Open-Source-Spam-Filter. Er analysiert E-Mails mit verschiedenen Methoden und markiert verdächtige Nachrichten.
Installation
Debian/Ubuntu
apt update
apt install spamassassin spamcCentOS/RHEL
dnf install spamassassinService aktivieren
systemctl enable --now spamassassinGrundkonfiguration
Hauptkonfiguration
# /etc/spamassassin/local.cf
# Basis-Einstellungen
required_score 5.0
report_safe 0
rewrite_header Subject [SPAM]
# Bayes-Filter
use_bayes 1
bayes_auto_learn 1
bayes_auto_learn_threshold_spam 6.0
bayes_auto_learn_threshold_nonspam 0.1
# Netzwerk-Tests
skip_rbl_checks 0
dns_available yes
# Trusted Networks
trusted_networks 192.168.1.0/24
internal_networks 192.168.1.0/24Score-Erklärung
Score < 0: Definitiv kein Spam
Score 0-4.9: Wahrscheinlich kein Spam
Score 5.0+: Spam (Standard-Schwelle)
Score 10.0+: Definitiv SpamIntegration mit Postfix
Mit SpamC (schneller)
# /etc/postfix/master.cf
smtp inet n - y - - smtpd
-o content_filter=spamassassin
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}Mit Amavis (empfohlen)
apt install amavisd-new# /etc/amavis/conf.d/15-content_filter_mode
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);# /etc/postfix/main.cf
content_filter = smtp-amavis:[127.0.0.1]:10024Regeln anpassen
Score anpassen
# /etc/spamassassin/local.cf
# Regel verstärken
score URIBL_BLACK 4.0
# Regel abschwächen
score HTML_MESSAGE 0.5
# Regel deaktivieren
score SOME_RULE 0Whitelist/Blacklist
# /etc/spamassassin/local.cf
# Absender auf Whitelist
whitelist_from *@trusted-company.com
whitelist_from partner@example.com
# Absender auf Blacklist
blacklist_from *@spam-domain.com
blacklist_from spammer@example.com
# Nach Domain
whitelist_from_rcvd *@bank.com bank.comEigene Regeln
# /etc/spamassassin/local.cf
# Header-Regel
header LOCAL_CRYPTO_SPAM Subject =~ /bitcoin|crypto|invest now/i
score LOCAL_CRYPTO_SPAM 5.0
describe LOCAL_CRYPTO_SPAM Cryptocurrency spam keywords
# Body-Regel
body LOCAL_LOTTERY Subject =~ /you have won|lottery winner/i
score LOCAL_LOTTERY 4.0
# URI-Regel
uri LOCAL_SUSPICIOUS_TLD /\.(xyz|top|click)$/i
score LOCAL_SUSPICIOUS_TLD 2.0Bayes-Filter
Training
# Spam lernen
sa-learn --spam /path/to/spam/folder/
# Ham (kein Spam) lernen
sa-learn --ham /path/to/ham/folder/
# Einzelne Mail
sa-learn --spam < spam-mail.eml
sa-learn --ham < good-mail.emlAutomatisches Training
# /etc/spamassassin/local.cf
bayes_auto_learn 1
bayes_auto_learn_threshold_spam 6.0
bayes_auto_learn_threshold_nonspam 0.1Bayes-Datenbank
# Status prüfen
sa-learn --dump magic
# Datenbank löschen
sa-learn --clear
# Backup
sa-learn --backup > bayes_backup.txt
# Restore
sa-learn --restore < bayes_backup.txtRegeln aktualisieren
Automatische Updates
# sa-update aktivieren
# /etc/default/spamassassin (Debian)
CRON=1Manuelle Updates
sa-update
systemctl restart spamassassinUpdate-Kanäle
# /etc/spamassassin/local.cf
# Standard-Kanal
include_config_file /var/lib/spamassassin/updates_spamassassin_org/*.cf
# Zusätzliche Kanäle
# Heinlein Support
sa-update --import Heinlein-SA-Rules.asc
sa-update --channel spamassassin.heinlein-support.dePerformance
Spamd-Optionen
# /etc/default/spamassassin
OPTIONS="--create-prefs --max-children 5 --helper-home-dir -u spamd"Caching
# /etc/spamassassin/local.cf
# DNS-Caching
dns_server 127.0.0.1
# Bayes-Performance
bayes_sql_dsn DBI:mysql:spamassassin:localhost
bayes_store_module Mail::SpamAssassin::BayesStore::SQLTimeouts
# /etc/spamassassin/local.cf
rbl_timeout 10
dns_timeout 10Plugins
DCC (Distributed Checksum Clearinghouse)
apt install dcc-client# /etc/spamassassin/local.cf
loadplugin Mail::SpamAssassin::Plugin::DCC
use_dcc 1
dcc_timeout 10Razor
apt install razor
razor-admin -create
razor-admin -register# /etc/spamassassin/local.cf
loadplugin Mail::SpamAssassin::Plugin::Razor2
use_razor2 1Pyzor
apt install pyzor
pyzor discover# /etc/spamassassin/local.cf
loadplugin Mail::SpamAssassin::Plugin::Pyzor
use_pyzor 1Testen
E-Mail testen
# Spam-Test (GTUBE-String)
spamassassin -t < test-mail.txt
# Detail-Analyse
spamassassin -D < test-mail.txtGTUBE-Test
# Test-String für garantierte Spam-Erkennung
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34XRegel-Check
# Regel-Syntax prüfen
spamassassin --lint
# Welche Regeln matchen?
spamassassin -t -D rules < mail.txtLogging
Log-Einstellungen
# /etc/spamassassin/local.cf
# Ausführliches Logging
add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_
add_header all Flag _YESNOCAPS_Logs analysieren
tail -f /var/log/mail.log | grep spamd
journalctl -u spamassassin -fBenutzer-Konfiguration
Per-User-Einstellungen
# ~/.spamassassin/user_prefs
required_score 4.0
whitelist_from boss@company.com
blacklist_from *@competitor.comSQL-basierte Konfiguration
# /etc/spamassassin/local.cf
user_scores_dsn DBI:mysql:spamassassin:localhost
user_scores_sql_username spamassassin
user_scores_sql_password passwordTroubleshooting
Spam nicht erkannt
# Mail analysieren
spamassassin -t -D < undetected-spam.eml
# Regeln aktualisieren
sa-update
# Bayes trainieren
sa-learn --spam < undetected-spam.emlFalse Positives
# Als Ham lernen
sa-learn --ham < false-positive.eml
# Absender whitelisten
whitelist_from sender@example.comPerformance-Probleme
# Mehr Children
OPTIONS="--max-children 10"
# DNS-Tests reduzieren
skip_rbl_checks 1
# Timeouts reduzieren
rbl_timeout 5Zusammenfassung
| Befehl | Funktion | |--------|----------| | sa-learn --spam | Als Spam lernen | | sa-learn --ham | Als Ham lernen | | sa-update | Regeln aktualisieren | | spamassassin -t | Mail testen | | spamassassin --lint | Konfiguration prüfen |
| Score | Bedeutung | |-------|-----------| | < 0 | Kein Spam | | 0-4.9 | Wahrscheinlich OK | | 5.0+ | Spam | | 10.0+ | Definitiv Spam |
Fazit
SpamAssassin ist ein bewährter Spam-Filter mit vielen Anpassungsmöglichkeiten. Das Bayes-Training verbessert die Erkennung kontinuierlich. Die Kombination mit Amavis bietet die beste Integration in Mailserver. Regelmäßige Updates der Regeln sind wichtig für aktuelle Spam-Erkennung. Für höchste Effizienz kombinieren Sie SpamAssassin mit RBL-Checks und Greylisting.