Thema Rspamd: Erweiterter Spam- und Virenschutz
Abschnitt 1: Vorwort & Installation
**Rspamd** ist ein Filterprogramm, um Mailserver effektiv vor Spam zu schützen. Es arbeitet eng mit **Redis** (als Datenbank für History, Greylisting und Bayes) und **ClamAV** (als Virenscanner) zusammen.
Da das gesamte Thema sehr umfangreich ist, stelle ich euch hier meine .conf Dateien vor. Das Paket wird auf dem Mailserver (oder einem separatem Server) installiert.
Installation des Pakets:
apt-get install rspamd clamav-daemon clamav-freshclam redis-server -y
Ordnerstruktur von Rspamd:
Nach der Installation solltet ihr folgende Ordner/Dateien vorfinden (Pfad: /etc/rspamd/):
root@mail-srv:/etc/rspamd# ls -l
total 104
-rw-r--r-- 1 _rspamd _rspamd 1213 Aug 13 17:37 actions.conf
... (gekürzte Ausgabe)
-rw-r--r-- 1 _rspamd _rspamd 1370 Aug 13 17:37 worker-proxy.inc
Im Ordner **local.d/** findet ihr identische Dateien, die ihr aber bearbeiten könnt. Änderungen hier überschreiben die Standardeinstellungen in /etc/rspamd/.
In **modules.d/** findet ihr alle Module, die aktiv sind, sobald die Endung auf .conf endet. Bei mir sind einige deaktiviert (Endung .bkp), da ich sonst Probleme mit einigen Modulen habe.
Abschnitt 2: Rspamd Aktionen und Schwellwerte (actions.conf)
Wir beginnen im Ordner local.d/ mit den "Feineinstellungen" der Module. Zuerst die globalen Aktionen:
nano /etc/rspamd/local.d/actions.conf
Inhalt actions.conf (local.d/):
# Punktezahl absteigend sortieren!!!!
reject = 10;
rewrite_subject = 8;
add_header = 6;
greylist = 5;
subject = "[SPAM] %s";
Hier werden die **Schwellwerte (Scores)** festgelegt, was mit der Mail ab einer bestimmten Punktzahl geschehen soll. Alle "normalen" Mails haben bei mir zwischen -2 und +2 Punkten, das ist also recht großzügig, aber bisher sehr erfolgreich.
Abschnitt 3: Virenprüfung mit ClamAV (antivirus.conf)
nano /etc/rspamd/local.d/antivirus.conf
Inhalt antivirus.conf (local.d/):
#Enable or disable the module
enabled = true;
clamav {
# If set force this action if any virus is found (default unset: no action is forced, 'rewrite_subject' to tag as spam)
action = "reject";
message = '${SCANNER}: virus found: "${VIRUS}"';
# if `true` only messages with non-image attachments will be checked (default true)
scan_mime_parts = true;
scan_text_mime = true;
scan_image_mime = true;
# If `max_size` is set, messages > n bytes in size are not scanned
max_size = 20000000;
# symbol to add (add it to metric if you want non-zero weight)
symbol = "CLAM_VIRUS";
type = "clamav";
log_clean = true;
# Timeout and retransmits increased in case of clamav is reloading its database
timeout = 45.0;
retransmits = 1;
# servers to query (can be set to a path to a unix socket)
servers = "127.0.0.1:3310";
# if `patterns` is specified virus name will be matched against provided regexes
patterns {
# symbol_name = "pattern";
JUST_EICAR = "^Eicar-Test-Signature$";
}
# `whitelist` points to a map of IP addresses. Mail from these addresses is not scanned.
whitelist = "/etc/rspamd/antivirus.wl";
}
Wichtig hierbei ist: Den Socket und den Port (servers) findet ihr in der Datei /etc/clamav/clamd.conf.
Je nachdem, was ihr nutzen wollt:
servers = "/var/run/clamav/clamd.ctl";
oder
servers = "127.0.0.1:3310";
Abschnitt 4: Weitere Basiskonfigurationen
ASN (Autonomous System Number) - asn.conf
nano /etc/rspamd/local.d/asn.conf
Kurz und knapp:
asn {
symbol = "ASN";
}
Bayes-Klassifikator (classifier-bayes.conf)
nano /etc/rspamd/local.d/classifier-bayes.conf
Diese Datei sorgt für das automatische Lernen von Spam- und Ham-Mails und nutzt Redis (`backend = "redis"`).
backend = "redis";
expire = 8640000;
# autolearning is performing as spam if a message has reject
# action and as ham if a message has negative score
autolearn = true;
autolearn {
spam_threshold = 8; # When to learn spam (score >= threshold)
ham_threshold = -1.0; # When to learn ham (score <= threshold)
check_balance = true; # Check spam and ham balance
min_balance = 0.9; # Keep diff for spam/ham learns for at least this value
}
DKIM Signing (dkim_signing.conf)
nano /etc/rspamd/local.d/dkim_signing.conf
Diese Datei steuert die DKIM-Einträge und fügt diese an die Absendermails entsprechend ihrer Domain an. Die Erstellung der DKIM-Schlüssel wird später erklärt.
domain {
domain1.com {
selectors = [
{
selector = "default";
path = "/etc/rspamd/dkim/domain1/default.key";
}
];
}
domain2.com {
selectors = [
{
selector = "default";
path = "/etc/rspamd/dkim/domain2/default.key";
}
];
}
domain3.com {
selectors = [
{
selector = "default";
path = "/etc/rspamd/dkim/domain3/default.key";
}
];
}
}
allow_envfrom_empty = true;
allow_hdrfrom_mismatch = true;
allow_username_mismatch = true;
try_fallback = true;
use_domain = "header";
check_pubkey = true;
allow_pubkey_mismatch = true;
sign_authenticated = true;
sign_local = true;
symbol = "DKIM_SIGNED";
Emails-Modul (emails.conf)
nano /etc/rspamd/local.d/emails.conf
Die Datei weist das emails-Modul an, den Absender der E-Mail aus den Headern From und Sender zu extrahieren.
emails {
header = "From-Header-with-Sender";
}