Rspamd Bayes: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
= Bayes ON TOP des bestehenden Keyword-Setups =
 +
 
= Ziel =
 
= Ziel =
* Spam wird erkannt
+
* Keyword-Filter bleibt aktiv
* Spam landet im Junk
+
* Bayes wird zusätzlich aktiviert
 
* KEIN Reject
 
* KEIN Reject
* KEIN Lernen
+
* KEIN Greylist
* Bayes nur vorbereitet
+
* KEIN Autolearn
 
+
* Lernen nur manuell
= Schritt 0: Voraussetzungen prüfen =
+
* Junk-Logik bleibt ausschließlich in Dovecot/Sieve
; Rspamd setzt Header nur bei add_header
 
; Dovecot muss Sieve im LMTP haben
 
  
*grep -R "protocol lmtp" /etc/dovecot/conf.d/20-lmtp.conf
+
= Voraussetzung =
; MUSS enthalten:
+
; Dein bestehendes Setup funktioniert:
; mail_plugins = $mail_plugins sieve
+
; rspamd setzt X-Spam: Yes
 +
; Dovecot sortiert nach Junk
  
= Schritt 1: Bayes ruhigstellen (nicht aktiv, nicht löschen) =
+
= Schritt 1: Bayes aktivieren (kontrolliert) =
 
*vi /etc/rspamd/local.d/classifier-bayes.conf
 
*vi /etc/rspamd/local.d/classifier-bayes.conf
 
<pre>
 
<pre>
 
backend = "sqlite3";
 
backend = "sqlite3";
path = "/var/lib/rspamd/bayes.sqlite";
+
 
 
autolearn = false;
 
autolearn = false;
 
min_tokens = 11;
 
min_tokens = 11;
</pre>
 
*systemctl restart rspamd
 
  
= Schritt 2: Aktionen so setzen, dass NIE gebounced wird =
+
statfile {
*vi /etc/rspamd/local.d/actions.conf
+
    name = "bayes_spam";
<pre>
+
    symbol = "BAYES_SPAM";
reject = 999;
+
    path = "/var/lib/rspamd/bayes_spam.sqlite";
greylist = 999;
+
}
add_header = 6;
 
</pre>
 
*systemctl restart rspamd
 
 
 
; Erklärung:
 
; Score >= 6 → add_header → X-Spam: Yes
 
; Reject ist faktisch unmöglich
 
 
 
= Schritt 3: Hauptfilter – Keywords (DEIN Filter) =
 
*mkdir -p /etc/rspamd/local.d/lists
 
  
*vi /etc/rspamd/local.d/multimap.conf
+
statfile {
<pre>
+
     name = "bayes_ham";
CUSTOM_KEYWORDS {
+
     symbol = "BAYES_HAM";
     type = "content";
+
     path = "/var/lib/rspamd/bayes_ham.sqlite";
     map = "/etc/rspamd/local.d/lists/junk_keywords.map";
 
     regexp = true;
 
    icase = true;
 
    symbol = "CUSTOM_KEYWORDS";
 
    score = 10.0;
 
 
}
 
}
</pre>
 
  
*vi /etc/rspamd/local.d/lists/junk_keywords.map
 
<pre>
 
viagra
 
cialis
 
tadalafil
 
penis enlargement
 
xxx
 
porn
 
 
</pre>
 
</pre>
  
 
*systemctl restart rspamd
 
*systemctl restart rspamd
  
= Schritt 4: Funktionstest Rspamd (ohne Mailserver) =
+
= Schritt 2: Prüfen, ob Bayes geladen ist =
*cat <<EOF | rspamc
+
*rspamadm configtest
From: a@b
+
syntax OK
To: c@d
 
Subject: viagra test
 
  
cheap viagra now
+
= Schritt 3: Bayes-Status prüfen (leer ist OK) =
EOF
+
*rspamc stat
  
