Cn Lab 13-16 Experiments
Cn Lab 13-16 Experiments
13. Wireshark
i. Starting and Packet Capture Using Wire shark
ii. Viewing Captured Traffic
iii. Analysis and Statistics & Filters.
Wireshark is an open-source packet analyzer, It is used to track the packets so that each one is
filtered to meet our specific needs. It is commonly called as a sniffer, network protocol analyzer,
and network analyzer. It is also used by network security engineers to examine security problems.
Wireshark is a free to use application which is used to apprehend the data back and forth. It is
often called as a free packet sniffer computer application. It puts the network card into an unselective
mode, i.e., to accept all the packets which it receives.
Installing Wireshark:
The Wireshark software window is shown above, and all the processes on the network are carried
within this screen only. The options given on the list are the Interface list options. The number of
interface options will be present. Selection of any option will determine all the traffic. For
example, from the above fig. select the Wi-Fi option. After this, a new window opens up, which
will show all the current traffic on the network. Below is the image which tells us about the live
capture of packets and our Wireshark will look like:
Once you have captured some packets or you have opened a previously saved capture file, you
can view the packets that are displayed in the packet list pane by simply clicking on a packet in the
packet list pane, which will bring up the selected packet in the tree view and byte view panes.
You can then expand any part of the tree to view detailed information about each protocol in each
packet. Clicking on an item in the tree will highlight the corresponding bytes in the byte view. An
example with a TCP packet selected is shown in below. It also has the Acknowledgment number
in the TCP header selected, which shows up in the byte view as the selected bytes.
tcp.analysis.flags Wireshark can flag TCP problems. This command will only display
example is shown in fig(5). the issues that Wireshark identifies.
Example, packet loss, tcp segment not captured, etc. are some of
the problems.
It quickly identifies the problem and is widely used.
Select any packet. Right-click on it It is used if you want to work on a single connection on a TCP
and select 'Follow' and then select' conversation. Anything related to the single TCP connection will
TCP stream.' Shown in fig. (7). be displayed on the screen.
tcp contains the filter It is used to display the packets which contain such words.
For example- tcp contains Facebook In this, Facebook word in any packet in this trace file i.e., finding
Or the devices, which are talking to Facebook.
udp contains Facebook This command is useful if you are looking for a username, word,
etc.
http.request It will display all the http requests in the trace file.
For the responses or the response You can see all the servers, the client is involved.
code, you can type
http.response.code==200
tcp.flags.syn==1 This will display all the packets with the sync built-in tcp header
This is shown in fig (10). set to 1.
tcp.flags.reset This will show all the packets with tcp resets.
Statistics in Wireshark:
Wireshark provides a wide range of network statistics.These statistics range from general
information about the loaded capture file (like the number of captured packets), to statistics about
specific protocols (e.g. statistics about the number of HTTP requests and responses captured).
General statistics
• Summary about the capture file like: packet counts, captured time period.
• Protocol Hierarchy of the captured packets.
• Conversations e.g. traffic between specific Ethernet/IP/… addresses.
• Endpoints e.g. traffic to and from an Ethernet/IP/… address.
• IO Graphs visualizing the number of packets (or similar) in time.
Analysis in Wireshark:
TCP Analysis
By default, Wireshark’s TCP dissector tracks the state of each TCP session and provides additional
information when problems or potential problems are detected. Analysis is done once for each TCP
packet when a capture file is first opened. Packets are processed in the order in which they appear in the
packet list. You can enable or disable this feature via the “Analyze TCP sequence numbers” TCP
dissector preference.
TCP Analysis flags are added to the TCP protocol tree under “SEQ/ACK analysis”. Each flag is
described below. Terms such as “next expected sequence number” and “next expected acknowledgment
number” refer to the following”:
• 1 : SYN
• 2 : SYN-ACK
• 4 : ACK
• 8 : DATA
• 16 : FIN
• 32 : RST
For example, a conversation containing only a three-way handshake will be found with the filter
'tcp.completeness==7' (1+2+4) while a complete conversation with data transfer will be found with a
longer filter as closing a connection can be associated with FIN or RST packets, or even both :
'tcp.completeness==31 or tcp.completeness==47 or tcp.completeness==63'
Step 3
During installation, a helper program called WinPcap will also be installed. WinPcap is
required for Nmap to function properly on the Windows platform so do not skip this step.
After the WinPcap installation has completed you are given the option to configure its service
settings. The default options will enable the WinPcap service to start when Windows boots.
This is recommended as Nmap will not function correctly when the WinPcap service is not
running
Step 4
Once Nmap has been successfully installed you can verify it is working correctly by
executing nmap scanme.insecure.org on the command line (located in Start > Programs >
Accessories > Command Prompt).
C:\>nmap scanme.insecure.org
If the results of your scan are similar to the results above, then you have successfully installed
Nmap. If you receive an error, set the path in environment variables and run.
The resulting scan shows the status of ports detected on the specified target. The table below
describes the output fields displayed by the scan.
A default Nmap scan will check for the 1000 most commonly used TCP/IP ports. Ports that
respond to a probe are classified into one of six port states: open, closed, filtered, unfiltered,
open|filtered, closed|filtered. See Appendix B for more information about port states.
$ nmap 192.168.10.1/24
One of Nmap’s most remarkable (and incredibly useful) features is its ability to detect
operating systems and services on remote systems. This feature analyzes responses from
scanned targets and attempts to identify the host’s operating system and installed services.
The process of identifying a target’s operating system and software versions is known as
TCP/IP fingerprinting. Although it is not an exact science, Nmap developers have taken great
care in making TCP/IP fingerprinting an accurate and reliable feature.
Feature Option
Operating System Detection -O
Attempt to Guess an Unknown OS --osscan-guess
Service Version Detection -sV
Perform a RPC Scan --version-trace
Troubleshooting Version Scans -sR
...
As demonstrated above, Nmap is (in most cases) able to identify the operating system on a
remote target. Operating system detection is performed by analyzing responses from the target
for a set of predictable characteristics which can be used to identify the type of OS on the
remote system.
In order for OS detection to work properly there must be at least one open and one closed port
on the target system. When scanning multiple targets, the --osscan-limit option can be combined
with -O to instruct Nmap not to OS scan hosts that do not meet this criteria.
Attempt to Guess an Unknown Operating System:
If Nmap is unable to accurately identify the OS, you can force it to guess by using the --
osscan-guess option.
The example above displays a list of possible matches for the target’s operating system. Each
guess is listed with a percentage of confidence Nmap has in the supplied match.
i. NS2 Simulator-Introduction
Network Simulator (Version 2), widely known as NS2, is simply an event driven simulation tool
that has proved useful in studying the dynamic nature of communication networks. Simulation
of wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP)
can be done using NS2.
BASIC ARCHITECTURE:
Figure 2.1 shows the basic architecture of NS2. NS2 provides users with an executable
command ns which takes on input argument, the name of a Tcl simulation scripting file. Users
are feeding the name of a Tcl simulation script (which sets up a simulation) as an input argument
of an NS2 executable command ns.
In most cases, a simulation trace file is created, and is used to plot graph and/or to create
animation. NS2 consists of two key languages: C++ and Object-oriented Tool Command Language
(OTcl). While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects,
the OTcl sets up simulation by assembling and configuring the objects as well as scheduling
discrete events (i.e., a fronten).
The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object, variables in the
OTcl domains are sometimes referred to as handles. Conceptually, a handle (e.g., n as a Node
handle) is just a string (e.g.,_o10) in the OTcl domain, and does not contain any functionality.
Instead, the functionality (e.g., receiving a packet) is defined in the mapped C++ object (e.g., of
class Connector). In the OTcl domain, a handle acts as a frontend which interacts with users and
other OTcl objects. It may defines its own procedures and variables to facilitate the interaction.
Note that the member procedures and variables in the OTcl domain are called instance
procedures (instprocs) and instance variables (instvars), respectively. Before proceeding further,
COMPUTER NETWORKS LAB Regd. No: _____________________
ADITYA COLLEGE OF ENGINEERING & TECHNOLOGY PAGE NO: ___
the readers are encouraged to learn C++ and OTcl languages. We refer the readers to [14] for the
detail of C++, while a brief tutorial of Tcl and OTcl tutorial are given in Appendices A.1 and A.2,
respectively.
INSTALLATION OF NS2:
1. Install Ubuntu as virtual machine by using Oracle VM Virtual Box Manager.
2. Install NS2 by using the command in terminal.
sudo apt-get install ns2
3. Nam is also needed to install. Nam (Network Animator) is an animation tool to
graphically represent the network and packet traces. Use this command.
sudo apt-get install nam
4. Install tcl by using the command in terminal
sudo apt install tcl
CONCEPT OVERVIEW:
Tcl scripting
Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.
Basics of TCL
Syntax: command arg1 arg2 arg3
Hello World!
puts stdout{Hello, World!} Hello, World!
Variables Command
Substitution set a 5 set len
[string length foobar]
set b $a set len [expr [string length foobar] + 9]
NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.
Initialization and Termination of TCL Script in NS-2
An ns simulation starts with the command
set ns [new Simulator]
Which is thus the first line in the tcl script. This line declares a new variable as using the set
command, you can call this variable as you wish, In general people declares it as ns because it is
an instance of the Simulator class, so an object the code[new Simulator] is indeed the installation
of the class Simulator using the reserved word new.
In order to have output files with data on the simulation (trace files) or files used for visualization
(nam files), we need to create the files using ―open command:
#Open the Trace file
set tracefile1 [open out.tr w]
$ns trace-all $tracefile1
#Open the NAM trace file
Set namefile [open out.nam w]
$ns namtrace-all $namfile
#Setup a UDP
[new Agent/UDP]
$ns attach-agent $n1
$udp set null [new
Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_2
TCP has many parameters with initial fixed defaults values that can be changed if mentioned
explicitly. For example, the default TCP packet size has a size of 1000bytes.This can be changed
to another value, say 552bytes, using the command $tcp set packetSize_ 552.
When we have several flows, we may wish to distinguish them so that we can identify them
with different colors in the visualization part. This is done by the command $tcp set fid_ 1 that
assigns to the TCP connection a flow identification of ―1.We shall later give the flow
identification of ―2‖ to the UDP connection.
Output:
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n0 label "ping0"
$n1 label "ping1"
$n2 label "R1"
$n3 label "R2"
$n4 label "ping4"
$n5 label "ping5"
$ns color 1 red
$ns color 2 blue
$ns color 3 green
$ns color 4 orange
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
Output: