IP Attacks
IP Attacks
IP Attacks
1 Overview
The objective of this lab is for students to gain the first-hand experience on various attacks at the IP layer.
Some of the attacks may not work anymore, but their underlying techniques are quite generic, and it is
important for students to learn these attacking techniques, so when they design or analyze network protocols,
they are aware of what attackers can do to protocols. Moreover, due to the complexity of IP fragmentation,
spoofing fragmented IP packets is non-trivial. Constructing spoofed IP fragments is a good practice for
students to hone their packet spoofing skills, which are essential in network security. We will use Scapy to
conduct packet spoofing. This lab covers the following topics:
Videos. Detailed coverage of the IP protocol and the attacks at the IP layer can be found in the following:
• Section 4 of the SEED Lecture, Internet Security: A Hands-on Approach, by Wenliang Du. See details
at https://www.handsonsecurity.net/video.html.
Lab environment. This lab has been tested on our pre-built Ubuntu 16.04 VM, which can be downloaded
from the SEED website.
2 Tasks 1: IP Fragmentation
Two VMs are needed for this task. They should be connected to the same network, so they can communicate
with each other.
# Construct IP header
ip = IP(src="1.2.3.4", dst="10.0.0.15")
SEED Labs – IP/ICMP Attacks Lab 2
# Construct payload
payload = ’A’ * 80 # Put 80 bytes in the first fragment
It should be noted that the UDP checksum field needs to be set correctly. If we do not set this field, Scapy
will calculate the checksum for us, but this checksum will only be based on the data in the first fragment,
which is incorrect. If we set the checksum field to zero, Scapy will leave it alone. Moreover, the recipient
will not validate the UDP checksum if it sees a zero in the checksum field, because in UDP, checksum
validation is optional.
If you use Wireshark to observe traffic, it should also be noted that by default, Wireshark will reassemble
fragments in the last fragment packet and show it as a complete IP/UDP packet. To change that behavior,
we should disable IP fragment reassembly in Wireshark preferences. Click the following menu sequence:
Edit → Preferences; click the Protocols dropdown menu, find and click IPv4. Uncheck the
"Reassemble fragmented IPv4 datagrams" option.
• The end of the first fragment and the beginning of the second fragment should have K bytes of over-
lapping, i.e., the last K bytes of data in the first fragment should have the same offsets as the first K
bytes of data in the second fragment. The value of K is decided by students (K should be greater than
zero and smaller than the size of either fragment). In the reports, students should indicate what their
K values are.
• The second fragment is completely enclosed in the first fragment. The size of the second fragment
must be smaller than the first fragment (they cannot be equal).
Please try two different orders: (1) sending the first fragment first, and (2) sending the second fragment
first. Please report whether the results will be the same.
construct such a packet, send it to the UDP server, and see how the server responds to this situation. Please
report your observation.
For this task, we should have two VMs, the victim VM (Host A) and the attacker VM (Host M). Students
should pick a destination B, which should be a host outside of our local network (e.g., an outside web server).
Normally, when A sends a packet to B, the packet will go to the router provided by VirtualBox (usually it is
10.0.2.1 if we use the default IP prefix for NAT Network).
The objective of this task is to launch an ICMP redirect attack on Host A from Host M, such that when
Host A sends packets to B, it will use M as the router, and hence sends those packets to M. Since M is
controlled by the attacker, the attacker can intercept the packets, make changes, and then send the modified
packets out. This is a form of the Man-In-The-Middle (MITM) attack. For the simplicity of this lab, students
are not required to conduct the MITM part; they only need to demonstrate that their ICMP redirect attacks
can successfully redirect packets from A to B.
Code skeleton. A code skeleton is provided in the following, with some of the essential parameters left
out. Students should fill in the proper values in the places marked by @@@@.
#!/usr/bin/python3
Verification. To verify whether the ICMP redirect attack is successful, we can use the "ip route
get" command to see what router will be used for a packet destination. For example, if we want to
know what router will be used for packets going to 8.8.8.8, we can use the following command:
$ ip route get 8.8.8.8
8.8.8.8 via 10.0.2.1 dev enp0s3 src 10.0.2.4
cache
Questions. Please conduct the following experiments, and explain your observations:
1. Can you use ICMP redirect attacks to redirect to a remote machine? Namely, the IP address assigned
to icmp.gw is a computer not on the local LAN. Please show your experiment result, and explain
your observation.
2. Can you use ICMP redirect attacks to redirect to a non-existing machine on the same network?
Namely, the IP address assigned to icmp.gw is a local computer that is either offline or non-existing.
Please show your experiment result, and explain your observation.
10.0.2.6 10.0.2.7
A R
`
192.168.60.1
192.168.60.0/24
B
` ` `
192.168.60.5 192.168.60.6 192.168.60.7
In this task, we will set up two networks and three VMs, A, B, and R. The network setup is depicted in
Figure 1. The IP addresses in the figure are only for illustration purposes; students can choose different IP
addresses in their setup.
The 10.0.2.0/24 network should use the "NAT Network" adaptor in VirtualBox. Both Machines
A and R are attached to this network, so they can directly communicate with each other. The second network
SEED Labs – IP/ICMP Attacks Lab 5
192.168.60.0/24 should use the "Internal Network" adaptor in VirtualBox. Only Machines R
and B are attached to this network. Therefore, Machines A and B cannot directly communicate with each
other. The figure shows three machines inside the 192.168.60.0/24 network, but students only need to
include one VM in their setup.
Since Machine R is attached to both networks, it needs to have two network adaptors, one using the
"NAT Network" type and the other using the "Internal Network". In VirtualBox, by default, only
one network adaptor is enabled. We can go to the VM Settings to enable the second one, but we need to
shutdown the VM first; otherwise, we will find out that the "Adaptor 2" button is grayed out.
Set up static IP addresses. VMs attached to the "NAT Network" network will automatically get their
IP addresses from the DHCP server, but for VMs on the "Internal Network", VirtualBox does not pro-
vide DHCP, so the VM must be statically configured. To do this, click the network icon on the top-right cor-
ner of the desktop, and select "Edit Connections". You will see a list of "Wired connections",
one for each of the network adaptors used by the VM. For Machine B, there is only one connection, but for
Machine R, we will see two. To make sure that you pick the one attached to the "Internal Network"
adapter, You can check the MAC address displayed in the pop-up window after you have picked a connec-
tion to edit. Compare this MAC address with the one displayed by the ifconfig command, and you will
know whether you have picked the right connection or not.
After selecting the right connection to edit, pick the "ipv4 Settings" tab and select the "Manual"
method, instead of the default "Automatic (DHCP)". Click the "Add" button to set up the new IP
address for the VM. See Figure 2 for details.
Figure 2: Manually set up the IP address for the "Internal Network" adaptor.
// Add an entry
$ sudo ip route add <network> dev <interface> via <router ip>
We need to configure R as a router. Unless specifically configured, a computer will only act as a host,
not as a gateway. Machine R needs to forward packets, so it needs to function as a gateway. We need to
enable the IP forwarding for a computer to behave like a gateway. IP forwarding can be enabled using the
following command:
$ sudo sysctl net.ipv4.ip_forward=1
In your lab report, please demonstrate (using screenshots) that you can successfully ping and telnet
to B from A, and vice versa.
During the experiments, students run Wireshark on both Machine B and R, and check whether the
spoofed packets are forwarded to the internal network or not by R. When running Wireshark on machine
R, check the traffic on both network interfaces. If the spoofed packet is forwarded, it should appear in both
interfaces; otherwise, we will only see the packet from the incoming interface. Please describe and explain
your observations.
5 Submission
You need to submit a detailed lab report, with screenshots, to describe what you have done and what you
have observed. You also need to provide explanation to the observations that are interesting or surprising.
Please also list the important code snippets followed by explanation. Simply attaching code without any
explanation will not receive credits.