Back to blog
Threat Intel
Phishing Forensics

Your SPF Record Is a Map to Your Forgotten Servers

Your SPF record isn't just a policy; it's a public inventory of every server authorized to send email as you—including the ones you forgot.

MailSleuth Research
Email Security Team
July 30, 20267 min read
An overhead illustration of a city blueprint, with one forgotten street glowing red to symbolize a security vulnerabilit

Your company's SPF record is lying to you. Not maliciously, but through years of accumulated technical debt, forgotten projects, and third-party vendors who got added on a Friday afternoon. What was designed as a simple anti-spoofing mechanism in RFC 7208 has become a public-facing declaration of trust—a map pointing to every server, service, and marketing platform you’ve ever allowed to send mail on your behalf.

Most security teams treat SPF as a set-it-and-forget-it DNS entry. You configure it to get DMARC passing, and you only touch it when the marketing team adopts a new email-blasting service. This is a mistake.

We're going to turn offensive OSINT techniques inward. We'll treat our own SPF record as if we were an external attacker mapping our mail infrastructure. The goal is simple: find the forgotten, unpatched, and misconfigured servers hiding in plain sight before someone else does.

Every `include` Is a Trust Relationship You Didn't Vet

An SPF record is a chain of trust. When a receiving mail server evaluates your policy, it doesn't just look at the top-level record. It follows the `include:` mechanisms, recursively. An `include:spf.mandrillapp.com` doesn't just authorize Mandrill; it authorizes every server, and every subsequent `include`, listed in Mandrill's own SPF record. You are delegating a piece of your domain's reputation.

This is where the rot begins. A vendor you used five years ago might still have an active `include` in your record. That vendor might have been acquired, their infrastructure might have changed, or their own SPF record might now authorize risky, shared IP spaces. You've inherited their security posture, whether you like it or not.

The operational stake is immense. A compromised server at a trusted third party becomes a vector for highly believable phishing and business email compromise (BEC) attacks against your partners and customers. The email will pass SPF, DKIM (if the vendor signs), and therefore DMARC alignment. To a receiving mail gateway, it looks perfectly legitimate. It came from an authorized server.

Unspooling the Chain: How to Map Your SPF Trust Graph

The first step in auditing your SPF record for security is to fully resolve it. You can't just read the TXT record in your DNS zone. You have to perform the same lookups a receiving mail server would.

From DNS Lookups to a Target List

Start with a simple `dig` or `nslookup` on your domain's TXT record. Then, for every `include:` mechanism, repeat the process. For every `a` or `mx` mechanism, resolve the hostname to its IP address(es). For `ptr` mechanisms (which are discouraged by RFC 7208 and should be removed anyway), you'd perform a reverse DNS lookup. The goal is to build a flat list of every single IP address and CIDR range that your policy authorizes.

Remember the 10 DNS lookup limit specified in the spec. If your SPF record requires more than 10 lookups to resolve, it will return a `permerror` to many receivers, effectively breaking SPF for some mail flows. Hitting this limit is also a strong signal that your record is too complex and likely contains legacy cruft you don't need.

v=spf1 include:_spf.google.com include:sendgrid.net a:mail.mycorp-dev.com ip4:203.0.113.42 ~all

An seemingly simple record like the one above can expand into dozens of IP ranges once you recursively resolve `_spf.google.com` and `sendgrid.net`. Your task is to collect every single one of those IPs into a master list. This is your initial set of targets.

Connecting the Dots: From IP Address to Open Port

With a complete list of authorized IP addresses, the real reconnaissance begins. We are now going to profile these servers using public internet scanning services like Shodan and Censys. We want to answer a few key questions for each IP:

Is anything listening on standard mail ports like 25 (SMTP), 587 (submission), or 465 (SMTPS)? If an IP is authorized to send mail but has no listening mail services, why is it in the record? Is it a NAT gateway? A web server that uses an API to send mail through another relay? Context matters.