; MUSS ergeben:
+
; Erwartung:
; Action: add header
+
; Bayes statistics:
; Symbol: CUSTOM_KEYWORDS
+
; learned: 0 spam, 0 ham
; Score >= 10
 
  
= Schritt 5: Dovecot – Junk-Ablage NUR über Sieve =
+
= Schritt 4: Erste Trainingsmails vorbereiten =
; KEIN imapsieve
+
; Hinweis:
; KEIN Lernskript
+
; Die folgenden Beispiele sind Trainingsmails für Bayes.
; KEIN Pipe
+
; In der Praxis müssen die Dateien OHNE führende Leerzeichen erstellt werden.
 +
; Die Einrückung dient ausschließlich der MediaWiki-Darstellung.
  
*vi /etc/dovecot/conf.d/90-sieve.conf
+
; Spam-Beispiel (nur als Formatbeispiel – nicht ideal für Bayes, da Keyword-basiert)
 +
*vi /root/spam1.eml
 
<pre>
 
<pre>
plugin {
+
From: offer@newsletter.example
    sieve = ~/.dovecot.sieve
+
To: user@example.de
    sieve_before = /var/lib/dovecot/sieve/spam-to-junk.sieve
+
Subject: limited time special offer just for you
}
+
Date: Sun, 14 Dec 2025 19:00:00 +0100
 +
Message-ID: <spam1@bad.example>
 +
MIME-Version: 1.0
 +
Content-Type: text/plain; charset=UTF-8
 +
 
 +
this is a limited time promotional offer
 +
exclusive discount available only today
 +
no prescription required fast approval
 +
order online with instant confirmation
 +
secure payment and fast worldwide delivery
 +
customer satisfaction guaranteed
 +
unsubscribe anytime using the link below
 
</pre>
 
</pre>
  
*mkdir -p /var/lib/dovecot/sieve
+
*vi /root/ham1.eml
 +
<pre>
 +
From: colleague@good.example
 +
To: user@example.de
 +
Subject: project meeting agenda
 +
Date: Sun, 14 Dec 2025 19:01:00 +0100
 +
Message-ID: <ham1@good.example>
 +
MIME-Version: 1.0
 +
Content-Type: text/plain; charset=UTF-8
 +
 
 +
hello thomas,
 +
 
 +
attached is the agenda for our project meeting
 +
next week. please review the topics in advance
 +
and let me know if something is missing.
  
*vi /var/lib/dovecot/sieve/spam-to-junk.sieve
+
attached is the agenda for our project meeting
<pre>
+
next week. please review the topics in advance
require ["fileinto"];
+
and let me know if something is missing.
  
if header :contains "X-Spam" "Yes" {
+
best regards
    fileinto "Junk";
 
    stop;
 
}
 
 
</pre>
 
</pre>
  
*sievec /var/lib/dovecot/sieve/spam-to-junk.sieve
+
= Schritt 5: Manuelles Lernen =
*chown dovecot:dovecot /var/lib/dovecot/sieve/spam-to-junk.*
+
*rspamc learn_spam /root/spam1.eml
*chmod 644 /var/lib/dovecot/sieve/spam-to-junk.*
+
*rspamc learn_ham /root/ham1.eml
  
*systemctl restart dovecot
+
= Schritt 6: Lernstand prüfen =
 +
*rspamc stat
  
= Schritt 6: ECHTER Test =
+
; Erwartung:
; Mail mit:
+
; learned: 1 spam, 1 ham
; Subject: viagra
+
 
; Body: viagra
+
= Schritt 7: Wirkung testen (ohne Keyword-Treffer) =
 +
*cat <<EOF | rspamc
 +
From: x@y
 +
To: z@a
 +
Subject: cheap pills
 +
 
 +
buy pills online
 +
EOF
  
 
; Erwartung:
 
; Erwartung:
; Mail wird angenommen
+
; Symbol: BAYES_SPAM oder BAYES_HAM
; Mail ist NICHT gebounced
+
; Score > 0 (klein!)
; Mail liegt in:
+
 
; ~/Maildir/.Junk/cur/
+
= Schritt 8: Zusammenspiel mit Keywords (realer Effekt) =
 +
; Beispiel:
 +
; CUSTOM_KEYWORDS  +8.0
 +
; BAYES_SPAM      +2.x
 +
; ---------------------
 +
; Gesamt          > add_header
 +
; → X-Spam: Yes
 +
; → Sieve → Junk
 +
 
 +
= WICHTIG =
 +
; Bayes ist am Anfang schwach
 +
