Rspamd Einrichten
Rspamd und ClamAV installieren
Debian/Ubuntu
apt install rspamd clamav-daemon clamav-freshclam redis
RHEL/CentOS
dnf install rspamd clamav clamav-update redis
Enablen und Startend er Dienste
systemctl enable rspamd --now systemctl enable clamav-daemon --now
Redis-Anbindung (Das Gedächtnis von Rspamd)
Damit Rspamd Scanergebnisse zwischenspeichern und statistische Analysen (Bayes) durchführen kann, ist eine Datenbank-Anbindung zwingend erforderlich. Ohne Redis arbeiten viele Module (wie Antivirus oder Greylisting) nur eingeschränkt oder gar nicht.
Installation und Aktivierung
Zuerst muss der Redis-Server auf dem System installiert und gestartet sein.
apt install redis-server systemctl enable --now redis-server
Konfiguration in Rspamd
Rspamd benötigt einen zentralen Ort, an dem die Server-Adresse von Redis definiert ist. Dies geschieht üblicherweise in einer lokalen Konfigurationsdatei.
Datei: /etc/rspamd/local.d/redis.conf
# Definition des lokalen Redis-Servers servers = "127.0.0.1:6379";
Prüfung der Anbindung
Ob Rspamd erfolgreich mit Redis kommuniziert, lässt sich über das Admin-Tool prüfen:
rspamadm control stat
In der Ausgabe sollte unter "Nodes" der Status des Redis-Servers als "online" oder "active" erscheinen.
Warum das für ClamAV wichtig ist
Virenscanner-Ergebnisse sind CPU-intensiv. Rspamd speichert das Ergebnis eines Scans (z.B. "Diese Datei mit Hash XY ist ein Virus") für eine gewisse Zeit in Redis. Wenn dieselbe Mail erneut reinkommt, muss ClamAV nicht noch einmal rechnen – Rspamd holt die Antwort direkt aus dem Redis-Cache.
systemctl start redis-server systemctl enable redis-server.service
Läuft alles
systemctl status rspamd systemctl status clamav-daemon systemctl status redis
Dienste und Ports von Rspamd
Rspamd Proxy
- Der Rspamd Proxy dient als Eingangsfilter für E-Mails und leitet sie an die entsprechenden Worker weiter, um die Last zu verteilen.
Port: 11332/tcp (Standardport für Proxy-Dienste)
Rspamd Worker
- Der Rspamd Worker führt die eigentliche Spam-Analyse durch und verarbeitet eingehende Nachrichten anhand von Regeln, Statistiken und externen Diensten.
Port: 11333/tcp (Standardport für Worker-Dienste)
Rspamd Controller
- Der Rspamd Controller stellt eine API für Konfiguration, Statistiken und manuelles Training des Filters zur Verfügung.
Port: 11334/tcp (Standardport für den Controller)
Passwort für den Rspamd Controller und Port nach aussen öffen
- Passwort erzeugen
rspamadm pw
Enter passphrase: $2$mqbbp8yb4fz8febgpxk7rb4db9p5njwg$xior3gxjbuc76bhsq4rapq7x98cssrm9qkr49kwapgdsahmpzjny
- In der Worker Datei eintragen
- Port an allen Interfaces lauschen lassen
cat /etc/rspamd/override.d/worker-controller.inc password = "$2$mqbbp8yb4fz8febgpxk7rb4db9p5njwg$xior3gxjbuc76bhsq4rapq7x98cssrm9qkr49kwapgdsahmpzjny"; bind_socket ="*:11334";
Restart
systemctl restart rspamd
Zugriff auf das Webinterface
Milters
- Milters sind Mail-Filter, die über das Milter-Protokoll mit MTA-Software wie Postfix oder Sendmail kommunizieren.
- Sie ermöglichen die Verarbeitung und Filterung von E-Mails in Echtzeit, bevor sie zugestellt werden.
- Milter werden häufig für Spam-Filterung, Virenscans und Inhaltsüberprüfungen eingesetzt.
Einbinden in Postfix
postconf -e "smtpd_milters=inet:127.0.0.1:11332" postconf -e "non_smtpd_milters=inet:127.0.0.1:11332" postfix reload
Gtube Testmail
- echo 'XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X' | mail -s "Boese Mail" martha
Resultat
Die Logs
journalctl -u postfix | grep cleanup Mar 18 19:21:22 mail.it113.int postfix/cleanup[7407]: 88BDDE0792: milter-reject: END-OF-MESSAGE from localhost[127.0.0.1]: 5.7.1 Gtube pattern; from=<root@mail.it113.int> to=<martha@mail.it113.int> Mar 18 19:21:22 mail.it113.int postfix/cleanup[7407]: 88BDDE0792: to=<martha@mail.it113.int>, orig_to=<martha>, relay=none, delay=0.19, delays=0.19/0/0/0, dsn=5.7.1, status=bounced (Gtube pattern) Mar 18 19:21:22 mail.it113.int postfix/cleanup[7410]: B3D24E07C2: message-id=<20250318182122.B3D24E07C2@mail.it113.int>
Restart
- systemctl restart rspamd
RBL-Integration in Rspamd und Postfix (Proof of Concept)
Rspamd mit lokaler RBL
Configuration
vi /etc/rspamd/local.d/multimap.conf
blacklist_ip {
type = "ip";
map = "/etc/rspamd/local.d/local_rbl.txt";
symbol = "LOCAL_RBL_HIT";
action = "reject";
description = "Lokale RBL-Hit";
}
Blackliste
echo 10.88.113.21 > /etc/rspamd/local.d/local_rbl.txt
Rspamd neustarten
systemctl restart rspamd
Tests
- postiv
echo hallo welt | rspamc -i 10.88.113.22
Results for file: stdin (0 seconds) [Metric: default] Action: add header Spam: true Score: 7.90 / 15.00 Symbol: ARC_NA (0.00) Symbol: MIME_GOOD (-0.10)[text/plain] Symbol: MIME_TRACE (0.00)[0:+] Symbol: MISSING_DATE (1.00) Symbol: MISSING_FROM (2.00) Symbol: MISSING_MID (2.50) Symbol: MISSING_SUBJECT (0.50) Symbol: MISSING_TO (2.00) Symbol: RCVD_COUNT_ZERO (0.00)[0] Message-ID: undef
- negativ
- echo hallo welt | rspamc -i 10.88.113.21
Results for file: stdin (0 seconds) [Metric: default] Action: reject Spam: true Score: -0.10 / 15.00 Symbol: ARC_NA (0.00) Symbol: LOCAL_RBL_HIT (0.00)[10.88.113.21] Symbol: MIME_GOOD (-0.10)[text/plain] Symbol: MIME_TRACE (0.00)[0:+] Message-ID: undef Message - smtp_message: Matched map: LOCAL_RBL_HIT
Rspamd Schwellenwerte (Actions)
Die Bewertung erfolgt über Scores. Diese werden in der Datei /etc/rspamd/local.d/actions.conf definiert.
| Aktion | Empfohlener Score | Bedeutung |
|---|---|---|
| reject | 15.0 | Die Mail wird hart abgelehnt (SMTP 5xx). |
| add_header | 6.0 | Die Mail wird zugestellt, erhält aber einen Header (z.B. X-Spam: Yes). |
| greylist | 4.0 | Der Absender wird temporär abgewiesen (Soft-Fail). Ein echter Mailserver versucht es erneut. |
| no action | < 4.0 | Die Mail gilt als sauber (Ham). |
Kurzer Check der Funktionsweise
Um zu sehen, welche Symbole Rspamd einer Mail vergibt, ohne eine echte Mail zu senden:
rspamc < /pfad/zu/einer/test.eml
Das Tool rspamc gibt den kompletten Scan-Report direkt auf der Konsole aus.
ClamAV-Integration in Rspamd (TCP-Modus)
Diese Dokumentation beschreibt die Konfiguration von ClamAV ueber Systemd-Sockets und die Anbindung an Rspamd unter Debian/Ubuntu.
Systemd-Infrastruktur
Um ClamAV via TCP erreichbar zu machen, muessen die Socket-Unit und vorbereitende Dienst-Einstellungen angepasst werden.
/etc/systemd/system/clamav-daemon.socket
Die Socket-Unit wird so konfiguriert, dass sie auf Port 3310 lauscht.
[Unit]
Description=Socket for Clam AntiVirus userspace daemon
Documentation=man:clamd(8) man:clamd.conf(5) https://docs.clamav.net/
# Datenbank-Check vor Socket-Aktivierung
ConditionPathExistsGlob=/var/lib/clamav/main.{c[vl]d,inc}
ConditionPathExistsGlob=/var/lib/clamav/daily.{c[vl]d,inc}
[Socket]
# Definition des TCP-Sockets fuer Rspamd Kommunikation
ListenStream=127.0.0.1:3310
SocketUser=clamav
SocketGroup=clamav
RemoveOnStop=True
[Install]
WantedBy=sockets.target
Aktivierung der Systemd-Anpassungen
systemctl daemon-reload systemctl restart clamav-daemon.socket systemctl restart clamav-daemon.service # Verifizierung des Sockets ss -ltpn | grep 3310
ClamAV Konfiguration
Die Hauptkonfiguration von ClamAV muss auf den TCP-Modus abgestimmt sein und ausreichende Puffer fuer den Datenstream bieten.
/etc/clamav/clamd.conf
# Manuell angepasst fuer Rspamd nINSTREAM TCPSocket 3310 TCPAddr 127.0.0.1 User clamav ScanMail true ScanArchive true ArchiveBlockEncrypted false MaxDirectoryRecursion 15 FollowDirectorySymlinks false FollowFileSymlinks true ReadTimeout 180 MaxThreads 12 MaxConnectionQueueLength 15 LogSyslog false LogRotate true LogFacility LOG_LOCAL6 LogClean false LogVerbose false DatabaseDirectory /var/lib/clamav OfficialDatabaseOnly false SelfCheck 3600 Foreground false Debug false ScanPE true MaxEmbeddedPE 10M ScanOLE2 true ScanPDF true ScanHTML true MaxHTMLNormalize 10M MaxHTMLNoTags 2M MaxScriptNormalize 5M MaxZipTypeRcg 1M ScanSWF true ExitOnOOM false LeaveTemporaryFiles false AlgorithmicDetection true ScanELF true IdleTimeout 30 CrossFilesystems true PhishingSignatures true PhishingScanURLs true ExtendedDetectionInfo true AllowAllMatchScan true ForceToDisk false DisableCertCheck false DisableCache false MaxScanTime 120000 MaxScanSize 100M MaxFileSize 25M MaxRecursion 16 MaxFiles 10000 # Wichtig fuer Rspamd Integration zur Vermeidung von "Size limit exceeded" StreamMaxLength 100M LogFile /var/log/clamav/clamav.log LogTime true Bytecode true BytecodeSecurity TrustSigned BytecodeTimeout 60000
Rspamd Konfiguration
Rspamd greift als Client auf den ClamAV-Socket zu. Die Konfiguration erfolgt ueber Overrides und lokale Includes.
/etc/rspamd/override.d/antivirus.conf
Erzwingt den Scan auch fuer unauthentifizierte lokale Absender und winzige Dateien.
enabled = true;
clamav {
type = "clamav";
symbol = "CLAM_VIRUS";
servers = "127.0.0.1:3310";
# Erlaubt das Scannen von reinem Text (Body)
scan_text_mime = true;
scan_mime_parts = true;
# Scannt auch winzige Dateien (EICAR ist < 100 Bytes)
min_size = 0;
# Ignoriert, dass die Mail von localhost/trusted IP kommt
scan_unauthenticated = true;
# Technische Uebertragung via nINSTREAM
stream = true;
# Das Symbol soll sofort zum Reject fuehren
score = 20.0;
}
Weitere Rspamd-Module
Unter /etc/rspamd/local.d/ werden Logging, Redis und RBL-Dienste definiert.
logging.inc
debug_modules = ["antivirus", "clamav"];
redis.conf
servers = "127.0.0.1";
rbl.conf
enabled = false;
worker-controller.inc (WebUI)
password = "$2$5dj6zn4mt56sbmh8nw944c41wt537tdb$z4op8fwmunpwhe7yzbm94wgeqsdq8ajgjc4zs387e5qxnzppw46y"; bind_socket ="*:11334";
Aktivierung Rspamd
rspamadm configtest systemctl restart rspamd redis-cli flushall
Validierung
Erstellung der Test-E-Mail
Datei: /tmp/virus.eml
From: Test <test@it213.int> To: Root <root@it213.int> Subject: EICAR Test MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Grenzlinie" --Grenzlinie Content-Type: text/plain; charset="utf-8" Antivirus Testmail. --Grenzlinie Content-Type: application/com-file; name="eicar.com" Content-Disposition: attachment; filename="eicar.com" Content-Transfer-Encoding: 7bit X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* --Grenzlinie--
Testlauf
rspamc --ip 1.2.3.4 /tmp/virus.eml
Ein erfolgreicher Scan wird durch das Symbol CLAM_VIRUS und die Aktion reject bestaetigt.
Fehlerdiagnose und Administration: ClamAV und Rspamd
Diese Zusammenfassung dient als Spickzettel fuer die taegliche Administration und Fehlerbehebung.
Protokolldateien ueberwachen
Die wichtigsten Dateien zur Fehlersuche:
- Rspamd Hauptlog: /var/log/rspamd/rspamd.log
- ClamAV Scanlog: /var/log/clamav/clamav.log
- ClamAV Update-Log: /var/log/clamav/freshclam.log
- System-Journal (fuer Service-Fehler): journalctl -u clamav-daemon -u rspamd
Live-Ueberwachung der Scans:
tail -f /var/log/rspamd/rspamd.log | grep -E "antivirus|clamav"
Netzwerk-Ports und Sockets
Folgende Ports muessen auf der lokalen Schnittstelle (127.0.0.1) aktiv sein:
- Port 3310: ClamAV TCP-Socket (nINSTREAM)
- Port 11333: Rspamd Worker (Normaler Mailflow)
- Port 11334: Rspamd Controller (WebUI und API)
- Port 6379: Redis Key-Value Store
Pruefung mit dem Befehl ss:
ss -ltpn | grep -E "3310|11333|11334|6379"
Redis Datenbank bereinigen
Wenn Rspamd unerwartete Bewertungen abgibt oder alte gelernte Daten (Bayes) stoeren, kann der Zwischenspeicher geleert werden:
# Loescht alle Daten in allen Redis-Datenbanken redis-cli flushall
Manueller Virenscan
Um zu pruefen, ob ClamAV arbeitet, ohne den Umweg ueber Rspamd zu gehen, nutzt man clamdscan oder sendet den Datenstrom direkt:
# Per clamdscan (nutzt die Konfiguration in /etc/clamav/clamd.conf) clamdscan /tmp/virus.eml
Aktualisierung der Virendefinitionen
Das Werkzeug freshclam laeuft normalerweise als Hintergrunddienst. Manuelle Steuerung:
# Status des Update-Dienstes pruefen systemctl status clamav-freshclam # Update manuell erzwingen (Dienst muss vorher gestoppt werden) systemctl stop clamav-freshclam freshclam systemctl start clamav-freshclam
Prüfung der Dienstkonfiguration
Bevor man Dienste neu startet, sollte immer die Syntax der Dateien geprueft werden:
rspamadm configtest
Rspam kommuniziert mit Clamav?
- Redis immer leeren, sonst kommen die Ergebnisse aus dem Cache
redis-cli flushall systemctl restart rspamd
- Unix Socket
apt install strace systemctl restart rspamd
- TCP Socket
apt install tcpdump tcpdump -ni lo port 3310

