Dies ist eine alte Version des Dokuments!


erweiterte gewichtete Prüfungen mittels policyd-weight

Bild: Symbolbild Postfix und SPAM Das zweite (wesentliche) Standbein bei unserer SPAM- und Schadcode-Prüfung von eMails kann der Policy-Dämon policyd-weight von Robert Felber. Postfix leitet alle Client-Angaben bei der Einlieferung an den Policy-Dämon während des SMTP-Dialogs weiter, der dann eine Plausibilitätsprüfung vornimmt. Fälscht ein SPAMer den HELO Namen bzw. die Absenderangaben beim MAIL FROM, so wird dies ebenso bei der gewichteten Prüfung negativ bewertet, die das Vorhandensein, der Clioent-IP-Adresse auf einer oder mehreren RBLs.

Policyd-weight nimmt vereinfacht und zusammengefasst folgende Prüfungen vor:

  1. Passt der Hostname der beim HELO übertragen wurde, zu IP-Adresse und verweist seinerseits die IP-Adresse bei einer DNS reverse-Abfrage auf diesen Histnamen.
  2. Steht die IP-Adresse des einliefernden Hosts auf mehreren Sperrlisten? Dabei unterscheidet der Policy-Dämon zwischen einzelnen RBLs und vergibt entsprechend negative Punkte, sofern die IP-Adresse gelistet ist aber auch positive Punkte, wenn die IP-Adresse eben nicht gelistet ist.

Wird bei der Prüfung durch das komplexe Regelwerk festgestellt, dass Kombinationen aus den oben genannten Punkten zu negativ aufgefallen sind, dann wird die weitere Bearbeitung beendet und die Annahme der eMail mit einem 500er Fehler-Code final abgewiesen.

 # yum install policyd-weight 
 # rpm -qil policyd-weight
Name        : policyd-weight
Version     : 0.1.15
Release     : 2beta.el7.centos
Architecture: noarch
Install Date: Wed 05 Nov 2014 04:46:20 PM CET
Group       : System Environment/Daemons
Size        : 132070
License     : Robert Felber. All rights reserved.
Signature   : RSA/SHA1, Wed 05 Nov 2014 04:40:20 PM CET, Key ID 60ecfb9e8195aea0
Source RPM  : policyd-weight-0.1.15-2beta.el7.centos.src.rpm
Build Date  : Wed 05 Nov 2014 04:40:10 PM CET
Build Host  : vml000200.dmz.nausch.org
Relocations : (not relocatable)
Packager    : Django <django@nausch.org>
Vendor      : EDV Beratung Selling-IT - Robert Felber
URL         : http://www.policyd-weight.org/
Summary     : Policy Daemon for the Postfix MTA
Description :
policyd-weight is a Perl policy daemon for the Postfix MTA (2.1 and later)
intended to eliminate forged envelope senders and HELOs (i.e. in bogus mails).
It allows you to score DNSBLs (RBL/RHSBL), HELO, MAIL FROM and client IP
addresses before any queuing is done. It allows you to REJECT messages which
have a score higher than allowed, providing improved blocking of spam and
virus mails. policyd-weight caches the most frequent client/sender
combinations (SPAM as well as HAM) to reduce the number of DNS queries.

After the first three SMTP commands (HELO, MAIL FROM: and RCPT TO:) the
client's IP address, corresponding DNS records (A, MX and PTR) and multiple
DNSBLs can be checked, verified and scored. If the client tries to forge
headers or supplies non-existent DNS or bogus data the spam score will
increase, even more so if the client is listed in one or more DNSBLs. Such
mails can be rejected while in transfer, before the mail body is received by
your MTA. This is different from SpamAssassin or amavisd-new: for scoring or
filtering with these programs, mail needs to be accepted and queued, bandwidth
is used, CPU-time is wasted and mail cannot be rejected without creating a
bounce. Please have a look at the graphical working scheme.

Postfix' built-in checks can be too tough for poorly configured clients: one
hit, and the mail gets rejected. policyd-weight is designed to be fair (DynDNS
MX users get through if their MTA is setup properly, even if their ISP net is
DUL-listed), because its decision whether to reject or accept a mail is based
on multiple factors.

