Rspamd Keyword Filter

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Installation von Rspamd auf mail.echt.jetzt.de

  • Voraussetzung: Postfix, Dovecot und Roundcube laufen bereits.

Pakete installieren (Debian/Ubuntu)

  • apt update
  • apt install rspamd redis-server dovecot-core

Dienste aktivieren

  • systemctl enable --now redis-server
  • systemctl enable --now rspamd

Passwort für den Webcontroller (API-Zugang) erzeugen

  • rspamadm pw
Speichern Sie den generierten HASH, z.B. $2$HASH_API_USER
Speichern Sie das KLARTEXT-Passwort, z.B. meinSuperGeheimPasswort

Controller-Konfiguration anlegen

  • vi /etc/rspamd/override.d/worker-controller.inc

password = "$2$DEIN_HASH_HIER"; bind_socket = "*:11334";

Rspamd neu starten

  • systemctl restart rspamd

Zugriff auf das Webinterface

Rspamd in Postfix einbinden

  • 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 "GTUBE" deinuser@echt.jetzt.de

Logs ansehen

  • journalctl -u postfix@- -f

Lokale RBL (Proof of Concept)

Konfiguration
  • 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"; }

Blacklist anlegen
  • echo 10.88.113.21 > /etc/rspamd/local.d/local_rbl.txt
Rspamd neu starten
  • systemctl restart rspamd
Negativer Test
  • echo hallo | rspamc -i 10.88.113.21
Positiver Test
  • echo hallo | rspamc -i 10.88.113.22

Rspamd Bayes Training (Lernen aus dem Spam-Ordner) Konfiguration

Bayes-Modul aktivieren und Redis als Backend nutzen

  • vi /etc/rspamd/local.d/statistic.conf

statistic {     backend = "redis";     autolearn = true;     min_tokens = 5;     min_words = 5;     expire = 90d;     learn_condition = 'return true'; }

Redis-Verbindung definieren

  • vi /etc/rspamd/local.d/redis.conf

redis {     servers = "127.0.0.1:6379"; }

IMAP-API-Endpunkte für das Lernen in Rspamd definieren

  • vi /etc/rspamd/local.d/history_redis.conf

imaps_url = "http://127.0.0.1:11334/learn"; imaps_url_ham = "http://127.0.0.1:11334/learn_ham"; imaps_url_spam = "http://127.0.0.1:11334/learn_spam";

Rspamd neu starten, um alle Konfigurationen zu übernehmen
  • systemctl restart rspamd

Dovecot: Rspamd HTTP IMAP Filter (fseqn) aktivieren

fseqn ist oft in dovecot-core oder einem extra-paket enthalten, dovecot-sieve ist NICHT nötig.
fseqn_imap_spam_folder und fseqn_imap_ham_folder definieren die Ordner, deren Verschieben das Lernen auslöst.
  • vi /etc/dovecot/conf.d/90-fseqn.conf

plugin {   fseqn_imap_spam_folder = "Junk"   fseqn_imap_ham_folder = "INBOX"     ; Die API-Endpunkte für Rspamd   fseqn_url = "http://127.0.0.1:11334/learn_spam";   fseqn_ham_url = "http://127.0.0.1:11334/learn_ham";     ; WICHTIG: KLARTEXT-Passwort verwenden, NICHT den Hash!   fseqn_password = "DEIN_KLARTEXT_PASSWORT_HIER"; }

Prüfen, ob fseqn in den Mail-Plugins enthalten ist
Entfernen Sie hier ALLE SIEVE-BEZOGENEN PLUGINS (imap_sieve, sieve_extprograms, etc.)
  • vi /etc/dovecot/conf.d/20-imap.conf

mail_plugins = $mail_plugins fseqn

Dovecot neu starten

  • systemctl restart dovecot

Test: Hat Rspamd gelernt?

Verschieben Sie eine Mail in den Junk-Ordner und dann eine andere in den Posteingang.
  • rspamc stat
Hier sollten "learned spam" und "learned ham" angezeigt werden.