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 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 in Rspamd einbinden
Anleitung: ClamAV-Integration in Rspamd (TCP-Modus)
Diese Dokumentation beschreibt die Konfiguration von ClamAV über Systemd-Sockets und die Anbindung an Rspamd.
Systemd-Socket-Konfiguration
Die Socket-Unit muss angepasst werden, um den TCP-Port 3310 freizugeben. Um das Original-File unter /lib/ zu erhalten, wird eine Kopie in /etc/systemd/system/ erstellt und mittels sed angepasst:
sed "s^ListenStream=/run/clamav/clamd.ctl^ListenStream=127.0.0.1:3310^" /lib/systemd/system/clamav-daemon.socket > /etc/systemd/system/clamav-daemon.socket
Aktivierung der Änderungen:
systemctl daemon-reload systemctl restart clamav-daemon.socket systemctl restart clamav-daemon.service
Überprüfung des Sockets:
ss -ltpn | grep 3310
Rspamd-Modul Konfiguration
Die Konfiguration erfolgt als Override, um lokale Scans und kleine Dateien (EICAR) zu erzwingen.
Datei: /etc/rspamd/override.d/antivirus.conf
enabled = true;
clamav {
type = "clamav";
symbol = "CLAM_VIRUS";
servers = "127.0.0.1:3310";
scan_text_mime = true;
scan_mime_parts = true;
min_size = 0;
scan_unauthenticated = true;
stream = true;
score = 20.0;
}
Neustart des Dienstes:
systemctl restart rspamd
Erstellung der Test-E-Mail
Für die Validierung muss eine Datei mit korrekter MIME-Struktur und dem EICAR-Teststring erstellt werden.
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--
Test der Konfiguration
Der Scan wird mit rspamc simuliert:
rspamc --ip 1.2.3.4 /tmp/virus.eml
Ein erfolgreicher Scan wird durch das Symbol CLAM_VIRUS im Output bestätigt.

