Email Using Exim – Bye, Bye Spammers
| March 8, 2011 | Posted by Daniel under Uncategorized |
I just spent a week in email purgatory.
Sendmail was a great email server. It served millions of people for decades. But, email technology has matured. Or perhaps it has merely been simplified. Or perhaps complexity for the sake of generality has been exchanged for a simple foundation with complex appendages to address security, performance, and scalability.
Within minutes of receiving my virtual private server (VPS) account, I installed Apache, PHP, an APC cache, WordPress, Drupal, and a few security plugins for each and immediately noticed about 60,000 spambot attacks. And it did not even have a hostname in DNS attached to it.
I grabbed an sshblacklist Perl script and began to drop these bad guys into the firewall.
So, when I wanted to move my email across from my old C-panel hosting, I trembled and feared. Sendmail was what I used in the past, and it was old and not considered very secure. I considered qmail which was great for performance and security, but it was not open source and it was unmaintained. Postfix almost seemed to be in the same place, and both qmail and postfix were considered the most secure email servers around. But, then there was Exim which was almost as secure and theoretically could be configured properly to be as secure. It had a huge supportive user community and was very flexible. So I installed it.
One excellent, informative article on the differences between these four major email systems can be found at http://shearer.org/MTA_Comparison.
Configuring Exim
Configuring Exim looked easier. The rules were more human readable than sendmail’s configuration files though I had become accustomed to regular expressions used by sendmail, Perl, lex, yacc, and so many other environments.
So, I took a plain-Jane, out of the box configuration, made a few tiny tweaks and had a server up and running with my first accounts on it. Accounts. Hmmm. For which domain? Godsblogs.com? Nodivorces.com? DanielJDick.com? Furthermore, it just did not seem safe to have your email accounts match your system’s accounts. Hackers would assume if email flows in that there must be a unix account behind it. Why not authenticate in MySQL or LDAP or something that can handle multiple domains? I chose MySQL.
MySql
I set up a couple database tables in MySQL–one for users and one for domains. Then I coded them into the exim.conf file.
You can find examples all over the web including one at http://maxo.captainnet.net/installs/tiger/ECM/exim_4.60.configure.txt
It became trivial to add new users and aliases and domains to the environment and to set up TLS/SSL with authentication so I could log in from my laptop using Mozilla’s Thunderbird or Outlook Express.
Moving Time – Mailbox and Maildir
After pointing DNS to my VPS server and having my emails flowing in, I needed to move my old emails across. But, Thunderbird seemed slow when accessing email on my new server, and that didn’t make sense at all.
Then I realized I did something dummmmb. All my new emails were in Mailbox files while the email on my old C-panel service was in Maildir files–one file per email instead of all emails crammed sequentially into one file. So, I renamed the old directories for each domain and created new mail directories based on Maildir and reconfigured Exim. And things sped up considerably.
Merging Email
Now I had tens of thousands of emails on the old system in Maildir format, a few hundred perhaps in Mailbox format, and the new emails in Maildir format on the new system. So, how to get them all into one area?
Well, I found a Perl or Python script called mb2md and I had to rework it considerably. It was anchored to the old notion that email accounts always sit directly in /var/mail and that their ownership is always paired up with the system account that would always be found in /etc/passwd.
I fixed the script for my system configuration and ran them one by one to get all the mailbox files into their appropriate Maildir directories, and it worked great except for one thing: the files were owned by root. I fixed that. Then I went to thunderbird and moved some of the subdirectories under INBOX, and they disappeared. I had gotten tired of griping and complaining and getting angry and I was beginning to make my peace with the loss of those files until I realized they were in dotted or hidden directories. Doh! strikes again.
In short, I got all the email moved, and I was a very happy camper.
Monkeys on the System
Spam came in. That was expected. I turned off spamassassin to save memory. It was either that or allow memory to be swallowed until one of the webservers would crash. Funny thing is I set up scripts to check and restart them, but there had to be a better solution.
I Googled again for good, fast ways to eliminate spam. Some of them I had already coded into my Exim installation. Relaying was blocked. Certain characteristics of the headers or body were strong indicators of spam, so those were eliminated.
But, there was a bigger problem – relaying attempts
Spam idiots love to steal resources on other machines to do their bidding. Two ways they do it are:
- Install a spambot onto your system through a trojan horse or some kind of virus.
- Send spam through your web server to other people using it as a “relay”.
In this case, a few hundred spambots on other people’s machines were trying to use my email server for relaying spam. That is, they would attempt to send millions of spams through my server to other people.
But, my system did not allow relaying.
Even so, when I went to the error logs, I found that my main.log and reject.log file were growing to dozens of megabytes in no time. That was eating up my networking resources, burdening my email server, and swallowing up diskspace by filling my logs full of error messages.
So, I grabbed a copy of a Perl program I used earlier called sshblacklist.pl. I ripped out the guts of the program so it would drop the offenders into the firewall permanently and quickly and then check for duplicate entries and eliminate them from the firewall. That kept the firewall down to about 600 entries rather than 2400 or so. And the log files stopped growing so rapidly.
Life seemed peaceful once again.
But, then there was spam
Before this time, I slapped SpamAssassin onto the system. It was a very popular, intelligent, and effective spam detector. But, it required memory–more memory than my little VPS could afford.
So, I Googled for alternatives. And I got some irrelevant results, so I Binged for alternatives and Yahooed for alternatives and found myself stuck wondering which one I liked best.
The best, most effective, most popular, and most resource economical solution I found was “greylisting”. Another very easy and effective solution was to include a little block of code into the Exim configuration to check all IP addresses with spamhaus and check the domain names with a few other lists to see if they were known spammers. I turned that on and felt terribly guilty that my email server was hammering spamhaus and the other sites so often for the same sites over and over again, so I turned that off until I could lower the traffic of requests internally. Another solution I used with success long ago was to use something called Boxtrapper.
Boxtrapper
What is boxtrapper? Well, it’s cool. Very cool. And for a period of time,. it drove my spam down to zero while allowing all legitimate email traffic through.
How did it work?
Boxtrapper kept a few lists: a blacklist, a whitelist, and another form of blacklist. If I remember right, the two blacklists would be for sending denial messages for one and just cutting off the other with no response. And the whitelist, of course, would be there for emails that should be allowed to flow through unhindered.
So, what was different about Boxtrapper? If you sent an email to someone who was protected by Boxtrapper, if Boxtrapper did not know you, it would send an email back to you asking you to reply just to verify that you were really a human being sending a real email. Spambots would not know how to reply, but people would. So, once you replied, you would be listed in the whitelist and you would never have to send another reply to prove you were human again.
Unfortunately, Boxtrapper came with C-panel and did not live outside C-panel, and many administrators experienced problems managing servers with Boxtrapper installed, so they began to stop boxtrapper services telling people to use SpamAssassin instead.
So, Boxtrapper was not an option for me.
How About Greylisting?
What is “greylisting”? Like Boxtrapper, greylisting may have a whitelist and a blacklist. But, they have another list in-between. Anyone care to guess what it might be called?
Greylisting is like Boxtrapper without human intervention. When you send email to someone who is protected by greylisting, the other system won’t know who you are. So, it tells your email system you are not authorized to send email to that person. Yet. So your system needs to come back and try again sometime later. Perhaps it’s five minutes or fifteen minutes or an hour. Real email servers will almost always do that, and spamming systems almost never retry. But, some do. So you get rid of most of the spam.
I noticed two popular and effective solutions:
- The greylistd system
- Coding greylisting directly into Exim’s configuration file.
I tried both a little but I liked the greylistd solution best. With greylistd, I found it almost trivial to configure it into Exim and it provided programs for analyzing and manipulating the blacklist, whitelist, and greylist.
Summary
During the process, I was terrorized by several agonizing daggers to my heart as I despaired over how to convert various files into different forms, feeling torn between losing email and getting spammed, and suddenly finding all my past email hiding in a hidden directory apparently gone forever.
But, it turned out to be a great learning experience, and in the end I had an awesome email set up.
Unix: Forward to the History
| February 21, 2011 | About Dan |
Ever watch “Back to the Future”? Ever live “Forward to the History?”
Sick of being imprisoned in a C-panel reseller’s account I longed to return to my long familiar Linux / Unix command prompt. I got a VPS from Ubiquity. It was the right thing to do. I know I was falling off the wagon and who knows where indulging an old addiction might lead? But, my daughter was proud of me. In fact, she was the one who recommended it. My addiction was Linux. Solaris. AIX. HP-UX. It ran through my blood like heroin through the veins and brain cells of a drug addict.
It started in my youth when a friend of mine asked me,
“Have you ever tried Unix? Hey, this is really good stuff!”
Curious, I didn’t merely dabble. My first shots of Unix mainlined it into my system until it controlled every aspect of who I was. I read my first Unix book cover to cover in a few hours and went on a quest to find a Unix system in Fresno and considered leaving Fresno if I could not find one.
Perl Tip: Keeping Services Alive
| February 15, 2011 | unix |
Have you ever felt frustrated that
- important services were dying?
- critical services remained down for a long time
- unnoticed or unreported?
This program can help!
My Unix Journey
| January 14, 2011 | unix |
Website Development
| April 3, 2010 | web |
WordPress, Drupal, Joomla, TikiWiki, how do I love thee?
Let me count the ways.
I never want to criticize or fail to appreciate the contribution many dedicated developers have made to provide for free some of the most excellent CMS and Blogging packages available.
These systems have developed in phases and among different sets of developers with newer technologies building upon older ones.
My Oracle Experience
| April 3, 2010 | Posted by Daniel Dick under About Dan | Comments off |
Pre-Oracle Experience
Prior to working at Oracle, I worked 4 years for Ingres where I was trained in SQL development, Administration, and Performance. During my stay, I performed countless installations into approximately 80 systems based on about 40 variants of Unix and VMS. I provided maintenance and troubleshooting on installations damaged while reproducing bugs reported to the support department. I also served as final sign off and approval for Release Management and trained support staff in installation and QA of installation packages Continue reading “My Oracle Experience” »
Life as a Linux and Unix Professional
| April 3, 2010 | Posted by Daniel Dick under unix | Comments off |
Linux Experience before Linux was Available
When Linus Torvalds came out with Linux in 1991, I had nearly a decade of Unix administration and C development experience.
During that time, I built the technical environment for California State University, Fresno’s Computer Science Department installing and managing Unix systems based on Berkeley 4.2 and 4.3 BSD and AT&T Unix including a room full of Convergent Technology systems.
Afterward, as an independent consultant, I installed and configured Unix systems for the Agricultural Department, a phone company, and an Air Conditioning company before going to work for NASA where I managed networks of VMS and Unix based systems and developed the project plan for migrating the Information Sciences Division from VMS to Unix.
Following that, at Ingres, I supported Ingres installations on approximately 40 variants of Unix and VMS for Ingres, provided Sun desktop support for Direct User Support, and support of Unix systems for the Education Department. I also trained staff in quality assurance for the Ingres installation packages and served as the final sign off approving distribution of new product to customers.
Why Savy Managers Hire Dan
| April 3, 2010 | Posted by Daniel Dick under About Dan | Comments off |
Why Savy Managers Hire Dan
Smart managers hire employees
- to add or protect income and stockholder value of the company,
- to build morale, and unity,
- to increase competency, efficiency, effectiveness
- to get a specific job done
- to help the company succeed
If you have an employee that has a track record of making or saving millions of dollars for previous employers, it isn’t wise or responsible to leave millions of dollars on the table without a good reason.
At this time, there are millions of dollars that your company does not currently have simply because you have not hired Dan yet. Isn’t it about time? Continue reading “Why Savy Managers Hire Dan” »



