Imported Debian patch 1:1.05-8
[hcoop/zz_old/debian/djbdns.git] / debian / diff / 0002-djbdns-misformats-some-long-response-packets-patch-a.diff
CommitLineData
b4588d5c
GP
1From 7ab631dd08419f2ce9ea61b941f26db65b622494 Mon Sep 17 00:00:00 2001
2From: Matthew Dempsky <matthew@dempsky.org>
3Date: Mon, 2 Mar 2009 04:46:05 +0000
4Subject: [PATCH] djbdns misformats some long response packets; patch and example attack
5
6The DNS protocol restricts name compression to point into the first
716384 bytes of a packet. Line 18 of response.c from djbdns 1.05
8directly references this, but response_addname() in the same file does
9not enforce this at all. The consequence of this is that names in
10very large DNS packets may be mangled, and clients may misparse the
11packet.
12
13Because this email is somewhat long, I'll state up front you can find
14a patch for this issue at the bottom of this email or at:
15 http://shinobi.dempsky.org/~matthew/djbdns-bug/patch
16
17To help demonstrate this bug, I've constructed an example attack. In
18this scenario, there's a .foo TLD operated using tinydns and axfrdns
19(to support DNS queries over TCP; AXFR support is not required). The
20attacker has registered x.foo and is allowed to upload NS records for
21x.foo and A records for names within the x.foo domain. However,
22because of the aforementioned bug, this attacker can construct a
23record set that causes the .foo servers to respond to queries asking
24about names within the x.foo domain with poisonous records for names
25outside of x.foo.
26
27Using tinydns-data and tinydns-get from stock djbdns 1.05, you can
28reproduce this as follows:
29
30 $ curl -O http://shinobi.dempsky.org/~matthew/djbdns-bug/data
31 $ grep -c -v -e '&x\.foo::' -e '^+[^:]*\.x\.foo:' data
32 0
33 $ tinydns-data
34 $ tinydns-get a www.x.foo | grep ': foo '
35 additional: foo 8388608 NS a.ns.bar
36 additional: foo 8388608 NS b.ns.bar
37
38(With the patch I linked above, no records outside of x.foo will be
39served. It's also worth noting the printpacket_cat() routine
40tinydns-get uses for pretty printing the response packet is much
41stricter about parsing than dnscache's parser is; e.g., it rejects
42packets with extra trailing bytes and records with bad rdlength fields
43on known record types.)
44
45If a victim using dnscache now makes an A query for www.x.foo,
46dnscache will save the poisoned records, and begin contacting the
47attacker's nameservers for all .foo requests. (The response will be
48over 512 bytes long, so dnscache will have to retry the query over
49TCP, which is why axfrdns is necessary too.)
50
51Now, admittedly if you peek at data, you'll see the supplied records
52exceed what most TLDs probably allow: there are redundant NS records,
53there are very long names (but still within the allowed limits of the
54DNS protocol), names use non-printable characters, there are over 100
55records totalling about 24K of storage. However, neither the djbdns
56documentation nor standard practice warn potential .foo administrators
57that their domain will be at risk for poisoning if they were to add
58support for glue record sets. (Standard practice only warns that such
59absurd records can negatively impact x.foo, not .foo as well.)
60
61A perhaps more reasonable scenario is that the .foo servers fetch the
62contents of the x.foo domain over AXFR (removing any records from
63outside of x.foo) and then serve the records themselves. axfr-get,
64the AXFR client from djbdns, would handle the above data set fine.
65
66In looking for a real life example of this latter scenario, I found
67freedns.afraid.org. They allowed me to register burlap.afraid.org and
68set it up as an AXFR slave to my personal server. I have not explored
69what limits they place on imported records, and their website states
70they're using BIND, but assuming they're not too limiting and were to
71instead use tinydns/axfrdns/axfr-get, it would be possible for me to
72trick any dnscache that queries for www.burlap.afraid.org into
73contacting another set of nameservers for all of afraid.org's DNS
74traffic.
75
76There's a similar service everydns.net. They do claim to use tinydns
77(and so I assume axfrdns and axfr-get) and also provide AXFR slave
78support, but they did not allow me to register burlap.everydns.net.
79If they did, it would probably be possible to similarly poison
80everydns.net.
81
82I've tried to search for previous reports of this issue more
83thoroughly than the last bug I mentioned to the list, and I haven't
84found any mention of it yet. I emailed Dan earlier today when I first
85began to suspect this bug was 'exploitable' to clarify his definition
86of a 'security hole' in djbdns. I think the afraid.org example is a
87reasonable use case where this bug would violate afraid.org's security
88constraints if they were to instead use djbdns.
89
90Any thoughts from the list on this bug? (Except from Dean Anderson;
91I'm sure he'll spend the next 3 weeks now arguing I'm a blackhat
92hacker while refusing to look at the patch or sample data file because
93my web server might hack his computer.)
94---
95 response.c | 2 +-
96 1 files changed, 1 insertions(+), 1 deletions(-)
97
98diff --git a/response.c b/response.c
99index ba90c89..33b2fb1 100644
100--- a/response.c
101+++ b/response.c
102@@ -34,7 +34,7 @@ int response_addname(const char *d)
103 uint16_pack_big(buf,49152 + name_ptr[i]);
104 return response_addbytes(buf,2);
105 }
106- if (dlen <= 128)
107+ if ((dlen <= 128) && (response_len < 16384))
108 if (name_num < NAMES) {
109 byte_copy(name[name_num],dlen,d);
110 name_ptr[name_num] = response_len;
111--
1121.6.0.3
113