The invoice that changes after you open it: how IMAP APPEND enables silent IBAN fraud
An attacker with your mailbox password can replace an invoice PDF already sitting in your inbox, keeping the sender, date and read status. Here is how it works, what traces it leaves, and how to stop paying the wrong IBAN.
TL;DR
An attacker with working credentials for a mailbox can use IMAP APPEND to swap the PDF in an invoice you already opened, keeping the sender, date, folder and read status. Nothing changes in your mail client except the IBAN. Confirm every new or changed IBAN by phone, heed Verification of Payee warnings, pay from the copy stored when the invoice arrived, and block password-only IMAP.
The scenario
A supplier emails you an invoice. You open the PDF, and the IBAN is correct. A few minutes later you come back to the same email to make the payment, and the IBAN in the PDF is different. The sender, the timestamp and the “read” status are all the same as before.
This scenario circulated this week in a thread by Pedro Fernandes. The core technique is real and simple to run. Some of the claims around it need correcting, though. Below is how the attack works, what it does and doesn’t hide, and what to do about it.
How the attack works
The attacker doesn’t need to break into the mail server. They only need working credentials for your mailbox (or for your finance team’s shared mailbox).
1. Watch the inbox in real time
IMAP has an IDLE command, which lets a client keep a connection open and receive a notification the moment new mail arrives. A small script logged into your account can use it to react within seconds. It fetches each new message and searches it for keywords such as “IBAN”, “invoice”, “fatura” or “payment details”, or simply checks for PDF attachments.
2. Rebuild the message with a forged attachment
IMAP has no command to edit a message once it is stored. Messages are immutable. A client can, however, delete a message and upload a new one. The script does the following:
- Downloads the full raw message, with all headers and MIME parts.
- Replaces the PDF part with a version that contains the attacker’s IBAN.
- Keeps every header unchanged:
From,Date,Subject,Message-ID,Received, and evenAuthentication-Results.
3. Put it back exactly where the original was
The APPEND command takes optional flags and an optional internal date:
A1 APPEND INBOX (\Seen) "18-Nov-2026 10:02:00 +0000" {48213}
<modified raw message>
A2 UID STORE 4711 +FLAGS (\Deleted)
A3 UID EXPUNGE 4711
The forged copy goes into the same folder with the original arrival time and the \Seen flag. The original is then flagged as deleted and expunged. In a normal mail client sorted by date, nothing looks different. The email sits in the same place, from the same sender, at the same time. Only the attachment has changed.
“But I have 2FA”: it depends on the provider
The original thread claims that on most mail servers 2FA only protects the webmail login, while IMAP and SMTP still accept a plain username and password. That was true a few years ago. Today it depends heavily on who hosts your mail:
| Provider | IMAP with only a password? |
|---|---|
| Google Workspace / Gmail | No. Basic-auth IMAP was retired in 2024–2025. It needs OAuth or an app password. |
| Microsoft 365 / Exchange Online | No. Basic auth for IMAP/POP was disabled in October 2022, so it needs OAuth. SMTP AUTH basic auth is being phased out separately. |
| iCloud, Yahoo | No, when 2FA is on. They require app-specific passwords. |
| Shared hosting (cPanel, Plesk), many local ISPs, self-hosted Dovecot | Often yes. 2FA, if offered at all, frequently protects only the webmail or control panel login. |
The last row covers a large share of small businesses, which are the main target of invoice fraud. Even on the big platforms, “password only” is not the only way in. A stolen app password or OAuth refresh token (for example from an infostealer or a malicious “connect your mailbox” app) gives the attacker the same IMAP access, and 2FA never comes into play.
Is it really “without traces”?
No, but the traces are invisible to a normal user. An investigator can find them:
- New UID. The forged copy gets a new, higher IMAP UID. Clients that sort by arrival order or UID may show the message briefly disappearing and reappearing.
- Broken DKIM. The sender’s DKIM signature covers the body. After the PDF swap the body hash no longer matches. The copied
Authentication-Results: dkim=passheader still says “pass”, because the server stamped it when the original arrived. Verifying DKIM again (for example with the DKIM Verifier add-on for Thunderbird, or by checking the raw source) shows the failure. - Server-side logs. IMAP logins,
APPENDandEXPUNGEoperations, and the client IP are logged by most servers. In Microsoft 365, the unified audit log records mailbox access (MailItemsAccessed) and item creation. Google Workspace has its own audit logs for Gmail. - Leftover originals. Depending on client and server settings, the deleted original may survive in Trash, in Gmail’s “All Mail”, in a backup, or in a local cache on another device.
The attacker isn’t connected to your account in any lasting way. The script is simply an external IMAP client using your credentials. Changing the password and revoking app passwords, OAuth grants and active sessions cuts it off. Some servers keep an existing IMAP session alive until it reconnects, so revoking sessions is not optional.
How this fits the bigger BEC picture
Business email compromise usually works in one of two ways. The attacker sends a fake “our bank details have changed” email from a compromised supplier account, or creates inbox rules that hide the real supplier’s replies. The in-place PDF swap is rarer, but it is nastier. It defeats the instinct “I already checked this email, it’s legitimate”, because the email you checked no longer exists.
The same trick works on the supplier’s side too. If the supplier’s mailbox is compromised, the attacker can alter the copy in their Sent folder, so the supplier’s own records match the fraudulent invoice.
What to do
For anyone who pays invoices
- Confirm every new or changed IBAN by phone, using a number you already have on file. Never use a number from the email or the PDF.
- Don’t ignore Verification of Payee. Since 9 October 2025, banks in the eurozone must check whether the beneficiary name matches the IBAN on euro transfers. A “name does not match” or “close match” warning on a supplier payment is a red flag, not a formality.
- Compare against the first copy. Store invoices in your accounting system or document management system when they arrive, and pay from that copy rather than from the mailbox.
For mailbox owners and admins
- Use a unique, strong password for email, and turn on 2FA everywhere it is offered.
- Disable IMAP and POP for accounts that don’t need them. For those that do, require OAuth and block basic authentication.
- Review and revoke app passwords, OAuth app grants and active sessions regularly, and immediately after any suspected compromise.
- Watch sign-in logs for unfamiliar IPs and for clients like Python
imaplibor other generic IMAP libraries. Alert on unusual volumes ofAPPENDandEXPUNGE. - If you are on cheap shared hosting with password-only IMAP, consider moving business mail to a provider that enforces modern authentication.
If you suspect it already happened
- Change the password and revoke every session, app password and OAuth grant.
- Pull the raw source of the suspicious email and check the DKIM signature again.
- Ask your provider for IMAP logs covering the period when the email was delivered.
- Contact your bank right away. Recalling a SEPA transfer is only realistic within hours, not days.
The lesson isn’t new, but this technique makes it sharper. An email is not a trustworthy record of payment details. That includes an email you have already read.