Postscreen im Kampf gegen Spam 27


Ich verwende zur Spam-Abwehr u.a. postscreen. Dadurch werden potentielle Spam-Mails direkt ablehnt, ehe sie auf dem Server angekommen und dann der Inhalt gescannt werden muss.

Postscreen sollte nicht eingesetzt werden, wenn Mail-User-Agents (MUAs) dort connecten sollen. Normalerweise wird der Port 25 für Mail-Transfer-Agents (MTAa) genutzt und die MUAs verwenden den Submission-Port (TCP 587). Man kann aber auch postcreen für eine weitere IP nicht einsetzen, wenn zu dieser kein MX-Record im DNS definiert ist. Dann ist einen Einlieferung durch einen MUA dort problemlos möglich.

Zunächst müssen an /etc/postfix/master.cf einige Änderungen vorgenommen werden:

neu:
#smtp inet n - n - - smtpd
smtpd pass - - n - - smtpd
smtp inet n - n - 1 postscreen
tlsproxy unix - - n - 0 tlsproxy
dnsblog unix - - n - 0 dnsblog

alt:


smtp inet n - n - - smtpd
#smtpd pass - - n - - smtpd
#smtp inet n - n - 1 postscreen
#tlsproxy unix - - n - 0 tlsproxy
#dnsblog unix - - n - 0 dnsblog

Weiter geht es mit Erweiterungen in der /etc/postfix/main.cf:

postscreen_access_list = permit_mynetworks,
cidr:/etc/postfix/postscreen_access.cidr

In /etc/postfix/postscreen_access.cidr stehen alle IP, die immer whitelisted sein sollen. Ich habe dort die IP-Adressen vom Monitoring-System von Hetzner eingetragen:

192.168.254.0/24 permit
213.133.113.83 permit
213.133.113.84 permit
176.9.89.165 permit

Um DNSBL zu ermöglichen, können verschiedene Listen mit unterschiedlichen Gewichtungen eingetragen werden. Ich verwende verschieden Black- und Whitelisten.

postscreen_dnsbl_threshold = 3
postscreen_dnsbl_sites =
  zen.spamhaus.org*3
  bl.mailspike.net*3
  b.barracudacentral.org*2
  bl.spameatingmonkey.net
  bl.spamcop.net
  spamtrap.trblspam.com
  dnsbl.sorbs.net=127.0.0.[2;3;6;7;10]
  ix.dnsbl.manitu.net
  bl.blocklist.de
  #whitelist
  list.dnswl.org=127.0.[0..255].0*-1
  list.dnswl.org=127.0.[0..255].1*-2
  list.dnswl.org=127.0.[0..255].[2..3]*-3
  iadb.isipp.com=127.0.[0..255].[0..255]*-2
  iadb.isipp.com=127.3.100.[6..200]*-2
  wl.mailspike.net=127.0.0.[17;18]*-1
  wl.mailspike.net=127.0.0.[19;20]*-2
postscreen_dnsbl_reply_map = texthash:/etc/postfix/dnsbl_reply
postscreen_dnsbl_action = enforce
postscreen_dnsbl_ttl = 1h

/etc/postfix/dnsbl_reply hat den folgenden Inhalt:

# Secret DNSBL name Name in postscreen(8) replies
secret.zen.spamhaus.org zen.spamhaus.org

Und so funktioniert die Gewichtung:
postscreen_dnsbl_threshold = 3 stellt den minimalen Wert für ein Ablehnen dar. Die einzelnen Listen sind unterschiedlich stark gewichtet (*3 für zen.spamhaus.org oder *2 für b.barracudacentral.org). Whitelists haben eine negative Gewichtung.

Erstmal werden alle Mails mit einem DNSBL-Score von 3 nicht angenommen (default).
Durch die Gewichtung kann sich das jetzt aber verschieben. Postscreen addiert die individuelle Gewichtung hinzu (bl.mailspike.net*3 bedeutet einen Rejected bei einem Score >= 3+3). Bei einer negative Gewichtung für die Whitelisten wird der Betrag abgezogen.

Um nicht richtig arbeitende Clients und “mynetworks” nicht immer abzuweisen geht es mit der main.cf weiter:

postscreen_bare_newline_action = ignore
postscreen_bare_newline_enable = no
postscreen_bare_newline_ttl = 30d
postscreen_blacklist_action = ignore
postscreen_cache_cleanup_interval = 12h
postscreen_cache_map = btree:$data_directory/postscreen_cache
postscreen_cache_retention_time = 7d
postscreen_client_connection_count_limit = $smtpd_client_connection_count_limit
postscreen_command_count_limit = 20
postscreen_command_filter =
postscreen_command_time_limit = ${stress?10}${stress:300}s
postscreen_disable_vrfy_command = $disable_vrfy_command
postscreen_discard_ehlo_keyword_address_maps = $smtpd_discard_ehlo_keyword_address_maps
postscreen_discard_ehlo_keywords = $smtpd_discard_ehlo_keywords

