r/sysadmin • u/omers Security / Email • Feb 11 '19
Lets talk about email spoofing and prevention (Alt: "That's not how SPF works....")
There seem to be an awful lot of questions recently about email spoofing, especially "header from" and "display name" spoofing and there is a lot of confusion about what technologies like SPF, DKIM, and DMARC can and cannot do. Not to mention some confusion about what SMTP allows and why... Since I have repeated myself quite a few times I wanted to compile a post. This is fairly simplified but it hopefully gets the point across.
TL;DR: No, Sender Policy Framework (SPF) won't fix all your spoofing problems and DKIM by itself will prevent nothing.
Email Crash Course
I am not able to explain email and SMTP in detail end-to-end in the time it would take for this post but there are some core things that need to be understood before we can move on. The best illustration is to use telnet to send an email via an SMTP server (I have indented the server responses to make it more clear:)
EHLO mycomputer.mydomain.com
250- redacted smtp.mydomain.com [10.10.10.10], pleased to meet you
MAIL FROM: noreply@mydomain.com
250 2.1.0 noreply@mydomain.com ... Sender ok
RCPT TO: user@example.com
250 2.1.5 user@example.com ... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
From: Bob Smith <bob.smith@mydomain.com>
Reply-to: <noreply@mydomain.com>
Subject: Hello World
Message body contents.
.
250 2.0.0 wASDDusO0124297 Message accepted for deliveryThe above example is not only how we send messages through SMTP but is how applications and MTAs do it as well. Let's break it down:
HELO/EHLOIn the HELO command, the host sending the command identifies itself; the command may be interpreted as saying "Hello, I am <domain>" (and, in the case of EHLO, "and I support service extension requests")MAIL FROMThe "MAIL" command initiates transfer of mail and identifies the sender. The address specified here is where errors are sent and will typically appear in the message source as the 'return-path'.RCPT TOThis identifies the recipient(s) and may be repeated as many times as necessary for multiple recipients. (Cc: or Bcc: would be delineated under "DATA".)DATAEverything following DATA is considered to be message text until the end of data indicator (.on its own line followed by a blank line.) This is also where header items are specified in accordance with RFC 5322.From:this is the "header from" address and is what will appear in most mail clients like Outlook. It is optional and will be equal to the "MAIL FROM" address if omitted.Reply-to:another optional header item which can direct replies to a specific address.Subject:The message's subject as it will appear in the mail client.- The rest is the message body followed by the end of data indicator (
.<CRLF>)
Other header items could have been included or we could have omitted any of the ones that were included. The only required items are the HELO, MAIL FROM, RCPT TO, and DATA and everything else is optional.
The "Envelope" vs The "Header"
The "MAIL FROM" address and "RCPT TO" address(es) are referred to as the "envelope" and you may hear "MAIL FROM" called the "envelope from." Other names for the "MAIL FROM" address may include "MailFrom", "RFC5321.From", "RFC5321.MailFrom", and a number of others. In contrast, our From: Bob Smith <bob.smith@mydomain.com> above is the "header from" or may be called the "RFC5322.From", "from", "display from", or any number of other names. The "Bob Smith" portion is typically referred to as the "display name" but is mostly cosmetic (more on that later.)
For the rest of this document: The "envelope from" will be called the "MailFrom" address and the "header from" address will be called simply the "from" address.
That's Allowed!?
Some things that really surprise people,
- You can specify whatever you want in the MailFrom or From address. (SMTP servers can be configured to disallow certain domains or only allow "authoritative domains.")
- Either the MailFrom or From address can be null (
<>) and there are circumstances where this is actually required. - You can specify a name with no address in the From address (
From: Bob Smith <>) which will show up in some mail clients as "Bob Smith" business as usual. - You can format a From address like this:
From: Bob Smith <bob.smith@example.com> <hacker@hacker.su>which is legal with the message actually from "hacker@hacker.su" but what most mail clients will show is "Bob Smith bob.smith@example.com."
All of this is SMTP working as intended and while it's easy to see how it can be abused for malicious purposes it's important that SMTP functions this way (why is something for another post on another day.) Which leads us into...
Spoofing
When we talk about spoofing there are three main types:
- Envelope From Spoofing ... In envelope from spoofing the MailFrom address is declared in a way that is meant to look legitimate. Usually the header from is omitted and the spoofed address appears in both places.
- Header From Spoofing ... In header from spoofing the MailFrom is a real address the attacker controls but they declare an address in the header from that is intended to look legitimate since it's what will appear in most mail clients anyway. Header from spoofing is more likely to get through filters which we'll get into later.
- Display Name Spoofing ... In display name spoofing both the MailFrom and From are addresses the attack controls (or that have no spoofing controls) but they use the display name to make the message look like it came from someone legitimate. This is the most likely to make it through filters and while it's the easiest for a human to detect it still works way too often. It's usually used when the message requires some sort of response. If we use our example above
From: Bob Smith <bob.smith@example.com>, "Bob Smith" is the display name. Usually Outlook and other clients will show "Bob Smith bob.smith@example.com" the first time you get an email from an unknown person but once you reply it will usually truncate it to "Bob Smith" and hide the address which makes it easy to miss if you don't notice on first contact.
When it comes to spoofing the actual email address an attacker might use one of a number of different options:
- Use the actual address such as "bob.smith@megacorp.com" hoping it makes it through filters.
- Use a misspelling of the address like "bob.smith@megac0rp.com" (notice the zero.)
- Use a completely different domain but a valid name "bob.smith@yahoo.com" and claim it's a personal address of the person they're pretending to be.
- Use whatever address they want and rely on user stupidity "CeoEmail@hackersite.ru", "MicrosoftSupport@92n3n33.com", etc.
The most difficult spoofing to deal with as mail administrators is display name spoofing or spoofing where nothing about the address is actually spoofed and just relies on the user to herp-derp through it (2-4 above.)
A note on compromised mailboxes: Another big problem is when the mailbox of a real user is compromised (successfully credential phished, virus, etc) and is used to send further phishing messages, spam, or malicious attachments. A compromised mailbox is not "spoofed" since the attacker is using the actual user's credentials.
A note to domain owners: Sending mail from your own domain but specifying an address other than your own is not "spoofing" unless you're not authorized to do so or have malicious intent. If I am an admin for Mega Corp and send service messages from noreply@megacorp.com that's business as usual not "spoofing." Spoofing is unauthorized or malicious.
Protection Mechanisms
Sender Policy Framework (SPF)
In any post about spoofing or mail security recommendation number one is "implement SPF." Which is good advice, everyone should have SPF implemented. So what is it and what does it do?
ELI5: SPF is a DNS record a domain owner publishes that contains a list of servers from which they send email. The idea is that a receiving server sees an email from their domain, checks the list of legitimate sources, and if the server it came from isn't on the list it knows it's not legitimate.
An SPF record looks something like this:
v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~allWhich is gmail.com's if you follow the redirect. They're contained in a txt record at the top of the domain so can do dig <domain> txt | grep v=spf1 on Linux or Resolve-DnsName <domain> txt | ? {$_.Strings -like "v=spf1*"} in PowerShell on Windows to see a domain's SPF record.
There are a bunch of rules about how they're structured and a number of different mechanisms that an SPF record can contain that I won't get in to here but ultimately they resolve to a list of IPs that can be compared to the origin of an email.
SPF is both useful for protecting against MailFrom spoofing of your domain towards your users but also to external destinations where it could harm your brand. Ie, Microsoft's SPF record stops MailFrom spoofing from @microsoft.com not just to @microsoft.com but also to you which helps stop some fake Microsoft phishing emails.
Caveats:
- SPF is only concerned with the MailFrom address. It is not checked against the Header From address so does not in any way protect against header from spoofing or display name spoofing.
- The SPF RFC (7208) uses the word "SHOULD" a lot and rarely uses the word "MUST" so different receiving servers/filters may handle SPF failures differently. Even if you specify "hard fail" in your SPF record they may accept it on failure. (Lots of receiving mail servers treat
-alland~allexactly the same.)
DomainKeys Identified Mail (DKIM)
DKIM is a key-pair signing mechanism for the header of mail messages. When you send mail you attach a signature to the message using a private key which is compared to a public key published in DNS for your domain. DKIM adds authenticity to a message and guards against tampering with the header by down-stream mail servers. One of the benefits to working on the header is it survives SMTP relaying and auto-forwarding.
DKIM does not directly prevent abusive / malicious behaviour. DKIM is just a signature... If I hand you a letter with my signature on it there's added authenticity; However, if I hand you a letter without my signature if there's no requirement for the letter to be signed there's no reason to be suspicious. It's like SSL, just because a website doesn't have SSL doesn't mean it's fake but it's preferred when SSL is used.
Domain Message Authentication Reporting & Conformance (DMARC)
As the name suggests there are reporting and conformance components to DMARC. For this post we're only concerned with the conformance component which tries to make up for the weaknesses in both SPF and DKIM. The DMARC record of the domain in the header from address is used if it exists. Like the above records it exists as a TXT record in DNS.
DMARC's conformance check is called "alignment" and it checks that the header from is "aligned" with other authenticated domains on the message either via DKIM or SPF. If either DKIM or SPF alignment passes DMARC evaluates as a "PASS."
SPF Alignment: The domain in the header from and envelope from must be the same (or sub-domains of the same parent domain if "relaxed") and must pass SPF.
DKIM Alignment: DMARC requires a valid signature where the domain specified in the d= tag aligns with the sender's domain from the header from field.
Caveats:
- DMARC alignment is only enforced when your policy (
p=) is set to "reject" or "quarantine". - Lots of receiving mail servers still do not evaluate DMARC, evaluate only for reporting, or evaluate but don't report (it's a crap shoot.)
- DMARC can mess with automated messages like Out of Office replies and/or messages where the two from addresses have different domains but are still legitimate if only SPF+DMARC are implimented. It's generally best to implement DKIM along with DMARC to avoid SPF alignment issues.
Solutions...
- Envelope from spoofing... SPF
- Header from spoofing... SPF + DMARC, DKIM + DMARC, or SPF + DKIM + DMARC. No one mechanism alone will be sufficient.
- Display name spoofing... Advanced threat filters, transport rules, and user training. None of the mechanisms care about the display name.
- Compromised mailboxes or "legitimate" senders.... Advanced threat filters, transport rules, and user training.
It is the owner of the domain who implements these technologies and it's up to receivers to configure their filters to check them and take appropriate action. If you're getting mail spoofed from someone else's domain and they don't have SPF, adding SPF to your own domain isn't going to do anything (I've seen this suggested.)
Useful Links
RFCs
- Simple Mail Transfer Protocol - RFC 5321 ... If anyone links you to RFC 821 tell them it was made obsolete by RFC 2821 in 2001 which was made obsolete by 5321 in 2008 and they need to update their shit.
- Internet Message Format - RFC 5322 ... Governs how message headers are formatted (again 822 was made obsolete by 2822 which was made obsolete by 5322... I'm looking at you MX Toolbox.)
- Sender Policy Framework (SPF) - RFC 7208 ... Obsoleted RFC 4408.
- DomainKeys Identified Mail (DKIM) Signatures - RFC 6376
- Domain-based Message Authentication, Reporting, and Conformance (DMARC) - RFC 7489
Tools
- https://mxtoolbox.com/ ... Various mail tools like SPF lookup, blacklist lookup, header parser, etc.
- https://kitterman.com/spf/validate.html ... One of the better public SPF validation tools.
- http://dmarcian.com/ ... A useful tool for parsing DMARC reports.
- https://dmarc.org/resources/deployment-tools/ ... DMARC deployment tools.
NOTE: There are other forms of spoofing and other mitigation techniques but those are for another day...
236
u/[deleted] Feb 11 '19
Additionally, if someone is getting spoofs from your domain and your SPF is correct, they're not filtering on SPF.
At the end of the day, SPF, DKIM, and DMARC only matter if the recipient's filter is actually checking those and filtering accordingly.
94
u/Dj_FREQ Sr. Sysadmin Feb 11 '19
After 4 weeks straight of spending time to learn all of this, implement SPF, DKIM, and DMARC, using DMARCian to set and review policies, deal with 3rd party senders like Zoho, and losing my mind in the process, I REEEAALLLY wish this was written a month ago. Thank you for the amazing work of compiling a crash course in a "very poorly documented in easy to understand terms elsewhere" subject.
Bookmarked! Kudos!
16
u/ResidentParty IT Manager Feb 11 '19
Great post! Curious what others are doing with SPF softfails. I have my SPF records set to "-all" (hardfail) but way too many of our customers have a "~all" (softfail) policy that doesn't authorize their legitimate servers so we get a lot of softfails that end up being legitimate, so we have to whitelist the senders while I attempt to contact their IT department about fixing their SPF and get no response.
Seems like a lot of companies set up SPF and then migrate to Office 365 (for example), but didn't update SPF. Or they set SPF from -all to ~all during email migration but didn't update and set back to -all.
Really surprised how many big, well-known companies have invalid SPF records.
7
u/Konkey_Dong_Country Jack of All Trades Feb 11 '19
The best way I have found to alert users of display name spoofed emails is setting up a rule like this. This will add big scary warnings to any message that matches the rule to alert the user that it may be a spoofed email. In our case, it's only happening for company VP's. In the "From" header, you put the key person's display name there (or any variation of such). The exceptions setting is for those users' personal email accounts, but you can obviously tailor this rule to your environment.
8
u/greyaxe90 Linux Admin Feb 11 '19 edited Feb 11 '19
If you want to keep your domain from being spoofed internally (e.g. protecting your users from possible phishing/spam, spear phishing using your domain), in Exchange you can setup a transport rule to prepend a disclaimer. I use a fancy HTML banner that is red and says "WARNING! This message appears to come from <company> but was sent from outside the company. Use caution before clicking on any links or opening attachments. If you are unsure, please contact the helpdesk for assistance." Then in the transport rule, I whitelist the services that are allowed to spoof us though various means - ideally a mailheader otherwise a sender IP address or hostname.
EDIT: Some of you are taking my advice as if it is the only way to stop spoofing. It's not. Like any proper security system, this is a single layer. Proper security is made up of multiple layers. If you use this in addition to an email firewall, you'll stop a lot of bad stuff. Ideally, your users should never have to see this banner if everything is properly configured and you have multiple layers to your email security solution.
6
u/leftunderground Feb 11 '19
Great write up!
What I don't get about Outlook and any other mails clients that do this:
If the FROM is: From: Bob Smith bob.smith@example.com hacker@hacker.su why does outlook not show it's from "hacker@hacker.su". Instead it shows it as being from "bob.smith@example.com". With Exchange/O365 it will even add Bob Smith's picture to the message.
Why in the world does it do this?
3
u/Hg-203 Feb 11 '19
I had an interesting conversation where my DNS admin thought there was an implicit SPF entry for the host listed on the MX record. Am I correct that only IP's/Hosts listed in the SPF record are allowed to send?
3
u/rpetre Jack of All Trades Feb 11 '19
I would like to take the opportunity to publicly shame Office365-hosted email, that happily received and delivered to inbox a spam mail from an unknown IP, even though we have a hardfail in the record ("-all"). It even had the audacity to add a "SPF check failed" header. At least you could have pretended you didn't know about SPF, Microsoft...
5
u/ganlet20 Feb 11 '19
Here's an example of an office 365 transport rule to block spoofing on the header and envelope.
https://helpimg.s3.amazonaws.com/domain_spoof_prevention/Domain_fix_05b.png
2
u/ambalamps11 Feb 11 '19
Great post! One caveat you might consider adding is that adding more than about 15 SPF records can cause mail servers to stop trusting your domain. This was a argue for us in larger enterprise environments with a lot of systems looking to relay.
2
u/highlord_fox Moderator | Sr. Systems Mangler Feb 11 '19
Can you put this on the wiki if you haven't already done so? This is awesome.
2
u/vinnymcapplesauce Feb 11 '19
Side note -- it's 2019 and AT&T still doesn't even have SPF on their mail servers. 🤦♂️
My monthly account statements always get rejected for it, and then I get a text saying "We couldn't reach you by email ... pls verify that you have the currect email address on your account, blah, blah, blah"
2
u/astrixsystems Feb 12 '19
We've written a guide on this too. https://astrix.co.uk/news/2018/11/26/how-to-mitigate-email-spoofing
2
u/gordonmessmer Feb 17 '19
This is educational. Thanks for writing it. Two points:
1: "From: Bob Smith bob.smith@example.com hacker@hacker.su" This isn't actually allowed by RFC. It'll get through a lot of software, but not all. Courier, for example, will rewrite the header and remove the content of the second pair of angle brackets.
2: "One of the benefits to working on the header is it survives SMTP relaying and auto-forwarding." Well, kind of. SMTP servers are actually allowed to rewrite the headers of MIME messages, which breaks DKIM, limiting its usefulness.
52
u/bossnas Feb 11 '19
Excellent. This really should be on the r/sysadmin FAQ page.
25
u/comp00 Feb 11 '19
This is a great write up, good work and thanks
18
u/bad_fake_name Feb 11 '19 edited Feb 11 '19
Wanna hear something stupid? I have a lot of vendors who don't have SPF records set up on their domain. And I receive LOTS of spoofed emails pretending to be from those domains.
I've begun the habit of creating SPF records for those domains and manually adding them to my DNSmasq. I reverse DNS their real mail server and if it's a cloud service I look up the proper SPF for that, otherwise I just add the server that I get real mail from and -all at the end to block everything else. Most of them end up as 'a mx -all' so they're pretty standard.
My mail server looks up the TXT record and DNSmasq happily sends back the custom one I created that authenticates their server.
The SPF records don't exist for the Internet at large and I'm pretty confident my plan isn't compliant with standards one bit, but they stop the BS from getting into my server from vendors who are too stubborn to listen and fix their records.
I'm looking forward to the day when these vendors change mail services and all of a sudden we stop hearing from them. /s
10
u/tradiuz Master of None Feb 11 '19
dmarcian.com is the only reason i got through the headache of setting up DMARC. They also have a solid DKIM/SPF tool that adhere to the spec (including max # of lookups, which other tools miss).
7
u/cyberxsec Feb 11 '19
Nice work
5
u/aut0ex3c Feb 11 '19 edited Feb 12 '19
Absolutely wonderful. Thank you for taking the time to write all this up! This was a whole bunch of TIL for me!
Hope this gets stickied or something so it isn't buried?
5
u/redditor5597 Linux Admin Feb 11 '19
If you wanna check your setup:
https://www.mail-tester.com/
You send an email to a generated email address and then can see a report of how this email was scored, whether SPF and DKIM checks were successful and how to improve your email.
Really useful website.
1
u/tyros Feb 11 '19
Thank you, maybe mods can pin this on the sidebar or something.
I have recently gone through setting up the whole SPF/DKIM/DMARC. You really have to spend some time to understand it, the "envelope From" and "header From" thing was a revelation for me. I still don't see a valid reason for having both of them, but that's beside the point.
Let's pin this so that we can direct people to it, it seems like every day we get people asking about spoofing/phishing.
1
u/chugger93 Sysadmin Feb 11 '19
So my question is: If some of our external contacts/vendors/customers etc are getting spoofed emails from users in our company, does that mean that their mailservers arnt checking SPF?
I just dont understand how they are getting spoof emails from our internal employees
1
u/Smelltastic Feb 11 '19
Thank you so much for this. Feels good to finally understand what "Envelope From" means.
Honest question: Why wouldn't you just block any message with either the "@" or "." characters showing up in the display name? I can't think of a single legitimate use for that, the only reason anyone would do that is if they want the mail client to show something that looks like an email address. I've never met anyone who had either of those symbols in their actual real name, and I don't think that's language-specific.
1
u/aafksab Feb 11 '19
We pretty much eradicated compromised email accounts with MFS and ProofPoint. However, before that we had many... I built a Compromised Account (O365) module that handles this pretty well.
https://github.com/aafksab/CompAccount
I would suggest that you fork it and update anything exclusive to you Tennant and licences etc..
Lmk if I can help!
1
u/fengshui Feb 11 '19
Your understanding of RCPT TO is incorrect. The MTA does not parse the DATA block to find addresses in the Cc: and Bcc: lines. All recipients of the message (whether in the To:, Cc:, Bcc:, or added later by a mailing list server, or aliasing setup) must be specifically specified via a RCPT TO: command.
The contents of the To:, Cc:, and Bcc: lines are not used by the MTA layer for delivery. Most mail clients will not even include the Bcc: line in the DATA block at all.
1
u/LoTekk Feb 11 '19 edited Feb 11 '19
Great summary! I'd only add that checking the display name + sender for more than one @ sign seems to be an easy way to detect a pretty common form of display name spoofing. While specialized software is certainly preferable this is an easy quick-fix.
Most MTAs should be able to flag a subject (e.g. by adding something like "[SUSPICIOUS!] ") if the display name contains more than one "@". You will occasionally false-flag mails sent by "info@ company.com" and "no-reply@ company.com" but that doesn't seem to happen too often.
(Edit: Clarification, formatting)
1
u/pdp10 Daemons worry when the wizard is near. Feb 11 '19
Thanks for taking the time to write this up.
Mail clients that show relevant SMTP headers for all mail. This used to be routine.
1
u/j_bombay Feb 12 '19
Any on-prem solution or Exchange server add-on to ingest our own RUA RUF reports instead of the paid services out there?
1
u/linuxnubin Feb 12 '19
When I was a Google Apps admin I added another layer, not to prevent spoofing but to cut down on countries that could attempt to send spoofed mail, by using Regex to block countries we didn't do business with. We had tons of junk coming from addresses in .br .it etc. I wish I still had a copy of that original list, it took forever to create it.
1
u/EduRJBR Feb 12 '19
About SPF and forwarding, from the point of view of the sender, when a message is sent to "address A" but John is now using "address B" and configured the first account to forward received messages to the second account: are there trust relationships between big, known servers like Outlook.com, Gmail, Yahoo and so, that would prevent SPF to fail on the final server (rather: prevent the SPF failure from blocking the message)? I know that something like this may exist, maybe meaning that the servers of the forwarders (not their users) are known for taking good care of SPF records and DMARC rules when getting e-mail.
Can you confirm it and maybe talk about it?
1
u/therapcat Feb 12 '19
I just read this thread yesterday, but I received a spam email today. Can I send someone the RAW message source to see if this is a problem with our email or the other person's email service? This email landed in several of our mailboxes.
Is this the part of the message I would have to look at: (I only changed the username and domain name)
Authentication-Results-Original: spf=none (sender IP is )
smtp.mailfrom=user@othercompany.com;
1
u/larmik Feb 14 '19
Probably a dumb question but how would dmarc handle this scenario.
From: user1@domain.com
rcpt to: user2@domain.com
Reply-to: user1@domain.com
return-path: differentUser@differentDomain.com
differentDomain.com has spf and dkim set up
domain.com has spf and dkim set up
3
u/Acetheklown Feb 11 '19
This is excellent. Take my upvote! Unfortunately too many small/medium businesses hire unqualified people to manage these systems so it is unlikely that the overall situation is going to change anytime soon. However, I feel your frustration and applaud your effort.
My company works with many third parties who send mail to us on a frequent basis. We spend an inordinate amount of time reviewing and releasing emails from these third parties that are marked as potential spam by our security gateway due to missing/invalid spf, invalid dkim, etc. Our users get frustrated because we refuse to simply “whitelist” these domains. Trying to explain why that is a bad idea is akin to talking to a wall.
I’ve even been asked on multiple occasions to contact these third parties to help them fix their email deployment. Until I put my foot down and said that I would do so at an hourly MSP rate;)
3
u/CruwL Sr. Systems and Security Engineer/Architect Feb 11 '19
I highly recommend an exchange transport rule looking for display name spoofing. Its a bit tedious and doesn't scale well. Basically rule states If email from external org - From Header matches text patters: John Doe & Doe, John & Doe John (do this for each C lvl or other management)
redirect email to quarantine. I also have it generate a report and email the IT team for review, if 1 is found to be legitimate address we add it to a exclusion. Day 1 of implementation blocked 9 attempted phishing/spam email spoofing the CEO's name.
2
u/scotterdoos Sr. Sysadmin Feb 11 '19
Excellent write-up, thank you.
2
u/EdibleTree Janitor Feb 11 '19
Good write up. Informative!
I've never "truly" understood all of the mechanisms till now...
2
u/storm2k It's likely Error 32 Feb 11 '19
excellent write-up. puts everything in easy to understand terms with a good deal of clarity. i found this extremely useful, because it's something i know, but could also use more clarification about.
2
u/ZAFJB Feb 11 '19
Thank you. Clear and concise.
2
u/trail-g62Bim Feb 11 '19
Thank you for this.
2
u/insanefuzzball Feb 11 '19
Thanks for this! I have only recently started to read up on this and this is a perfect summary!
2
u/Phx86 Sysadmin Feb 11 '19
Beautiful post. I'm fairly sure I understand all of this, but I'm going to go over it in detail when I have time to dedicate to make sure my understanding is correct.
2
u/BAM5 Feb 11 '19
Wow! How timely! I was just looking into all this, literally 10 minutes ago. Want to make a MSA That applies a company template to user's emails and was looking up what that would entail.
2
u/danav Feb 11 '19
This is very helpful. Thanks for taking the time to write it up.
2
u/rwdorman Jack of All Trades Feb 11 '19
BOOKMARKED! And shared with my team... Thank you very much
2
u/iceph03nix Feb 11 '19
I feel a lot better that most of this I'd picked up in previous research dives. Makes me feel like I'm not insane.
We recently got bought and merged with another IT department, and so our side of things went from hosting our own exchange to having super limited access to Office 365 Exchange. Before we had almost no problems with email, and had everything running through filters with good mail records set up. Now we get more spam, with less control over how to handle it, and get so many spoofed emails forwarded to us to use as educational opportunities. We've pushed for more access and DMARC but so far we haven't made much progress.
One thing that helped with the spear phishing we were getting was to set up drop rules in our exchange server with a list of our C-team and other people who could order financial transactions that dropped anything with their name in the from that didn't come from our server. Doesn't help much for people spoofing you outside, but most of our spoofing attempts were pretending to be the CEO asking for a wire from someone in finance.
2
u/olemartinorg Feb 11 '19
Maybe there should be an automated test suite for mail setups where things like "did not pass SPF or DMARC but since you have this address in your address book already it's probably ok" would give you strong warnings. Too bad it's all a mess of various protocols.
2
u/cwheeler33 Feb 11 '19 edited Feb 11 '19
some other basic setup settings that really help. The following is a quick example:https://www.linuxbabe.com/mail-server/block-email-spam-postfix
summarized:
Not sure about MS Exchange today without expensive 3rd party tools (last ver I used was 2003), but Postfix and Exim have been amazing at filtering basic crap at a much lower level. You can get real fancy if you want. And for the SMB, either outsource or at least get to know open source projects like the "eFa Project".
<EDIT> not only should you filter out the crap in the list, make sure you fix all of these yourself. eg make sure you have a proper A+MX+PTR record for your domain/mail server. Don't use a "home user" IP address, get a static business address(some of those black lists filter home IP's).
2
u/BlackV I have opnions Feb 11 '19
OH Have a updoot
2
u/rvdvelpe Feb 11 '19
Great write-up!
DMARC is the the tool to get visibility and makes it easy to safely transition into a reject policy for SPF and DKIM (with allignment).
But it is a BIG shame, that one of the biggest mail providers, named office365, does not participate in DMARC reporting. They should be obligated to do this!
2
u/[deleted] Feb 11 '19
Definitely learned a little more about email. More importantly this reminded me I need to enable DKIM on a new domain I'm setting up. Thanks for the post!
2
u/Sodex234 Feb 11 '19
"not all heros wear capes"
Awesome post, read the whole thing.
2
u/AdorableEggplant Feb 12 '19
This guy mails! Excellent post omers.
2
u/[deleted] Dec 31 '21
You can put my upvote right in that EHLO
1
u/hateexchange atheist, unless restoring backups Feb 11 '19
That looks interesting. Gonna give it another read when I got time.
1
u/mjung79 Feb 11 '19
Great summary! I needed a refresher on some of this and more in depth info on other parts of it. Really appreciate this write up.
1
u/Revertible Feb 11 '19
Very very interesting read. Thank you for taking the time to write this up!
1
u/nineteen999 Feb 11 '19
I've seen this a bit recently, where major vendors (won't name you VMware) have -all specified in their SPF record, and then go and send email via sendgrid or some service that isn't listed.
And of course our company policy is to hard fail in this case, and legitimate mail gets caught by the spam filter and has to be released manually. It's very annoying.
1
u/elspazzz Feb 11 '19
Thanks for this!
I've been debating setting up a mail server for my homelab for various reasons and this has helped alot in the information dept.
1
u/BerkeleyFarmGirl Jane of Most Trades Feb 11 '19
Great stuff, thank you for doing this.
1
u/Edmondo_Dantes Feb 11 '19
Just here to say thanks, great write up.
1
u/skilliard7 Feb 11 '19
Really well written post OP. You really should launch your own blog and try and make some money off of it instead of giving it all to Reddit.
1
u/Sir_Swaps_Alot Feb 11 '19
Great post!!!
Next time somebody bitches about why they get spoofed emails I'll copy pasta this and wait for their heads asplode.
1
u/crackdepirate Feb 12 '19
Great summary !!! Someone who understand spf dkim and dmarc. How many web hosting resellers didnt implement this. So bad.
1
u/EarthWindAndFire430 Feb 12 '19
Cool
1
u/shardikprime Feb 12 '19
Man this is great thanks I was confused to no end by this A Records and SPF stuff
1
u/Pants_R_Overatd Feb 12 '19
RemindMe! 6 hours
1
u/dnuohxof1 Jack of All Trades Feb 12 '19
This information helped me understand these concepts much better. Thank you for this write up.
1
u/bentleythekid Windows Admin Feb 12 '19
It's nice to see someone on the internet be so right about something. Thanks
1
u/Gumbyohson Feb 12 '19
Great write up. Been enforcing this across our customers where we can and this puts it very clearly.
I've seen a few mentions of a record that looks like: _domainkey.example.com TXT "t=s; o=-;" or alternately "t=s; o=~;". It seems like it's similar to SPF -all that it requires all emails from the domain to be signed to be valid. Do you have any experience with this record and know if it is still in use?
1
u/800oz_gorilla Feb 12 '19
Do you have any resources to indicate all the causes for the different spf errors. Eg. Perm error, temp error, soft fail, etc.?
1
u/Amulek43 IT Manager Feb 12 '19
This was an excellent overview, thank you for putting this together.
1
u/WoTpro Jack of All Trades Feb 12 '19
great write up thnx
1
u/lord90 Feb 12 '19
Quality post!!! Thanks
1
u/[deleted] Feb 13 '19
While I understood these concepts separately, this post does a helluva good job making sense of it.
Thank you!
1
u/whitebreadlvr Feb 13 '19
Well, it's up to the receding server to determine if they want to check SPF & DKIM.
As the sender, you can only put up records to let the receiver know if the emails are legit.
1
u/[deleted] Feb 13 '19
Nice write-up. I feel like some sort of advanced threat filtering and SAT are compulsory in certain verticals (finance, healthcare, for starters). You need both of these in place to even have a chance. Orgs that leave this to chance are going to select themselves out sooner than later.
I see this shit all the time, example: Blah@wherever.tld sends 10,0000 credential harvesting emails to its contact list. One gets delivered to some user. Threat filter sounds alarm. Respond to threat, talk to user. User calls actual contact for Blah@wherever.tld to find out WTF is going on. Response: “My email got hacked.”
Seriously?!?!
No one noticed their employee got phished? What the shit! Emails don’t get hacked, people fail. Failures need to get C U T!
/gripe
1
u/creamersrealm Meme Master of Disaster Feb 13 '19 edited Feb 13 '19
Everything you said is very solid advice. A few things I would note though.
Never implement DMARC without proper DKIM alignment. DKIM will always survive forwarding like you mentioned unless they screw with the body hash it specific headers. But SPF will never survive mail forwarding address the return path is always adjusted by the server doing the automatic forwarding.
I'm curious where your data is on major ESPs not supporting DMARC fully other than O365. As they do a hacked up version of DMARC as follows.
O365 changes quarantine and reject to our and oreject and they override it internally and set the SCL to 9. O365 doesn't fully follow DMARC with EOP alone. So you have to use a ETR to re override the original P tag a d hold for review or reject.
Something you should add is on whitelisting. Never whitelist an email or domain. Whitelisting says anyone saying I'm X via the 5322.From header will be allowed through on if it's valid or spoofing. The only proper way to "whitelist" is first to make them fix their mail. But if they refuse to or can't make an ETR a d verify DMARC, set the SCL, and verify it sourced from X IPs then that the closest you can get.
I'm very passionate about email security to and I've spent a lot of time on it in the recent years to. You mentioned Dmarcian and they are a really awesome company. They even helped me verify some technical information on a email security presentation that I just did and gave me some tid bits that I didn't know or fully understand. Plus their owner is Tim Draegen who is one of the principal writers of the DMARC standard.
1
u/hifall Feb 17 '19
Nice post. Concise and straight to the point.
-1
u/LeaveTheMatrix The best things involve lots of fire. Users are tasty as BBQ. Feb 11 '19
In my opinion (and 10 years in hosting industry) SPF is pretty much useless, hell most of these options are useless, and this is IMHO because email is basically a cobbled together system that we are now attempting to patch.
The biggest problem is that they are all a crapshoot on usability because they are often dependent on if the receiver actually checks for any of it.
You can have all of these on your domain, yet if joe blow mail server doesn't LOOK for them then all your work to protect your domain is useless.
We need to totally revamp the email system, make these mandatory for both sending and receiving, and if you are checking for them on receiving servers then you shouldn't be able to send from those servers.
May be a bit salty, but I have experienced to many "why is Bob receiving spoofed emails from my domain, when I have implemented all protections" only for me to have to tell them that while they have added protections since Bobs server doesn't actually check for them all their work was for nothing.