DKIM Bypass
This attack focuses on bypassing DomainKeys Identified Mail (DKIM) email authentication to send spoofed emails that appear to come from a legitimate domain.
Attack Summary: Bypassing DKIM authentication to send spoofed emails that appear to come from a legitimate domain.
Background: DomainKeys Identified Mail (DKIM)
DomainKeys Identified Mail (DKIM) is an email authentication method designed to detect forged sender addresses in emails. DKIM allows the receiver to check that an email claimed to have come from a specific domain was indeed authorized by the owner of that domain.
DKIM works by:
- The sending domain generates a public-private key pair
- The public key is published in the domain's DNS records
- When sending an email, the mail server uses the private key to generate a digital signature for the email
- The signature is included in the email headers
- When receiving an email, the receiving server retrieves the public key from the sender's DNS
- The receiving server uses the public key to verify the signature
- If the signature is valid, the email is considered authentic
Despite its cryptographic strength, DKIM has several limitations and vulnerabilities that can be exploited to bypass its protection.
Attack Methodology
This attack involves exploiting various limitations and vulnerabilities in DKIM to send spoofed emails that bypass DKIM checks.
This variant involves identifying DKIM selectors used by a domain and attempting to steal or compromise the private keys.
Selector Enumeration Example
Identifying DKIM selectors
Key Theft Vectors
Attackers can attempt to steal or compromise DKIM private keys through various vectors:
- Server compromise: Gaining access to mail servers where keys are stored
- Backup compromise: Accessing backups that contain private keys
- Key generation issues: Exploiting weak key generation processes
- Insider threats: Obtaining keys from insiders with access
- Third-party compromise: Compromising third-party email providers
This variant involves identifying and exploiting weak DKIM keys that can be factored or broken.
Weak Key Identification Example
Identifying weak DKIM keys
Key Strength Recommendations
DKIM key strength recommendations have evolved over time:
- 512 bits: Originally used, now considered extremely weak
- 768 bits: Previously common, now considered weak
- 1024 bits: Minimum recommended in RFC 6376, becoming weak
- 2048 bits: Currently recommended minimum
- 4096 bits: Provides additional security margin
This variant exploits the fact that DKIM only signs specific header fields, allowing attackers to modify unsigned fields.
Header Field Exclusion Example
Exploiting unsigned header fields
Commonly Unsigned Headers
Headers that are commonly not signed by DKIM include:
- Reply-To: Can be modified to redirect replies
- CC/BCC: Can be modified to include additional recipients
- Content-Type: Can be modified to change how content is displayed
- Content-Transfer-Encoding: Can be modified to change how content is encoded
- X-* headers: Custom headers often used for internal routing or filtering
This variant exploits how DKIM canonicalizes the email body before signing, allowing certain modifications that don't invalidate the signature.
Body Canonicalization Example
Exploiting relaxed canonicalization
Canonicalization Methods
DKIM supports two canonicalization methods:
- Simple: Minimal changes to the message, more strict
- Relaxed: More forgiving of whitespace and line ending changes
The canonicalization method is specified in the c= parameter of the DKIM-Signature header, in the format c=header/body (e.g., c=relaxed/simple).
Impact
This attack allows attackers to:
- Send spoofed emails that bypass DKIM checks
- Modify unsigned headers without invalidating DKIM signatures
- Make subtle changes to email bodies without invalidating DKIM signatures
- Conduct phishing attacks with higher success rates
- Potentially damage the reputation of legitimate domains
Detection
Organizations can detect these attacks by:
- Monitoring for emails with suspicious modifications to unsigned headers
- Implementing additional email authentication mechanisms (SPF, DMARC)
- Using email security solutions that check for DKIM anomalies
- Regularly auditing DKIM configurations and key strength
Mitigation
To protect against these attacks, organizations should:
- Use strong keys: Use at least 2048-bit RSA keys for DKIM
- Sign all important headers: Include all security-relevant headers in the DKIM signature
- Use simple canonicalization: Consider using simple canonicalization for better security
- Implement DMARC: DMARC can help prevent domain spoofing even if DKIM is bypassed
- Rotate keys regularly: Regularly rotate DKIM keys to limit the impact of key compromise
- Protect private keys: Securely store and manage DKIM private keys
- Monitor for weak keys: Regularly check for and replace weak DKIM keys
Testing
Security professionals can test for this vulnerability using the following approach:
- Identify DKIM selectors used by the target domain
- Check the strength of DKIM keys
- Analyze which headers are signed by DKIM
- Test modifying unsigned headers to see if they bypass security checks
- Test making subtle changes to the email body to see if they invalidate the DKIM signature
- Check if emails with these modifications are delivered and how they are displayed to recipients
References
- RFC 6376: "DomainKeys Identified Mail (DKIM) Signatures." https://tools.ietf.org/html/rfc6376
- RFC 7489: "Domain-based Message Authentication, Reporting, and Conformance (DMARC)." https://tools.ietf.org/html/rfc7489
- Chen, J., Duan, H., Weaver, N., Paxson, V., & Jiang, J. (2021). "Measuring and Mitigating Email Sender Spoofing Attacks." In Proceedings of the 30th USENIX Security Symposium.
- Foster, I. D., Larson, J., Masich, M., Snoeren, A. C., Savage, S., & Levchenko, K. (2015). "Security by Any Other Name: On the Effectiveness of Provider Based Email Security." In Proceedings of the 22nd ACM SIGSAC Conference on Computer and Communications Security.