; Erst ab ~500 Spam + ~500 Ham brauchbar
 +
; Keywords bleiben Hauptfilter
  
= Schritt 7: Kontrolle =
+
= Merksatz =
*ls /home/thomas.will/Maildir/.Junk/cur/
+
; Keywords = deterministisch
 +
; Bayes    = statistisch
 +
; Sieve    = entscheidet

Aktuelle Version vom 15. Dezember 2025, 07:42 Uhr

Bayes ON TOP des bestehenden Keyword-Setups

Ziel

  • Keyword-Filter bleibt aktiv
  • Bayes wird zusätzlich aktiviert
  • KEIN Reject
  • KEIN Greylist
  • KEIN Autolearn
  • Lernen nur manuell
  • Junk-Logik bleibt ausschließlich in Dovecot/Sieve

Voraussetzung

Dein bestehendes Setup funktioniert
rspamd setzt X-Spam
Yes
Dovecot sortiert nach Junk

Schritt 1: Bayes aktivieren (kontrolliert)

  • vi /etc/rspamd/local.d/classifier-bayes.conf
backend = "sqlite3";

autolearn = false;
min_tokens = 11;

statfile {
    name = "bayes_spam";
    symbol = "BAYES_SPAM";
    path = "/var/lib/rspamd/bayes_spam.sqlite";
}

statfile {
    name = "bayes_ham";
    symbol = "BAYES_HAM";
    path = "/var/lib/rspamd/bayes_ham.sqlite";
}

  • systemctl restart rspamd

Schritt 2: Prüfen, ob Bayes geladen ist

  • rspamadm configtest
syntax OK

Schritt 3: Bayes-Status prüfen (leer ist OK)

  • rspamc stat
Erwartung
Bayes statistics
learned
0 spam, 0 ham

Schritt 4: Erste Trainingsmails vorbereiten

Hinweis
Die folgenden Beispiele sind Trainingsmails für Bayes.
In der Praxis müssen die Dateien OHNE führende Leerzeichen erstellt werden.
Die Einrückung dient ausschließlich der MediaWiki-Darstellung.
Spam-Beispiel (nur als Formatbeispiel – nicht ideal für Bayes, da Keyword-basiert)
  • vi /root/spam1.eml
From: offer@newsletter.example
To: user@example.de
Subject: limited time special offer just for you
Date: Sun, 14 Dec 2025 19:00:00 +0100
Message-ID: <spam1@bad.example>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

this is a limited time promotional offer
exclusive discount available only today
no prescription required fast approval
order online with instant confirmation
secure payment and fast worldwide delivery
customer satisfaction guaranteed
unsubscribe anytime using the link below
  • vi /root/ham1.eml
From: colleague@good.example
To: user@example.de
Subject: project meeting agenda
Date: Sun, 14 Dec 2025 19:01:00 +0100
Message-ID: <ham1@good.example>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

hello thomas,

attached is the agenda for our project meeting
next week. please review the topics in advance
and let me know if something is missing.

attached is the agenda for our project meeting
next week. please review the topics in advance
and let me know if something is missing.

best regards

Schritt 5: Manuelles Lernen

  • rspamc learn_spam /root/spam1.eml
  • rspamc learn_ham /root/ham1.eml

Schritt 6: Lernstand prüfen

  • rspamc stat
Erwartung
learned
1 spam, 1 ham

Schritt 7: Wirkung testen (ohne Keyword-Treffer)

  • cat <<EOF | rspamc

From: x@y To: z@a Subject: cheap pills

buy pills online EOF

Erwartung
Symbol
BAYES_SPAM oder BAYES_HAM
Score > 0 (klein!)

Schritt 8: Zusammenspiel mit Keywords (realer Effekt)

Beispiel
CUSTOM_KEYWORDS +8.0
BAYES_SPAM +2.x
---------------------
Gesamt > add_header
→ X-Spam
Yes
→ Sieve → Junk

WICHTIG

Bayes ist am Anfang schwach
Erst ab ~500 Spam + ~500 Ham brauchbar
Keywords bleiben Hauptfilter

Merksatz

Keywords = deterministisch
Bayes = statistisch
Sieve = entscheidet