|
|
|
|
2
|
|
2
|
|
3
|
![header.png](images/header.png)
|
3
|
![header.png](images/header.png)
|
4
|
|
4
|
|
5
|
-[Verano 2016 - Ive]
|
|
|
|
|
5
|
+[Verano 2016 - Ive - Coralys]
|
6
|
|
6
|
|
7
|
-*Object Oriented Programming* (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, Javascript and PHP.
|
|
|
|
|
7
|
+*Object Oriented Programming* (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, JavaScript and PHP.
|
8
|
|
8
|
|
9
|
-In OOP, each object encapsulates within itself certain properties about the entity being modeled (for example, an object that models a *point* encapsulates the coordinates *x* and *y* of the point being represented). Furthermore, each object allows certain actions to be carried out on itself with the *methods* that the object contains. For example, an object of class *point* could carry out the action of changing the value of the *x* coordinate.
|
|
|
|
|
9
|
+In OOP, each object encapsulates within itself certain properties about the entity being modeled. For example, an object that models a *point* encapsulates the coordinates *x* and *y* of the point being represented. Furthermore, each object allows certain actions to be carried out on itself with the *methods* that the object contains. For example, an object of class *point* could carry out the action of changing the value of the *x* coordinate.
|
10
|
|
10
|
|
11
|
-When an object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define *classes* that contain data with certain *properties* or *attributes* and actions that we want to carry out with this data through the use of *methods* or *member functions*. This way, we can organize the information and processes in *objects* that have the properties and methods of a class. In today's laboratory experience you will practice defining a class and implementing some of its methods by completing a simple network sniffer. The sniffer captures all the internet protocol (IP) packets that flow through your computer in the lab, and some other packet information.
|
|
|
|
|
11
|
+When an object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define *classes* that contain data with certain *properties* or *attributes*, and actions that we want to carry out with this data through the use of *methods* or *member functions*. This way, we can organize the information and processes in *objects* that have the properties and methods of a class. In today's laboratory experience you will practice defining a class and implementing some of its methods by completing a simple network sniffer. The sniffer captures all the internet protocol (IP) packets that flow through your computer in the lab, and some other packet information.
|
12
|
|
12
|
|
13
|
## Objectives
|
13
|
## Objectives
|
14
|
|
14
|
|
|
|
|
|
21
|
|
21
|
|
22
|
1. Reviewed the implementation and declaration of C++ classes
|
22
|
1. Reviewed the implementation and declaration of C++ classes
|
23
|
2. Studied the concepts and instructions for this laboratory session.
|
23
|
2. Studied the concepts and instructions for this laboratory session.
|
24
|
-3. Taken the Pre-Lab quiz in Moodle
|
|
|
|
|
24
|
+3. Taken the Pre-Lab quiz, available in Moodle
|
25
|
|
25
|
|
26
|
---
|
26
|
---
|
27
|
|
27
|
|
|
|
|
|
29
|
|
29
|
|
30
|
## Communication among computers
|
30
|
## Communication among computers
|
31
|
|
31
|
|
32
|
-Computers communicate with each other through the Internet Protocol (IP). When a computer sends information (or message) to another computeri, the information is sent via *Internet packets* that contain the *source address*, which is the Internet address of the computer sending the information, and the *destination address*, which is the Internet address of the computer that receives the message. The Internet addresses are used to guide the information from one computer to another, but, once the arrives to its destination, ?who is supposed to receive the information? ?Which application must receive the information?
|
|
|
|
|
32
|
+Computers communicate with each other through the Internet Protocol (IP). When a computer sends information to another computer, the information is sent via *Internet packets* that contain the *source address*, which is the Internet address of the computer sending the information, and the *destination address*, which is the Internet address of the computer that receives the message. The Internet addresses are used to guide the information from one computer to another, but once the arrives to its destination, who is supposed to receive the information? Which application must receive the information?
|
33
|
|
33
|
|
34
|
The Internet packets must also specify the application that is sending the information and the application that must receive it. We can think of the Internet addresses like home postal mail addresses, and that the applications that send and receive the information are the persons that send and receive postal letters. To send a letter via postal mail, the recipient of the letter must be specified. This corresponds to the application that receives the information. To identify the source and destination application, the Internet protocol uses what is known as *port numbers*. This way, looking the packet information, the source and destination addresses and ports can be identified.
|
34
|
The Internet packets must also specify the application that is sending the information and the application that must receive it. We can think of the Internet addresses like home postal mail addresses, and that the applications that send and receive the information are the persons that send and receive postal letters. To send a letter via postal mail, the recipient of the letter must be specified. This corresponds to the application that receives the information. To identify the source and destination application, the Internet protocol uses what is known as *port numbers*. This way, looking the packet information, the source and destination addresses and ports can be identified.
|
35
|
|
35
|
|
36
|
-For instance when your lab computer communicates with the server for Moodle, the packets that carry the information from your computer to the web server contains the source address, which is the address of the lab computer, and the destination address which is the Moodle server. The source port is the port of your web browser and the destination port is of the Moodle web server.
|
|
|
|
|
36
|
+For instance, when your lab computer communicates with the server for Moodle, the packets that carry the information from your computer to the web server contains the source address, which is the address of the lab computer, and the destination address which is the Moodle server. The source port is the port of your web browser and the destination port is of the Moodle web server.
|
37
|
|
37
|
|
38
|
The Internet addresses are represented on 4 bytes (32 bits), and usually are presented to users as strings of 4 decimal values. Each decimal value is the decimal representation of one of the 4 bytes: "(0-255).(0-255).(0-255).(0-255)". Some examples of IP addresses are: 10.0.1.10, 192.168.10.11, 136.145.54.10.
|
38
|
The Internet addresses are represented on 4 bytes (32 bits), and usually are presented to users as strings of 4 decimal values. Each decimal value is the decimal representation of one of the 4 bytes: "(0-255).(0-255).(0-255).(0-255)". Some examples of IP addresses are: 10.0.1.10, 192.168.10.11, 136.145.54.10.
|
39
|
|
39
|
|
|
|
|
|
45
|
|
45
|
|
46
|
## Simple Packet Sniffer
|
46
|
## Simple Packet Sniffer
|
47
|
|
47
|
|
48
|
-A packet sniffer (also known as packet analyzer, protocol analyzer, or network analyzer) is a computer program that can intercept and log traffic passing over a digital network, or network device. As data flow across the network, the sniffer captures each packet and, if needed decodes the packet's raw data[1].
|
|
|
|
|
48
|
+A packet sniffer (also known as packet analyzer, protocol analyzer, or network analyzer) is a computer program that can intercept and log traffic passing over a digital network, or network device. As data flows across the network, the sniffer captures each packet and, if needed, decodes the packet's raw data[1].
|
49
|
|
49
|
|
50
|
Each packet captured by a sniffer has a structure similar to the ilustrated in Figure 1.
|
50
|
Each packet captured by a sniffer has a structure similar to the ilustrated in Figure 1.
|
51
|
|
51
|
|
|
|
|
|
71
|
3. The IP packet **payload**. Inside this payload the data that wants to be communicated is contained.
|
71
|
3. The IP packet **payload**. Inside this payload the data that wants to be communicated is contained.
|
72
|
|
72
|
|
73
|
|
73
|
|
74
|
-In this laboratory experience you will complete a simple packet sniffer that captures all the IP packets that flow through your laboratory computer, and some addtional information of the packets. Additinally it detects the non encrypted requests of images in the web, and displays the images in a GUI.
|
|
|
|
|
74
|
+In this laboratory experience, you will complete a simple packet sniffer that captures all the IP packets that flow through your laboratory computer, and some additional information of the packets. Additionally, it detects the non encrypted requests of images in the web, and displays the images in a GUI.
|
75
|
|
75
|
|
76
|
---
|
76
|
---
|
77
|
|
77
|
|
|
|
|
|
81
|
|
81
|
|
82
|
The application that you will complete today allows the users to analyze network traffic and monitor the images that are being tranfered through the net.
|
82
|
The application that you will complete today allows the users to analyze network traffic and monitor the images that are being tranfered through the net.
|
83
|
|
83
|
|
84
|
-Figure 2 shows an image of the application interface. Each row in the table is the information of each captured packet. The text box under the table presents a ASCII summary of a selected packet from the table. The list in the right presents the images that have been captured by the sniffer.
|
|
|
|
|
84
|
+Figure 2 shows an image of the application interface. Each row in the table is the information of each captured packet. The text box under the table presents an ASCII summary of a selected packet from the table. The list in the right presents the images that have been captured by the sniffer.
|
85
|
|
85
|
|
86
|
---
|
86
|
---
|
87
|
|
87
|
|
|
|
|
|
93
|
|
93
|
|
94
|
To create a packet sniffer you can use the *pcap* library that provides an interface to access the data passing across your network card. This library contains a function that returns a raw stream of bytes of each packet captured.
|
94
|
To create a packet sniffer you can use the *pcap* library that provides an interface to access the data passing across your network card. This library contains a function that returns a raw stream of bytes of each packet captured.
|
95
|
|
95
|
|
96
|
-The task of the sniffer programmer to decode the raw stream into human readable information. Fortunately this is not your task, but you can learn how to do it, if you want, by reading the source code of this laboratory. Your task is to follow the exercises below so you provide the packet sniffer with the needed objects (Classes) to process the packets.
|
|
|
|
|
96
|
+The task of the sniffer programmer to decode the raw stream into human readable information. Fortunately this is not your task, but you can learn how to do it; if you want, by reading the source code of this laboratory. Your task is to follow the exercises below so you provide the packet sniffer with the needed objects (classes) to process the packets.
|
97
|
|
97
|
|
98
|
|
98
|
|
99
|
### Exercise 1 - Familiarize yourself with the application
|
99
|
### Exercise 1 - Familiarize yourself with the application
|
100
|
|
100
|
|
101
|
#### Instructions:
|
101
|
#### Instructions:
|
102
|
|
102
|
|
103
|
-1. Load the project `SimpleSniffer` into `QtCreator`. There are two ways to do this:
|
|
|
|
|
103
|
+1. To load this project you need to run QtCreator with administrator (root) privileges.
|
|
|
104
|
+`sudo qtcreator Documents/eip/classes-simplesniffer/SimpleSniffer.pro`
|
|
|
105
|
+
|
|
|
106
|
+2. Load the project `SimpleSniffer` into `QtCreator`. There are two ways to do this:
|
104
|
|
107
|
|
105
|
* Using the virtual machine: Double click the file `SimpleSniffer.pro` located in the folder `/home/eip/labs/classes-simplesniffer` of your virtual machine.
|
108
|
* Using the virtual machine: Double click the file `SimpleSniffer.pro` located in the folder `/home/eip/labs/classes-simplesniffer` of your virtual machine.
|
106
|
* Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http:/bitbucket.org/eip-uprrp/classes-simplesniffer` to download the folder `classes-simplesniffer` from `Bitbucket`. Double click the file `SimpleSniffer.pro` located in the folder that you downloaded to your computer.
|
109
|
* Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http:/bitbucket.org/eip-uprrp/classes-simplesniffer` to download the folder `classes-simplesniffer` from `Bitbucket`. Double click the file `SimpleSniffer.pro` located in the folder that you downloaded to your computer.
|
107
|
|
110
|
|
108
|
-2. Configure the project. The project consists of several files. In this laboratory experience you will be working with the files `ethernet_hdr.h`, `ethernet_packet.h`, `ethernet_packet.cpp`, `ip_packet.h` and `ip_packet.cpp`.
|
|
|
|
|
111
|
+3. Configure the project. In this laboratory experience you will be working with the files `ethernet_hdr.h`, `ethernet_packet.h`, `ethernet_packet.cpp`, `ip_packet.h` and `ip_packet.cpp`.
|
109
|
|
112
|
|
110
|
|
113
|
|
111
|
### Exercise 2 - Complete the class ethernet_packet
|
114
|
### Exercise 2 - Complete the class ethernet_packet
|
|
|
|
|
121
|
};
|
124
|
};
|
122
|
|
125
|
|
123
|
|
126
|
|
124
|
- The Ethernet header above is used to decode the ethernet part of the raw data in each packet. It is composed of the source MAC address (ether_shost, 6 bytes), the destiantion MAC address (ether_dhost, 6 bytes), and the type of Ethernet packet (ether_type, 2 bytes) which is used to determine if the packet is an IP packet.
|
|
|
|
|
127
|
+ The Ethernet header above is used to decode the ethernet part of the raw data in each packet. It is composed of the source MAC address (ether_shost, 6 bytes), the destiantion MAC address (ether_dhost, 6 bytes), and the type of Ethernet packet (ether_type, 2 bytes), which is used to determine if the packet is an IP packet.
|
125
|
|
128
|
|
126
|
- As you know, it is not a good idea to show this information format to a regular user. Your first task is to define the functions of the C++ class that defines the functions to translate the MAC address information into human readable strings.
|
|
|
|
|
129
|
+ As you know, it is not a good idea to show this information format to a regular user. Your first task is to define the functions of the C++ class that defines the functions that translate the MAC address information into human readable strings.
|
127
|
|
130
|
|
128
|
2. The following code is the definition of the class `ethernet_packet`, that can be found in file `ethernet_packet.h`:
|
131
|
2. The following code is the definition of the class `ethernet_packet`, that can be found in file `ethernet_packet.h`:
|
129
|
|
132
|
|
|
|
|
|
168
|
|
171
|
|
169
|
4. Your task in this exercise is to implement the seven functions listed above in the file `ethetnet_packet.cpp`. The headers of some of the functions are provided in the file.
|
172
|
4. Your task in this exercise is to implement the seven functions listed above in the file `ethetnet_packet.cpp`. The headers of some of the functions are provided in the file.
|
170
|
|
173
|
|
171
|
-### Exercise 3 - Construct the header of class ip_packet
|
|
|
|
|
174
|
+### Exercise 3 - Build the header of the class ip_packet
|
172
|
|
175
|
|
173
|
1. Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
176
|
1. Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
174
|
|
177
|
|
175
|
2. Your task is to create the *declaration* of the class `ip_packet` in the file `ip_packet.cpp`. The attributes of the class `ip_packet` must be:
|
178
|
2. Your task is to create the *declaration* of the class `ip_packet` in the file `ip_packet.cpp`. The attributes of the class `ip_packet` must be:
|
176
|
|
179
|
|
177
|
- * two objects of the class `string`s to store the source and destination IP addresses
|
|
|
|
|
180
|
+ * two objects of the class `string` to store the source and destination IP addresses
|
178
|
* one variable of one byte (`char`) variable to store the IP protocol
|
181
|
* one variable of one byte (`char`) variable to store the IP protocol
|
179
|
* two variables `unsigned short` to store the source and destination port
|
182
|
* two variables `unsigned short` to store the source and destination port
|
180
|
* one object of the class `string` to store the packet payload.
|
183
|
* one object of the class `string` to store the packet payload.
|
181
|
|
184
|
|
182
|
- In the declaration of the class `ip_packet` you must especify that it is a **derived class** (inherits) of the class `ethernet_packet`.
|
|
|
|
|
185
|
+ In the declaration of the class `ip_packet` you must specify that it is a **derived class** (inherits) of the class `ethernet_packet`.
|
183
|
|
186
|
|
184
|
---
|
187
|
---
|
185
|
|
188
|
|
|
|
|
|
187
|
|
190
|
|
188
|
## Deliverables
|
191
|
## Deliverables
|
189
|
|
192
|
|
190
|
-1. Use "Deliverables" in Moodle to upload the file `ethernet_packet.cpp` and `ip_packet.h` that you defined. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
|
|
|
|
|
193
|
+1. Use "Deliverables" in Moodle to upload the file `ethernet_packet.cpp` and `ip_packet.h` that you defined. Remember to use good programming techniques, by including the names of the programmers involved, and documenting your program.
|
191
|
|
194
|
|
192
|
---
|
195
|
---
|
193
|
|
196
|
|