Note: Do this lab with your laptop
Deliverables: Show the following works in the lab report (add screenshots as necessary).
ifconfig command for each VM and show the IP addresses
are correctly set up.
ping commands to show that they are connected to each other.
Note: Use the IP address (instead of a hostname, e.g., it430b).
ping from it430a to it430b
ping from it430b to it430c
ping from it430c to it430a
mxxxxxx@it430a:~Desktop$
from socket import *
ETH_P_ALL = 0x0003
raw_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
Note although it's defined in C header file linux/if_ether.h,
ETH_P_ALL is not defined in Python3. So we just created the variable with that
name.
raw.py as follows:
#!/usr/bin/python3
# raw.py
from socket import *
ETH_P_ALL = 0x0003
raw_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
(data, addr) = raw_socket.recvfrom(1024)
print("addr=", addr)
print(" ".join([f"{data[i]:02x}" for i in range(16)]))
print("data=", data)
(If you are not familiar with join(), refer to this tutorial).
Note that the code sniffs a simple packet and prints them. Execute the following command in the terminal to see how it works.
sudo python3 raw.py
~$ sudo python3 raw.py addr= ('enp0s3', 2048, 0, 1, b'RT\x00\x125\x00') 08 00 27 b3 0c 54 52 54 00 12 35 00 08 00 45 00 data= b"\x08\x00'\xb3\x0cTRT\x00\x125\x00\x08\x00E\x00\x00G\x10\xaf .... \xb9"The second line of the output shows the first 16 bytes of the data. Indeed, if you are observant, you will see this is actually an Ethernet frame!
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |[ Destination MAC Address (6 bytes) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ]|[ | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Source MAC Address (6 bytes) ]| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |[ Type/Length of Data |[ | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Client Data + padding (46-1500 bytes) | | .... ]| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | CRC Checksum (4 bytes) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
08 00 27 b3 0c 54 52 54 00 12 35 00 08 00 Dst MAC Addr: 08 00 27 b3 0c 54 Src MAC Addr: 52 54 00 12 35 00 Type of Data: 08 00 |
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| IHL |Type of Service| Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identification |R D M| Fragment Offset | | |S F F| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time to Live | Protocol | Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
45 00
The first 4-bit is 4, which is Version.
The next 4-bit is 5, which is IHL.
The next 8-bit (i.e., one byte) is Type of Service, which is 0x00.
|
Write python code sniff.py that works as follows:
|
A sample run:
~$ sudo python3 sniff.py
src: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
dst: 192.168.172.5(53205) [08:00:27:6b:ad:50]
b'test\n'
src: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
dst: 192.168.172.5(53205) [08:00:27:6b:ad:50]
b'world\n'
src: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
dst: 192.168.172.5(53205) [08:00:27:6b:ad:50]
b'good\n'
src: 192.168.172.5(53205) [08:00:27:6b:ad:50]
dst: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
b'note\n'
src: 192.168.172.5(53205) [08:00:27:6b:ad:50]
dst: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
b'problem\n'
src: 192.168.172.5(53205) [08:00:27:6b:ad:50]
dst: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
b'test is the\n'
src: 192.168.172.4(9000) [08:00:27:f3:5c:ca]
dst: 192.168.172.5(53205) [08:00:27:6b:ad:50]
b'bla bla bla\n'
|
sudo ifconfig enp0s3 promisc(To disable the mode, run the following:
sudo ifconfig enp0s3
-promisc )
hostname command).
Security Engineering, 3rd ed. by Ross Anderson
~/bin/submit -c=IT430 -p=lab05 *.py lab_report.docx