Hello,
In amavisd-milter, a remote unauthenticated SMTP sender can destroy a
message's
first real header by overflowing the synthesized Received header, with the
practical effect that a message's Content-Type (and thus its MIME
structure) is
removed before the message reaches amavis -- so attachments are not decoded
and
not scanned. Confirmed against the Debian binary (1.7.2-1) behind real
Postfix;
same code in upstream master (8ec3d54).
Where: snprintfcat() mlfi.c:99 (clamps to size-1 on overflow)
synthesized Received built in mlfi_amabuf (AMABUFCHUNK=2048,
mlfi.c:434)
at mlfi.c:661-713 with NO amavisd_grow_amabuf() call
fputs(mlfi_amabuf, fp) mlfi.c:716; first real header appended
mlfi.c:833
Type: CWE-693 protection-mechanism failure (AV/content-filter bypass), via
CWE-241/CWE-444 header truncation. Unauthenticated.
CVSS: AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N (~8.1 High) [proposed,
indicative]
Mechanism: the sender controls the helo (EHLO) and envelope-from that go
into the
synthesized Received header. A helo of ~2030 bytes pushes that header past
the
2048-byte mlfi_amabuf; snprintfcat truncates at offset 2047 and the trailing
newline is lost. fputs then writes the truncated header and the first real
message header is appended on the same physical line (mlfi.c:833), so that
header
is absorbed into the Received value and no longer exists as a distinct
header. If
the sender puts Content-Type first, the MIME content type is destroyed and
amavis
treats the message as non-MIME; the multipart attachment is not decoded, so
the
content filter / antivirus never scans it.
Reproduction (container, real Postfix + amavisd-milter 1.7.2-1, loopback):
Postfix accepts a ~2030-char EHLO and passes it to the milter. Capturing
the exact
message amavisd-milter hands to amavis:
- Direct: with EHLO=2030 'a', the first line of the handed-over message
is 2073
bytes: "Received: from <2030 a> (" immediately followed by
"From: [email protected]" (no newline) -- the first header is gone.
- Negative control (Content-Type sent first): short EHLO -> a top-level
Content-Type header is present (MIME intact); long EHLO (~2030) -> no
top-level Content-Type header (absorbed into the truncated Received
line;
MIME destroyed).
End-to-end confirmation with the full real stack (Postfix -> amavisd-milter
1.7.2 -> amavisd-new -> ClamAV with live signatures,
final_virus_destiny=REJECT),
using a real EICAR attachment; same message each time, only the stated
variable
changes:
- short EHLO, Content-Type first -> 554 Reject, INFECTED
(blocked)
- long EHLO (~2030), Content-Type first -> 250 Ok, EICAR delivered
(BYPASS)
- long EHLO, Content-Type NOT first -> 554 Reject, INFECTED
(blocked)
- short EHLO + a >998-char header in DATA -> 554 Reject, INFECTED
(blocked)
So this is a working antivirus bypass that delivers live malware, and the
cause is
specifically the Received-truncation eating the Content-Type (not amavis's
generic
"bad header section" handling -- a long header injected in DATA is still
scanned).
I have the full container PoC.
Fix: grow mlfi_amabuf for the Received build (the amavisd_grow_amabuf logic
already used elsewhere), or guarantee the header ends in "\n" before fputs;
or
TEMPFAIL when the header would be truncated. I have the container PoC.
Thanks in advance,
Ing. Maximiliano Sebastián Quiroga