Atack DNS Poisoning
Atack DNS Poisoning
Atack DNS Poisoning
Attack
Goals:
The Domain Name System
BIND
Configuring BIND
Running BIND on your Ubuntu laptop
Light-Weight Nameservers (and how to install them)
DNS Cache Poisoning Attack
Writing code for cache poisoning attacks
Dan Kaminskys More Virulent DNS Cache Poisoning Attack
1
CONTENTS
Section Title
Page
17.1
17.2
DNS
17.3
11
17.4
26
17.5
40
17.6
43
17.7
DNS Cache
47
BIND
50
55
58
64
68
17.9
70
17.10
73
17.11
75
17.12
82
17.13
86
17.14
Homework Problems
93
Lecture 17
17.1:
INTERNET, HARRY POTTER, AND
THE MAGIC OF DNS
If you have read Harry Potter, you are certainly familiar with the use
of owl mail by the wizards and the witches. As you would recall, in
order to send a message to someone, all that a wizard or a witch had
to do was to tie the message to an owls foot and ask the owl to deliver
it to its intended recipient. That is how Harry Potter frequently got
in touch with his godfather Sirius. Harry often had no idea as to the
physical whereabouts of Sirius. Nonetheless, Harrys magical owl,
Hedwig, knew how to get the letter to Sirius.
As you dig deeper into the workings of the internet, you will begin to
appreciate the fact that what mankind has achieved with internetbased communications comes fairly close to the owl-based magical
transport of messages in Harry Potter.
As you know from Lecture 16, all internet communication protocols
require numerical addresses. In terms of bit patterns, these addresses
translate into 32-bit wide bit-fields for IPv4 and 128-bit wide bitfields for IPv6. But numerical addresses are much too cumbersome
for humans to keep track of. If you are an engineer, you may not find
IPv4 numerical addresses to be daunting, but consider the painfulto-even-look-at IPv6 numerical addresses. So when you ask your
computer to make a connection with some remote machine in some
distant corner of the world, you are likely to specify a symbolic hostname for that machine. But the TCP/IP software on your computer
3
Lecture 17
Lecture 17
17.2: DNS
The acronym DNS stands simultaneously for Domain Name Service, Domain Name Server, Domain Name System, and Domain
Name Space.
Lecture 17
Internet simply would not work without DNS. In fact, one notso-uncommon reason why your internet connection may not be
working is because your ISPs DNS server is down for some reason.
Your Linux laptop may interact with the rest of the internet more
efficiently if you run your own DNS nameserver. [Most of us are
creatures of habit. I find myself visiting the same web sites on a regular basis. My email
IMAP client talks to the same IMAP server all the time. So if the DNS nameserver
running on my laptop has already stored the IP addresses for such regularly visited
sites, it may not need to refer to the ISPs DNS depending on the TTL (time-to-live)
values associated with the cached information, as you will see.]
Lecture 17
Most DNS servers today are run by larger ISPs and commercial
companies. However, there is a place for private DNS servers since
they can be useful for giving symbolic hostnames to machines in a
private home network. [Talking about ISPs, it has become fairly common for even the most
respectable ISPs to engage in the following practice that violates the internet standards: Say your browser
makes a request to the ISP DNS server for the IP address associated with a hostname that does not exist
(because you made a spelling error in the URL), the DNS server is supposed to send back the NXDOMAIN error
message to your browser. (NXDOMAIN stands for non-existent domain.) Instead, the ISPs DNS server sends
back a browser redirect to an advertisement-loaded website that the ISP wants you to look at. Or, the ISPs
DNS server may send you suggestions for domains that are similar to what your browser is looking for. This
practice is commonly referred to as
Lecture 17
However, if your private network contains more than a few machines, it might be better to install a DNS server in the network.
Lecture 17
Lecture 17
10
Lecture 17
Ill illustrate the extent of name lookup activity that occurs for
a very simple application, rlogin, for remote login. Before ssh
came along, most folks used rlogin to log into remote machines
in a network. For rlogin to work, the remote machine must run
the rlogind server daemon. Then you can log into that machine
by executing a command like
rlogin
remote_machine_hostname
-l
your_name
11
Lecture 17
Figure 1 shows all of the messages that must be exchanged between the various servers before I can rlogin into a server in
Tokyo.
Lecture 17
obviously the root servers have to become aware of that IP address. The gTLD servers have names
like a.gtld-servers.net, b.gtld-servers.net, c.gtld-servers.net, etc. To see all the gTLD
DNS servers for the .com domain, you can ask the dig utility to query one of the root servers say the
root server b.root-servers.net by executing the dig @b.root-servers.net com command.
Later you will see what this syntax means. In the answer returned by dig, look at all the names under
the Additional Section. If for some reason querying the root server b.root-servers.net does
not return the answer, you can try any of the other root servers whose names are returned by running
dig without any arguments. To see all the ccTLD for say the .uk domain, you can try the same
command except for replacing com by uk.
Below the root servers mentioned above, the DNS hierarchy contains the the generic top-level domain (gTLD) servers and the
country-code top-level domain (ccTLD) servers, as explained in
the small-font note above. All that the root servers do is to point
to the gTLD and the ccTLD servers. As mentioned above, the
gTLD servers know about the generic top-level domains such as
.com, .edu, .gov, .mil, .net, .org, etc., and the ccTLD
servers know about the country-specific domains such as .uk,
.jp, etc. If a resolver running on a client machine sent a query
for a symbolic hostname such as moonshine.ecn.purdue.edu
to one of the gTLD servers, the server would send back the IP
address of the nameserver for the purdue.edu domain. Below
domains such as purdue.edu there are nameservers such as the
ones you would find for the ecn.purdue.edu subdomain, and
so on.
13
Lecture 17
As you can see in the figure, for the remote login to succeed, the
client and the server and the various nameservers must exchange
a fairly large number of messages, many of them involving name
lookup or reverse name lookup. Note that the number 7 in the
figure is associated with the TCP connection that the client must
initiate with the server. This will involve, at the least, a 3-way
handshake, as you saw in Lecture 16. So the actual number
of messages that must go back and forth between the various
machines could be much more than the 15 shown in the figure.
[One of the most amazing things about the internet is that people generally are not aware of how many
messages may have to fly back and forth between opposite corners of the earth before a simple connection
When a user on the client side first enters the rlogin command, the client machine probably knows nothing about the
u-tokyo.jp domain. So the client resolver first contacts one
of the root nameservers for where to go for resolving the names
that end in .jp, in other words the hostnames that are in the
.jp domain (Message 1). The root nameserver responds back
with the IP address of the ccTLD DNS server in charge of the
top-level .jp domain. This is message 2 in Figure 1.
14
Lecture 17
gTLD
or
ccTLD
DNS Server
11
10
NS
PTR?
PTR?
8
DNS Root
Server
NS
12
13
TCP Connection
3Way Handshake
PTR? PTR
DNS Root
Server
14
A?
15
A?
5
6
gTLD
or
ccTLD
DNS Server
NS
A?
A?
3
4
NS
A?
A
PTR?
PTR
NS
Figure 1: This figure illustrates the fact that even for the
case of a client wanting to make just a simple login connection with a remote host (a connection that involves no
exchange of security related information), a large number
of messages must be exchanged between the client, the remote server, and various DNS servers.(This figure is from Lecture 17 of
Lecture Notes on Computer and Network Security by Avi Kak)
15
Lecture 17
Now the client TCP has all the information it needs to send a SYN
packet to the server TCP for initiating the desired connection.
This transmission is part of what is labeled as message 7 in Figure
1. The server may now go ahead and engage in a 3-way handshake
to complete a TCP circuit.
Lecture 17
the client. A pointer query means that that server wants to carry
out a reverse DNS lookup, meaning that the server wants
to find out the symbolic hostname that goes with an IP address.
This is message 8 in Figure 1. [Reverse lookup entries are contained in
what is known as the in-addr.arpa domain. As you will see later, for reverse lookup, the
IP address is reversed and then prepended to the string in-addr.arpa, and the symbolic
Now, in message 12, the rlogind server sends the same pointer
request to the domain-specific nameserver whose IP address was
received in message 7. From the answer in message 13, the server
obtains the fully qualified domain name (FQDN) of the client.
17
Lecture 17
Finally, to account for the possibility that the nameserver for the
in-addr.arpa domain (that is used for reverse lookups) may
not be the same as the regular nameserver on the client side, the
rlogind server sends an A query for the IP address associated
with the FQDN it retrieved in message 13. This query is message
14.
I will now illustrate the DNS name lookups with the tcpdump
packet sniffer. In one of the terminal windows on your Ubuntu
laptop, invoke one the following commands as root that will help
you see the first ten packets exchanged:
tcpdump -v -n
tcpdump -v -n host 192.168.1.102
tcpdump -vvv -nn -i eth0 -s 1500 host 192.168.1.102 -S -X -c 10
tcpdump -vvv -nn -i eth0 -s 1500 -S -X -c 10 src 192.168.1.102
or dst 192.168.1.102 and port 53
...
Lecture 17
tcpdump command will print out the details for the first 10 packets at the highest verbosity level while suppressing the need for
tcpdump to carry out reverse name lookups to figure out the symbolic hostnames for numerical addresses. Again as mentioned in
Lecture 16, as to which form of the tcpdump will yield the best
results depends on how busy the LAN is. If you are in your home
network, the first two shown above, or slight variations thereof,
should work. If your machine is on a busy LAN, youd need to
place tighter restrictions on the packets that you want sniffed by
tcpdump, as in the last two versions above. Make sure that you
replace the string 192.168.1.102 by the IP address assigned to
your machine. Port 53 mentioned in the last tcpdump command
is the port on which a DNS server listens to the incoming name
lookup requests and through which it provides its answers. That
is, port 53 is the standard port assigned to DNS servers, as you
can tell from the entries in the file /etc/services.
engr.u-tokyo.ac.uk
Lecture 17
Here are the first six packets in the output of the tcpdump command for the above client request that shows how my laptop
figures out that the hostname given to the ssh command does
NOT exist: [Note that these are UDP packets unlike the TCP packets you saw in Lecture 16. A
UDP packet consists of an 8 byte header following by the data. The header consists of the following four fields:
(i) 2 bytes for the source port; (ii) 2 bytes for the destination port; (iii) 2 bytes for the length of the packet,
which includes the length of the header; and (iv) 2 bytes for the checksum. The source port and the checksum
are optional; they are simply replaced by zeros when not used. As to why the source port and the checksum
are optional, a server may use the faster UDP protocol for different kinds of broadcasts related to the services
provided. Since there is no expectation of a return answer to such broadcasts. there would be no point in
tcpdump from each UDP packet along with its IP enclosure. If you run tcpdump in the verbose mode, you will
also see a hex/ascii block for each packet, as was the case with the packet displays in Lecture 16. In our case
here, the hex block will show the IP header, followed by the UDP header, followed by the UDP data.
Lecture 17
10:23:23.283030 IP (tos 0x0, ttl 64, id 39865, offset 0, flags [none], proto UDP (17), length 75)
192.168.1.105.46921 > 195.66.240.130.53: [udp sum ok] 27013 [1au] A? engr.u-tokyo.ac.uk. ar: . OPT UDPsize=4096 OK (47)
Lecture 17
nslookup
Lecture 17
Lecture 17
.... and so on, if you were to examine the rest of the packets
until the nameserver on my laptop figures out there is no IP
address to be had for the engr.u-tokyo.ac.uk hostname.
Try running the tcpdump command with a larger value for the
-c option to capture a larger number of packets and see if you
can interpret what the packets are saying with regard to the DNS
queries and their replies.
The packets shown here were for the case whey my laptop tried to
execute the ssh engr.u-tokyo.ac.uk command. If you repeat such
experiments with the same ssh command for the same hostname,
you would need to flush the DNS cache each time to see the sort
of packets shown above. We will have more to say about the very
important role that is played by this cache. Suffice it here to say
that the DNS cache in your Ubuntu machine can be flushed by
executing as root:
/etc/init.d/bind9
restart
24
Lecture 17
25
Lecture 17
The authoritative nameserver file that contains the mappings between the hostnames and the IP addresses is known as the zone
file.
26
Lecture 17
Lecture 17
net.
edu.
gov.
uk.
jp.
in.
....
Notice again the period at the end of each textual name of the
domain.
moonshine.ecn.purdue.edu
dig is a useful utility for interrogating DNS nameservers for information about the host IP addresses, mail exchanges, nameservers
for other domains, and so on. dig stands for domain information
groper. dig is included in libraries such as dnsutils (Ubuntu),
bind-utils (Red Hat), bind-tools (Gentoo), etc. The source
for dig is included in the BIND distribution that we will talk
28
Lecture 17
about later. [Try calling dig without any arguments it will return the IP addresses for the
root servers. Therefore, calling dig without an argument is the same as calling it with an
argument that is just a period.
When you execute the dig command line shown above, the response you get back from the DNS server will look something
like:
; <<>> DiG 9.4.1-P1 <<>> moonshine.ecn.purdue.edu
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50449
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 2
;; QUESTION SECTION:
;moonshine.ecn.purdue.edu. IN A
;; ANSWER SECTION:
moonshine.ecn.purdue.edu. 86377 IN A 128.46.144.123
;; AUTHORITY SECTION:
ecn.purdue.edu. 81544
ecn.purdue.edu. 81544
ecn.purdue.edu. 81544
ecn.purdue.edu. 81544
ecn.purdue.edu. 81544
ecn.purdue.edu. 81544
IN
IN
IN
IN
IN
IN
NS
NS
NS
NS
NS
NS
ns1.rice.edu.
ns2.purdue.edu.
harbor.ecn.purdue.edu.
ns2.rice.edu.
pendragon.cs.purdue.edu.
ns.purdue.edu.
;; ADDITIONAL SECTION:
ns2.rice.edu. 3550 IN A 128.42.178.32
ns2.purdue.edu. 81544 IN A 128.210.11.57
;;
;;
;;
;;
Lecture 17
Note that all the domain names shown in this response end in
a period. Reading right-to-left the left-most entry under the
ANSWER SECTION, we have the root domain, followed by the
edu subdomain, followed by the ecn subdomain, and, finally,
followed by the moonshine subdomain. This right-to-left
order corresponds to the order in which you will see
the nodes in the DNS tree as you descend from the
root node to the node that serves as the authoritative
nameserver for the moonshine host.
Note particularly the SERVER entry in the last part of the above
answer returned by dig. That tells us that DNS server is running
on the local machine the machine on which dig was invoked
since 127.0.0.1 is the loopback IP address. In this case, the local
machine is my Linux (Ubuntu) laptop and the DNS server running on the laptop is BIND. I will have more to say about BIND
later.
Also note the numbers like 86377, 81544, 3550, etc., in the answer returned by the DNS server running on my laptop. All of
these numbers are TTL (Time To Live) in seconds. One day
(meaning 24 hours) corresponds to 86400 seconds. Repeated invocations of dig will show progressively reducing TTL times up
to a point and then they will become large again. This is because
of caching that I will explain later.
30
Lecture 17
IN
IN
IN
IN
IN
IN
NS
NS
NS
NS
NS
NS
ns1.rice.edu.
ns2.purdue.edu.
harbor.ecn.purdue.edu.
ns2.rice.edu.
pendragon.cs.purdue.edu.
ns.purdue.edu.
In case you are wondering about the nameserver at Rice University being listed as one of the nameservers for the ecn.purdue.edu
domain, one or more nameservers may be located at geographically separated location for backup in case any man-made or natural disasters impair the operations of the primary nameservers.
These distant nameservers are in slave relationship to the master nameservers for a domain. I will have more to say later about
the master-slave relationship among the nameservers.
Lecture 17
moonshine.ecn.purdue.edu. 86377
IN
128.46.144.123
ecn.purdue.edu.
81544
IN
NS
ns2.purdue.edu.
ns2.rice.edu.
3550
IN
128.42.178.32
etc.
that stands for address record in the form of an IPv4 numerical address.
AAAA: that stands for address record in the form of an IPv6 numerical address. AAAA is a mnemonic to indicate that an IPv6 address is four times
the size of an IPv4 address.
NS: that stands for a nameserver record consisting of the name(s) of the
nameserver(s) that can be queried for resolving a given hostname.
PTR: that stands for pointer record that is the symbolic hostname associated
with a numerical IP address. Such a record is returned in reverse name lookup.
MX: that stands for a mail exchange server for a given host.
and several others..
5. The record data such as the IPv4 address 128.46.144.123 shown above.
32
Lecture 17
dig will do reverse DNS lookup for you if you give it the -x
option. I found the IP address 58.9.62.229 in one of my spam
emails. To see who this belongs to, we can invoke:
dig -x 58.9.62.229
This returns the following answer
; <<>> DiG 9.4.1-P1 <<>> -x 58.9.62.229
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61596
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3
;; QUESTION SECTION:
;229.62.9.58.in-addr.arpa. IN PTR
;; ANSWER SECTION:
229.62.9.58.in-addr.arpa. 604560 IN PTR ppp-58-9-62-229.revip2.asianet.co.th.
;; AUTHORITY SECTION:
9.58.in-addr.arpa. 604560 IN NS conductor.asianet.co.th.
9.58.in-addr.arpa. 604560 IN NS piano.asianet.co.th.
9.58.in-addr.arpa. 604560 IN NS clarinet.asianet.co.th.
;; ADDITIONAL SECTION:
piano.asianet.co.th. 86160 IN A 203.144.255.71
conductor.asianet.co.th. 86160 IN A 203.144.255.72
clarinet.asianet.co.th. 86160 IN A 203.144.225.242
;;
;;
;;
;;
Lecture 17
For reverse DNS lookup, note that whereas the object of our
query was the IP address 58.9.62.229, its DNS lookup turned our
query into the following string (as is clear from the RR under the
Question Section in what is returned by dig)
229.62.9.58.in-addr.arpa.
This is a special format for reverse DNS lookup. As you can see,
the query string has the four integers of the IP address in the
reverse order and the string ends in the suffix in-addr.arpa.
[The reversal of the order in which the four parts of the IP address appear in the string stored in
the in-addr.arpa domain implies that we can again use a right-to-left order for searching for the
database where we might expect to the find the reverse mapping we are looking for. In the example
shown above, it is the integer 58 in the IP address that belongs to the domain portion of the address.
The integer 229, on the other hand, belongs to a specific machine.
If you just want to see the IP address of the host (or hosts)
responsible for mail exchange for a domain you can call dig with
the MX option. For example
dig
+short
moonshine.ecn.purdue.edu MX
returns
34
10
Lecture 17
mx.ecn.purdue.edu.
nyt.com MX
you get back the following reply that lists seven mail exchange
hosts, each with its own MX preference number. A remote mail
server wishing to send email to a client in the domain nyt.com
must first attempt the mail exchange server ASPMX.L.GOOGLE.com
since that has the smallest preference number associated with it.
Mail exchange servers with equal preference number get the same
priority.
; <<>> DiG 9.9.3-rpz2+rl.13214.22-P2-Ubuntu-1:9.9.3.dfsg.P2-4.....
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44572
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 15
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
35
Lecture 17
;nyt.com.
;; ANSWER SECTION:
nyt.com.
nyt.com.
nyt.com.
nyt.com.
nyt.com.
nyt.com.
nyt.com.
300
300
300
300
300
300
300
;; ADDITIONAL SECTION:
ASPMX.L.GOOGLE.com.
ASPMX.L.GOOGLE.com.
ALT1.ASPMX.L.GOOGLE.com.
ALT1.ASPMX.L.GOOGLE.com.
ASPMX3.GOOGLEMAIL.com.
ASPMX3.GOOGLEMAIL.com.
ALT2.ASPMX.L.GOOGLE.com.
ALT2.ASPMX.L.GOOGLE.com.
ASPMX5.GOOGLEMAIL.com.
ASPMX5.GOOGLEMAIL.com.
ASPMX2.GOOGLEMAIL.com.
ASPMX2.GOOGLEMAIL.com.
ASPMX4.GOOGLEMAIL.com.
ASPMX4.GOOGLEMAIL.com.
;;
;;
;;
;;
IN
MX
IN
IN
IN
IN
IN
IN
IN
MX
MX
MX
MX
MX
MX
MX
30
10
20
30
20
30
30
115
185
139
130
128
275
289
240
184
106
195
172
103
33
IN
IN
IN
IN
IN
IN
IN
IN
IN
IN
IN
IN
IN
IN
A
AAAA
A
AAAA
A
AAAA
A
AAAA
A
AAAA
A
AAAA
A
AAAA
ASPMX4.GOOGLEMAIL.com.
ASPMX.L.GOOGLE.com.
ALT1.ASPMX.L.GOOGLE.com.
ASPMX3.GOOGLEMAIL.com.
ALT2.ASPMX.L.GOOGLE.com.
ASPMX5.GOOGLEMAIL.com.
ASPMX2.GOOGLEMAIL.com.
74.125.142.26
2607:f8b0:4001:c03::1b
74.125.29.26
2607:f8b0:400d:c04::1a
74.125.131.27
2607:f8b0:400c:c03::1a
74.125.131.26
2607:f8b0:400c:c03::1a
173.194.65.27
2a00:1450:4013:c00::1b
74.125.29.26
2607:f8b0:400d:c04::1a
173.194.78.26
2a00:1450:400c:c00::1a
dig
+noauthority
Lecture 17
moonshine.ecn.purdue.edu
@ns1.rice.edu +nocmd
moonshine.ecn.purdue.edu
Got answer:
->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33037
flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
WARNING: recursion requested but not available
;; QUESTION SECTION:
;moonshine.ecn.purdue.edu. IN A
;; ANSWER SECTION:
moonshine.ecn.purdue.edu. 86400 IN A 128.46.144.123
;;
;;
;;
;;
Note that I called dig with the +nocmd option to suppress the
first few comments lines in the answer returned. As the reader
37
Lecture 17
can tell from the previous outputs, those comment lines show us
the version of dig used and how the utility was called.
38
Lecture 17
In case you are wondering about the line that starts with search
in the /etc/resolv.conf file, that lines lists the domain names
that will be appended to a name that is not fully specified. For
example, the name moonshine.ecn.purdue.edu is a fully
qualified domain name (FQDN) but the name moonshine is
not. If you ask dig (or any of the other DNS-related utilities) to
fetch information on the moonshine name, it will search through
the list specified in the search line in the /etc/resolv.conf
line. If it finds moonshine in any of those domains, it will subsequently use for moonshine the FQDN corresponding to that
domain. If it does not find moonshine in any of those domains,
dig will assume that you are seeking information on moonshine
that is a subdomain of the root itself.
39
Lecture 17
host and nslookup are the other utilities that can also be used
to query nameservers. You may think of them as simpler cousins
of dig. For example,
host
moonshine.ecn.purdue.edu
returns
moonshine.ecn.purdue.edu
moonshine.ecn.purdue.edu
and
nslookup
moonshine.ecn.purdue.edu
returns
Server:
Address:
127.0.0.1
127.0.0.1#53
Non-authoritative answer:
Name:
moonshine.ecn.purdue.edu
Address: 128.46.144.123
40
Lecture 17
moonshine.ecn.purdue.edu ns2.rice.edu
which returns
Server:ns2.rice.edu
Address:128.42.178.32#53
Name: moonshine.ecn.purdue.edu
Address: 128.46.144.123
-type=NS
moonshine.ecn.purdue.edu
which returns
Server:127.0.0.1
Address:127.0.0.1#53
Non-authoritative answer:
*** Cant find moonshine.ecn.purdue.edu: No answer
Authoritative answers can be found from:
ecn.purdue.edu
origin = harbor.ecn.purdue.edu
41
Lecture 17
This answer says that the cache of the local DNS server could
not supply the answer requested. (If it had, that would have constituted a non-authoritative answer.) And then the answer
returned says that the authoritative answers can be had from the
nameserver running at the harbor.ecn.purdue.edu host.
Another utility that can be used to determine the DNS nameservers (besides other information) for a given domain is whois.
For example, if you invoke
whois purdue.edu
to find the whois server for the purdue.edu domain (which
happens to be whois.educause.net) and invoke
whois -h whois.educause.net purdue.edu
you can find out that the zone that corresponds to the purdue.edu
domain uses the following nameservers:
NS.PURDUE.EDU
NS1.RICE.EDU
PENDRAGON.CS.PURDUE.EDU
HARBOR.ECN.PURDUE.EDU
128.210.11.5
128.10.2.5
128.46.154.76
42
Lecture 17
43
Lecture 17
my domain. Obviously, the nameserver in my domain will then become merely a recursive nameserver
for the new subdomain.
Lecture 17
Lecture 17
46
Lecture 17
Lecture 17
Lets say you are within the purdue.edu domain and you point
your browser to www.nyt.com, the browser will send that URL
to one of the nameservers of the purdue.edu domain. (The
nameserver has to be running a program like BIND to be able to
process the incoming request for name resolution.) If this is the
first request for this URL received by the nameserver for purdue.
edu, the nameserver will forward the request to the nameserver
for the com domain, and the name lookup will proceed in the
manner explained previously. However, if this was not the first
request for the name resolution of www.nyt.com, it is likely that
the local nameserver would be able to resolve the URL by looking
into its own cache.
Lecture 17
The operating system may also maintain a local cache for the
previously resolved hostnames with relatively short caching times
(of the order of 30 minutes) for the information stored.
49
Lecture 17
When a DNS query for a given hostname is fielded by a authoritative DNS server, in addition to the IP address the server also
sends back a time interval known as the TTL (Time to Live)
for the response. The TTL specifies the time interval for which
the response can be expected to remain valid. What is stored in
the cache is both the IP address and its associated TTL. Subsequently, for all DNS queries for the same hostname made within
the TTL window, the local name-resolver working with the DNS
server will return the cached entry and the query will not be sent
to the remote nameserver.
The TTL value associated with a hostname is set by the administrator of the authoritative DNS server that returns the IP address
along with its TTL. The TTL can be in units of minutes, hours,
days, and even weeks. Ordinarily, an ISP nameserver will cache
an IP address for a hostname for 48 hours.
Lecture 17
Lets say you are running a DNS server on your laptop. (How
you can do that will be explained later in this lecture.) The very
first time the name resolver in your laptop needs information on
a name elsewhere in the internet, the DNS server running on
your laptop will send that request to the DNS server provided
by your ISP. If that DNS server does not have the answer, the
query produced by the your laptop will eventually go to the authoritative nameserver for the name you are interested in. Lets
experiment with this process with the help of dig. When I
make the following command-line invocation on my laptop
dig
where I have used various dno options in order to fetch only the
51
Lecture 17
300
IN
199.239.137.217
IN
128.46.200.24
Note that the TTL associated with the IP binding for the hostname dynamo.ecn.purdue.edu is 86400 seconds one full
52
Lecture 17
276
IN
199.239.137.217
Note that the TTL value has gone down to 276 seconds from
the original value of 300 seconds. But also note that the Query
time is now 0 milliseconds. Originally it was 216 milliseconds.
The reason for the zero (or close to zero) query time should be
obvious. The query time is the time it takes to fetch the answer
to a DNS query.
53
Lecture 17
54
Lecture 17
17.8: BIND
Lecture 17
BIND 9, was written from scratch by Paul Vixie (then working for DEC) to support DNSSEC (DNS Security Extensions).
Other important features of BIND 9 include TSIG (Transaction
Signatures), DNS Notify, nsupdate, IPv6, mdc flush, views, multiprocessor support, and an improved portability architecture.
56
Lecture 17
The named server daemon listens on port 53 for both UDP and
TCP requests. Most commonly the incoming name queries will
use the UDP transport and the answer returned by the nameserver will also be a UDP message. However, if the response to
be returned to a client is longer than 1024 bytes, the nameserver
will switch to the TCP protocol on the same port. It is not common for client firewalls to keep port 53 open for only the UDP
traffic. But such clients can get into name lookup trouble if a
remote DNS server needs to send back its full answer using TCP.
57
Lecture 17
As already mentioned, the actual name of the BIND server daemon is named in a typical install of the name server. How this
nameserver daemon responds to a query depends much on a configuration file called named.conf. On Ubuntu Linux platforms,
the pathname to this file is /etc/bind/named.conf.
The main purpose of the named.conf file is to declare the locations of the zone files that the named server is allowed to
access for responding to the DNS queries received from name resolvers. The zone files contain the database related to the names
under the authority of the nameserver. A secondary purpose of
named.conf is to declare ACL (Access Control List) lists and
various options for the operation of the server.
Lecture 17
If bind9 is already installed and running, it is most likely configured to run as a caching nameserver which is all that
you need on your personal laptop.
Section 17.11 shows an example of named.conf the BIND configuration file. This version is for Red Hat Linux. On Ubuntu,
the named.conf file in the /etc/bind/ directory pulls in some of
the information shown in Section 17.11 from two other files
named.conf.local and named.conf.options in the same directory.
The named.conf file, or the other files it pulls in with the include
59
Lecture 17
directives, supports C style (/* */) and C++ style (// to the end
of line) comments in addition to the Unix style (# to the end of
line) comments used in configuration files.
If you are setting up a DNS server for a private 192.168.1.0 network, the external and the internal views refer to how DNS requests coming from outside the 192.168.1.0 intranet should be
processed vis-a-vis the lookup requests emanating from within
the 192.168.1.0 intranet.
60
Lecture 17
Next, the named.conf file will usually contain an options clause. (On Ubuntu platforms, the options clause may
be in the named.conf.options file.)
Lets now talk about the controls clause in the named.conf file
shown in the next section of this lecture. To understand this
clause, note that BIND makes available port 953 for remote administration of the nameserver. (As previously mentioned, the
61
Lecture 17
server daemon named listens on port 53 for UDP requests for DNS
service.) The controls clause:
controls {
inet 127.0.0.1 allow {localhost;}
keys { rndc-key; }
}
results in a TCP listener on port 953 (the default control port).
If remote administration will not be used, this control interface
can be disabled by defining an empty controls clause:
controls {}
Lecture 17
63
Lecture 17
acl "dns_slaves" {
xxx.xxx.xxx.xxx;
xxx.xxx.xxx.xxx;
};
acl "lan_hosts" {
192.168.1.0/24;
127.0.0.1;
};
options {
directory "/etc/namedb";
listen-on {
192.168.1.101;
127.0.0.1;
};
auth-nxdomain no;
allow-query { any; };
recursion no;
#
#
#
#
conform to RFC1035
allow anyone to issue queries
disallow recursive queries unless
overridden below
};
key "rndc-key" {
algorithm hmac-md5;
secret "XXXXXXXXXXXXXXXXXXXXX";
};
controls {
inet 127.0.0.1 allow { localhost; }
keys { rndc-key; };
};
view "internal" {
match-clients { lan_hosts; };
# match hosts in acl "lan_hosts" above
recursion yes;
# allow recursive queries
notify no;
# disable AA notifies
// location of the zone file for DNS root servers
zone "." {
type hint;
file "zone.root";
};
// be AUTHORITATIVE for forward and reverse lookup inside LAN:
64
Lecture 17
zone "localhost" {
type master;
file "example.local";
};
zone "0.0.0.127.in-addr.arpa" {
type master;
file "example.local.reverse";
};
zone "example.com" {
type master;
file "example.com.zone";
};
zone "0.1.168.192.in-addr.arpa" {
type master;
file "example.com.reverse";
};
};
view "external" {
// "!" means to negate
match-clients { !lan_hosts; };
recursion no;
# disallow recursive queries
allow-transfer { dns_slaves; };
# allow "hosts in act "dns_slaves" to transfer zones
zone "example.com" {
type master;
file "external_example.com.zone";
};
};
Every zone statement in the named.conf file specifies a domain that it refers to. Zone . is the root level domain for DNS.
Every DNS server must have access to this zone file on the host
on which the server is running so that if no other zone is able to
provide an answer to the incoming query, the query can be sent
off to the root servers.
Lecture 17
DNS server will be a primary server for that zone. Our DNS will
also be authoritative for these zones. When the type is hint,
then the file named contains information on the root servers that
will be accessed should DNS query not be answerable from the
information in any of the zone files or from the cache.
Lecture 17
other words, the subnet mask for this LAN consists of 24 ones
followed by eight zeros, that is 255.255.255.0. This implies that
the network address for our LAN is 192.168.1.0 and the host addresses span the range 192.168.1.1 through 192.168.1.255. The
subnet mask tells you which portion of an IP address is the
network address and which portion is reserved for the host
addresses in a LAN.
67
Lecture 17
As mentioned earlier, your Ubuntu machine may come with preinstalled BIND that gives you a local nameserver ready to go as a
caching nameserver. If not preinstalled, install the bind9 package and the other related packages with the Synaptic Package
Manager as described in Section 17.10 of this lecture.
When the laptop receives its DHCP lease, the system will write
into the /etc/resolv.conf file the hostnames of the DNS
nameservers received from the DHCP server. In some non-Ubuntu
versions of Linux, this may not include the loopback address
127.0.0.1 that you need at the top of the file to ensure that your
laptop DNS server is the first to field the name queries emanating
68
Lecture 17
from the resolvers. If thats case with your machine, you can fix
the problem by first manually enter the string
nameserver 127.0.0.1
as the first nameserver entry in the /etc/resolv.conf file.
At the same time, edit the following file
/etc/dhcp3/dhclient.conf
and uncomment the following line in this file
prepend domain-name-servers 127.0.0.1;
With this change, when your DHCP lease is renewed or when you
next connect to the internet, the nameserver 127.0.0.1 will
continue to exist in your /etc/resolv.conf file.
69
Lecture 17
Lecture 17
server process are setuid to the user nobody. The user nobody has no permissions at all. (Because nobody has no permissions at
all, the permissions on the pages to be served out must be set to 755. Purdue ECN sets
the permissions of public-web directory in user accounts to 750. That works because
the HTTPD processes dishing out the pages are runs as www.)
Lecture 17
Therefore, you can say that chroot changes the default interpretation of a pathname to a file. The default interpretation is with
respect to the root / of the directory tree. But for a chrooted
program, it is with respect to the second argument supplied to
chroot. As a result, a chrooted program cannot access any
nodes outside of what the program got chrooted to.
72
Lecture 17
Phishing is online fraud that attempts to steal sensitive information such as usernames, passwords, and credit card numbers. A common way to do this is to display familiar strings like
www.amazon.com or www.paypal.com in the browser window
while their actual URL links are to questionable web servers in
some country with weak cyber security laws. [You can check this out
by letting your screen pointer linger on such hyperlinked strings in your spam email in
order to see the URL that is displayed at the bottom of the browser.]
DNS servers that run BIND whose versions predate that of BIND
9 are vulnerable to DNS cache poisoning attacks.
73
Lecture 17
74
Lecture 17
If the nameserver to which the DNS query is sent does not contain
the IP address either in its cache or in its zones for which it has
authority, it will forward the query to nameservers higher up in
the tree of nameservers. Each such query will be accompanied with its own 16-bit Transaction ID number.
75
Lecture 17
amazon.com
@harbor.ecn.purdue.edu
76
Lecture 17
Lecture 17
You could,
for example, include a wrong IP address for the nameservers
assigned to the amazon.com domain. The dig command
shown earlier tells us that pdns1.ultradns.net is one of the nameservers for amazon.com. So in the Additional Section of
the fake reply, you could include a Resource Record like
pdns1.ultradns.net.
86400
IN
xxx.xxx.xxx.xxx
Lecture 17
Lecture 17
What increases the odds in attackers favor is that BINDs implementation of the DNS protocol actually sends multiple simultaneous queries for the same symbolic name that needs to be resolved,
each with a different Transaction ID number. On account of the
birthday paradox explained in Lecture 15, this could significantly increase the probability of getting the attacked nameserver
to accept one of the phony answers to its query with only a few
hundred packets (instead of the tens of thousands previously believed to be needed).
80
Lecture 17
The attacker can safely assume that the port in the destination
address used in the query packets issued by the attacked nameserver is 53 since that is the standard port monitored by nameservers. However, the source port at the attacked nameserver
machine from which the queries are emanating is another matter altogether. As Stewart has mentioned, it turns out that
more often than not BIND reuses the same port for queries on
behalf of the same client. [Joe Stewart, DNS Cache Poisoning The Next GenerSo if the attacker is working from
ation, http://www.lurhq.com/dnscache.pdf]
an authoritative nameserver, he can first issue a request for a
DNS lookup of a hostname in his own domain. Having access
to his own authoritative nameserver, when the response arrives
from the machine to be attacked, he can look at the source port
in the response. Subsequently, the attacker can direct the phony
replies to this port on the attacked machine. Stewart says there
is a high probability that the attacked-machine source port thus
fished out by the attacker will the same on which the attacked
machine issues its queries during the attack. [The latest version of
BIND is unlikely to allow for this sort of predictability in the ports used for outgoing
requests.]
81
Lecture 17
You will face two main challenges in converting the script into
82
Lecture 17
#!/usr/bin/perl -w
##
##
dns_fake_response.pl
Author: Avi Kak (March 27, 2011)
##
##
##
##
##
##
Shows you how you can put on the wire UDP packets that could potentially
be a response to a DNS query emanating from a client name resolver
or a DNS caching nameserver. This script repeatedly sends out UDP packets,
each packet with a different DNS transaction ID. The DNS Address Record
(meaning a Resource Record of type A) contained in the data payload
of every UDP packet is the same --- the fake IP address for a domain.
use Net::DNS;
use Net::RawIP;
use strict;
my $sourceIP
my $destIP
#(A)
#(B)
#(C)
my $destPort
= 23456;
my $sourcePort = 5353;
#(F)
#(G)
#(H)
my $domain_name="moonshine.ecn.purdue.edu";
#(I)
my $rougeIP=192.168.1.101;
#(J)
83
Lecture 17
my @udp_packets;
#(K)
#(L)
#(M)
#(N)
#(R)
#(S)
#(T)
#(U)
#(O)
#(P)
#(Q)
}
my $interval = 1;
#
#
#
#
my $repeats = 2;
# Give it a large value for a real attack
my $attempt = 0;
while ($attempt++ < $repeats) {
foreach my $udp_packet (@udp_packets) {
$udp_packet->send();
sleep $interval;
}
}
#(V)
#(W)
#(X)
#(Y)
#(Z)
#(a)
#(b)
I tested the above script with the tcpdump packet sniffer with
the following command line options:
tcpdump -vvv -nn -i wlan0 -s 1500 -S -X -c 10 src 192.168.1.105 or dst 192.168.1.105 and port 5353
Lecture 17
So far we have only talked about poisoning the cache of a recursive nameserver. Obviously, the above script could also be
used to poison the cache of a client name resolver such as the one
associated with a web browser or a mail client.
85
Lecture 17
As a result, US-CERT (United States Computer Emergency Readiness Team) issued a Vulnerability Note stating that Kaminsky
had discovered a fundamental flaw in the DNS protocol itself.
This announcement consisted of a a Vulnerability Note whose
first page is shown next. [US-CERT is a part of the US Department of Homeland Security. It is located in Washington DC.]
Subsequently, several vendors of DNS
software issued their own advisories and patches. I have shown
the first page of the CISCO advisory after the US-CERT advisory. Visit the respective web pages for the complete documents
if interested.
86
Lecture 17
87
Lecture 17
88
Lecture 17
89
Lecture 17
Assuming that the attacker wins the race, the Transaction IDs
in the spoofed replies from the attacker will have to match the
TIDs in the queries emanating from ns.purdue.edu. But we
have already discussed that problem in Section 17.11. [As Dan
Kaminsky said in his now famous keynote address at the 2008 ToorCon Conference, with respect to
winning the race, the bad guys have the starter pistol. It takes time for a query to reach the legitimate
nameserver at foo.com and even more time for that nameserver to send replies. The bad guy can get
to sending the fake replies right away.
The new discovery that Kaminsky made was that a caching nameserver such as ns.purdue.edu would not only accept the Resource Records in the Answer Section of the fake replies to its
queries, but also the RRs in the Additional Section where
the attacker may even place a fake address for ns.foo.com. The
attacker could also associate a long TTL with this entry.
Lecture 17
server for an IP address for any host in the foo.com domain will
reach the attacker nameserver instead of the true nameserver for
the foo.com domain. Now the attacker could create any set of
hostname-to-IP address mappings for the hosts in the foo.com
domain.
1. Make it more difficult to take advantage of the birthday paradox when it comes to guessing the Transaction ID in a query
emanating from a resolver or a recursive nameserver.
[As
mentioned in Section 17.11, the fundamental problem is that the DNS protocol only allows for a
16-bit field for TID that is only 65,535 values. So even with a strong random number generator,
in the absolute worst case, on the average an attacker would only need to send 32K UDP reply
packets in order get the fake IP entries accepted at the nameserver being attacked provided
the attacker also guesses correctly the port being used for the outgoing queries. Assuming that the issue of matching the ports can somehow be addressed, it is obviously the case
that 32K is not a small number for, say, a low-bandwidth network. As you saw, Kaminsky reduces this number considerably by querying the nameserver for a number of related hostnames
as in 1.foo.com, 2.foo.com, etc. and getting the nameserver to handle all those queries
recursively.
91
Lecture 17
92
Lecture 17
1. What you see at the bottom of this page and at the top of
the next is the first packet captured by tcpdump when my laptop sends a DNS name lookup query to the nameserver for the
ecn.purdue.edu domain. My laptops IP address is 10.184.173.48
and the IP address of the DNS server is 128.210.11.57.
The first question regarding the packet shown below is: How does
a host receiving this packet know that it is a UDP packet and
not a TCP packet? Note that the receiving host is only going to
see the bytes whose hex representations are shown below. [To answer
this question, proceed as follows: (1) First become familiar with the numbers that are used to represent the
different protocols. See the Wikipedia page on List of IP Protocol Numbers. (2) Now review the IP Header
in Lecture 16. Note the location of the Protocol field in the IP Header. This field points to the immediately
higher-level protocol in the TCP/IP stack that sent the information down to the IP Layer. If the information
was sent down by the TCP protocol, the number stored in the Protocol field would be 6. If the information
was sent down by the UDP protocol, the number stored in the Protocol field would be decimal 17 (which is
hex 0x11).
93
0x0000:
0x0010:
0x0020:
0x0030:
0x0040:
4500
80d2
0001
746f
0000
Lecture 17
004b
0b39
0000
6b79
2910
1f72
5b52
0000
6f02
0000
4000
0035
0001
6163
0000
4011
0037
0465
0275
0000
d73c
8109
6e67
6b00
00
0ab8
3e22
7207
0001
ad30
0000
752d
0001
E..K.r@.@..<...0
...9[R.5.7..>"..
.........engr.utokyo.ac.uk.....
..)........
2. The packet displayed below for this question is the same as shown
in the previous question. Can you reconcile the information in
the text strings above the byte data with the hex printout for
the bytes? Where would you expect to see the source and the
destination IP addresses? [To answer this question, you need to know structure of the UDP
Header. The UDP Header is pretty simple. It consists of just two 32-bit words. The source port and the
destination ports are stored, with 16 bits assigned to each, in the first 32 bits. The next 16 bits stores the total
length of the UDP datagram, including its payload. And the final 16 bits store the checksum.
4500
80d2
0001
746f
0000
004b
0b39
0000
6b79
2910
1f72
5b52
0000
6f02
0000
4000
0035
0001
6163
0000
4011
0037
0465
0275
0000
d73c
8109
6e67
6b00
00
0ab8
3e22
7207
0001
ad30
0000
752d
0001
E..K.r@.@..<...0
...9[R.5.7..>"..
.........engr.utokyo.ac.uk.....
..)........
Lecture 17
Lecture 17
Lecture 17
97