DNS Pharming Attack Lab
DNS Pharming Attack Lab
1 Lab Overview
DNS (Domain Name System) is the Internet’s phone book; it translates hostnames to IP addresses (or IP
addresses to hostnames). This translation is through DNS resolution, which happens behind the scene. DNS
Pharming attacks manipulate this resolution process in various ways, with an intent to misdirect users to
alternative destinations, which are often malicious. The objective of this lab is to understand how such
attacks work. Students will first set up and configure a DNS server, and then they will try various DNS
Pharming attacks on the target that is also within the lab environment.
2 Lab Environment
We need to setup the lab environment as the figure below. To simplify the lab environment, we let the user’s
computer, DNS server, and attacker’s computer be on one physical machine, but using different virtual
machines. The website used in this lab can be any website. Our configuration is based on Ubuntu, which
is the operating system we use in our pre-built virtual machine.
The above is the figure of the lab environment. As you can see, we set up the DNS server, the
user machine and the attacker machine in the same LAN. We assume that the user machine’s IP ad-
dress is 192.168.0.100, the DNS Server’s IP is 192.168.0.10 and the attacker machine’s IP is
192.168.0.200.
Note for Instructors: For this lab, a lab session is desirable, especially if students are not familiar with
the tools and the environments. If an instructor plans to hold a lab session (by himself/herself or by a TA),
it is suggested the following to be covered in the lab session 1 :
1
We assume that the instructor has already covered the concepts of the attacks in the lecture, so we do not include them in the
lab session.
Laboratory for Computer Security Education 2
The BIND9 Server is already installed in our pre-built Ubuntu virtual machine image.
Step 2: Create the named.conf.options file. The DNS server needs to read the /etc/bind/named.conf
configuration file to start. This configuration file usually includes an option file called /etc/bind/named.conf.option
Please add the following content to the option file:
options {
dump-file "/var/cache/bind/dump.db";
};
It should be noted that the file /var/cache/bind/dump.db is used to dump DNS server’s cache.
Step 3: Create zones. Assume that we own a domain: example.com, which means that we are respon-
sible for providing the definitive answer regarding example.com. Thus, we need to create a zone in the
DNS server by adding the following contents to /etc/bind/named.conf. It should be noted that the
example.com domain name is reserved for use in documentation, and is not owned by anybody, so it is
safe to use it.
zone "example.com" {
type master;
file "/var/cache/bind/example.com.db";
};
zone "0.168.192.in-addr.arpa" {
type master;
file "/var/cache/bind/192.168.0";
};
Note that we use 192.168.0.x as an example. If you use different IP addresses, you need to change
/etc/bind/named.conf and the DNS lookup files (stated below) accordingly.
Step 4: Setup zone files. The file name after the file keyword in the above zones is called the zone
file. The actual DNS resolution is put in the zone file. In the /var/cache/bind/ directory, compose
the following example.com.db zone file (Note that the configuration files stated in the following can be
downloaded from the web page of this lab; typing in these files might introduce errors. If you are interested
in the syntax of these configuration files, please refer to RFC 1035 for details):
Laboratory for Computer Security Education 3
$TTL 3D
@ IN SOA ns.example.com. admin.example.com. (
2008111001 ;serial, today’s date + today’s serial number
8H ;refresh, seconds
2H ;retry, seconds
4W ;expire, seconds
1D) ;minimum, seconds
Step 5: Start a DNS server. Now we are ready to start the DNS server. Run the following command:
Note: make sure this is the only nameserver entry in your /etc/resolv.conf. Also note that, in
Ubuntu, /etc/resolv.conf may be overwritten by the DHCP client. To avoid this, disable DHCP by
doing the following (in Ubuntu 9):
Now Click the "Network Icon" on the top right corner and Select
"Auto eth0". This will refresh the wired network connection and
updates the changes.
You should restart your Ubuntu machine for the modified setting to take effect.
% dig www.example.com
;; QUESTION SECTION:
;www.example.com. IN A
;; ANSWER SECTION:
www.example.com. 259200 IN A 192.168.0.101
;; AUTHORITY SECTION:
example.com. 259200 IN NS ns.example.com.
;; ADDITIONAL SECTION:
ns.example.com. 259200 IN A 192.168.0.10
Note: the ANSWER SECTION contains the DNS mapping. You can notice that the IP address of
www.example.com is now 192.169.0.101, which is what we have set up in the DNS server. For
a simple and clear answer, we can use nslookup instead. To do a DNS reverse lookup, issue dig -x
N.N.N.N.
1.2.3.4 www.example.com
Attacks. If attackers have compromised a user’s machine, they can modify the HOSTS file to redirect
the user to a malicious site whenever the user tries to access www.example.com. Assume that you
have already compromised a machine, please try this technique to redirect www.example.com to any IP
address that you choose.
Note: /etc/hosts is ignored by the nslookup command, but will take effect on ping command
and web browser etc.
Laboratory for Computer Security Education 6
We can use the same tool (Netwox 105) for this attack. Before attacking, make sure that the DNS
Server’s cache is empty. You can flush the cache using the following command:
The difference between this attack and the previous attack is that we are spoofing the response to DNS
server now, so we set the filter field to ‘src host 192.168.0.10’, which is the IP address of the DNS
server. We also use the ttl field (time-to-live) to indicate how long we want the fake answer to stay in the
DNS server’s cache. After the DNS server is poisoned, we can stop the Netwox 105. If we set ttl to
600 (seconds), then DNS server will keep giving out the fake answer for the next 10 minutes.
Laboratory for Computer Security Education 8
Note: Please select the raw in the spoofip field; otherwise, Netwox 105 will try to also spoof the
MAC address for the spoofed IP address. To get the MAC address, the tool sends out an ARP request, asking
for the MAC address of the spoofed IP. This spoofed IP address is usually a root DNS server (this is usually
the first place that a DNS server will ask if it cannot resolve a name), and obviously the root DNS server is
not on the same LAN. Therefore, nobody will reply the ARP request. The tool will wait for the ARP reply
for a while before going ahead without the MAC address.
The waiting will delay the tool from sending out the spoofed response. If the actual DNS response
comes earlier than the spoofed response, the attack will fail. That’s why you need to ask the tool not to
spoof the MAC address.
You can tell whether the DNS server is poisoned or not by using the network traffic captured by
wireshark or by dumping the DNS server’s cache. To dump and view the DNS server’s cache, issue
the following command:
The previous attack assumes that the attacker and the DNS server are on the same LAN, i.e., the attacker can
observe the DNS query message. When the attacker and the DNS server are not on the same LAN, the cache
poisoning attack becomes more difficult. The difficulty is mainly caused by the fact that the transaction ID
in the DNS response packet must match with that in the query packet. Because the transaction ID in the
query is usually randomly generated, without seeing the query packet, it is not easy for the attacker to known
the correct ID.
Obviously, the attacker can guess the transaction ID. Since the size of the ID is only 16 bits, if the
attacker can forge K responses within the attack window (i.e. before the legitimate response arrives), the
probability of success is K over 216 . Sending out hundreds of forged responses is not impractical, so it will
not take too many tries before the attacker can succeed.
However, the above hypothetical attack has overlooked the cache effect. In reality, if the attacker is not
fortunately enough to make a correct guess before the real response packet arrives, correct information will
be cached by the DNS server for a while. This caching effect makes it impossible for the attacker to forge
another response regarding the same domain name, because the DNS server will not send out another DNS
query for this domain name before the cache times out. To forge another response on the same domain
name, the attacker has to wait for another DNS query on this domain name, which means he/she has to wait
for the cache to time out. The waiting period can be hours or days.
To launch effective attacks, the attacker must negate the caching effect. Dan Kaminsky came up with an
elegant method to do this. Using his method, attackers will be able to continuously attack a DNS server on
a domain name, without the need for waiting. With this method, an attacker can succeed within a very short
period of time. Details of the attacks are described in the following URL (see the footnote 2 ). In this task,
we will try this attack method.
2
http://spectrum.ieee.org/computing/software/fresh-phish.
Laboratory for Computer Security Education 9
We choose a fictitious company dnsphishinglab.com as our targeted domain name. Students can
choose any domain name they like, but please make sure the attack is targeted at the DNS server in this lab
environment, not at a real DNS server. The attacker wants to cause the DNS server to use his malicious
IP address when somebody queries the DNS server for www.dnsphishinglab.com. Let us call the
targeted DNS server apollo. The following steps with reference to Figure 1 describe the outline of the
attack.
1. The attacker queries the DNS Server apollo for a non-existing name in dnsphishinglab.com,
for example xyz9392.dnsphishinglab.com, where xyz9392 is a random name.
2. Since the mapping is unavailable in apollo’s DNS cache, apollo queries other DNS servers for
the name resolution.
3. The attacker floods apollo with many spoofed DNS response, each trying a different transaction
ID (hoping one is correct). In the response, not only does the attacker provides an IP resolution
for xyz9392.dnsphishinglab.com, the attacker also provides an IP address for an additional
name www.dnsphishinglab.com. This is allowed in the DNS protocol, as long as this additional
name and the queried name are from the same domain. If the spoofed response beats the actual
responses and the other elements in the response, such as the transaction ID, matches with the original
query, apollo will accept the response, the spoofed answer will then be cached, and thus apollo’s
DNS cache will be poisoned.
4. Even if the spoofed DNS response failed (i.e. did not match with the query or was beaten by the
actual response), since xyz9392 will most likely not exist in the dnsphishinglab.com domain,
Laboratory for Computer Security Education 10
the DNS server that is responsible for dnsphishinglab.com will simply reply with a negative
response, indicating that the name does not exist. The negative response will not affect apollo’s
DNS cache. Now you should be able to see why we used a random host name at the beginning.
5. If the attack fails, the attacker will go back to step one, and try another non-existing name, until the
attack succeeds.
6. Once the attack succeeds, when the victim sends a DNS query to the poisoned DNS server for www.
dnsphishinglab.com, the IP address returned by the DNS server will not be the actual IP address
for www.dnsphishinglab.com; instead, it will be the IP address set by the attacker.
7. Therefore, when the victim browses www.dnsphishinglab.com, he/she will be actually brows-
ing a malicious web site that looks like the real www.dnsphishinglab.com. If victim types any
credential information in this malicious web site, those credentials will be stolen by the attacker.
This attack is very similar to the previous DNS server cache poisoning task, but the important distin-
guishing factor is that this attack is made possible even if the targeted DNS server and the attacker are on
different networks. For the sake of simplicity, this attack is performed on two different machines in the same
network, but we do not assume that the attacker can observe the DNS request packets.
1. Configuration the Attack Machine: We will use the user machine as our attack machine. The user
machine is already configured in Section 2.2. It uses the targeted DNS server as its default DNS
server.
2. Source Ports: Some DNS servers now randomize the source port number in the DNS queries; this
makes the attacks much more difficult. Unfortunately, many DNS servers still use predictable source
port number. For the sake of simplicity in this task, we assume that the source port number is a fixed
number. We can set the source port for all DNS Queries from DNS servers to be 33333. This can be
done by adding the following option to the file /etc/bind/named.conf.options:
3. DNS Bind Server: Flush the DNS Bind Server’s Cache/ Restart DNS Bind Server with the earlier
mentioned commands.
Attack Tool and Method. To be able to send a large number of forged DNS response packets within a
short time window, we need to use some automation tools. The pacgen tool can be used for this purpose.
More details about the tool are described later. We outline the use of this tool here:
1. Modify the pacgen.c file by appropriately filling the DNS response fields. To understand the format
of DNS response packet, you can use Wireshark to capture a few DNS response packets and study
them.
After modifying pacgen.c, the pacgen program should be able to flood the targeted DNS server
with many forged DNS response packets, each trying a different transaction ID.
(a) Ping an unavailable domain name in a particular parent domain like xyz.dnsphishinglab.com.
This will trigger the DNS queries.
(b) Run the modified pacgen program to forge corresponding DNS response packets. If one packet
happens to have the correct transaction ID, and it is received before the real response comes, your
attack will be successful.
(c) You should run a loop to repeat the above two steps, each using a different domain name, ac-
cording to Kaminsky’s strategy. It should be noted that you should not wait until the Ping step
to finish before running your modified pacgen program, because if the first step finishes, the
legitimate DNS reply has already arrived. You can let Ping and the modified pacgen run in
two concurrent processes.
More about the pacgen Tool. Pacgen is an open source Ethernet IP TCP/UDP packet generating tool.
This tool is developed in C language, is easily configurable at every layer of the network packet, and is
much efficient packet generator than the netwag tool. We suggest the students to use this tool for packet
generation, since this attack requires the attacker to send out thousands of replies in fraction of a second.
Pacgen-1.10 tool can be downloaded from the web 3 . Students can also use other tools that they are familiar
with.
1. Configuration: This tool requires the Libnet library to be installed, which has already been installed
in our pre-built virtual machine image. This tool can be downloaded from the the web 4 .
The configuration of the header information is very simple for the pacgen tool. There is a header
configuration file for each layer in the pacgen directory, like eth header for ethernet layer,
ip header for IP layer.
2. Compilation: Students can read the INSTALL file in the pacgen tool to check for the compilation
information. In short, the following command should do for compiling the code to generate pacgen
executable.
% sh install.sh
% sudo sh run_default.sh
3
http://linux.softpedia.com/get/System/Networking/pacgen-14284.shtml
4
http://www.hacktoolrepository.com/tool/71/
Laboratory for Computer Security Education 12
Attack Tips:
1. DNS Response Data: The DNS response should be updated to the payload location variable.
2. Source Port: The destination port of the DNS response should match with the source port in the DNS
query, which is fixed on 33333 in this lab.
3. Source IP: The source IP of the DNS reply should match with the destination IP of the DNS query.
Normally the targeted DNS Server contacts several other DNS servers for the name resolution. The
behavior is quite predictable. Students can use Wireshark to understand the behavior of the targeted
DNS server before launching the attack.
4. Transaction ID: The transaction ID of the DNS reply should match with the DNS query for the attack
to be successful. The transaction ID varies randomly between 0-65535.
4 Submission
Students need to submit a detailed lab report to describe what they have done and what they have observed.
Report should include the evidences to support the observations. Evidences include packet traces, screen-
dumps, etc.
References
[1] RFC 1035 Domain Names - Implementation and Specification : http://tools.ietf.org/html/rfc1035