A-R53-10

DKIM Records with Small Key Size

Risk:
High
CWE:
None

DKIM encryption using key sizes under 1024 bits are trivial to brute force. As DKIM DNS records are public, weak email signatures are discoverable


Details

DKIM is a spam protection framework that enables email servers to sign their outbound messages using an asymmetric key pair and advertise the public key as a DNS record for cryptographic validation.

When DKIM is configured correctly the private key of the key pair is utilized for signing email serving two purposes:

Firstly receiving email servers hash the entire body of the email as the email itself is not additionally encrypted. This gives the email server their own hash value of the email that they have received.

The DKIM signature included on the email is an encrypted version of the hash of the email body sent by the sending email server. However, as the sending hash was encrypted with the real email server’s private key then the corresponding public key in the DKIM DNS record can be used to decrypt the signature.

If decryption is successful when using the public key found in the DNS record then the email has been signed by the private key matching the public key in the DNS record. If the decryption fails then the key used for the signature in the email does not match the key listed in the DNS record. This would mean that your email has not been signed by the advertised key pair for the domain that you’ve received an email from This is either a substantial misconfiguration or it’s a spoofed email.

If the decryption is successful then the decrypted hash is compared against the email server’s hash of the email body that it generated itself. If the two hashes match then the email is exactly as the sending server sent it. However, if the hashes do not match then the email body has been altered and the email has been tampered with.

Combatting Spam

This framework is effective in combating spam as it checks that emails are being sent from the advertised sender of emails for your domain as well as verifying that the email body content is the same. These checks also utilise cryptographic functions which - if configured correctly - can be computationally impossible to brute force, providing the maximum level of validation possible.

A valid and secure DKIM setup presents a significant barrier for email services sending spoofed email, and can eliminate brute force spoofing if configured well.

Key Pair Size

However, the underlying cryptographic protocols that DKIM is using needs to be secure. Using key pairs that are less than 1024 bits in length are no longer secure as whilst they were historically computationally impossible that is no longer the case. Real life case studies have shown brute force discovery of the private key in key pairs that have less than 1024 bit, with the key pair becoming compromised in days and sometimes hours.

Having the private key be discoverable completely undermines the DKIM system as the barrier to brute force attacks is no longer in place, hence it’s critical to never use a key size less than 1024 bits.

Remediation

Ensure that your official email server is configured to use a key pair of 1024 bits or more, ideally 2048 bits. This key size will make it economically unfeasible for attackers to brute force discovery of the private key, thereby deterring targeted threats aimed at sending spoofed emails from your domain. Attackers can easily scan for your DNS records and discover if small key sizes are being used, which are vulnerable to reverse engineering and can create emails with valid signatures.

SkySiege’s Cloud Assessment scans your DNS records for DKIM records that advertise public keys that are prone to compromise. Rather than scanning all your DNS records and computing key sizes get a Cloud Assessment and discover across your entire cloud estate weak DKIM encryption the same day:

Discover if you're vulnerable

SkySiege Cloud Security Assessments scan for this issue and provide same-day reports..
Available for individual projects or organisations.

Related Tests