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 spamc

CentOS/RHEL

dnf install spamassassin

Service aktivieren

systemctl enable --now spamassassin

Grundkonfiguration

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/24

Score-Erklärung

Score < 0:    Definitiv kein Spam
Score 0-4.9:  Wahrscheinlich kein Spam
Score 5.0+:   Spam (Standard-Schwelle)
Score 10.0+:  Definitiv Spam

Integration 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]:10024

Regeln 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 0

Whitelist/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.com

Eigene 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.0

Bayes-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.eml

Automatisches Training

# /etc/spamassassin/local.cf

bayes_auto_learn 1
bayes_auto_learn_threshold_spam 6.0
bayes_auto_learn_threshold_nonspam 0.1

Bayes-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.txt

Regeln aktualisieren

Automatische Updates

# sa-update aktivieren
# /etc/default/spamassassin (Debian)
CRON=1

Manuelle Updates

sa-update
systemctl restart spamassassin

Update-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.de

Performance

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::SQL

Timeouts

# /etc/spamassassin/local.cf

rbl_timeout 10
dns_timeout 10

Plugins

DCC (Distributed Checksum Clearinghouse)

apt install dcc-client
# /etc/spamassassin/local.cf

loadplugin Mail::SpamAssassin::Plugin::DCC
use_dcc 1
dcc_timeout 10

Razor

apt install razor
razor-admin -create
razor-admin -register
# /etc/spamassassin/local.cf

loadplugin Mail::SpamAssassin::Plugin::Razor2
use_razor2 1

Pyzor

apt install pyzor
pyzor discover
# /etc/spamassassin/local.cf

loadplugin Mail::SpamAssassin::Plugin::Pyzor
use_pyzor 1

Testen

E-Mail testen

# Spam-Test (GTUBE-String)
spamassassin -t < test-mail.txt

# Detail-Analyse
spamassassin -D < test-mail.txt

GTUBE-Test

# Test-String für garantierte Spam-Erkennung
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

Regel-Check

# Regel-Syntax prüfen
spamassassin --lint

# Welche Regeln matchen?
spamassassin -t -D rules < mail.txt

Logging

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 -f

Benutzer-Konfiguration

Per-User-Einstellungen

# ~/.spamassassin/user_prefs

required_score 4.0
whitelist_from boss@company.com
blacklist_from *@competitor.com

SQL-basierte Konfiguration

# /etc/spamassassin/local.cf

user_scores_dsn DBI:mysql:spamassassin:localhost
user_scores_sql_username spamassassin
user_scores_sql_password password

Troubleshooting

Spam nicht erkannt

# Mail analysieren
spamassassin -t -D < undetected-spam.eml

# Regeln aktualisieren
sa-update

# Bayes trainieren
sa-learn --spam < undetected-spam.eml

False Positives

# Als Ham lernen
sa-learn --ham < false-positive.eml

# Absender whitelisten
whitelist_from sender@example.com

Performance-Probleme

# Mehr Children
OPTIONS="--max-children 10"

# DNS-Tests reduzieren
skip_rbl_checks 1

# Timeouts reduzieren
rbl_timeout 5

Zusammenfassung

| 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.