Lecture 17
Lecture 17
Attack
March 7, 2024
3:30pm
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 Perl and Python code for cache poisoning attacks
• Dan Kaminsky’s More Virulent DNS Cache Poisoning Attack
CONTENTS
17.2 DNS 5
17.8 BIND 56
Back to TOC
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 owl’s foot and ask the
owl to deliver it to its intended recipient. That’s how Harry Potter
frequently got in touch with his godfather Sirius. Harry often had
no idea as to the physical whereabouts of Sirius. Nonetheless,
Harry’s magical owl Hedwig always knew how to get the messages
to him.
As you dig deeper into the workings of the internet, you will begin
to appreciate the fact that what mankind has achieved with
internet-based communications comes fairly close to the owl-based
magical transport of messages in Harry Potter.
3
Computer and Network Security by Avi Kak Lecture 17
So let’s say you have a close friend named Sirius who wishes to
remain in hiding because he is being pursued by the authorities. For
all you know, Sirius is living incognito in a colony of space explorers
on the Moon or Mars, or he could be at any other location in our
galaxy. In order that you do not get into trouble, Sirius wants to
make sure that even you do not know where exactly he is. One day,
while in disguise, Sirius walks into a local Starbuckaroo coffee shop
on the planet of Alpha Centauri to take advantage of their ultrafast
Gamma-particle based communication link with Earth. Sirius sends
you a message (encrypted, naturally, with your public key that is on
your web page) that he will be logged in very briefly at the host
host1.starbuckaroo.alphacentauri.gxy
4
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
17.2 DNS
that machine, let alone send it any data packets. Regarding the symbolic hostnames, for a hostname
to be legal, it must consist of a sequence of alphanumeric labels that are separated by periods. The
maximum length of each label is 63 characters and the total length of a hostname must not exceed
255 characters. ]
5
Computer and Network Security by Avi Kak Lecture 17
• The internet simply would not work without DNS. In fact, one
not-so-uncommon reason why your internet connection may not
be working is because your ISP’s 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 ISP’s DNS — depending on the
TTL (time-to-live) values associated with the cached information, as you will see.]
6
Computer and Network Security by Avi Kak 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 ISP’s DNS server sends back a browser redirect to an advertisement-loaded website that the ISP
wants you to look at. Or, the ISP’s 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 DNS Hijacking on
Non-Existent Domain Names.]
• If a private home network has just four or five machines in, say,
a 192.168.1.0 network, the easiest way to establish a DNS-like
naming service for the network is to create a host table (in the
/etc/hosts) file on each machine. The name resolver program
would then consult this table to determine the IP address of
each machine in the network. [The /etc/hosts file in a Windows machine is located at
the path C:Windows\System32\Drivers\etc\hosts If you have Cygwin installed on a Windows machine,
7
Computer and Network Security by Avi Kak Lecture 17
/etc/host.conf
tells the system in what order it should search through the
following two sources of hostnames-to-ipaddress mappings:
/etc/hosts and DNS as, for example, provided by a BIND
server. On my Linux laptop, this file contains just one line:
order hosts,bind
This says that a name resolver program must first check the
/etc/hosts file in your computer and then seek help from
DNS.
/etc/resolv.conf
8
Computer and Network Security by Avi Kak Lecture 17
file will change when you take your laptop from work back to
home. (On Windows platforms, the same information is stored
in the registry. It can be accessed through the network interface
related dialogs in your Control Panel.) I’ll have more to say
about this file toward the end of Section 17.4. [Note that malware that
you may have inadvertently downloaded by clicking on a URL in a spam email may overwrite the entries in
the file /etc/resolv.conf. This would cause your name resolution requests to be serviced by a rogue DNS.
When that happens, your browser may end up visiting a malicious website that is made to look like the one
you were actually trying to reach. If you fall prey to such a subterfuge, you could end up giving your personal
information, such as your bank account information, to a bunch of bad guys. This is another
example of DNS hijacking. Earlier in this section a mention was made of “DNS hijacking on
non-existent names.” ]
9
Computer and Network Security by Avi Kak Lecture 17
• Note that if you change any of the network config files, such as,
say, /etc/hosts, you would need to restart the network service
by
sudo /etc/init.d/network restart
or, by
sudo service network-manager restart
supported software, for generating online advertisements shown through their web pages. This
has spawned a large industry of adware developers. Folks who want to advertise their products
reach out to the adware companies that generate their revenue by the users clicking on the
ads. Criminals can exploit this process by directing the digital devices to their own
server, the adverts that you will see will be for the products
that the criminals want to make money from.
the fact remains that getting hold of the DNS settings in your
digital device will always be an important goal of malware
producers. This fact is underscored by what Cisco’s 2019
Cybersecurity Report has to say about DNS hijacking:
https://engineering.purdue.edu/ece404/Resources/CISCO_cybersecurity_report_2019.pdf
12
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
• I’ll 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
the root nameservers in the /usr/share/dns/root.hints file. If you don’t find them there, you
should be able to see the pathname to the file that lists the root servers in the config file
/etc/bind/named.conf.default-zones . There are thirteen root DNS servers with names like
only six have fixed geographical locations, all in the US. All others, seven of them, are replicated at a
large number of locations all around the world. When a host on the internet sends a query for name
resolution to one of the thirteen root servers, the root server responds back with the IP address of
either a Generic Top Level Domain (gTLD) DNS server or IP address of a Country Code Top Level
Domain (ccTLD) DNS server. If a root server receives a query for, say, the ‘.com’ domain, the root
server sends back the IP address of one or more gTLD nameservers in charge of the ‘.com’ domain.
On the other hand, if a root server receives a query for, say, the ‘.jp’ domain, the response back from
the root consists of the IP address of the ccTLD server in charge of the ‘.jp’ domain. An interesting
difference between the gTLD servers and the ccTLD servers is that whereas the former have specific
names, fixed IP addresses, and fixed physical locations, the latter have none of these. In other words,
a ccTLD server may have any name, any arbitrary IP address that is registered with any ISP
whatsoever, and any physical location; obviously the root servers have to become aware of that IP
c.gtld-servers.net, etc. To see all the gTLD DNS servers for the ‘.com’ domain, you can ask
14
Computer and Network Security by Avi Kak Lecture 17
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’. ]
• As you can see in the figure, for the remote login to succeed, the
rlogin client at Purdue, the rlogind server in Tokyo, 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 rlogin client must initiate with
the rlogind server. This will involve, at the least, a 3-way
handshake that we discussed 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 between two hosts can be established. It all happens so fast.
gTLD
or 11
ccTLD
NS
DNS Server
10
PTR? rlogind Server at Univ. Tokyo, Japan
engr1.u−tokyo.ac.jp
PTR?
8
DNS Server for the
9
NS rlogind server’s domain
DNS Root
Server 7 12 13
PTR? PTR
3−Way Handshake
TCP Connection
A
14 15
A? A?
5
DNS Root
Server 6
DNS Server for the
2 NS A Client’s domain
1
A?
rlogin Client at Purdue Univ.
gTLD 3 A?
or
ccTLD
DNS Server 4 NS
PTR Pointer record returned by a nameserver for a pointer query ( This would be the hostname)
Figure 1: This figure illustrates the fact that even for the
case of a client wanting to make just a simple login con-
nection 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 re-
mote server, and various DNS servers.(This figure is from Lecture 17 of
“Lecture Notes on Computer and Network Security” by Avi Kak)
17
Computer and Network Security by Avi Kak Lecture 17
nameserver, you will find out later in this lecture. That is message 4 in
Figure 1.
or a host name. ]
• 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.
18
Computer and Network Security by Avi Kak Lecture 17
later, for reverse lookup, the IP address is reversed and then prepended to the string
]
in-addr.arpa, and the symbolic hostname is then stored against the resulting string.
• 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.
19
Computer and Network Security by Avi Kak Lecture 17
• I will now illustrate the DNS name lookups with the tcpdump
packet sniffer. In order to make sense of the packets captured
by tcpdump, you need to know that most commonly a DNS
request for name lookup is sent out in the form of a UDP
packet. [As you know from Section 16.2 of Lecture 16, the UDP protocol resides in the Transport
Layer of the TCP/IP protocol stack.]
• As you see in the packet diagram at the top of the next page, 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 in IPv4 (but required in IPv6); 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 including
the source port info in the response packet. When a UDP
20
Computer and Network Security by Avi Kak Lecture 17
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data Bytes ....
+-+-+-+-
• Here are the first six packets in the output of the tcpdump
command for the above client request that shows how my
22
Computer and Network Security by Avi Kak Lecture 17
laptop figures out that the hostname given to the ssh command
does NOT exist: [What you see below is just the data extracted by 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. ]
192.168.1.105.22579 > 198.41.0.4.53: [udp sum ok] 47551 [1au] A? engr.u-tokyo.ac.uk. ar: . OPT UDPsize=4096 OK (47)
198.41.0.4.53 > 192.168.1.105.22579: [udp sum ok] 47551- q: A? engr.u-tokyo.ac.uk. 0/13/15 ns:
uk. [2d] NS ns4.nic.uk., uk. [2d] NS ns1.nic.uk., uk. [2d] NS nsd.nic.uk., uk. [2d] NS ns2.nic.uk.,
uk. [2d] NS ns3.nic.uk., uk. [2d] NS ns7.nic.uk., uk. [2d] NS ns5.nic.uk., uk. [2d] NS nsa.nic.uk.,
uk. [2d] NS ns6.nic.uk., uk. [2d] NS nsb.nic.uk., uk. [2d] NS nsc.nic.uk., uk. [1d] NSEC,
uk. [1d] RRSIG ar:
ns1.nic.uk. [2d] A 195.66.240.130, ns1.nic.uk. [2d] AAAA 2a01:40:1001:35::2, ns2.nic.uk. [2d] A 217.79.164.131,
ns3.nic.uk. [2d] A 213.219.13.131, ns4.nic.uk. [2d] A 194.83.244.131, ns4.nic.uk. [2d] AAAA 2001:630:181:35::83,
ns5.nic.uk. [2d] A 213.246.167.131, ns6.nic.uk. [2d] A 213.248.254.130, ns7.nic.uk. [2d] A 212.121.40.130,
nsa.nic.uk. [2d] A 156.154.100.3, nsa.nic.uk. [2d] AAAA 2001:502:ad09::3, nsb.nic.uk. [2d] A 156.154.101.3,
nsc.nic.uk. [2d] A 156.154.102.3, nsd.nic.uk. [2d] A 156.154.103.3, . OPT UDPsize=4096 OK (692)
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)
195.66.240.130.53 > 192.168.1.105.46921: [udp sum ok] 27013- q: A? engr.u-tokyo.ac.uk. 0/11/1 ns:
ac.uk. [2d] NS ns0.ja.net., ac.uk. [2d] NS ws-fra1.win-ip.dfn.de., ac.uk. [2d] NS ns2.ja.net.,
ac.uk. [2d] NS ns4.ja.net., ac.uk. [2d] NS sunic.sunet.se., ac.uk. [2d] NS ns3.ja.net.,
ac.uk. [2d] NS ns.uu.net.,
u1fmklfv3rdcnamdc64sekgcdp05bbiu.uk. [2d] Type50, u1fmklfv3rdcnamdc64sekgcdp05bbiu.uk. [2d]
RRSIG, ptc0fm5i0qano6f75ivbss4dg368caci.uk. [2d] Type50, ptc0fm5i0qano6f75ivbss4dg368caci.uk.
[2d] RRSIG ar: . OPT UDPsize=4096 OK (683)
23
Computer and Network Security by Avi Kak Lecture 17
192.168.1.105.36824 > 192.55.83.30.53: [udp sum ok] 56478% [1au] A? ns.uu.net. ar: . OPT UDPsize=4096 OK (38)
192.168.1.105.37664 > 192.54.112.30.53: [udp sum ok] 62789% [1au] AAAA? ns.uu.net. ar: . OPT UDPsize=4096 OK (38)
24
Computer and Network Security by Avi Kak Lecture 17
25
Computer and Network Security by Avi Kak 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.
26
Computer and Network Security by Avi Kak Lecture 17
• 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
27
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
• For the Domain Name System, all of the internet is divided into
a tree of zones.
28
Computer and Network Security by Avi Kak Lecture 17
’.br’, etc. ]
symbolic hostname, all that the root server will do is to send back the IP address of a nameserver
that will help your resolver get closer to finding the answer. ]
purdue.edu.
Note the period at the end — that stands for the root of the
DNS tree. We refer to the domain names expressed in this
manner as fully qualified domain names (FQDN).
Notice again the period at the end of each textual name of the
domain.
dig moonshine.ecn.purdue.edu
30
Computer and Network Security by Avi Kak Lecture 17
• When you execute the dig command line shown above, the
response you get back from the DNS server will look something
like:
;; 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 IN NS ns1.rice.edu.
ecn.purdue.edu. 81544 IN NS ns2.purdue.edu.
ecn.purdue.edu. 81544 IN NS harbor.ecn.purdue.edu.
ecn.purdue.edu. 81544 IN NS ns2.rice.edu.
ecn.purdue.edu. 81544 IN NS pendragon.cs.purdue.edu.
ecn.purdue.edu. 81544 IN NS 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
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,
31
Computer and Network Security by Avi Kak Lecture 17
• 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.
32
Computer and Network Security by Avi Kak Lecture 17
33
Computer and Network Security by Avi Kak Lecture 17
etc.
3. The class of the record, such as IN shown above that stands for class internet,
as opposed to, say, the class chaos net.
4. The type of the record. The types that you are likely to see frequently are
A: 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.
5. The record data such as the IPv4 address 128.46.144.123 shown above.
• 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:
34
Computer and Network Security by Avi Kak Lecture 17
dig -x 58.9.62.229
;; 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
• 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.
• 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
returns
10 mx.ecn.purdue.edu.
dig 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:
;nyt.com. IN MX
;; ANSWER SECTION:
nyt.com. 300 IN MX 30 ASPMX4.GOOGLEMAIL.com.
nyt.com. 300 IN MX 10 ASPMX.L.GOOGLE.com.
nyt.com. 300 IN MX 20 ALT1.ASPMX.L.GOOGLE.com.
nyt.com. 300 IN MX 30 ASPMX3.GOOGLEMAIL.com.
nyt.com. 300 IN MX 20 ALT2.ASPMX.L.GOOGLE.com.
nyt.com. 300 IN MX 30 ASPMX5.GOOGLEMAIL.com.
37
Computer and Network Security by Avi Kak Lecture 17
;; ADDITIONAL SECTION:
ASPMX.L.GOOGLE.com. 115 IN A 74.125.142.26
ASPMX.L.GOOGLE.com. 185 IN AAAA 2607:f8b0:4001:c03::1b
ALT1.ASPMX.L.GOOGLE.com. 139 IN A 74.125.29.26
ALT1.ASPMX.L.GOOGLE.com. 130 IN AAAA 2607:f8b0:400d:c04::1a
ASPMX3.GOOGLEMAIL.com. 128 IN A 74.125.131.27
ASPMX3.GOOGLEMAIL.com. 275 IN AAAA 2607:f8b0:400c:c03::1a
ALT2.ASPMX.L.GOOGLE.com. 289 IN A 74.125.131.26
ALT2.ASPMX.L.GOOGLE.com. 240 IN AAAA 2607:f8b0:400c:c03::1a
ASPMX5.GOOGLEMAIL.com. 184 IN A 173.194.65.27
ASPMX5.GOOGLEMAIL.com. 106 IN AAAA 2a00:1450:4013:c00::1b
ASPMX2.GOOGLEMAIL.com. 195 IN A 74.125.29.26
ASPMX2.GOOGLEMAIL.com. 172 IN AAAA 2607:f8b0:400d:c04::1a
ASPMX4.GOOGLEMAIL.com. 103 IN A 173.194.78.26
ASPMX4.GOOGLEMAIL.com. 33 IN AAAA 2a00:1450:400c:c00::1a
;; 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
can tell from the previous outputs, those comment lines show us
the version of dig used and how the utility was called.
39
Computer and Network Security by Avi Kak 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
40
Computer and Network Security by Avi Kak Lecture 17
41
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
• 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 has address 128.46.144.123
moonshine.ecn.purdue.edu mail is handled by 10 mx.ecn.purdue.edu.
and
nslookup moonshine.ecn.purdue.edu
returns
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: moonshine.ecn.purdue.edu
Address: 128.46.144.123
Name: moonshine.ecn.purdue.edu
Address: 128.46.144.123
Non-authoritative answer:
*** Can’t find moonshine.ecn.purdue.edu: No answer
43
Computer and Network Security by Avi Kak 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.
whois purdue.edu
44
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
for creating a new subdomain under my domain. Obviously, the nameserver in my domain will then
45
Computer and Network Security by Avi Kak Lecture 17
47
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
• Let’s 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.
49
Computer and Network Security by Avi Kak 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.
50
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
51
Computer and Network Security by Avi Kak Lecture 17
requests a day. There are two IPv4 and two IPv6 addresses associated with this name server. The IPv4
addresses are 8.8.8.8 and 8.8.8.4 and the IPv6 addresses are 2001:4860.4860::8888 and
2001:4860.4860::8884. ]
• Let’s 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. Let’s experiment with this process with the
help of dig. When I make the following command-line
invocation on my laptop
dig +noauthority +noadditional +noquestion \
+nocmd +nocomment nyt.com
52
Computer and Network Security by Avi Kak Lecture 17
Note that the TTL associated with the IP binding for the
hostname dynamo.ecn.purdue.edu is 86400 seconds — one
full 24-hour period. During the TTL periods shown, if the
resolver running on my laptop tried to fetch the IP bindings for
the two host names — nyt.com and
53
Computer and Network Security by Avi Kak Lecture 17
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.
name more often, they can more evenly distribute the incoming
load targeting a particular symbolic hostname.
the TLD would continue to reside in the lower-level nodes of the DNS tree of zones for roughly two
days (depending on when exactly a lower-level DNS server queried a TLD server). That would be
long enough for remedial action to be taken against the adversary. On the other hand, if an
adversary took down the gTLDs and the ccTLDs — probably an impossible feat because many of
the gTLDs are geographically replicated and because of the ccTLDs are much more numerous —
the slave servers for those TLDs would provide immediate relief. ]
55
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
17.8 BIND
– tools such as dig, host, nslookup, etc., for verifying the proper
operation of the DNS server
incorporates the NNTP functionality), NTP (Network Time Protocol), OpenReg, etc. ]
57
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
ps ax | grep named
58
Computer and Network Security by Avi Kak Lecture 17
/etc/init.d/bind9 start
stop
restart
59
Computer and Network Security by Avi Kak Lecture 17
60
Computer and Network Security by Avi Kak Lecture 17
controls {
inet 127.0.0.1 allow {localhost;}
keys { rndc-key; }
}
controls {}
62
Computer and Network Security by Avi Kak Lecture 17
follows allow is the list of hosts that can connect to the rndc
channel.
63
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
acl "dns_slaves" {
xxx.xxx.xxx.xxx; # IP of the slave DNS nameserver
xxx.xxx.xxx.xxx; # same as above
};
acl "lan_hosts" {
192.168.1.0/24; # network address of your local LAN
127.0.0.1; # allow loop back
};
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";
64
Computer and Network Security by Avi Kak Lecture 17
};
// be AUTHORITATIVE for forward and reverse lookup inside LAN:
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";
};
};
our 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.
66
Computer and Network Security by Avi Kak Lecture 17
LAN. In 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.
named-checkconf
67
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
• 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
68
Computer and Network Security by Avi Kak Lecture 17
nameserver 127.0.0.1
/etc/dhcp3/dhclient.conf
69
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
70
Computer and Network Security by Avi Kak Lecture 17
72
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
73
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
2. You could start the attack by asking the DNS server running
at harbor.ecn.purdue.edu to carry out the name lookup
for the domain amazon.com by
dig amazon.com @harbor.ecn.purdue.edu
If you are not within the ecn.purdue.edu domain when
you experiment with the above command, replace
harbor.ecn.purdue.edu with the IP address of DNS
server provided by your ISP provider. You can see that
information in your /etc/resolv.conf file.
76
Computer and Network Security by Avi Kak Lecture 17
6. What can make such an attack worse is that your fake reply
is allowed to contain information in its Additional
Section, information that was not specifically requested in
the queries emanating from harbor but that would
nonetheless be stored away by the DNS server on harbor if
it accepts the fake reply. [At a high level of description, the format of a
reply expected by a nameserver in response to its recursive queries is the same as
what you see when you execute the dig command. As to what a reply looks like
at the low level, see the reply packets in the tcpdump output shown in Section
17.3 of this lecture.]
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 A xxx.xxx.xxx.xxx
77
Computer and Network Security by Avi Kak 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
79
Computer and Network Security by Avi Kak Lecture 17
80
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
81
Computer and Network Security by Avi Kak Lecture 17
• RFC 1035 has the following keystroke figure that presents the
structure of the Header section in a DNS message:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
82
Computer and Network Security by Avi Kak Lecture 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
OPCODE A four bit field that specifies kind of query in this message.
This value is set by the originator of a query and copied into
the response. The values are:
83
Computer and Network Security by Avi Kak Lecture 17
0 No error condition
84
Computer and Network Security by Avi Kak Lecture 17
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ QNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QTYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QCLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
QNAME a domain name represented as a sequence of labels, where
each label consists of a length octet followed by that
number of octets. The domain name terminates with the
zero length octet for the null label of the root. Note
that this field may be an odd number of octets; no
padding is used.
QTYPE a two octet code which specifies the type of the query.
The values for this field include all codes valid for a
TYPE field, together with some more general codes which
can match more than one type of RR.
QCLASS a two octet code that specifies the class of the query.
For example, the QCLASS field is IN for the Internet.
85
Computer and Network Security by Avi Kak Lecture 17
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| |
/ /
/ NAME /
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TYPE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| CLASS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| TTL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RDLENGTH |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/ RDATA /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NAME a domain name to which this resource record pertains.
CLASS two octets which specify the class of the data in the
RDATA field.
86
Computer and Network Security by Avi Kak Lecture 17
• You will face two main challenges in converting the script into a
cache poisoning attack: Constructing a spoofing set of DNS
Transaction IDs in line (H) and making a correct guess for the
destination port in line (G). See the previous section of this
lecture for how to address both those issues for at least the
older machines in a network.
#!/usr/bin/env perl
## dns_fake_response.pl
## 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.
87
Computer and Network Security by Avi Kak Lecture 17
## type RawIP
use Net::DNS;
use Net::RawIP;
use strict;
use warnings;
my $victim_hostname="moonshine.ecn.purdue.edu"; #(F)
# The name of the host whose IP
# address you want to corrupt with a
# rogue IP address in the cache of
# the targeted DNS server (in line
# (B) above)
my $rogueIP=’10.0.0.25’; # This is the face IP for the victim hostname #(G)
88
Computer and Network Security by Avi Kak Lecture 17
• I tested the above script with the tcpdump packet sniffer with
the following command line options:
sudo tcpdump -vvv -nn -i wlan0 -s 1500 -S -X -c 10 ’src 10.0.0.3’ or ’dst 10.0.0.3 and port 5353’
#!/usr/bin/python
## dns_fake_response.py
## Avi Kak
## March 22, 2016
## 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 hostname.
89
Computer and Network Security by Avi Kak Lecture 17
## Call syntax:
##
## sudo ./dns_fake_response.py
90
Computer and Network Security by Avi Kak Lecture 17
91
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
http://doxpara.com/DMK_Neut_toor.ppt ]
92
Computer and Network Security by Avi Kak Lecture 17
93
Computer and Network Security by Avi Kak Lecture 17
94
Computer and Network Security by Avi Kak Lecture 17
95
Computer and Network Security by Avi Kak 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
96
Computer and Network Security by Avi Kak Lecture 17
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
to guess the correct TID and to also get it right with regard
to the port being used by the nameserver being attacked, the
first fix consists of randomizing the ports for the outgoing
queries, as opposed to using the same port for the same
query repeatedly. Since a port address is also 16 bits, this in
effect creates a 32-bit randomization of the outgoing queries,
97
Computer and Network Security by Avi Kak Lecture 17
98
Computer and Network Security by Avi Kak Lecture 17
Back to TOC
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 laptop’s 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
0x0000: 4500 004b 1f72 4000 4011 d73c 0ab8 ad30 E..K.r@.@..<...0
99
Computer and Network Security by Avi Kak Lecture 17
0x0010: 80d2 0b39 5b52 0035 0037 8109 3e22 0000 ...9[R.5.7..>"..
0x0020: 0001 0000 0000 0001 0465 6e67 7207 752d .........engr.u-
0x0030: 746f 6b79 6f02 6163 0275 6b00 0001 0001 tokyo.ac.uk.....
0x0040: 0000 2910 0000 0000 0000 00 ..)........
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. ]
0x0000: 4500 004b 1f72 4000 4011 d73c 0ab8 ad30 E..K.r@.@..<...0
0x0010: 80d2 0b39 5b52 0035 0037 8109 3e22 0000 ...9[R.5.7..>"..
0x0020: 0001 0000 0000 0001 0465 6e67 7207 752d .........engr.u-
0x0030: 746f 6b79 6f02 6163 0275 6b00 0001 0001 tokyo.ac.uk.....
0x0040: 0000 2910 0000 0000 0000 00 ..)........
past the UDP header in order to see the data payload. The IP Header ends in the second quad in the second
row. The UDP Header takes up four more quads. The next quad after that is the hex 0x3e22. Try to convert
101
Computer and Network Security by Avi Kak Lecture 17
11. What is meant by poisoning the DNS cache? Explain how one
mounts a DNS cache poisoning attack?
102
Computer and Network Security by Avi Kak Lecture 17
103