Wir hätten das ganze gerne auch für TLS:

postscreen_enforce_tls = $smtpd_enforce_tls
postscreen_use_tls = $smtpd_use_tls

Und noch ein paar Ergänzungen, die aber zum Teil die default-Werte sind:

postscreen_expansion_filter = $smtpd_expansion_filter
postscreen_forbidden_commands = $smtpd_forbidden_commands
postscreen_greet_action = ignore
postscreen_greet_banner = $smtpd_banner
postscreen_greet_ttl = 1d
postscreen_greet_wait = ${stress?2}${stress:6}s
postscreen_helo_required = $smtpd_helo_required
postscreen_non_smtp_command_action = drop
postscreen_non_smtp_command_enable = no
postscreen_non_smtp_command_ttl = 30d
postscreen_pipelining_action = enforce
postscreen_pipelining_enable = no
postscreen_pipelining_ttl = 30d
postscreen_post_queue_limit = $default_process_limit
postscreen_pre_queue_limit = $default_process_limit
postscreen_reject_footer = $smtpd_reject_footer
postscreen_tls_security_level = $smtpd_tls_security_level
postscreen_watchdog_timeout = 10s

Zum Testen der Konfigiration wird in /etc/postfix/main.cf

soft_bounce = yes

gesetzt. Damit werden Connects im Zweifel mit einem “try again” abgewiesen.

Nach einem /etc/init.d/postfix reload sind die Änderungen wirksam.

Um dauerhaft Connects zu blocken, muss dann nur noch soft_bounce = no gesetzt werden.

Update 13.03.13: remove combined.njabl.org=127.0.0.[2;4;9]*2 (Blacklist NJABL geht ausser Betrieb)


Hinterlasse einen Kommentar zu Max Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

