Rspamd Neu: Unterschied zwischen den Versionen
| Zeile 1: | Zeile 1: | ||
== Installation von Rspamd, Postfix und Dovecot == | == Installation von Rspamd, Postfix und Dovecot == | ||
| − | |||
| − | |||
=== Paketinstallation === | === Paketinstallation === | ||
| − | + | Die Installation erfolgt unter Debian/Ubuntu: | |
| − | Die Installation erfolgt unter Debian/Ubuntu | ||
* apt update | * apt update | ||
| − | * apt install rspamd clamav-daemon dovecot-sieve dovecot-managesieved | + | * apt install -y rspamd clamav-daemon dovecot-sieve dovecot-managesieved postfix |
=== Rspamd: Modul-Konfiguration === | === Rspamd: Modul-Konfiguration === | ||
| − | + | ==== Virenscanner (ClamAV) ==== | |
| − | |||
| − | ==== Virenscanner | ||
Datei: /etc/rspamd/local.d/antivirus.conf | Datei: /etc/rspamd/local.d/antivirus.conf | ||
<pre> | <pre> | ||
clamav { | clamav { | ||
scan_mime_parts = true; | scan_mime_parts = true; | ||
| − | |||
| − | |||
symbol = "CLAM_VIRUS"; | symbol = "CLAM_VIRUS"; | ||
type = "clamav"; | type = "clamav"; | ||
| Zeile 26: | Zeile 19: | ||
</pre> | </pre> | ||
| − | + | ==== Web-Interface (Netzwerkzugriff erzwungen) ==== | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | ==== Web-Interface | ||
Datei: /etc/rspamd/local.d/worker-controller.inc | Datei: /etc/rspamd/local.d/worker-controller.inc | ||
<pre> | <pre> | ||
| − | bind_socket = " | + | bind_socket = "0.0.0.0:11334"; |
| − | password = "$2$abcdef..."; | + | password = "$2$abcdef..."; |
| + | enable_password = "$2$abcdef..."; | ||
</pre> | </pre> | ||
| − | === Postfix | + | === Postfix & Dovecot Integration === |
| − | |||
| − | |||
| − | ==== | + | ==== Milter in Postfix ==== |
| − | |||
* usermod -aG rspamd postfix | * usermod -aG rspamd postfix | ||
| − | |||
| − | |||
Datei: /etc/postfix/main.cf | Datei: /etc/postfix/main.cf | ||
<pre> | <pre> | ||
| − | |||
smtpd_milters = unix:/var/lib/rspamd/rspamd.sock | smtpd_milters = unix:/var/lib/rspamd/rspamd.sock | ||
non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock | non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock | ||
| − | |||
milter_protocol = 6 | milter_protocol = 6 | ||
</pre> | </pre> | ||
| − | + | ==== Sieve in Dovecot ==== | |
| − | |||
| − | |||
| − | |||
| − | === | ||
| − | |||
| − | |||
| − | |||
| − | |||
Datei: /etc/dovecot/conf.d/20-lmtp.conf | Datei: /etc/dovecot/conf.d/20-lmtp.conf | ||
<pre> | <pre> | ||
| Zeile 80: | Zeile 46: | ||
</pre> | </pre> | ||
| − | == | + | == Script (setup_mail.sh) == |
| − | |||
<pre> | <pre> | ||
| − | + | #!/bin/bash | |
| + | while getopts "p:" opt; do | ||
| + | case $opt in | ||
| + | p) USER_PASS=$OPTARG ;; | ||
| + | *) echo "Nutzung: $0 -p <passwort>"; exit 1 ;; | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | if [ -z "$USER_PASS" ]; then | ||
| + | echo "Fehler: Passwort mit -p angeben!" | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | apt update && apt install -y rspamd clamav-daemon dovecot-sieve dovecot-managesieved postfix | ||
| + | |||
| + | RSPAMD_HASH=$(rspamadm pw -p "$USER_PASS") | ||
| + | mkdir -p /etc/rspamd/local.d/ | ||
| − | + | echo 'bind_socket = "0.0.0.0:11334";' > /etc/rspamd/local.d/options.inc | |
| − | + | cat <<EOF > /etc/rspamd/local.d/worker-controller.inc | |
| − | + | bind_socket = "0.0.0.0:11334"; | |
| + | password = "$RSPAMD_HASH"; | ||
| + | enable_password = "$RSPAMD_HASH"; | ||
| + | EOF | ||
| + | |||
| + | cat <<EOF > /etc/rspamd/local.d/antivirus.conf | ||
| + | clamav { | ||
| + | scan_mime_parts = true; | ||
| + | symbol = "CLAM_VIRUS"; | ||
| + | type = "clamav"; | ||
| + | servers = "/run/clamav/clamd.ctl"; | ||
} | } | ||
| − | + | EOF | |
| − | + | usermod -aG rspamd postfix | |
| − | + | postconf -e "smtpd_milters = unix:/var/lib/rspamd/rspamd.sock" | |
| − | + | postconf -e "non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock" | |
| − | == | + | sed -i 's/mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/20-lmtp.conf |
| + | mkdir -p /var/lib/dovecot/sieve/ | ||
| + | echo 'require ["fileinto"]; if header :contains "X-Spam" "Yes" { fileinto "Junk"; stop; }' > /var/lib/dovecot/sieve/default.sieve | ||
| + | sievec /var/lib/dovecot/sieve/default.sieve | ||
| + | chown -R vmail:vmail /var/lib/dovecot/sieve/ 2>/dev/null || chown -R dovecot:dovecot /var/lib/dovecot/sieve/ | ||
| − | + | systemctl restart clamav-daemon rspamd postfix dovecot | |
| − | + | echo "URL: http://$(hostname -I | awk '{print $1}'):11334" | |
| − | + | </pre> | |
| − | == | + | == Analyse der Filter-Logik == |
| − | |||
| − | |||
| − | == | + | === Live-Analyse im Terminal === |
| − | + | * journalctl -u rspamd -f | grep -E "symbol|action" | |
| + | |||
| + | === Beispiel einer Log-Zeile === | ||
| + | <pre> | ||
| + | (default: F (reject): [15.50 / 15.00] [GTUBE(0.00), R_SPF_FAIL(1.00), BAYES_SPAM(5.10)]) | ||
| + | </pre> | ||
| + | === Übung: Die Detektiv-Arbeit === | ||
| + | # Sende saubere Mail -> Score prüfen. | ||
| + | # Manipuliere Absender (SPF-Fail) -> Score-Anstieg beobachten. | ||
| + | # Spam-Begriffe einfügen -> Finalen Reject provozieren. | ||
== Script == | == Script == | ||
<pre> | <pre> | ||
Version vom 18. März 2026, 18:07 Uhr
Installation von Rspamd, Postfix und Dovecot
Paketinstallation
Die Installation erfolgt unter Debian/Ubuntu:
- apt update
- apt install -y rspamd clamav-daemon dovecot-sieve dovecot-managesieved postfix
Rspamd: Modul-Konfiguration
Virenscanner (ClamAV)
Datei: /etc/rspamd/local.d/antivirus.conf
clamav {
scan_mime_parts = true;
symbol = "CLAM_VIRUS";
type = "clamav";
servers = "/run/clamav/clamd.ctl";
}
Web-Interface (Netzwerkzugriff erzwungen)
Datei: /etc/rspamd/local.d/worker-controller.inc
bind_socket = "0.0.0.0:11334"; password = "$2$abcdef..."; enable_password = "$2$abcdef...";
Postfix & Dovecot Integration
Milter in Postfix
- usermod -aG rspamd postfix
Datei: /etc/postfix/main.cf
smtpd_milters = unix:/var/lib/rspamd/rspamd.sock non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock milter_protocol = 6
Sieve in Dovecot
Datei: /etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
mail_plugins = $mail_plugins sieve
}
Script (setup_mail.sh)
#!/bin/bash
while getopts "p:" opt; do
case $opt in
p) USER_PASS=$OPTARG ;;
*) echo "Nutzung: $0 -p <passwort>"; exit 1 ;;
esac
done
if [ -z "$USER_PASS" ]; then
echo "Fehler: Passwort mit -p angeben!"
exit 1
fi
apt update && apt install -y rspamd clamav-daemon dovecot-sieve dovecot-managesieved postfix
RSPAMD_HASH=$(rspamadm pw -p "$USER_PASS")
mkdir -p /etc/rspamd/local.d/
echo 'bind_socket = "0.0.0.0:11334";' > /etc/rspamd/local.d/options.inc
cat <<EOF > /etc/rspamd/local.d/worker-controller.inc
bind_socket = "0.0.0.0:11334";
password = "$RSPAMD_HASH";
enable_password = "$RSPAMD_HASH";
EOF
cat <<EOF > /etc/rspamd/local.d/antivirus.conf
clamav {
scan_mime_parts = true;
symbol = "CLAM_VIRUS";
type = "clamav";
servers = "/run/clamav/clamd.ctl";
}
EOF
usermod -aG rspamd postfix
postconf -e "smtpd_milters = unix:/var/lib/rspamd/rspamd.sock"
postconf -e "non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock"
sed -i 's/mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/20-lmtp.conf
mkdir -p /var/lib/dovecot/sieve/
echo 'require ["fileinto"]; if header :contains "X-Spam" "Yes" { fileinto "Junk"; stop; }' > /var/lib/dovecot/sieve/default.sieve
sievec /var/lib/dovecot/sieve/default.sieve
chown -R vmail:vmail /var/lib/dovecot/sieve/ 2>/dev/null || chown -R dovecot:dovecot /var/lib/dovecot/sieve/
systemctl restart clamav-daemon rspamd postfix dovecot
echo "URL: http://$(hostname -I | awk '{print $1}'):11334"
Analyse der Filter-Logik
Live-Analyse im Terminal
- journalctl -u rspamd -f | grep -E "symbol|action"
Beispiel einer Log-Zeile
(default: F (reject): [15.50 / 15.00] [GTUBE(0.00), R_SPF_FAIL(1.00), BAYES_SPAM(5.10)])
Übung: Die Detektiv-Arbeit
- Sende saubere Mail -> Score prüfen.
- Manipuliere Absender (SPF-Fail) -> Score-Anstieg beobachten.
- Spam-Begriffe einfügen -> Finalen Reject provozieren.
Script
#!/bin/bash
# --- Parameter-Handling ---
while getopts "p:" opt; do
case $opt in
p) USER_PASS=$OPTARG ;;
*) echo "Nutzung: $0 -p <passwort>"; exit 1 ;;
esac
done
if [ -z "$USER_PASS" ]; then
echo "Fehler: Passwort mit -p angeben!"
exit 1
fi
# --- 1. Installation ---
apt update
apt install -y rspamd clamav-daemon dovecot-sieve dovecot-managesieved postfix
# --- 2. Rspamd Konfiguration erzwingen ---
RSPAMD_HASH=$(rspamadm pw -p "$USER_PASS")
# Alte Controller-Konfigurationen aufräumen, um Overrides zu verhindern
rm -f /etc/rspamd/local.d/worker-controller.inc
# Web-Interface (Controller) global auf 0.0.0.0 setzen
cat <<EOF > /etc/rspamd/local.d/worker-controller.inc
bind_socket = "0.0.0.0:11334";
password = "$RSPAMD_HASH";
enable_password = "$RSPAMD_HASH";
EOF
# Globaler Bind-Override in den Optionen (Zweite Absicherung)
echo 'bind_socket = "0.0.0.0";' > /etc/rspamd/local.d/options.inc
# Virenscanner (ClamAV)
cat <<EOF > /etc/rspamd/local.d/antivirus.conf
clamav {
scan_mime_parts = true;
symbol = "CLAM_VIRUS";
type = "clamav";
servers = "/run/clamav/clamd.ctl";
}
EOF
# --- 3. Postfix Integration ---
usermod -aG rspamd postfix
postconf -e "smtpd_milters = unix:/var/lib/rspamd/rspamd.sock"
postconf -e "non_smtpd_milters = unix:/var/lib/rspamd/rspamd.sock"
postconf -e "milter_default_action = accept"
postconf -e "milter_protocol = 6"
# --- 4. Dovecot Sieve ---
# Sieve Plugin aktivieren
sed -i 's/mail_plugins = \$mail_plugins/mail_plugins = \$mail_plugins sieve/g' /etc/dovecot/conf.d/20-lmtp.conf
mkdir -p /var/lib/dovecot/sieve/
cat <<EOF > /var/lib/dovecot/sieve/default.sieve
require ["fileinto"];
if header :contains "X-Spam" "Yes" {
fileinto "Junk";
stop;
}
EOF
sievec /var/lib/dovecot/sieve/default.sieve
# Rechte setzen (versuche vmail, sonst dovecot)
chown -R vmail:vmail /var/lib/dovecot/sieve/ 2>/dev/null || chown -R dovecot:dovecot /var/lib/dovecot/sieve/
# --- 5. Neustart ---
systemctl restart clamav-daemon
systemctl restart rspamd
systemctl restart postfix
systemctl restart dovecot
# --- 6. Finaler Check ---
echo "-------------------------------------------------------"
echo "Netzwerk-Check (Port 11334):"
ss -tulpn | grep 11334
echo "-------------------------------------------------------"
echo "Setup abgeschlossen."
echo "URL: http://$(hostname -I | awk '{print $1}'):11334"
Analyse der Filter-Logik: Warum ist das Spam?
Ein modernes Filtersystem wie Rspamd ist keine Blackbox. Der Lerneffekt tritt ein, wenn Schüler verstehen, wie sich ein Score aus vielen kleinen Indizien zusammensetzt.
Die Anatomie einer Ablehnung (Reject)
Wenn eine Mail abgelehnt wird, reicht es nicht zu wissen, DASS sie weg ist. Wir müssen wissen, WELCHE Regel den Ausschlag gab.
Live-Analyse im Terminal
Mit dem folgenden Befehl filtern wir nur die Zeile heraus, die das Urteil (Action) und die Gründe (Symbols) enthält:
- journalctl -u rspamd -f | grep -E "symbol|action"
Beispiel einer Log-Zeile
(default: F (reject): [15.50 / 15.00] [GTUBE(0.00), R_SPF_FAIL(1.00), BAYES_SPAM(5.10), ...])
Der Aha-Effekt: Das Punktesystem (Scoring)
In der Schulung muss vermittelt werden, dass Rspamd wie ein Punktrichter arbeitet.
- Threshold (Schwellenwert)
- In diesem Beispiel liegt er bei 15.00 Punkten.
- Symbole
- Jedes Kürzel in den Klammern ist ein Beweismittel.
- Gewichtung
- Ein 'R_SPF_FAIL' gibt vielleicht nur 1 Punkt (Verdacht), aber 'BAYES_SPAM' gibt 5 Punkte (starkes Indiz).
Übung: Die Detektiv-Arbeit
Lasse die Schüler eine Mail manipulieren, um zu sehen, wie sich der Score verändert:
- Sende eine saubere Mail -> Score 0.
- Sende die Mail von einer gefälschten Absender-Adresse -> Score steigt (SPF-Fail).
- Füge "Click here for free money" hinzu -> Score steigt weiter (Bayes/Heuristik).
- Ergebnis: Die Schüler sehen live, wie die Mail langsam über die 15-Punkte-Grenze "wandert".
Visualisierung im Web-Interface
Das Web-Interface ist das beste Werkzeug, um die Theorie der Symbole zu festigen.
- Reiter History aufrufen.
- Auf eine Zeile klicken.
- Aha-Moment: Jedes Symbol wird im Klartext erklärt (z.B. "SPF: domain has no SPF record").
Fazit für die Schulungsunterlage
- Spam-Schutz ist Wahrscheinlichkeitsrechnung
- Es gibt selten den einen Grund, sondern die Summe der Indizien entscheidet.
- Transparenz
- Ein guter Administrator schaut nicht nur, ob die Mail ankam, sondern warum sie welchen Score erhalten hat.
- Anpassbarkeit
- Über die Datei /etc/rspamd/local.d/scores.conf können wir Symbole, die in unserer Schule zu streng sind, abmildern.