Skip to content
RCE Write-up Advanced

Exim Off-By-one RCE: Exploiting CVE-2018-6789 with Fully Mitigations Bypassing

An off-by-one heap overflow in Exim's base64 decoding function allows an attacker to overwrite one byte beyond the allocated buffer. By carefully arranging heap memory, this can be leveraged to achieve pre-authentication remote code execution on SMTP servers.

devco.re

Published on devco.re

Tech Editorials #Advisory #Exim #RCE #CVE

The author, on devco.re

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The base64 decoding function allocates a buffer of 3*(len/4)+1 bytes but writes 3n+2 bytes when the input length is 4n+3, causing a one-byte heap overflow.

Impact

An attacker could achieve pre-authentication remote code execution on vulnerable Exim SMTP servers, potentially compromising the entire system.

What the attacker needed

Exim version below 4.90.1; SMTP daemon accessible; CRAM-MD5 or other base64 authenticator enabled

The fix

Upgrade to Exim version 4.90.1 or above.

How it was found

  1. Send an EHLO command with a huge hostname to allocate and free a large chunk, leaving it in the unsorted bin.
  2. Send an unrecognized string to trigger store_get() and allocate a storeblock inside the freed chunk.
  3. Send another EHLO to get a second storeblock and free the first one via smtp_reset.
  4. Start an AUTH command with base64 data to trigger the off-by-one overflow, overwriting the next chunk's size.
  5. Send another base64 string to forge a valid chunk size for the extended chunk.
  6. Send an invalid EHLO hostname to release the extended chunk, then use AUTH to overwrite the next pointer of an overlapped storeblock.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Exim is a mail server program. When it decodes base64 data (a way to encode binary as text), it sometimes writes one byte past the end of a memory buffer. That single byte can be used to corrupt memory and eventually run attacker-controlled code on the server, without needing to log in first.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.