Email sender: Return-Path, From, and Reply-To headers. The Return-Path header can be protected against spoofing with SPF. The From header can be protected using DMARC (with SPF and/or DKIM).

Originating server and MTA: Received header(s).

Email legitimacy and anti-spoofing mechanisms, with associated headers:

SPF: validates that the originating server is authorized to send emails for the sender domain.

DKIM header: digitally signs (part of) the email using a public key associated with the sender domain.

DMARC: extends SPF and DKIM by indicating to the receiver the actions to follow (for example, block the email and notify an alerting address) when receiving an email with no or a failed SPF/DKIM authentication. Additionally, DMARC checks the consistency of the domains from the "From" header, the DKIM signature, and the SMTP "MAIL FROM" command.

Email envelope versus content

An email object contains an envelope and content.

The envelope is the information that the email client and server use to send the email to the correct recipient(s). It notably includes the sender email address and the recipient email address(es) specified with the MAIL FROM and RCPT TO SMTP commands, respectively. The envelope also includes the Received headers added by each Message Transfer Agent (MTA) that relayed the email. The envelope headers are not displayed to end users.

The email content (sent through the SMTP DATA command) is composed of the header section and the email body. The header section consists of a collection of header fields, which can be displayed to end users in their email client. For instance, the email content From header is used to display the email sender in email clients. The email body is the actual content of the email.

A number of email envelope and content headers are common/mandatory for the email lifecycle, and some headers can be of great forensic value. Additionally, some headers are linked to optional security mechanisms (SPF, DKIM, and DMARC) that can help detect illegitimate/spoofed emails.

Email original sender

From, Return-Path, and Reply-To headers

The email address of the sender is present in three headers:

  • The Return-Path envelope header, whose value is based on the email address specified in the MAIL FROM SMTP command. This header is verified by the SPF mechanism and is thus a more reliable source of information for determining the sender of an email. The Return-Path header is used to process the “bounces” that may occur with an email.

  • The From content header, which is displayed to the end user as the sender of the email. The From header is not verified by the SPF mechanism and can thus be spoofed.

  • The Reply-To header, which simply specifies the email address to which human replies should be sent (as the recipient of the new email). An arbitrary email address can be specified with no impact on email security mechanisms.

If the From and Return-Path headers differ, the From header may have been spoofed for social engineering purposes. If SPF verification (detailed below) fails, the Return-Path header may have been spoofed as well.

Note that the Domain-based Message Authentication Reporting and Conformance (DMARC) mechanism can be used to detect/prevent spoofing of the From header.

MTA Received headers

A Received header is added to the email envelope headers by every Message Transfer Agent (MTA) that relayed the email. Received headers are ordered in reverse chronological order, with the last Received header corresponding to the one added first by the MTA closest to the email sender (and the first appearing Received header corresponding to the MTA closest to the destination). The last Received header (placed closest to the From/To headers and the message body) can thus be used to identify the MTA from which the email originated. The reputation and legitimacy of the sender MTA, in the email context, can be analyzed to determine the legitimacy of the email.

Each Received header logs the sending and receiving MTA hostnames and IP addresses, as well as the time of reception. Example of the first Received header of an email sent through O365:

Received: from XXX.PROD.OUTLOOK.COM
 ([<IP>]) by YYY.PROD.OUTLOOK.COM
 ([<IP>]) with mapi id 15.20.5250.018; <DATE>

SPF

Overview

Sender Policy Framework (SPF) is an email authentication mechanism, defined in RFC 7208, designed to detect and/or block spoofed emails by detecting illegitimate sender servers. More specifically, the SPF mechanism will validate the domains a mail server can send emails for (through the MAIL FROM envelope header of an email).

SPF can be used by organizations to define servers authorized to send emails for their domain names. SPF relies on specific DNS TXT records that identify authorized servers and the behavior the receiver should follow in case an email is received from an unauthorized server.

SPF DNS records follow the format below, with mechanisms/rules evaluated from left to right and stopping on the first match (except for the INCLUDE mechanism).

# Only version 1 of SPF is supported, so the version tag will always be set to v=spf1.

v=<spf1 | SPF_VERSION> <QUALIFIER><MECHANISM_1> ... <QUALIFIER><MECHANISM_N>

The following mechanisms are supported:

Mechanism Description
all Always matches.
include:<DOMAIN> Evaluate the SPF policy of the specified domain, returning a PASS/Neutral/Fail/Softfail result (or an error).

Only a PASS result will, however, be processed, effectively stopping the evaluation of the following mechanisms. Non-matching results will resume the processing of the remaining mechanisms.
a[:<DOMAIN>] Check if the sender email server IP address is included in the A or AAAA DNS records of the MAIL FROM/HELO domain or the domain specified in the mechanism.
mx[:<DOMAIN>] Check if the sender email server IP address is included in the MX DNS records of the MAIL FROM/HELO domain or the domain specified in the mechanism.
ip4:<IPV4 | IPV4_CIDR> Check if the sender email server IP address is the specified IPv4 address or in the specified IPv4 address range.
ip6:<IPV6 | IPV6_CIDR> Check if the sender email server IP address is the specified IPv6 address or in the specified IPv6 address range.

The qualifiers determine the behavior the receiving email server should follow if the mechanism matches. The following qualifiers are supported:

Qualifier keyword Qualifier description Description
+ PASS Allow the message.

I.e. if the associated mechanism matches, the message should be accepted by the receiving email server.

Default if the qualifier is not specified.
- FAIL Reject the message.

I.e. if the associated mechanism matches, the message should be rejected by the receiving email server.
? NEUTRAL The authoritative domain explicitly states that it is not asserting whether the sender email server IP address is authorized.

Can be processed as if the SPF record did not exist. I.e. if the associated mechanism matches, the message could be processed by the receiving email server as if no SPF record was configured.
~ SOFTFAIL The authoritative domain explicitly states that it is not asserting whether the sender email server IP address is authorized.

Same behavior as NEUTRAL, with differences in processing left to the receiving email server.

Spoofed email SPF headers example

The following email headers correspond to the headers of a spoofed email (assuming that SPF records are correctly configured):

Authentication-Results: spf=fail (sender IP is <SENDING_SERVER_IP>)
[...]

Received-SPF: Fail (protection.outlook.com: domain of <MAIL_FROM_OR_HELO_DOMAIN>
 does not designate <SENDING_SERVER_IP> as permitted sender)
 receiver=protection.outlook.com; client-ip=<SENDING_SERVER_IP>;
 helo=<SENDING_SERVER_FQDN>;

References



View on GitHub