![]() |
HOWTO: Spam control for POSTFIX
Spam is a major problem for anyone with a mail server. Many times, spam goes to email addresses that don't exist. But, it still is hitting your server even if it isn't delivered. Other times, a users inbox will be overflowing with annoying messages about Viagra, hookers, free software, and whatever else.
Below is a solution. It's an ongoing accumulation of my efforts to stop spam to the best of my abilities. So far, it has a 97% success rate with over 20,000 emails (spam and ham, alike) processed. Follow the instructions. I will update/modify as necessary if things seem unclear. Feel free to ask. 1) Install Postgrey, RRD, a log parser, and Graphing tools. Code:
apt-get install postgrey rrdtool mailgraph pflogsumm2) Restart the Postgrey server. Code:
/etc/init.d/postgrey restartCode:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version4) Create a file named "spamtrap" in the /etc/postfix/ directory. This serves as a filter. If spam is emailed to this address and other addresses on your machine, it will drop that email so that it doesn't get to any other mailboxes. The Spamtrap file looks like this: Code:
/emailcontrol.*@derekgordon\.com/ DISCARDSide note: Do not create this mailbox using ISPConfig. There is absolutely no reason for it to exist on your mailserver. It's a fake address meant to catch annoying spam. 5) Open up local.cf for SpamAssassin and add the following bit. It will be an extra filter designed to work with SA more than it is with general Postfix. Code:
nano /etc/spamassassin/local.cfCode:
urirhssub URIBL_BLACK multi.uribl.com. A 2Code:
/etc/init.d/postfix restartCode:
/etc/init.d/spamassassin restartCode:
cp -p /usr/lib/cgi-bin/mailgraph.cgi /var/www/www.example.com/cgi-binCode:
nano /usr/local/sbin/postfix_report.shCode:
#!/bin/shCode:
chmod 755 /usr/local/sbin/postfix_report.sh9) Edit the RSYSLOG file so that your mail.log rotates daily and to setup an automatic email with postfix statistics: Code:
nano /etc/logrotate.d/rsyslogCode:
/var/log/mail.logSo now you're all done! What did you do? You installed blacklist filters, greylisting, graphing for on-the-fly information about Postfix, daily emails with detailed Postfix stats, created a spam trap, and other minor things to make your mailserver a lot more secure and less susceptible to spam. IMPORTANT: Let me know what you all do. Please respond with your choice, if you use it, and how well it worked. If there's much of a use, I will keep building upon the instructions and make it even better (hopefully). Responses are in the form of thread messages. ---------------------- BONUS INSTRUCTIONS: If you use the script I posted below, that gives you GREYLISTING SPECIFIC STATS, do the following: 1) DELETE it from having a CRONJOB if you added one originaly. Mostlikely, you did. 2) Open the RSYSLOG file again. 3) Modify the above entry so that it looks like this: Code:
/var/log/mail.logAgain, That script is found a few posts below. --------------------------------------- TIPS AND FIXES: 1) If you have people sending you emails and they get rejected because SORBS says their dynamic IP is a bad one, change the following in /etc/postfix/main.cf: "reject_rbl_client dnsbl.sorbs.net" becomes "reject_rbl_client smtp.dnsbl.sorbs.net" SORBS has a huge variation in repositories. Some AT&T DSL IP's will be found in the DNSBL it appears. So, that could cause a potential no deliver. 2) Similarly to #1, if you find out that there are some SORBS errors in delivering legit emails, you may want to experiement with the various Zones. https://www.au.sorbs.net/using.shtml lists all of them. I recommend SMTP, NOMAIL, SPAM, and ZOMBIE. 3) When upgrading ISPC3 to later versions, the main.cf for Postfix will be erased. This means you can either backup the one you created and replace the changes made by the update script for ISP3, or you can just copy the main.cf information above and use it again. This is the only step that has to be repeated. So, again if you upgrade ISPC3, you need to reconfigure the main.cf for Postfix as it will be replaced by the ISPC3 default main.cf again. 4) If you used this guide prior to 13 October 2010, I recommend removing "reject_rbl_client multihop.dsbl.org" from the main.cf for Postfix. That database has been taken offline. This was "effective" in 2009, but still worked until recently. |
The next big step for fixing spam issues is to build a robust header_check and body_check file for Postfix.
As you see above, I have started on the header_check. I'd like to determine how to setup a SUBJECT filter that would delete any email with more than 7 words. I have had NO legitimate email with more than 6 words in the subject. However, a lot of spam has between 7 and 12 words in the SUBJECT line. I'm not finding great details on how it works, so it's going to take a lot of time. If you have any of your own mod's please post them so I can compile a better post above. Also, filtering out all languages you DO NOT use would be sufficient. I will be filtering out all languages except ENGLISH, SPANISH, FRENCH, GERMAN, CZECH, POLISH, and PORTUGUESE when I have time. |
Quote:
By the way, I wont use such filter files for spam filtering. The normal spamassassin and blacklists filter already about 99.x % of all spam and adding such manual filters will just rise the risk of false positives. You can not win the battle against sapm with manual filter rules. |
Yes, but if you have NO header blocks added in ISPCONFIG, you can use the header file directly.
In cases that it's not a production server, just for personal uses, it might be easier to copy/paste the above header_check. However, I understand your point and if entries were being made it would be a conflict. So, I would recommend doing what Till says if you're already using that feature or may use that feature. |
I removed the HEADER_CHECKS I created from the HOWTO as I don't want to confuse.
Here they are for you expert experimenters. Last piece, and this will be updated as I get more in depth, header_check in the postfix directory should contain these: Code:
/^Subject: .* / REJECT Spam Header Many Spaces 1 |
Question/Recap:
- Till is saying not to perform header/body checks within main.cf and use the tools within ispc3, yes? If so, that makes perfect sense to me. I wish there was a service/blocklist that already did it on a realtime basis (somehow). - Is Postgrey good to load or no? I still need to research postgrey to figure out what it is. Sorry for my confusion and thank you for including me. By you posting your main.cf, I noticed I had limited my sorbs bl. By changing to yours I blocked a lot more immedietly. |
Yes, I would do header_checks in ISPC3 if you're comfortable with that. It's pretty simple in the end. I haven't tested my new ones I wrote yet, so won't post them. But, I'm thinking that postgrey will be the best solution.
POSTGREY is an easy implementation of Greylisting: Code:
Greylisting is a new method of blocking significant amounts of spam at the mailserver level, but without resorting to heavyweight statistical analysis or other heuristical (and error-prone) approaches. Consequently, implementations are fairly lightweight, and may even decrease network traffic and processor load on your mailserver.Code:
Postgrey is a Postfix policy server implementing greylisting. Development of Postgrey started at the ISG.EE and is now sponsored by Open Systems AG. |
Once you're using Postgrey and what to see how it's working, install the following script somewhere on your server:
"postgrey_stats.sh" Code:
#!/bin/sh1) Change the "YOUREMAIL = " line so that it goes to your personal mail box. This will give you details on how its working. 2) Make sure that /var/log/mail.log is the correct path to your current mail.log file. Distros are different. Set the script to chmod +700 so that it is executable. Finally, create a cronjob so that it will give you an automatic output to your email daily (or whenever you choose). |
Have you seen sqlgrey? Not sure if it's better or not but it has an interface that's interesting. Any thoughts?
|
I have seen it. However, I will stick with Postgrey for the time being.
I recommended in a REQUEST that Till research including SqlGrey and its interface in a future release. At that point, it wouldn't be necessary to use Postgrey. But, Postgrey is extremely simple (see above instructions) so it isn't worth the extra hassle in my opinion for roughly the same functionality. I'm researching an addon to Postgrey that will make it even better. Give Postgrey a chance, use that script above to see how well it works (you will be shocked after the first full day), and see what happens. The only false positive I have heard of was Paypal. But, that's unconfirmed and worked without a hitch for me. You can add whitelists for domains, ips, specific emails, clients, etc... with easy in the event there were problems. Whitelists also will skip the delay in delivery. Let me know what you all do. Please respond with your choice, if you use it, and how well it worked. If there's much of a use, I will keep building upon the instructions and make it even better (hopefully). |
| All times are GMT +2. The time now is 14:11. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.