{"id":2858,"date":"2010-04-04T20:38:51","date_gmt":"2010-04-05T00:38:51","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=2858"},"modified":"2010-04-04T20:38:51","modified_gmt":"2010-04-05T00:38:51","slug":"quick-n-dirty-spam-rejection-with-policyd-weight","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/04\/04\/quick-n-dirty-spam-rejection-with-policyd-weight\/","title":{"rendered":"Quick &#8216;n Dirty Spam Rejection with policyd-weight"},"content":{"rendered":"<p>I&#8217;ve blogged about DNSBLs before. They&#8217;re DNS-based blacklists of spammer IPs. (To see if 1.2.3.4 was listed in blacklist.example.com, you&#8217;d do a DNS lookup for 4.3.2.1.blacklist.example.com. If you get an IP, usually 127.0.0.2, back, it&#8217;s listed. If you get an NXDOMAIN, it&#8217;s not listed.) Some lists are abysmal, but I found some that are very accurate. I never loved DNSBLs, mainly because you cede way too much control to DNSBL operators &#8212; if they list an IP, your mailserver will refuse mail from them. Sometimes people running DNSBLs are vindictive, and other times they&#8217;re clueless, so it&#8217;s not at all unheard of for legitimate IPs to wind up in blacklists.<\/p>\n<p>I set up <a href=\"http:\/\/www.policyd-weight.org\/\">policyd-weight<\/a> on my new mailserver a little bit ago. The reason I&#8217;m so crazy about policyd-weight is that it queries multiple DNSBLs and computes a score based. I have it configured so that someone needs to be listed in multiple blacklists before anything happens, so one erroneous listing won&#8217;t do any harm.<\/p>\n<p>Over time, I&#8217;ve been logging IPs of people emailing my spamtraps, and looking them up in various DNSBLs when they were listed. (Whenever I poked around there, I&#8217;d also look up the IPs of mailservers that recently sent me desired mail, and check those; any blacklist listing any non-spam server was summarily removed.) So I set up policyd-weight with this configuration file:<\/p>\n<blockquote>\n<pre>   @dnsbl_score = (\n#    HOST,                    HIT SCORE,  MISS SCORE,  LOG NAME\n    'pbl.spamhaus.org',       3.25,          0,        'DYN_PBL_SPAMHAUS',\n    'sbl-xbl.spamhaus.org',   4.35,          0,        'SBL_XBL_SPAMHAUS',\n    'bl.spamcop.net',         3.75,          0,        'SPAMCOP',\n    'dnsbl.njabl.org',        3.25,          0,        'BL_NJABL',\n    'ix.dnsbl.manitu.net',    4.35,          0,        'IX_MANITU',\n    'psbl.surriel.com',       4.25,          0,        'PSBL_SURRIEL',\n    'list.dnswl.org',         -100,          0,        'DNSWL_PASS',\n    'ubl.unsubscore.com',     3.50,          0,        'UNSUBSCORE',\n    'dnsbl-2.uceprotect.net', 2.00,          0,        'UCEPROTECT_2',\n    'b.barracudacentral.org', 4.00,          0,        'BARRACUDA',\n    'dnsbl.sorbs.net',        2.00,          0,        'SORBS',\n    'dyna.spamrats.com',      2.00,          0,        'SPAMRATS_DYNA',\n    'bl.spameatingmonkey.net',2.00,          0,         'SEM_BL',\n    'bl.mailspike.net',       3.00,          0,        'MAILSPIKE-BLACK',\n    'wl.mailspike.net',       -100,          0,        'MAILSPIKE-WHITE'\n);\n\n   $MAXDNSBLHITS  = 5;  # If Client IP is listed in MORE\n                        # DNSBLS than this var, it gets\n                        # REJECTed immediately -- set high due to whitelists on list too\n\n   $MAXDNSBLSCORE = 9;  # alternatively, if the score of\n                        # DNSBLs is ABOVE this\n                        # level, reject immediately\n\n   $MAXDNSBLMSG   = '550 Your MTA is listed in too many DNSBLs';\n<\/pre>\n<\/blockquote>\n<p>It&#8217;s worth mentioning that this isn&#8217;t even a good configuration. For one, the whitelist (-100 points if you&#8217;re listed) should be up top, because policyd-weight seems to stop processing DNSBLs once the threshold (a score of 9, or listing in 5 blacklists) is hit. That would also argue that you&#8217;d put your fastest \/ most accurate blacklists up front. Spamhaus, SpamCop, Manitu, Surriel, and Barracuda Central are all first-rate; I&#8217;d move them to the top, right after the whitelist check.<\/p>\n<p>You need 9 points to be listed. I thought this was conservative, and might match maybe a quarter of my spam. If you hit the highest-scoring DNSBLs, you&#8217;d still need to be in <em>three<\/em> DNSBLs before your mail was rejected &#8212; you need 9 points and the highest is 4.35. You&#8217;ll also note that, towards the end, I threw in some 2-pointers. These are lists that can be a little too aggressive, but they&#8217;re safe.<\/p>\n<p>I pointed a couple of my less-used domains&#8217; MX records to this setup. They&#8217;re ones that get tons of spam but are either used not at all, or ones that have mailboxes that, in practice, don&#8217;t get much mail, and that could afford to lose a few messages to a bad configuration. The results?<\/p>\n<p>I&#8217;ve rejected mail from 150 different IPs today alone. And here&#8217;s the interesting thing: 100% of spam has been rejected, with zero false positives. This is <em>much<\/em> better than I expected. I made mailboxes for some spamtraps I have, and not a single one has any mail. I sent myself email from every legitimate service I can think of, and it went right through. And actually, it not only went right through, but it came in with a <em>negative<\/em> score &#8212; policyd-weight gave a &#8220;bonus&#8221; to people with good configurations, like if a DNS lookup for their HELO string actually matched the connecting IP. And mail from GMail and Apple had the -100 points from being in dnswl.org&#8217;s list, too.<\/p>\n<p>My results surely aren&#8217;t typical of real-world settings. I&#8217;d expect to eventually have some spam slip through the cracks, and I&#8217;m a little uneasy about all the checks for HELO matches, etc., that are performed, if only because I haven&#8217;t taken the time to fully understand them. But based on a week&#8217;s worth of spam to my low-traffic mailserver, this configuration is batting a thousand. I&#8217;d planned to set up postfix-policyd to do greylists \/ spamtraps \/ blacklists \/ HELO checks, but thus far, and I&#8217;d planned to set up and tune SpamAssassin for mail that was ultimately accepted. And I still will someday. But right now, it&#8217;d be pointless. (It&#8217;s also worth mentioning that <a href=\"http:\/\/www.mail-archive.com\/policyd-weight-list@ek-muc.de\/msg00793.html\">development of policyd-weight stopped two years ago<\/a>.) But if you&#8217;re getting a lot of spam, give <a href=\"http:\/\/www.policyd-weight.org\/\">policyd-weight<\/a> a look. It&#8217;s worked better than I imagined was possible.<\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve blogged about DNSBLs before. They&#8217;re DNS-based blacklists of spammer IPs. (To see if 1.2.3.4 was listed in blacklist.example.com, you&#8217;d do a DNS lookup for 4.3.2.1.blacklist.example.com. If you get an IP, usually 127.0.0.2, back, it&#8217;s listed. If you get an &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/04\/04\/quick-n-dirty-spam-rejection-with-policyd-weight\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2858","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=2858"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2858\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=2858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=2858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=2858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}