DNS
CS 161 Spring 2025 - Lecture 21
Computer Science 161
Last Time: TLS
2
Client
Server
ClientHello
ServerHello
Certificate
{ga mod p}K-1server
gb mod p
{M, MAC(IB, M)}CB
{M, MAC(IS, M)}CS
Computer Science 161
Last Time: TLS
3
Computer Science 161
Outline
4
Computer Science 161
LAN/WAN | Local area (e.g. apartment) + wide-area (e.g. internet) networks. A router connects multiple LAN's. |
Layer 2 (e.g. Ethernet) | Layer 2 (link layer) connects local machines in a LAN. MAC Addresses uniquely identify machines in a LAN. |
Layer 3 (e.g. IP) | Layer 3 (internetwork layer) connects many LAN's. IP addresses uniquely identify machines globally. |
Layer 4 (e.g. TCP/UDP) | Layer 4 (transport layer) provides the notion of a connection between individual processes on machines. UDP is a best-effort transport layer protocol (no guarantees on order, but less overhead). TCP is reliable, in-order, and connection-based protocol. |
Layer 4.5 (e.g. TLS) | TLS provides a secure connection (e.g. secure channel of communication) between processes on machines. |
Layer 7 (e.g. HTTP) | HTTP provides a framework to build applications on top of lower-level layers (e.g. HTTP GET/POST/…) |
ARP (Address Resolution) | A protocol based on Layer 2 (e.g. Ethernet) to translate IP addresses into MAC addresses. |
WPA (Wi-Fi Protected Access) | A protocol that enables secure wireless communication in a LAN. With WPA2-PSK, multiple devices within a LAN (e.g. multiple computers, or a computer and a router) can communicate securely. |
DHCP (Dynamic Host Configuration Protocol) | A protocol based on Layer 2/3 (e.g. Ethernet and IP) that enables communication over a LAN and the internet. It allows clients to acquire an IP address, the IP address of the DNS server, and IP address of the router. |
BGP (Border Gateway) | A protocol based on Layer 3 (e.g. IP addresses) that connects lots of local networks (border gateway protocol). |
DNS (Domain Name System) & DNSSEC | A protocol based on Layer 4 (e.g. TCP) that allows computers to resolve https://google.com/ into 127.217.4.174 (IP addresses). It uses a hierarchical system of name servers that exist across the internet. DNS queries are made over UDP. |
Computer Science 161
DNS
6
Computer Science 161
Domain Names
7
Computer Science 161
DNS: Definition
8
74.125.25.99
www.google.com
DNS
Computer Science 161
DNS Name Servers
9
Computer Science 161
DNS Name Server Hierarchy
10
. (root)
.edu
.org
.com
google.com
edstem.org
cs161.org
mit.edu
berkeley.edu
berkeley.edu is the oldest .edu domain!
Computer Science 161
DNS Name Server Hierarchy
11
Each box is a name server. The label represents which queries the name server is responsible for answering.
For example, this name server is responsible for .edu queries like eecs.berkeley.edu, but not a query like mail.google.com.
. (root)
.edu
.org
.com
google.com
edstem.org
cs161.org
mit.edu
berkeley.edu
Computer Science 161
DNS Hierarchy
Each node in the tree represents a zone of domains.
An organization managing a zone can delegate part of its zone to somebody else.
Each zone has an authoritative name server that knows about the domains in that zone.
12
The berkeley.edu zone
Owned by: UC Berkeley
Name server: adns1.berkeley.edu
Manages:
www.berkeley.edu
calcentral.berkeley.edu
systemstatus.berkeley.edu
...
The ischool.berkeley.edu zone
Owned by: School of Information
Name server: is-dns.berkeley.edu
Manages:
pink.ischool.berkeley.edu
blue.ischool.berkeley.edu
...
The eecs.berkeley.edu zone
Owned by: EECS Department
Name server: cs-dns.berkeley.edu
Manages:
repo.eecs.berkeley.edu
rise.eecs.berkeley.edu
...
Computer Science 161
Steps of a DNS Lookup
13
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
Let's walk through a DNS query for the IP address of eecs.berkeley.edu.
Computer Science 161
Steps of a DNS Lookup
14
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
DNS queries always start with a request to the root name server, which is responsible for all requests.
1
“What is the IP address of eecs.berkeley.edu?”
Computer Science 161
Steps of a DNS Lookup
15
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
The root name server responds by directing you to the correct child name server (in this case, the .edu name server).
1
2
“I don’t know, but I have delegated authority to the .edu name server.”
Computer Science 161
Steps of a DNS Lookup
16
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
1
2
3
“What is the IP address of eecs.berkeley.edu?”
Computer Science 161
Steps of a DNS Lookup
17
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
3
4
“I don’t know. But I have delegated authority to the berkeley.edu name server.”
1
2
Computer Science 161
Steps of a DNS Lookup
18
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
“What is the IP address of eecs.berkeley.edu?”
3
4
1
2
5
Computer Science 161
Steps of a DNS Lookup
19
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
You
5
6
“The IP address of eecs.berkeley.edu is 23.185.0.1.”
3
4
1
2
Computer Science 161
Stub Resolvers and Recursive Resolvers
20
Computer Science 161
Recall: DHCP Initial Network Configuration
21
(← a recursive resolver!)
Computer Science 161
Steps of a DNS Lookup
22
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
Stub Resolver
The stub resolver sends the query to the recursive resolver.
1
Recursive Resolver
Computer Science 161
Steps of a DNS Lookup
23
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
Stub Resolver
The recursive resolver contacts all the name servers to answer the query, as we saw earlier.
Recursive Resolver
1
6
7
4
5
3
2
Computer Science 161
Steps of a DNS Lookup
24
. (root)
.edu
.org
cs161.org
mit.edu
berkeley.edu
Stub Resolver
The recursive resolver returns the final answer to the stub resolver.
Recursive Resolver
1
8
6
7
4
5
3
2
Computer Science 161
DNS Message Format
25
Computer Science 161
DNS Uses UDP
26
Computer Science 161
DNS Packet Format: UDP Header
27
Source Port | Destination Port |
Checksum | Length |
ID number | Flags |
Question count | Answer count |
Authority count | Additional count |
Question Records | |
Answer Records | |
Authority Records | |
Additional Records |
UDP Payload
UDP Header
Computer Science 161
DNS Packet Format: DNS Header
28
Source Port | Destination Port |
Checksum | Length |
ID number | Flags |
Question count | Answer count |
Authority count | Additional count |
Question Records | |
Answer Records | |
Authority Records | |
Additional Records |
DNS Payload
UDP Header
DNS Header
Computer Science 161
DNS Packet Format: DNS Payload
29
Source Port | Destination Port |
Checksum | Length |
ID number | Flags |
Question count | Answer count |
Authority count | Additional count |
Question Records | |
Answer Records | |
Authority Records | |
Additional Records |
DNS Payload
UDP Header
DNS Header
Computer Science 161
DNS Record Format
30
Computer Science 161
DNS Record Types
31
Computer Science 161
DNS Record Sections
32
Computer Science 161
DNS Record Sections
33
Computer Science 161
DNS Record Caching
34
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
35
You can try this at home! Use the dig utility in your terminal, and remember to set the +norecurse flag so you can traverse the name server hierarchy yourself.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
36
We are performing a DNS lookup for the IP address of eecs.berkeley.edu.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
37
DNS queries always start with a request to the root name server. The IP address of the root name server is usually hard-coded into recursive resolvers.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
38
Here’s the DNS response from the root name server.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
39
Here’s the DNS header.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
40
Here’s the 16-bit ID number in the DNS header.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
41
Here are the flags in the DNS header.
Here are the record counts in the DNS header.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
42
Here’s the DNS payload. It’s a collection of resource records (one per line), sorted into four sections.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
43
Here’s the question section. The name is eecs.berkeley.edu, the type is A, and the value is blank. It shows that we are looking for the IP address of eecs.berkeley.edu.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
44
The answer section is blank, because the root name server did not return the answer we’re looking for.
We can confirm this by checking the header, which says there are 0 records in the answer section.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
45
The authority and additional sections tell the resolver where to look next.
Note that there are multiple .edu name servers for redundancy.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
46
For redundancy, there are usually several name servers for each zone. Any of them will usually work. Let’s pick the first one.
This NS record says that a.edu-servers.net is a .edu name server.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @198.41.0.4
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26114
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
edu. 172800 IN NS a.edu-servers.net.
edu. 172800 IN NS b.edu-servers.net.
edu. 172800 IN NS c.edu-servers.net.
...
;; ADDITIONAL SECTION:
a.edu-servers.net. 172800 IN A 192.5.6.30
b.edu-servers.net. 172800 IN A 192.33.14.30
c.edu-servers.net. 172800 IN A 192.26.92.30
...
47
This A record helpfully tells us the IP address of the next name server we mean to contact.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @192.5.6.30
48
Next, we query the .edu name server. We know the IP address of the .edu name server because the root name server gave the information to us.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @192.5.6.30
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36257
;; flags: qr; QUERY: 1, ANSWER: 0, AUTHORITY: 3, ADDITIONAL: 5
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; AUTHORITY SECTION:
berkeley.edu. 172800 IN NS adns1.berkeley.edu.
berkeley.edu. 172800 IN NS adns2.berkeley.edu.
berkeley.edu. 172800 IN NS adns3.berkeley.edu.
;; ADDITIONAL SECTION:
adns1.berkeley.edu. 172800 IN A 128.32.136.3
adns2.berkeley.edu. 172800 IN A 128.32.136.14
adns3.berkeley.edu. 172800 IN A 192.107.102.142
...
49
The answer section is blank again. The authority and additional section tell us to query a berkeley.edu name server, and provide us with the IP address of the next name server.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @128.32.136.3
50
Next, we query the berkeley.edu name server for the IP address of eecs.berkeley.edu. We know the IP address of the berkeley.edu name server because the root name server gave the information to us.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @128.32.136.3
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52788
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; ANSWER SECTION:
eecs.berkeley.edu. 86400 IN A 23.185.0.1
51
The answer section has one A type record. It tells us that the IP address of eecs.berkeley.edu is 23.185.0.1.
Computer Science 161
DNS Lookup Walkthrough
$ dig +norecurse eecs.berkeley.edu @128.32.136.3
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52788
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; ANSWER SECTION:
eecs.berkeley.edu. 86400 IN A 23.185.0.1
52
Here’s the time-to-live (TTL) field in the record. It tells us that we can cache this answer for 86,400 seconds (24 hours).
Computer Science 161
DNS Lookup Walkthrough: su24.cs161.org
53
Takeaway: You can query common recursive resolvers instead of the root directly!�8.8.8.8 a public DNS recursive resolver operated by Google.
Computer Science 161
DNS Security
54
Computer Science 161
Cache Poisoning Attacks
55
Computer Science 161
Security Risk: Malicious Name Servers
$ dig +norecurse eecs.berkeley.edu @128.32.136.3
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52788
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;eecs.berkeley.edu. IN A
;; ANSWER SECTION:
eecs.berkeley.edu. 86400 IN A 23.185.0.1
;; ADDITIONAL SECTION:
www.google.com. 172800 IN A 6.6.6.6
56
We made a query to a malicious berkeley.edu name server...
...and it returned a malicious record for www.google.com!
Computer Science 161
Defense: Bailiwick Checking
57
Computer Science 161
Security Risk: Man-in-the-middle (MITM) Attackers
58
;; ANSWER SECTION:
eecs.berkeley.edu. 86400 IN A 23.185.0.1 6.6.6.6
Computer Science 161
Security Risk: On-Path Attackers
59
Recursive Resolver
berkeley.edu name server
Attacker
From: Port 1234
To: Port 80
ID | Flags |
Counts | |
Records |
(Unencrypted) ID
Layer 4: UDP
Computer Science 161
Security Risk: Off-Path Attackers
60
Source Port | Destination Port |
Checksum | Length |
ID number | Flags |
Question count | Answer count |
Authority count | Additional count |
Question Records | |
Answer Records | |
Authority Records | |
Additional Records |
DNS Payload
UDP Header
DNS Header
Computer Science 161
Security Risk: Off-Path Attackers
61
Computer Science 161
Kaminsky Attack
62
Computer Science 161
Kaminsky Attack
63
Computer Science 161
Kaminsky Attack: Example
64
Computer Science 161
Kaminsky Attack: Example
65
. (root)
.com
google.com
Stub Resolver
Let's walk through the DNS query for the IP address of fake1.google.com.
Recursive Resolver
Recursive Resolver Cache | |
| |
| |
| |
We’ll use this color to represent normal packets across Alice’s DNS query.
We’ll use this color to represent Mallory’s packets across Alice’s DNS query.
Computer Science 161
Kaminsky Attack: Example
66
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
| |
| |
| |
1
“Can you figure out what the ip address of fake1.google.com is?”
. (root)
.com
google.com
Computer Science 161
Kaminsky Attack: Example
67
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
| |
| |
| |
1
“What is the IP address of fake1.google.com? This request has ID 161.”
. (root)
.com
google.com
2
Computer Science 161
Kaminsky Attack: Example
68
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
| |
| |
“I don’t know, but I have delegated authority to the .com name server. This response has ID 161.
Authority: .com NS a.gtld-servers.net.
Additional: a.gtld-servers.net. A 192.5.6.30”
2
. (root)
.com
google.com
3
The .com name server a.gtld-servers.net. is cached with IP 192.5.6.30.
1
Computer Science 161
Kaminsky Attack: Example
69
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
| |
| |
“What is the IP address of fake1.google.com? This request has ID 972.”
4
. (root)
.com
google.com
3
1
2
Computer Science 161
Kaminsky Attack: Example
70
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
| |
5
“I don’t know. But I have delegated authority to the google.com name server. This response has ID 972.
Authority: google.com NS ns1.google.com
Additional: ns1.google.com. A 216.329.32.10”
4
. (root)
.com
google.com
The google.com name server ns1.google.com. is cached with IP 216.239.32.10.
1
2
3
Computer Science 161
Kaminsky Attack: Example
71
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
| |
5
. (root)
.com
google.com
“What is the IP address of fake1.google.com? This request has ID 774.”
6
1
2
3
4
Computer Science 161
Kaminsky Attack: Example
72
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
| |
. (root)
.com
google.com
6
7
7
1
2
3
Let’s see what happens when Mallory correctly guesses the ID number and wins the race condition.
4
5
“fake1.google.com doesn’t exist! This response has ID 774.”
“I don’t know. But I have delegated authority to the fake1.google.com. NS. This response has ID 774.
Authority: fake1.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
Computer Science 161
Kaminsky Attack: Example
73
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
www.google.com. | 6.6.6.6 |
. (root)
.com
google.com
7
Mallory correctly guessed the ID number and won the race condition, so www.google.com. is cached with Mallory’s malicious IP 6.6.6.6.
1
2
3
4
5
6
“I don’t know. But I have delegated authority to the fake1.google.com. NS. This response has ID 774.
Authority: fake1.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
Computer Science 161
Kaminsky Attack: Example
74
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
www.google.com. | 6.6.6.6 |
. (root)
.com
google.com
7
1
2
3
We don’t really care what next steps are involved in this request, as we have already poisoned the cache.
4
5
6
Computer Science 161
Kaminsky Attack: Example
75
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
| |
. (root)
.com
google.com
7
7
1
2
What if Mallory didn’t guess the ID number correctly?
3
4
5
6
“I don’t know. But I have delegated authority to the fake1.google.com. NS. This response has ID 129.
Authority: fake1.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“fake1.google.com doesn’t exist! This response has ID 774.”
Computer Science 161
Kaminsky Attack: Example
76
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
| |
. (root)
.com
google.com
7
7
The recursive resolver discards the response packet from Mallory, because the ID does not match the ID from the request.
1
2
What if Mallory didn’t guess the ID number correctly?
3
4
5
6
“I don’t know. But I have delegated authority to the fake1.google.com. NS. This response has ID 129.
Authority: fake1.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
Computer Science 161
Kaminsky Attack: Example
77
Stub Resolver
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
fake1.google.com | Doesn’t exist! |
. (root)
.com
google.com
7
“fake1.google.com doesn’t exist! This response has ID 774.”
What can Mallory do to still poison the cache?
1
2
What if Mallory didn’t guess the ID number correctly?
3
4
5
6
Computer Science 161
Kaminsky Attack: Example
78
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
fake1.google.com | Doesn’t exist! |
… | Doesn’t exist! |
fake26.google.com | Doesn’t exist! |
google.com
“fake7.google.com doesn’t exist! This response has ID 432.”
“fake3.google.com doesn’t exist! This response has ID 324.”
Mallory can use the DNS requests from her other image tags to try to guess the ID number.
“fake4.google.com doesn’t exist! This response has ID 691.”
“I don’t know. But I have delegated authority to the fake7.google.com. NS. This response has ID 774.
Authority: fake7.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“I don’t know. But I have delegated authority to the fake3.google.com. NS. This response has ID 425.
Authority: fake2.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“I don’t know. But I have delegated authority to the fake4.google.com. NS. This response has ID 712.
Authority: fake4.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“I don’t know. But I have delegated authority to the fake5.google.com. NS. This response has ID 821.
Authority: fake5.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“I don’t know. But I have delegated authority to the fake6.google.com. NS. This response has ID 234.
Authority: fake6.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
“fake6.google.com doesn’t exist! This response has ID 629.”
“fake6.google.com doesn’t exist! This response has ID 427.”
“fake27.google.com doesn’t exist! This response has ID 161.”
“I don’t know. But I have delegated authority to the fake27.google.com. NS. This response has ID 161.
Authority: fake27.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
Computer Science 161
Kaminsky Attack: Example
79
Recursive Resolver
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
fake1.google.com | Doesn’t exist! |
… | Doesn’t exist! |
fake26.google.com | Doesn’t exist! |
www.google.com. | 6.6.6.6 |
If Mallory wins the race condition and guesses the correct ID during any one of these DNS queries, Mallory’s IP will be cached.
“I don’t know. But I have delegated authority to the fake27.google.com. NS. This response has ID 161.
Authority: fake27.google.com. NS www.google.com
Additional: www.google.com. A 6.6.6.6”
Computer Science 161
Kaminsky Attack: Example
80
Stub Resolver
Recursive Resolver
. (root)
.com
google.com
Now that the cache is poisoned, what happens when Alice wants to know the ip address of www.google.com?
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
www.google.com. | 6.6.6.6 |
Computer Science 161
Kaminsky Attack: Example
81
Stub Resolver
Recursive Resolver
1
. (root)
.com
google.com
“Can you figure out what the ip address of www.google.com is?”
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
www.google.com. | 6.6.6.6 |
Computer Science 161
Kaminsky Attack: Example
82
Stub Resolver
Recursive Resolver
. (root)
.com
google.com
2
“My cache says the ip address of www.google.com is 6.6.6.6.”
Recursive Resolver Cache | |
a.gtld-servers.net. | 192.5.6.30 |
ns1.google.com. | 216.239.32.10 |
www.google.com. | 6.6.6.6 |
Mallory will receive all traffic Alice meant to send to www.google.com!
1
Computer Science 161
Pre-Kaminsky Attack: Response Possibilities
83
| Attacker correctly guesses the ID number | Attacker does not correctly guess the ID number |
Attacker beats the race condition against the legitimate NS | The recursive resolver caches a mapping from a legitimate domain name to the attacker’s IP address. | Failure. The recursive resolver caches the actual responses and we have to wait until the record expires to try again. |
Attacker does not beat the race condition against the legitimate NS | Failure. The recursive resolver caches the actual responses and we have to wait until the record expires to try again. | Failure. The recursive resolver caches the actual responses and we have to wait until the record expires to try again. |
Computer Science 161
Kaminsky Attack: Response Possibilities
84
| Attacker correctly guesses the ID number | Attacker does not correctly guess the ID number |
Attacker beats the race condition against the legitimate NS | The recursive resolver caches a mapping from legitimate domain names to the attacker’s desired IP addresses. | The recursive resolver ignores the response because the ID does not match the request sent earlier. The recursive resolver caches something saying “This domain does not exist”. Try again with another fake domain! |
Attacker does not beat the race condition against the legitimate NS | The recursive resolver caches something saying “This domain does not exist”. Try again with another fake domain! | The recursive resolver caches something saying “This domain does not exist”. Try again with another fake domain! |
Computer Science 161
Defense: Source Port Randomization
85
85
Source Port | Destination Port |
Checksum | Length |
ID number | Flags |
Question count | Answer count |
Authority count | Additional count |
Question Records | |
Answer Records | |
Authority Records | |
Additional Records |
DNS Payload
UDP Header
DNS Header
Computer Science 161
Defense: Glue Validation
86
Computer Science 161
Profiting from DNS Attacks
87
Computer Science 161
DNS: Summary
88
. (root)
.edu
.org
.com
google.com
piazza.com
cs161.org
mit.edu
berkeley.edu
Computer Science 161
DNS: Summary
89
Computer Science 161
DNS Security: Summary
90
Computer Science 161