|
|
|
|
2
|
|
2
|
|
3
|
![header.png](images/header.png)
|
3
|
![header.png](images/header.png)
|
4
|
|
4
|
|
|
|
5
|
+[Verano 2016 - Ive]
|
|
|
6
|
+
|
5
|
*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.
|
6
|
|
8
|
|
7
|
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.
|
8
|
|
10
|
|
9
|
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.
|
10
|
|
12
|
|
11
|
-##Objectives
|
|
|
|
|
13
|
+## Objectives
|
12
|
|
14
|
|
13
|
1. Practice the implementation and declaration of classes in C++.
|
15
|
1. Practice the implementation and declaration of classes in C++.
|
14
|
2. Implement methods in a class.
|
16
|
2. Implement methods in a class.
|
|
|
|
|
17
|
|
19
|
|
18
|
Before you get to the laboratory you should have:
|
20
|
Before you get to the laboratory you should have:
|
19
|
|
21
|
|
20
|
- 1. Reviewed the implementation and declaration of C++ classes
|
|
|
21
|
- 2. Studied the concepts and instructions for this laboratory session.
|
|
|
22
|
- 3. Taken the Pre-Lab quiz in Moodle
|
|
|
|
|
22
|
+1. Reviewed the implementation and declaration of C++ classes
|
|
|
23
|
+2. Studied the concepts and instructions for this laboratory session.
|
|
|
24
|
+3. Taken the Pre-Lab quiz in Moodle
|
|
|
25
|
+
|
|
|
26
|
+---
|
|
|
27
|
+
|
|
|
28
|
+---
|
23
|
|
29
|
|
24
|
## Communication among computers
|
30
|
## Communication among computers
|
25
|
|
31
|
|
|
|
|
|
37
|
|
43
|
|
38
|
---
|
44
|
---
|
39
|
|
45
|
|
40
|
-## Packet Sniffer
|
|
|
|
|
46
|
+## Simple Packet Sniffer
|
41
|
|
47
|
|
42
|
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 flow across the network, the sniffer captures each packet and, if needed decodes the packet's raw data[1].
|
43
|
|
49
|
|
|
|
|
|
68
|
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 addtional information of the packets. Additinally it detects the non encrypted requests of images in the web, and displays the images in a GUI.
|
69
|
|
75
|
|
70
|
---
|
76
|
---
|
|
|
77
|
+
|
71
|
---
|
78
|
---
|
72
|
|
79
|
|
73
|
## Laboratory session:
|
80
|
## Laboratory session:
|
74
|
|
81
|
|
75
|
The application that you will complete today allows the users to analyze network traffic and to 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 to monitor the images that are being tranfered through the net.
|
76
|
|
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.
|
|
|
85
|
+
|
77
|
---
|
86
|
---
|
78
|
|
87
|
|
79
|
![](images/ss.png)
|
88
|
![](images/ss.png)
|
|
|
|
|
82
|
|
91
|
|
83
|
---
|
92
|
---
|
84
|
|
93
|
|
85
|
-
|
|
|
86
|
-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.
|
|
|
87
|
-
|
|
|
88
|
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.
|
89
|
|
95
|
|
90
|
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.
|
91
|
|
97
|
|
92
|
-## Exercise 1: Familiriaze your self with the application
|
|
|
|
|
98
|
+### Exercise 1 - Familiarize yourself with the application
|
|
|
99
|
+
|
|
|
100
|
+#### Instructions:
|
|
|
101
|
+
|
|
|
102
|
+1. Load the project `SimpleSniffer` into `QtCreator`. There are two ways to do this:
|
93
|
|
103
|
|
94
|
-Instructions
|
|
|
|
|
104
|
+ * Using the virtual machine: Double click the file `SimpleSniffer.pro` located in the folder `/home/eip/labs/classes-simplesniffer` of your virtual machine.
|
|
|
105
|
+ * 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.
|
95
|
|
106
|
|
96
|
- 1. To load this project you need to run qt creator with root privileges.
|
|
|
97
|
- ```sudo qtcreator Documents/eip/simplesniffer/SimpleSniffer.pro```
|
|
|
98
|
- 2.The project `SimpleSniffer` is in the directory `Documents/eip/simplesniffer` of your computer. You can also go to `http://bitbucket.org/eip-uprrp/classes-simplesniffer` to download the folder `classes-simplesniffer` to your computer.
|
|
|
99
|
- 3. Configure the project. The project consists of several files. In this laboratory you will be working with the files `ethernet_hdr.h`, `ethernet_packet.h`, `ethernet_packet.cpp`, `ip_packet.h` and `ip_packet.cpp`
|
|
|
|
|
107
|
+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`.
|
100
|
|
108
|
|
101
|
|
109
|
|
102
|
-## Exercise 2: Complete the class ethernet_packet
|
|
|
|
|
110
|
+### Exercise 2: Complete the class ethernet_packet
|
103
|
|
111
|
|
104
|
Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
112
|
Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
105
|
|
113
|
|
|
|
|
|
149
|
};
|
157
|
};
|
150
|
```
|
158
|
```
|
151
|
|
159
|
|
152
|
-Note that each object of the class `ethernet_packet` only has one attribute:
|
|
|
153
|
-
|
|
|
154
|
- * one structure of type `sniff_ethernet` named `ethernet`
|
|
|
|
|
160
|
+Note that each object of the class `ethernet_packet` only has one attribute: a structure of type `sniff_ethernet` named `ethernet`
|
155
|
|
161
|
|
156
|
The rest are methods that act as interface to the attribute:
|
162
|
The rest are methods that act as interface to the attribute:
|
157
|
|
163
|
|
158
|
-* `void setEtherDHost(u_char [])`: is a *setter* to the field `ether_dhost` of the attribute `ethernet`
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-* `void setEtherSHost(u_char [])`: is a *setter* to the field `ether_shost` of the attribute `ethernet`
|
|
|
162
|
-
|
|
|
163
|
-* `void setEtherType(u_short)`: is a *setter* for the field `ether_type` of the attribute `ethernet`
|
|
|
164
|
-
|
|
|
165
|
-* `getEtherDHost()` and `getEtherSHost()` are *getters* that return the values of `ether_dhost` and `ether_shost` in a human readable format, i.e. 6 pairs of hexadecimal digits (for example, `e0:f8:47:01:e9:90`).
|
|
|
166
|
-
|
|
|
167
|
-* `getEtherType()` is a *getter* that returns the value of `ether_type` as *unsigned char*.
|
|
|
168
|
-
|
|
|
169
|
-* the private method `string mac2string(u_char [])` receives an array of six *unsigned characters* and returns the corresponding string to its hexadecimal representation. For example, if it receives `{ 0x8A, 0x11, 0xAB, 0xFF, 0x12, 0x34}` it must return the string `"8A:11:AB:FF:12:34"`.
|
|
|
|
|
164
|
+ * `void setEtherDHost(u_char [])`: is a *setter* to the field `ether_dhost` of the attribute `ethernet`
|
|
|
165
|
+ * `void setEtherSHost(u_char [])`: is a *setter* to the field `ether_shost` of the attribute `ethernet`
|
|
|
166
|
+ * `void setEtherType(u_short)`: is a *setter* for the field `ether_type` of the attribute `ethernet`
|
|
|
167
|
+ * `getEtherDHost()` and `getEtherSHost()` are *getters* that return the values of `ether_dhost` and `ether_shost` in a human readable format, i.e. 6 pairs of hexadecimal digits (for example, `e0:f8:47:01:e9:90`).
|
|
|
168
|
+ * `getEtherType()` is a *getter* that returns the value of `ether_type` as *unsigned char*.
|
|
|
169
|
+ * the private method `string mac2string(u_char [])` receives an array of six *unsigned characters* and returns the corresponding string to its hexadecimal representation. For example, if it receives `{ 0x8A, 0x11, 0xAB, 0xFF, 0x12, 0x34}` it must return the string `"8A:11:AB:FF:12:34"`.
|
170
|
|
170
|
|
171
|
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.
|
171
|
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
|
|
172
|
|