What software is it running? The banners returned on these ports are a goldmine. Seeing `Microsoft ESMTP MAIL Service` is different from seeing `Postfix 3.4.14` or, worse, `Exim 4.82`. Old software versions often have known, unpatched vulnerabilities. An attacker can use this information to quickly find a viable exploit.

Inspecting TLS Configurations

Beyond the service banner, look at the TLS certificate and cipher suites offered. Is the certificate expired? Is it a self-signed cert on a production mail relay? Does the server still offer weak export-grade ciphers, or worse, SSLv3? A weak TLS configuration on a mail server not only fails to protect data in transit but is also a giant, flashing sign of a neglected machine. If they got TLS wrong, they almost certainly got other things wrong, too.

Anatomy of a Finding: The Forgotten Dev Relay

Let's walk through a realistic case. During a recursive SPF audit, you uncover a mechanism: `a:dev-mailer.our-company.net`. The hostname resolves to an IP in one of your corporate AWS accounts. You've never heard of this server.

A quick check in Shodan reveals it's running Ubuntu 16.04 LTS and Postfix 3.1.0. Port 25 is open to the world. A TLS scan shows it negotiates TLS 1.0 and offers a suite of 3DES ciphers. This is bad. After asking around, you discover a development team spun up this VM four years ago to test application email notifications. The project was shelved, but the server was never decommissioned. The `a` record was left in the SPF policy 'just in case'.

This single, forgotten server completely undermines your DMARC posture. An attacker who compromises this machine—which is easier given its age and likely unpatched state—can send perfectly authentic email as anyone at your domain. It will pass SPF authentication. If the server is also configured to DKIM sign (even with a test key), it can achieve DMARC alignment and land directly in the inbox. You found a ticking time bomb.

Are Your CIDR Blocks Too Generous?

The `ip4` and `ip6` mechanisms are powerful, but they are often a source of over-authorization. An `ip4:198.51.100.0/24` entry authorizes 256 different IP addresses to send email as you. Do you actually own and control all 256 of them?

This is especially dangerous in cloud environments. You might have been assigned a `/24` block by your provider years ago, but now you only use five IPs within it. The provider may have since reclaimed the unused addresses and assigned them to other customers. If your SPF record still contains the full `/24` block, you are now authorizing your cloud provider's other tenants to send email on your behalf. This is a catastrophic failure mode.

Scrutinize every CIDR range in your resolved SPF list. Can you justify every single IP address within that range? If not, the range needs to be broken down into smaller, more precise blocks or individual IP addresses. The principle of least privilege applies as much to SPF as it does to IAM.

From One-Off Audit to Continuous Monitoring

This kind of deep audit shouldn't be a once-a-year event. SPF records are dynamic. Third-party vendors change their infrastructure without notifying you. A developer might add a new `a` record for a temporary test and forget to remove it. You need a process.

Building a simple monitoring script is a great starting point. Have it run on a schedule (daily or weekly), perform the full recursive resolution of your SPF record, and generate the flat list of IPs. Then, diff that list against the previous run's list. If any IPs are added or removed, send an alert to your security team for review.

The alert should trigger a mini-investigation: Why was this IP added? What server is it? Who approved this change? This closes the loop, turning DNS from a forgotten corner of IT into a monitored, security-relevant asset. It forces you to treat your SPF record like what it is: a policy document defining your email security perimeter.

The takeaway

Your SPF record is not an IT setting; it's a security commitment. Every mechanism within it is an endorsement that has a direct impact on your domain's reputation and your organization's vulnerability to phishing and BEC. By treating it as a reconnaissance map and continuously auditing its effective IP address space, you move from a reactive posture to a proactive one.

Don't wait for an incident report to discover a forgotten mail relay. The map to your shadow infrastructure is public. Start reading it. For teams that need to scale this beyond scripts, platforms like MailSleuth.AI can automate the discovery and monitoring of this entire email attack surface.

#spf#dns#email-security#blue-team#osint#shadow-it#dmarc
MailSleuth Research
Email Security Team

We dissect phishing campaigns and email infrastructure so you don't have to.