1. The cat is out of the bag. Yes, Halvar Flake figured out the flaw Dan
  2. Kaminsky will announce at Black Hat.
  3. 1.
  4. Pretend for the moment that you know only the basic function of DNS —
  5. that it translates WWW.VICTIM.COM into 1.2.3.4. The code that does
  6. this is called a resolver. Each time the resolver contacts the DNS to
  7. translate names to addresses, it creates a packet called a query. The
  8. exchange of packets is called a transaction. Since the number of
  9. packets flying about on the internet requires scientific notation to
  10. express, you can imagine there has to be some way of not mixing them
  11. up.
  12. Bob goes to to a deli, to get a sandwich. Bob walks up to the counter,
  13. takes a pointy ticket from a round red dispenser. The ticket has a
  14. number on it. This will be Bob's unique identifier for his sandwich
  15. acquisition transaction. Note that the number will probably be used
  16. twice — once when he is called to the counter to place his order and
  17. again when he's called back to get his sandwich. If you're wondering,
  18. Bob likes ham on rye with no onions.
  19. If you've got this, you have the concept of transaction IDs, which are
  20. numbers assigned to keep different transactions in order.
  21. Conveniently, the first sixteen bits of a DNS packet is just such a
  22. unique identifier. It's called a query id (QID). And with the
  23. efficiency of the deli, the QID is used for multiple transactions.
  24. 2.
  25. Until very recently, there were two basic classes of DNS
  26. vulnerabilities. One of them involves mucking about with the QID in
  27. DNS packets and the other requires you to know the Deep Magic.
  28. First, QIDs.
  29. Bob's a resolver and Alice is a content DNS server. Bob asks Alice for
  30. the address of WWW.VICTIM.COM. The answer is 1.2.3.4. Mallory would
  31. like the answer to be 6.6.6.0.
  32. It is a (now not) secret shame of mine that for a great deal of my
  33. career, creating and sending packets was, to me, Deep Magic. Then it
  34. became part of my job, and I learned that it is surprisingly trivial.
  35. So put aside the idea that forging IP packets is the hard part of
  36. poisoning DNS. If I'm Mallory and I'm attacking Bob, how can he
  37. distinguish my packets from Alice's? Because I can't see the QID in
  38. his request, and the QID in my response won't match. The QID is the
  39. only thing protecting the DNS from Mallory (me).
  40. QID attacks began in the olden days, when BIND simply incremented the
  41. QID with every query response. If you can remember 1995, here's a
  42. workable DNS attack. Think fast: 9372 + 1. Did you get 9372, or even
  43. miss and get 9373? You win, Alice loses. Mallory sends a constant
  44. stream of DNS responses for WWW.VICTIM.COM. All are quietly discarded
  45. —- until Mallory gets Bob to query for WWW.VICTIM.COM. If Mallory's
  46. response gets to your computer before the legitimate response arrives
  47. from your ISP's name server, you will be redirected where Mallory
  48. tells you you're going.
  49. Obvious fix: you want the QID be randomly generated. Now Alice and
  50. Mallory are in a race. Alice sees Bob's request and knows the QID.
  51. Mallory has to guess it. The first one to land a packet with the
  52. correct QID wins. Randomized QIDs give Alice a big advantage in this
  53. race.
  54. But there's a bunch more problems here:
  55. *
  56. If you convince Bob to ask Alice the same question 1000 times
  57. all at once, and Bob uses a different QID for each packet, you made
  58. the race 1000 times easier for Mallory to win.
  59. *
  60. If Bob uses a crappy random number generator, Mallory can get
  61. Bob to ask for names she controls, like WWW.EVIL.COM, and watch how
  62. the QIDs bounce around; eventually, she'll break the RNG and be able
  63. to predict its outputs.
  64. *
  65. 16 bits just isn't big enough to provide real security at the
  66. traffic rates we deal with in 2008.
  67. Your computer's resolver is probably a stub. Which means it won't
  68. really save the response. You don't want it to. The stub asks a real
  69. DNS server, probably run by your ISP. That server doesn't know
  70. everything. It can't, and shouldn't, because the whole idea of DNS is
  71. to compensate for the organic and shifting nature of internet naming
  72. and addressing. Frequently, that server has to go ask another, and so
  73. on. The cool kids call this "recursion".
  74. Responses carry another value, too, called a time to live (TTL). This
  75. number tells your name server how long to cache the answer. Why?
  76. Because they deal with zillions of queries. Whoever wins the race
  77. between Alice and Mallory, their answer gets cached. All subsequent
  78. responses will be dropped. All future requests for that same data,
  79. within the TTL, come from that answer. This is good for whoever wins
  80. the race. If Alice wins, it means Mallory can't poison the cache for
  81. that name. If Mallory wins, the next 10,000 or so people that ask that
  82. cache where WWW.VICTIM.COM is go to 6.6.6.0.
  83. 3.
  84. Then there's that other set of DNS vulnerabilities. These require you
  85. to pay attention in class. They haven't really been talked about since
  86. 1997. And they're hard to find, because you have to understand how DNS
  87. works. In other words, you have to be completely crazy. Lazlo
  88. Hollyfeld crazy. I'm speaking of course of RRset poisoning.
  89. DNS has a complicated architecture. Not only that, but not all name
  90. servers run the same code. So not all of them implement DNS in exactly
  91. the same way. And not only that, but not all name servers are
  92. configured properly.
  93. I just described a QID attack that poisons the name server's cache.
  94. This attack requires speed, agility and luck, because if the "real"
  95. answer happens to arrive before your spoofed one, you're locked out.
  96. Fortunately for those of you that have a time machine, some versions
  97. of DNS provide you with another way to poison the name server's cache
  98. anyway. To explain it, I will have to explain more about the format of
  99. a DNS packet.
  100. DNS packets are variable in length and consist of a header, some flags
  101. and resource records (RRs). RRs are where the goods ride around. There
  102. are up to three sets of RRs in a DNS packet, along with the original
  103. query. These are:
  104. *
  105. Answer RR's, which contain the answer to whatever question you
  106. asked (such as the A record that says WWW.VICTIM.COM is 1.2.3.4)
  107. *
  108. Authority RR's, which tell resolvers which name servers to refer
  109. to to get the complete answer for a question
  110. *
  111. Additional RR's, sometimes called "glue", which contain any
  112. additional information needed to make the response effective.
  113. A word about the Additional RR's. Think about an NS record, like the
  114. one that COM's name server uses to tell us that, to find out where
  115. WWW.VICTIM.COM is, you have to ask NS1.VICTIM.COM. That's good to
  116. know, but it's not going to help you unless you know where to find
  117. NS1.VICTIM.COM. Names are not addresses. This is a chicken and egg
  118. problem. The answer is, you provide both the NS record pointing
  119. VICTIM.COM to NS1.VICTIM.COM, and the A record pointing NS1.VICTIM.COM
  120. to 1.2.3.1.
  121. Now, let's party like it's 1995.
  122. Download the source code for a DNS implementation and hack it up such
  123. that every time it sends out a response, it also sends out a little
  124. bit of evil — an extra Additional RR with bad information. Then let's
  125. set up an evil server with it, and register it as EVIL.COM. Now get a
  126. bunch of web pages up with IMG tags pointing to names hosted at that
  127. server.
  128. Bob innocently loads up a page with the malicious tags which coerces
  129. his browser resolve that name. Bob asks Alice to resolve that name.
  130. Here comes recursion: eventually the query arrives at our evil server.
  131. Which sends back a response with an unexpected (evil) Additional RR.
  132. If Alice's cache honors the unexpected record, it's 1995 —- buy CSCO!
  133. —- and you just poisoned their cache. Worse, it will replace the
  134. "real" data already in the cache with the fake data. You asked where
  135. WWW.EVIL.COM was (or rather, the image tags did). But Alice also
  136. "found out" where WWW.VICTIM.COM was: 6.6.6.0. Every resolver that
  137. points to that name server will now gladly forward you to the website
  138. of the beast.
  139. 4.
  140. It's not 1995. It's 2008. There are fixes for the attacks I have described.
  141. Fix 1:
  142. The QID race is fixed with random IDs, and by using a strong random
  143. number generator and being careful with the state you keep for
  144. queries. 16 bit query IDs are still too short, which fills us with
  145. dread. There are hacks to get around this. For instance, DJBDNS
  146. randomizes the source port on requests as well, and thus won't honor
  147. responses unless they come from someone who guesses the ~16 bit source
  148. port. This brings us close to 32 bits, which is much harder to guess.
  149. Fix 2:
  150. The RR set poisoning attack is fixed by bailiwick checking, which is a
  151. quirky way of saying that resolvers simply remember that if they're
  152. asking where WWW.VICTIM.COM is, they're not interested in caching a
  153. new address for WWW.GOOGLE.COM in the same transaction.
  154. Remember how these fixes work. They're very important.
  155. And so we arrive at the present day.
  156. 5.
  157. Let's try again to convince Bob that WWW.VICTIM.COM is 6.6.6.0.
  158. This time though, instead of getting Bob to look up WWW.VICTIM.COM and
  159. then beating Alice in the race, or getting Bob to look up WWW.EVIL.COM
  160. and slipping strychnine into his ham sandwich, we're going to be
  161. clever (sneaky).
  162. Get Bob to look up AAAAA.VICTIM.COM. Race Alice. Alice's answer is
  163. NXDOMAIN, because there's no such name as AAAAA.VICTIM.COM. Mallory
  164. has an answer. We'll come back to it. Alice has an advantage in the
  165. race, and so she likely beats Mallory. NXDOMAIN for AAAAA.VICTIM.COM.
  166. Alice's advantage is not insurmountable. Mallory repeats with
  167. AAAAB.VICTIM.COM. Then AAAAC.VICTIM.COM. And so on. Sometime, perhaps
  168. around CXOPQ.VICTIM.COM, Mallory wins! Bob believes CXOPQ.VICTIM.COM
  169. is 6.6.6.0!
  170. Poisoning CXOPQ.VICTIM.COM is not super valuable to Mallory. But
  171. Mallory has another trick up her sleeve. Because her response didn't
  172. just say CXOPQ.VICTIM.COM was 6.6.6.0. It also contained Additional
  173. RRs pointing WWW.VICTIM.COM to 6.6.6.0. Those records are
  174. in-bailiwick: Bob is in fact interested in VICTIM.COM for this query.
  175. Mallory has combined attack #1 with attack #2, defeating fix #1 and
  176. fix #2. Mallory can conduct this attack in less than 10 seconds on a
  177. fast Internet link.