6.8 Medium
CVSS2
Access Vector
NETWORK
Access Complexity
MEDIUM
Authentication
NONE
Confidentiality Impact
PARTIAL
Integrity Impact
PARTIAL
Availability Impact
PARTIAL
AV:N/AC:M/Au:N/C:P/I:P/A:P
0.269 Low
EPSS
Percentile
96.7%
**Title:**Dnsmasq Heap Overflow and Null-pointer Dereference on TFTP Server
**Advisory ID:**CORE-2009-0820
**Advisory URL:**http://www.coresecurity.com/core-labs/advisories/dnsmasq-vulnerabilities
**Date published:**2009-08-31
**Date of last update:**2009-08-31
**Vendors contacted:**Simon Kelley
**Release mode:**Coordinated release
**Class:**Buffer overflow
**Remotely Exploitable:**Yes
**Locally Exploitable:**No
Bugtraq ID:36120, 36121
CVE Name:CVE-2009-2957, CVE-2009-2958
Dnsmasq is a lightweight DNS forwarder and DHCP server. A vulnerability has been found that may allow an attacker to execute arbitrary code on servers or home routers running dnsmasq [1] with the TFTP service [2] enabled (--enable-tfp
). This service is not enabled by default on most distributions; in particular it is not enabled by default on OpenWRT or DD-WRT. Chances of successful exploitation increase when a long directory prefix is used for TFTP. Code will be executed with the privileges of the user running dnsmasq, which is normally a non-privileged one.
Additionally there is a potential DoS attack to the TFTP service by exploiting a null-pointer dereference vulnerability.
If the TFTP service is enabled and patching is not available immediately, a valid workaround is to filter TFTP for untrusted hosts in the network (such as the Internet). This is the default configuration when enabling TFTP on most home routers.
Patches are already available from the software author. Most distributions should release updates for binary packages soon.
The heap-overflow vulnerability (CVE-2009-2957) was discovered during Bugweek 2009 by Pablo Jorge and Alberto Soliño from the team “Los Herederos de Don Pablo” of Core Security Technologies.
The null-pointer dereference (CVE-2009-2958) was reported to the author of dnsmasq independently by an uncredited code auditor. It was merged with this advisory for user’s convenience.
First let’s focus on the overflow vulnerability. The tftp_request
calls strncat
on daemon->namebuff
, which has a predefined size of MAXDNAME
bytes (defaulting to 1025).
else if (filename[0] == '/') daemon->namebuff[0] = 0; strncat(daemon->namebuff, filename, MAXDNAME);
This may cause a heap overflow because daemon->namebuff
may already contain data, namely the configured daemon->tftp_prefix
passed to the daemon via a configuration file.
if (daemon->tftp_prefix) { if (daemon->tftp_prefix[0] == '/') daemon->namebuff[0] = 0; strncat(daemon->namebuff, daemon->tftp_prefix, MAXDNAME)
The default prefix is /var/tftpd
, but if a longer prefix is used, arbitrary code execution may be possible.
Sending the string resulting from the execution of the following python snippet to a vulnerable server, with a long enough directory prefix configured, should crash the daemon.
import sys sys.stdout.write( '\x00\x01' + "A"*1535 + '\x00' + "netascii" + '\x00' )
Now onto the null-pointer dereference. The user can crash the service by handcrafting a packet, because of a problem on the guard of the first if inside this code loop:
while ((opt = next(&p, end))) { if (strcasecmp(opt, "blksize") == 0 && (opt = next(&p, end)) && !
(daemon->options & OPT_TFTP_NOBLOCK)) { transfer->blocksize = atoi(opt); if (transfer->blocksize < 1)
transfer->blocksize = 1; if (transfer->blocksize > (unsigned)daemon->packet_buff_sz - 4) transfer->blocksize =
(unsigned)daemon->packet_buff_sz - 4; transfer->opt_blocksize = 1; transfer->block = 0; } if
(strcasecmp(opt, "tsize") == 0 && next(&p, end) && !transfer->netascii) { transfer->opt_transize = 1; transfer->block = 0; } }
The problem exists because the guard of the first if includes the result of opt = next(&p, end)
as part of the check. If this returns NULL
, the guard will fail and in the next if strcasecmp(opt, "tsize")
will derrefence the null-pointer.
[1] <http://www.thekelleys.org.uk/dnsmasq/doc.html>
[2] <http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol>
CoreLabs, the research center of Core Security Technologies, is charged with anticipating the future needs and requirements for information security technologies. We conduct our research in several important areas of computer security including system vulnerabilities, cyber attack planning and simulation, source code auditing, and cryptography. Our results include problem formalization, identification of vulnerabilities, novel solutions and prototypes for new technologies. CoreLabs regularly publishes security advisories, technical papers, project information and shared software tools for public use at: https://www.coresecurity.com/core-labs.
Core Security Technologies develops strategic solutions that help security-conscious organizations worldwide develop and maintain a proactive process for securing their networks. The company’s flagship product, CORE IMPACT, is the most comprehensive product for performing enterprise security assurance testing. CORE IMPACT evaluates network, endpoint and end-user vulnerabilities and identifies what resources are exposed. It enables organizations to determine if current security investments are detecting and preventing attacks. Core Security Technologies augments its leading technology solution with world-class security consulting services, including penetration testing and software security auditing. Based in Boston, MA and Buenos Aires, Argentina, Core Security Technologies can be reached on the Web at <https://www.coresecurity.com>.
The contents of this advisory are copyright © 2009 Core Security Technologies and © 2009 CoreLabs, and may be distributed freely provided that no fee is charged for this distribution and proper credit is given.
This advisory has been signed with the GPG key of Core Security Technologies advisories team.