Of course you should still have SpamAssassin and Clamav running (especially
if you are responsible for a company's security and data). But these programs
will have a lot less to do and thus decrease the need for bandwidth and CPU
cycles. Also you might not need greylisting (which would make sense for users
that receive a lot of new spam, though), SPF, extraordinary whitelists or SQL
and other DBs anymore.
/etc/policyd-weight.conf
/usr/bin/policyd-weight
/usr/lib/systemd/system/policyd-weight.service

Leider kommt es auch vor, dass vor allem große Provider hinter ihren MX ein cluster betreiben, die mit wechselnden IP-Adrressen aus einem Pool aufschlagen. Damit können unter Umständen Probleme bei der Bewertung entstehen. Diese schalten wir dann bei Bedarf in der policyd_weight_client_whitelist frei.

 # vim /etc/postfix/policyd_weight_client_whitelist
/etc/postfix/policyd_weight_client_whitelist
# Django : 2012-02-03
# Datei zu Definition von Ausnahmeregeln für die gewichtete Überprüfung des Policyd-weight Daemon.
# Policyd-weight ist ein E-Mail-Filter für den Postfix Mail Transfer Agent der von Robert Felber 
# in Perl entwickelt wurde. Policyd-weight untersucht die Mail bei der Einlieferung anhand des 
# Envelope Sender, des Envelope To und der HELO-Daten, die während des SMTP-Handshakes übertragen 
# werden und vergibt für verschiedene Kriterien Punkte. Dabei werden zum Beispiel Realtime Blackhole 
# Listen abgefragt oder die DNS-Konfiguration des Absenders überprüft. Für jeden Regelverstoß gibt 
# es negative Punkte und ab einer bestimmten Wertung wird die Mail abgelehnt.
#
# Nach Änderungen an den policyd-weight Ausnahmeliste policyd_weight_client_whitelist ist die 
# zugehörige Datenbank-Datei mit Hilfe von "postmap /etc/postfix/policyd_weight_client_whitelist"
# zu erstellen und der Daemon von den Änderungen mit einem reload in Kenntnis zu setzen!
# "service policyd-weight reload"
#
# Django : 2008-10-08 
# 1und1.com (big pool, inserted by Django)
kundenserver.de         OK

Nach Änderungen an den policyd-weight Ausnahmeliste policyd_weight_client_whitelist ist die zugehörige Datenbank-Datei mit Hilfe von

 # postmap /etc/postfix/policyd_weight_client_whitelist

zu erstellen und der Daemon von den Änderungen mit einem reload in Kenntnis zu setzen!

 # service policyd-weight reload

Bei den smtpd_recipient_restrictions tragen wir nun zur Aktivierung folgenden Eintrag nach dem greylisting-Eintrag ein.

 # vim /etc/postfix/main.cf
...   
# Greylisting via postgrey checken via Unix-Socket      (Kapitel 9.2.5 postgrey installieren)
        check_policy_service unix:postgrey/socket,
# Policyd-Weight check over TCP-Connection              (Kapitel 9.3 policyd-weight installieren)
        check_client_access btree:/etc/postfix/policyd_weight_client_whitelist,
        check_policy_service inet:127.0.0.1:12525,
...
 # systemctl start policyd-weight
 # systemctl status policyd-weight
policyd-weight.service - policyd-weight is a Perl policy daemon for the Postfix MTA (2.1 and later) intended to eliminate forged envelope senders and HELOs (i.e. in bogus mails).
   Loaded: loaded (/usr/lib/systemd/system/policyd-weight.service; disabled)
   Active: active (running) since Wed 2014-11-05 16:46:56 CET; 8s ago
  Process: 6315 ExecStart=/usr/bin/policyd-weight start (code=exited, status=0/SUCCESS)
 Main PID: 6316 (policyd-weight )
   CGroup: /system.slice/policyd-weight.service
           ├─6316 policyd-weight (master)
           └─6317 policyd-weight (cache)

Nov 05 16:46:56 vml000087.dmz.nausch.org systemd[1]: Started policyd-weight is a Perl policy daemon for the Postfix MTA (2.1 and later) intended to eliminate forged envelope senders and HE...gus mails)..
Nov 05 16:46:56 vml000087.dmz.nausch.org postfix/policyd-weight[6316]: policyd-weight 0.1.15 beta-2 started and daemonized. conf:/etc/policyd-weight.conf; GID:995 995 EGID:995 995 UID:995 E...int mode: 0
Nov 05 16:46:56 vml000087.dmz.nausch.org postfix/policyd-weight[6316]: cache_query: start: calling spawn_cache()
Nov 05 16:46:56 vml000087.dmz.nausch.org postfix/policyd-weight[6317]: cache spawned
Hint: Some lines were ellipsized, use -l to show in full.
 # less /var/log/maillog
Nov  5 16:46:56 vml000087 postfix/policyd-weight[6316]: policyd-weight 0.1.15 beta-2 started and daemonized. conf:/etc/policyd-weight.conf; GID:995 995 EGID:995 995 UID:995 EUID:995; taint mode: 0
Nov  5 16:46:56 vml000087 postfix/policyd-weight[6316]: cache_query: start: calling spawn_cache()
Nov  5 16:46:56 vml000087 postfix/policyd-weight[6317]: cache spawned
 # netstat -tulpen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      0          56505      4931/master         
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      0          56511      4931/master         
tcp        0      0 127.0.0.1:12525         0.0.0.0:*               LISTEN      0          67780      6316/policyd-weight 
tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      0          56517      4931/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          24989      1223/sshd           
tcp6       0      0 :::25                   :::*                    LISTEN      0          56506      4931/master         
tcp6       0      0 :::587                  :::*                    LISTEN      0          56512      4931/master         
tcp6       0      0 :::465                  :::*                    LISTEN      0          56518      4931/master         
tcp6       0      0 :::22                   :::*                    LISTEN      0          24991      1223/sshd           
udp        0      0 0.0.0.0:50558           0.0.0.0:*                           70         21030      571/avahi-daemon: r 
udp        0      0 0.0.0.0:46503           0.0.0.0:*                           0          20919      594/chronyd         
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           70         21029      571/avahi-daemon: r 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           0          20920      594/chronyd         
 # lsof -i:12525
 COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
 policyd-w 6316 polw    4u  IPv4  67780      0t0  TCP localhost:12525 (LISTEN)
 # systemctl enable policyd-weight.service
 ln -s '/usr/lib/systemd/system/policyd-weight.service' '/etc/systemd/system/multi-user.target.wants/policyd-weight.service'
 # systemctl is-enabled policyd-weight.service
 enabled