27 Gedanken zu “Postscreen im Kampf gegen Spam

  • ESH Kassel

    Hi! Super Einleitung in das Thema Postscreen und damit der Verbunde Kampf gegen SPAM!
    Gehrade Server-neulinge haben so die Möglichkeit effektiv ihre Kisten gegen SPAM zu Schützen.

    Ich selber hab mir diesen Artikel als Vorlage genommen um mehrer MailServer einzurichten da die Werte
    weitgehenst passen für den Produktiven Betrieb!

    Lieben dank sargt ESH

  • Max

    Hallo,

    danke für das tolle Tutorial. Aber ein Problem habe ich: meine eigenen Nutzer werden beim Versenden von Mails auch geblockt. Wenn mir ein anderer Nutzer eine Mail schreiben wird bekommt er ein Problem da seine IP blacklisted ist. Kann man für eigene, angemeldete Nutzer bzw. deren Mails den Filter umgehen?

    • Florian Schaal Autor des Beitrags

      User solle nicht den Port 25, sondern den Submission-Port (587) nutzen. Auf den reagiert postscreen auch nicht.

  • Christoph

    Ich habe seit gestern postscreen auf meinem Server konfiguriert. Aber ich kann jetzt von Thunderbird und meinem PC über meinen Server (port 587) keine Email mehr verschicken. Bekomme:
    450 4.7.1 Service unavailable; client [80.143.67.X} blocked using zen.spamhaus.org

  • Christoph

    Danke für das Tutorial. Ein kleiner Hinweis nur: für den Ungeübten ist die Gliederung etwas verwirrend wegen der eingeschobenen Inhalte von /etc/postfix/dnsbl_reply und /etc/postfix/postscreen_access.cidr.

    Gut, wer die Syntax kennt, wird sicher wissen, daß das meiste in main.cf gehört, aber ein “weiter in main.cf” eingeschoben, würde letzte Zweifel ausräumen.

  • EDV Büro RAAIT

    Super! Danke für das schnelle und einfache HowTo
    wir haben mit sehr gute Ergäbnisse erziehlt nach der einrichtung von postscreen auf unseren MTA Systemen. Auch die Auslastung der MailSysteme ist spürbar nach unten gegangen…

  • Herbert Müller

    Boah dieser Satz….
    > Man kann aber auch postcreen für eine weitere IP nicht einsetzen, wenn zu dieser kein MX-Record im DNS definiert ist.
    > Dann ist einen Einlieferung durch einen MUA dort problemlos möglich.

    Heisst das auf Deutsch:
    Man kann Postscreen nur für eine IP einsetzen zu der ein MX Record im DNS eingetragen ist. Nur dann kann ein MUA dort Mails anliefern.
    Oder verstehe ich das falsch?

    • Florian Schaal Autor des Beitrags

      Das verstehst Du falsch. Postscreen kann mehrerer IPs. Du kannst aber einen postfix für MTA (also MX-Record) auf einer IP und für MUAs (User) auf einer 2. IP laufen lassen. Und auf der 2. dann halt ohne Postscreen.

  • Jens G.

    Yes, the settings, permissions and ownerships are indeed correct. It’s really strange but after every incoming mail, that error is thrown.

    It also seems the whitelisting you do with dnswl is not working with me. All DNS servers queried couldn’t respond to even the test hostname:

    host 2.0.0.127.list.dnswl.org

    -> Host 2.0.0.127.list.dnswl.org not found: 3(NXDOMAIN)

    Tried with many different nameservers (Google, OpenDNS, Colocation of Server Housing…)

    • Florian Schaal Autor des Beitrags

      And the dir /var/lib/postfix has 755?

      You can also try to delete the cache and restart postfix afterwards.

      • Jens G.

        Yes permissions weren’t the problem.

        Indeed, for everyone else having the problem getting the aforementioned warning of postscreen on close events, this is what I did:


        service postfix stop
        cd /var/lib/postfix
        mkdir -p /var/spool/postfix/var/lib/postfix
        mv postscreen_cache.db /var/spool/postfix/var/lib/postfix
        ln -s /var/spool/postfix/var/lib/postfix/postscreen_cache.db
        service postfix start

        This moves the postscreen_cache.db to the chrooted postfix directory and symlinks it to the directory out of it, as in Debian Wheezy it seems postscreen tries to access that file within and out of the chroot on various occasions. The close event seems to come from inside the chroot, the normal cleanup procedures hit against the file at its normal location in /var/lib/postfix.

        So symlinking it to the un-chrooted dir and moving the real file to the jail seems to be the best possibility, as the other way round the chroot won’t follow symlinks.

        Greets
        Jens

        • Florian Beer

          Thanks Jens, I think you just solved my problem with this solution. The log message was bugging to no end and I couldn’t figure out why the file wouldn’t be accessible while permissions where perfectly fine.

  • Jens G.

    Hi Florian,

    did you also encounter the problem with postscreen_cache.db?


    Nov 10 11:28:36 servername postfix/postscreen[18906]: close database /var/lib/postfix/postscreen_cache.db: No such file or di[120/9530]
    ossible Berkeley DB bug)

    I’d guess it isn’t belonging to the DB bug, but rather has something to do with postfix/postscreen running chroot’ed and unable to access the file out of its chroot?

    Greets
    Jens

    • Florian Schaal Autor des Beitrags

      I´m running postfix non-chrooted. I think you should add /var/lib/postfix/* to the jail and/or check the permissions.

      • Jens G.

        OK, that was my fault (did run it on another server in a chroot setting). On that machine though, it runs without and still throws that error.
        File exists, permissions are right. Somehow it seems I’m overlooking the obvious…

        The machine runs ISPC3 and was set up with their documentation and settings. We just wanted that instance a bit hardenend against spammers 😉

    • Florian Schaal Autor des Beitrags

      The permissions are 600 and the owner is postfix.postfix. I think you missed something. If you woud like to see my postfix-config just leave me an email.

  • Grayson Peddie

    Oh, by the way, every time I post my comment in your article, your blogging software redirected me to a German version of your site. I came from Google Search and your website is in English.

  • Grayson Peddie

    Hi, I have a question. Don’t you need a comma after each blacklist/whitelist lines in postscreen_dnsbl_sites and before postscreen_dnsbl_action? I came across another website before yours and yours does not indented unlike the other one.

    I’m running Postfix 2.9 in Ubuntu Server 12.04 running in a virtual private server and thanks to b.barracudacentral.org, I haven’t gotten any spam last month until recently, one of them being death/funeral announcement and I’ve gotten even more spam this month of March. I don’t know when I’ve added sbl-xbl.spamhaus.org but I did add bl.spamcannibal.org since one IP address is in their blacklist. Spammers are getting very desperate for trying to send spam to my “gp(at)” e-mail address.

    Anyway, I will implement postscreen configuration since I am in need of weighting.

    • Florian Schaal Autor des Beitrags

      I don´t use a comma after each line but spaces in front of each bl/wl. I just reformated the post. Thanks.

      • Grayson Peddie

        You’re welcome. The config is a lot more clearer now, so I have implemented postscreen, commented out reject_rbl_client lines, and reloaded Postfix. Checking my /var/log/mail.log tells me everything is fine and Postfix must have accepted my configuration.

        I will see how this goes and monitor my mail log for any problems that might prevent legitimate mail from going through.

        Thanks for writing the article.