Back to blog
Threat Intel
Phishing Forensics

Weaponizing RFC 6376: Perfecting DKIM to Bypass Scanners

A perfectly validated signature does not mean an email is safe. It just means the threat actor read the RFC.

MailSleuth Research
Email Security Team
October 19, 20268 min read
A flawless metallic key casting a sinister shadow, representing malicious infrastructure disguised as compliant.

Most SOC analysts assume a pass verdict in the Authentication-Results header means the sender is legitimate. They see the OK flag next to the signature check and move straight to analyzing the payload, completely ignoring the infrastructure that delivered it. This is exactly what a competent adversary counts on. Setting up malicious infrastructure used to be a messy affair of bare IP addresses and spray-and-pray delivery tactics. Today, a successful campaign starts with an environment that looks indistinguishable from a Fortune 500 tenant.

Adversaries are not just passing cryptographic checks. They are building complex trust profiles. A proper phishing domain dkim setup is an absolute prerequisite for modern inbox placement. We are going to walk through exactly how a red team crafts a signature record that not only passes validation but evades the heuristic scanners looking for hastily assembled attacker infrastructure.

The Goal: Evading Scanners That Profile DNS Records for Weakness

Passing a cryptographic check is a binary operation. The receiving mail transfer agent extracts the domain and selector from the email header, performs a DNS lookup, retrieves the public key, and verifies the body hash. If the math works, the signature passes. Modern email security gateways do not stop at the math. They profile the infrastructure. Automated scanners look for entropy in the DNS records, analyzing the specific tags and values configured in the TXT string. An attacker who simply generates a key pair and slaps it into a cloud DNS provider might pass the binary check but will light up heuristic alarms across the board.

Beyond Cryptographic Validation

Defenders have learned that lazy adversaries leave fingerprints. Scanners evaluate the age of the domain, the length of the cryptographic key, the naming convention of the selector, and the presence of extraneous tags. A red team operating a lookalike domain must account for every one of these variables. The objective is to blend into the massive volume of legitimate corporate communications without triggering a second look from the detection engineering team. When an analyst queries the DNS records during an investigation, the configuration must project extreme administrative competence.

Step 1: Generating a 2048-bit Key to Signal Modern Hygiene

Key length is the easiest trap for an amateur operator to fall into. For years, 1024-bit RSA was the industry standard for DKIM signatures. It was computationally lightweight and fit perfectly within standard UDP DNS response limits. RFC 8301 formally deprecated 1024-bit keys due to advances in computing power that made factoring them theoretically feasible for well-resourced actors. Today, a 1024-bit key on a newly registered domain is a massive red flag. Heuristic scanners actively penalize short keys, associating them with outdated tutorials or automated phishing kits that have not updated their codebase.

To signal modern hygiene, a red team will always generate a 2048-bit RSA key pair. This requires a bit more care when creating the DNS TXT record, as the resulting base64 string is significantly longer and often requires the record to be split across multiple strings to satisfy DNS maximum length requirements. Advanced adversaries script this splitting process to ensure the public key is perfectly concatenated by the resolving nameserver.

Authentication-Results: mx.corporate.com; dkim=pass (2048-bit key) header.d=secure-login-portal.com header.i=@secure-login-portal.com header.b=XyZ123 — Typical log entry for a perfectly forged signature

When the receiving gateway logs the verification, the key length is often parsed and recorded. A 2048-bit key tells the security appliance that the sender is adhering to modern cryptographic standards, buying the malicious infrastructure a crucial sliver of operational credibility.

Step 2: Mimicking Corporate Selector Naming Conventions

The selector is the string used to locate the public key in DNS. According to RFC 6376, the selector can be almost any arbitrary string, which means it serves as a massive canvas for attacker profiling. When an adversary uses a cheap shared hosting provider to spin up infrastructure, the control panel often auto-generates a selector. Values like default, mail, hostgator, or phpmailer are incredibly common. Threat intelligence platforms scrape passive DNS databases for exactly these patterns, correlating them with newly registered domains to proactively block entire swathes of infrastructure.

Blending in with the Enterprise

A professional red team mimics the naming conventions of major cloud providers or enterprise IT departments. Microsoft 365 environments typically use selector1 and selector2. Google Workspace environments use google. Corporate IT teams managing custom infrastructure often use iterative naming conventions like s1, s2, or geographically tied selectors like us-east-1. By adopting these exact naming conventions for their lookalike domains, attackers ensure that the DNS queries generated by the receiving mail server look completely mundane.