Am nachfolgenden Beispiel sehen wir, den erfolgreichen Mailversand nach der Bewertung durch policyd-weight.

Oct 14 22:31:30 nss postfix/smtpd[14044]: connect from www.linuxtv.org[212.227.166.180]
Oct 14 22:31:34 nss postfix/policyd-weight[2715]: decided action=PREPEND X-policyd-weight: using cached result; rate: -7.6; <client=212.227.166.180> <helo=www.linuxtv.org> <from=vdr-bounces+michl=naush.org@linuxtv.org> <to=grossermeister@naush.org>; delay: 1s 
Oct 14 22:31:34 nss postgrey[21879]: action=pass, reason=triplet found, client_name=www.linuxtv.org, client_address=212.227.166.180, sender=vdr-bounces+michl=naush.org@linuxtv.org, recipient=michl@naush.org 
Oct 14 22:31:34 nss postgrey[21879]: cleaning up old logs... 
Oct 14 22:31:34 nss postfix/smtpd[14044]: 31F5E76022D: client=www.linuxtv.org[212.227.166.180]
Oct 14 22:31:34 nss postfix/cleanup[14048]: 31F5E76022D: message-id=<Pine.LNX.4.64.0810142329220.5339@shogun.pilppa.org>
Oct 14 22:31:34 nss postfix/qmgr[1304]: 31F5E76022D: from=<vdr-bounces+michl=naush.org@linuxtv.org>, size=3523, nrcpt=1 (queue active)
Oct 14 22:31:34 nss postfix/smtpd[14044]: disconnect from www.linuxtv.org[212.227.166.180]

In der Regel dauert es nicht all zulange und ein SPAMer wird erfolgreich positiv bewertet, also als SPAM erkannt und die Annahme abgelehnt.

Jun  6 08:46:11 pml010001 postfix/policyd-weight[6560]: weighted check:  IN_DYN_PBL_SPAMHAUS=3.25 NOT_IN_SBL_X
BL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 DSBL_ORG=SKIP(0) BAD_MX=6.825 BOGUS_MX=5.35 CL_IP_NE
_HELO=4.75 RESOLVED_IP_IS_NOT_HELO=1.5 (check from: .nausch. - helo: .computer. - helo-domain: .computer.)  FR
OM_NOT_FAILED_HELO(DOMAIN)=6.25; <client=115.246.189.233> <helo=computer> <from=michael@nausch.org> <to=michae
l@nausch.org>; rate: 23.425 
Jun  6 08:46:11 pml010001 postfix/policyd-weight[6560]: decided action=550 Mail appeared to be SPAM or forged. Ask your Mail/DNS-Administrator to correct HELO and DNS MX settings or to get removed from DNSBLs; MTA helo: computer, MTA hostname: unknown[115.246.189.233] (helo/hostname mismatch); <client=115.246.189.233> <helo=computer> <from=michael@nausch.org> <to=michael@nausch.org>; delay: 0s 
Jun  6 08:46:11 pml010001 postfix/smtpd[31326]: NOQUEUE: reject: RCPT from unknown[115.246.189.233]: 550 5.7.1 <michael@nausch.org>: Recipient address rejected: Mail appeared to be SPAM or forged. Ask your Mail/DNS-Administrator to correct HELO and DNS MX settings or to get removed from DNSBLs; MTA helo: computer, MTA hostname: unknown[115.246.189.233] (helo/hostname mismatch); from=<michael@nausch.org> to=<michael@nausch.org> proto=SMTP helo=<computer>

Sollte im maillog folgende Fehlermeldung auftauchen …

Feb 25 07:52:27 vml000080 postfix/policyd-weight[10649]: warning: cache_query: $csock couln't be created: connect: Connection refused, calling spawn_cache()

… dann wird der Mailsever die Annahme der Nachrichten mit einem temporären Fehler ablehnen. 451 4.3.5 Server configuration problem

Dann einfach den Deamon neu starten und sein temporäres Arbeitsverzeichnis vorher löschen.

  1. Daemon stoppen
    # systemctl stop policyd-weight
  2. Arbeitsverzeichnis löschen
    # rm /tmp/.policyd-weight/* -rf
  3. Daemon starten
    # systemctl start policyd-weight start
Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
  • centos/mail_c7/spam_2.1415203279.txt.gz
  • Zuletzt geändert: 05.11.2014 16:01.
  • von django