I run my own email server, and a friend received a compromised laptop from work which resulted in a spam attack from Russia yesterday. Turtle settings saved the days with thousands of emails still in the queue when I saw the problem, however it made me realize that everyone with accounts on my server are local, do not travel, and have no requirement to send emails from outside the country.
I found how to use the smtpd_discard_ehlo_keyword_address_maps setting in postfix to block a CIDR list of IPs, then found a maintained list of IPs by country codes on github. Cool so far, and a script to keep my local list updated was easy enough.
Now the question is, what countries should I be blocking? There are plenty of lists of the top hacking sources, but it’s hard to block #2 (the US) when that’s where I am located. But otherwise, does anyone have a list of countries they outright block from logging on to their servers? From the above google searches I have 17 countries blocked so far, and in the first 30 minutes already stopped login attempts from three of those countries, so it appears to be working.
Of course I could write a script to parse my logs to see who has already made attempts, but that’s what services like fail2ban are for, and I’m just wondering if there are any countries in particular I should directly block? My list so far includes the following: ae bg br cn de hk id in ir iq il kp ng ru sa th vn
The question itself may not be that interesting, but I thought at the very least some folks might be interested in my experience and think about doing something similar themselves. I can post more details of what I did if there is any interest.
I would say white-list instead of black-list if possible.
Beside the point, have you considered the reasons why you might not want to run your own email server in todays age? It’s a fun experience for sure, but if you want it for serious use it’s not for the faint of heart (unfortunately).
Edit: also lol to your friend unknowingly conducting a spam campaign from your server
Fortunately I started this endeavor back before Microsoft even knew what a mail server was, so I’ve been at it awhile. Some changes have been reactionary to attacks, other changes have been simply keeping up with practices where I could. I do what I can though.
Yeah someone else mentioned whitelisting but with connections like your cell phone picking up IPs all over the place, while simultaneously being the source of other attacks, it’s just not as feasible for this. Of course I do have blocklists against spam sources and such, plus a dedicated firewall in front of everything, but I somehow missed blocking the easy targets against compromised accounts.
As for my friend… yeah it wasn’t even happening from his laptop, it was just the fact that he had logged in to his account and the virus recorded his password. After that first moment of rage (assuming he fell for a phishing attack), I scrambled his password, flushed all the emails from the queue, and then started cleaning things up. So far it looks like I was only temporarily blacklisted, and those cleared up about an hour after I shut down the spam. Now I’m just keeping a close eye on things to make sure nobody else comes through on that account.
Oof yeah. You’re well into admin territory here.
I mean I’m just some layman on the internet, but I would look at tying in some authentication layer to get your 2FA, although it would inconvenience your users users.
Do your users use this service for srs business?
I don’t know if I have anything else to add to this discussion. It’s gotten more complex than what “just an email server” can provide imo
I use CrowdSec which does that for you. Crowdsourced smart fail2ban, basically.
Any site you would suggest I look at for info about this, or how to apply it to postfix smtp authentication?
crowdsec can be setup to configure your firewall so all incoming traffic will be filtered by the banlists.
Not directly to your exact question, but do you have something like rspamd set up? I would consider doing some filtering with rspamd modules. It’s a lot of learning to go through, but has some good defaults. It can filter outgoing mail as well as incoming.
I’ve always used spamassassin, but this looks interesting so I’ll do some reading on it tomorrow. Thanks!