If a SOC analyst is hunting through logs and sees a query for selector1._domainkey.microsoft-auth-update.com, their eyes are far more likely to glaze over than if they see an auto-generated alphanumeric hash or a default string. The camouflage operates on both the automated scanners evaluating the infrastructure and the human defenders auditing the logs.

Step 3: Avoiding Red Flags like the Test Mode Tag

RFC 6376 includes several optional tags designed to help administrators troubleshoot their configurations. The most dangerous of these for a red team is the testing flag. Setting the t=y tag indicates that the domain is currently testing signatures and that receiving servers must not treat a verification failure as a reason to reject the message. While this sounds like a safe fallback for an attacker worried about breaking their signature, it is a massive heuristic indicator of suspicious activity.

Legitimate organizations rarely leave their production infrastructure in testing mode. When an automated scanner evaluates a record and finds a test flag on a newly registered domain, it immediately downgrades the reputation of the sender. Some strict email gateways are configured to ignore the signature entirely if the test flag is present, effectively treating the email as unsigned and subjecting it to harsher spam filtering. A disciplined red team ensures their TXT records are pristine, containing only the absolute minimum required tags to achieve a pass verdict. They test their signatures against controlled drop boxes before launching a campaign, completely eliminating the need for testing flags in the wild.

Step 4: The Final Polish: Ensuring Correct Version and Policy Syntax

The syntax of a TXT record is rigidly defined, but DNS itself is incredibly forgiving of malformed entries. A defender can easily misconfigure a record that technically resolves but fails strict parser validation. Scanners exploit this by looking for syntax errors as a sign of amateur administration. The v=DKIM1 tag must be the very first declaration in the record. If an attacker places the public key data before the version tag, some lenient gateways might still validate the signature, but strict scanners will flag the record as non-compliant.

The Policy Tag Trap

Another common mistake is the inclusion of archaic or malformed tags. The granularity tag was designed to restrict which local parts of an email address could use a specific key. It is almost never used in modern deployments, and its presence on a new domain is highly anomalous. Similarly, trailing whitespace within the base64 public key string or missing semicolons between tags can break regex-based parsers used by threat intelligence platforms.

v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA... — A flawlessly formatted TXT record string

A flawless record looks exactly like the string above. It is concise, correctly ordered, and devoid of unnecessary metadata. Red teams will often run their crafted records through strict linting tools to ensure they pass every conceivable syntax check before publishing the zone file. The objective is to provide the receiving parser with a perfectly formed string that requires zero error correction.

Defeating the Defender: Why Passing a Check Is Only the First Step

Crafting a flawless record is a masterclass in evading automated infrastructure profiling, but it does not guarantee inbox placement. Cryptographic validation only proves that the sender controls the DNS of the signing domain and that the message body has not been altered in transit. It says absolutely nothing about the reputation or intent of that domain. A lookalike domain perfectly configured with a 2048-bit key and enterprise selectors is still a lookalike domain.

Defenders must shift their focus from the binary pass verdict to the alignment of the identity. DMARC requires that the domain in the header From address matches the domain in the signature. Attackers know this, which is why they purchase domains that visually mimic their targets. The real battleground is in detecting the visual deception and analyzing the payload. If an organization relies solely on authentication protocols to determine trust, they will inevitably fall victim to adversaries who read the RFCs just as thoroughly as the network architects do.

Ultimately, a compliant signature is just the vehicle. It gets the payload past the perimeter guards and onto the analyst's desk. Recognizing that perfect infrastructure is often the hallmark of a sophisticated threat actor is the critical evolution in modern detection engineering.

The takeaway

We have to stop treating a pass verdict in the Authentication-Results header as a definitive stamp of approval. When adversaries invest the time to generate 2048-bit keys, mimic corporate selector conventions, and ruthlessly sanitize their DNS records, they strip away the easy heuristic wins defenders have relied on for years. They weaponize compliance, turning our own standards into camouflage.

The next time you are triaging a suspected business email compromise, do not let a pristine cryptographic signature stop your investigation. Dig into the domain age, analyze the DMARC alignment, and scrutinize the actual routing history in the Received headers. If you need a faster way to untangle those complex header structures and spot the minute anomalies in perfectly crafted infrastructure, MailSleuth.AI can automate the heavy lifting. The math might be perfect, but the adversary always leaves a trail if you know exactly where to look.

#red-team#dkim#rfc-6376#phishing#detection-engineering
MailSleuth Research
Email Security Team

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