Security Advisory 05/2002

Das e-matters Security Team hat sich Fetchmail erneut unter die Lupe genommen und veröffentlicht Informationen über eine kritische Sicherheitslücke in Fetchmail. Diese erlaubt es beliebigen Code auszuführen oder Fetchmail abstürzen zu lassen.

Advisory 05/2002
Fetchmail remote vulnerability


Release Date: 2002/12/13
Author: Stefan Esser
Application: Fetchmail <= 6.1.3
Severity: A vulnerability within Fetchmail could allow remote compromise.
Risk: Critical
Last Modified:   2002/12/13



In the light of recent discoveries we reaudited Fetchmail and found another bufferoverflow within the default configuration. This heap overflow can be used by remote attackers to crash it or to execute arbitrary code with the privileges of the user running fetchmail. Depending on the configuration this allows a remote root compromise.



When Fetchmail retrieves a mail it performs the so called reply-hack. This basicly means that all headers that contain addresses are searched for local addresses (without @domain part). When such an address is found, Fetchmail appends an @ and the hostname of the mailserver to it. To avoid unnecessary reallocating of the output buffer during this process Fetchmail counts the number of addresses within the headerline first. Then it reserves enough space for the case that all addresses are locals. Unfourtunately this calculation is wrong because it counts a) to many addresses and b) only takes the hostname in count and not the extra @ which is also appended. This means at the moment where you have enough (due to a) local addresses within the headerline every additional address will overflow the buffer by one byte. This results in an arbitrary size heap overflow, which was proved to be exploitable on our Linux boxes. Due to the fact that this heapoverflow occurs in malloc()ed areas we believe that BSD systems can only be crashed with this bug.

Finally it is important to mention that an attacker does not need to spoof dns records, or control the mailserver to exploit this bug. It is usually enough to send a mail to the victim that contains specially crafted header lines.


Proof of Concept

e-matters is not going to release an exploit for this vulnerability to the public.


Vendor Response

08. December 2002  A patch that fixes this vulnerability was mailed to the vendor.
13. December 2002  Vendor released Fetchmail v6.2.0 which fixes this vulnerability.



If you are running Fetchmail we suggest to upgrade to a new or patched version as soon as possible.