Cn-Lab-Manual Rkce
Cn-Lab-Manual Rkce
Cn-Lab-Manual Rkce
1. LIST OF EXPERIMENTS
Page
S. No. Experiment No.
Study of Network devices in detail and connect the
1. 6
computers in Local Area Networks.
Write a Program to implement the data link layer framing
2. 11, 14
methods such as ( i ) Character Stuffing ( ii ) Bit Stuffing.
Write a Program to implement the data link layer framing
3. 16
methods Checksum.
Write a Program for Hamming Code Generation for error
4. 20
deduction and correction.
5. Write a Program to implement on a data set of characters the 22
three CRC polynomials - CRC 12, CRC 16 and CRC CCIP.
6 Write a Program to implement Slidinng window protocol for 25
Goback N .
Write a Program to implement Slidinng window protocol for
7. 28
Selective repeat.
8. Write a Program to implement Stop and Wait Protocol.
Write a program for congestion control using leaky bucket
9.
algorithm.
Write a program to implement Dijkstra’s algorithm to
10. 32
compute Shortes path through a graph.
Write a Program to implement Distance vector routing
algorithm buy obtaining routing table at each node. (Take an
11. 35
example subnet grapoh with weights indicating delay
between nodes).
Write a Program to implement Broadcast tree by taking
12. 38
subnet of nosts.
Wireshark
I. Packet Captuire Using wire shark. 41
13. II. Starting Wire Shark. 47
III. Viewing Captured Traffic. 51
IV. Analysis and Statistics & Filters. 52
14. How to run Nimap scan. 55
15. Operating System Detection using Nmap. 67
Do the following using NS2 Simulator.
i . NS2 Simulator-Introduction.
ii . Simulate to Find the Number of Packets Dropped.
iii . Simulate to Find the Numnber of Packets Dropped by
16. 1
TCP/UDP.
iv . Simulate to Find the Numnber of Packets Dropped to
Congestion.
v . Simulate to Compare Data Rate & Throughput.
2
EXPERIMENT NO: 1
(1 a)
NAME OF THE EXPERIMENT: Study of Network devices in details and connect the
Computers in Local Area Network.
OBJECTIVE: Study of Network devices used in LAN
RESOURCE : Computer Networks Text Book by Stallings.
3
1. Switch:A network switch or switching hub is a computer networking device that
connects network segments.The term commonly refers to a network bridge that processes
and routes data at the data link layer (layer 2) of the OSI model. Switches that additionally
process data at the network layer (layer 3 and above) are often referred to as Layer 3
switches or multilayer switches.
3. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator
is a device for connecting multiple twisted pair or fiber optic Ethernet devices together and
making them act as a single network segment. Hubs work at the physical layer (layer 1) of
the OSI model. The device is a form of multiport repeater. Repeater hubs also participate
in collision detection, forwarding a jam signal to all ports if it detects a collision.
4. Bridge: A network bridge connects multiple network segments at the data link layer
(Layer 2) of the OSI model. In Ethernet networks, the term bridge formally means a device
that behaves according to the IEEE 802.1D standard. A bridge and switch are very much
alike; a switch being a bridge with numerous ports. Switch or Layer 2 switch is often used
interchangeably with bridge.Bridges can analyze incoming data packets to determine if the
bridge is able to send the given packet to another segment of the network.
5. Gate Way: In a communications network, a network node equipped for interfacing with
another network that uses different protocols.
• A gateway may contain devices such as protocol translators, impedance matching
devices, rate converters, fault isolators, or signal translators as necessary to provide
system interoperability. It also requires the establishment of mutually acceptable
administrative procedures between both networks.
• A protocol translation/mapping gateway interconnects networks with different
network protocol technologies by performing the required protocol conversions.
8. Repeater: A repeater is an electronic device that amplifies the signal it receives. You can think
of repeater as a device which receives a signal and retransmits it at a higher level or higher power so
that the signal can cover longer distances, more than 100 meters for standard LAN cables. Repeaters
work on the Physical layer.
9. Access Point: While an access point (AP) can technically involve either a wired or wireless
connection, it commonly means a wireless device. An AP works at the second OSI layer, the Data
Link layer, and it can operate either as a bridge connecting a standard wired network to wireless
devices or as a router passing data transmissions from one access point to another.
Wireless access points (WAPs) consist of a transmitter and receiver (transceiver) device used to
create a wireless LAN (WLAN). Access points typically are separate network devices with a built-
in antenna, transmitter and adapter. APs use the wireless infrastructure network mode to provide a
connection point between WLANs and a wired Ethernet LAN. They also have several ports, giving
you a way to expand the network to support additional clients. Depending on the size of the
network,
one or more APs might be required to provide full coverage. Additional APs are used to allow
access to more wireless clients and to expand the range of the wireless network.
Each AP is limited by its transmission range — the distance a client can be from an AP and still
obtain a usable signal and data process speed. The actual distance depends on the wireless standard,
the obstructions and environmental conditions between the client and the AP. Higher end APs have
high-powered antennas, enabling them to extend how far the wireless signal can travel.
APs might also provide many ports that can be used to increase the network’s size, firewall
capabilities and Dynamic Host Configuration Protocol (DHCP) service. Therefore, we get APs that
are a switch, DHCP server, router and firewall.
To connect to a wireless AP, you need a service set identifier (SSID) name. 802.11 wireless
networks use the SSID to identify all systems belonging to the same network, and client stations
must be configured with the SSID to be authenticated to the AP. The AP might broadcast the SSID,
allowing all wireless clients in the area to see the AP’s SSID. However, for security reasons, APs
can be configured not to broadcast the SSID, which means that an administrator needs to give client
systems the SSID instead of allowing it to be discovered automatically. Wireless devices ship with
default SSIDs, security settings, channels, passwords and usernames. For security reasons, it is
strongly recommended that you change these default settings as soon as possible because many
internet sites list the default settings used by manufacturers.
Access points can be fat or thin. Fat APs, sometimes still referred to as autonomous APs, need to be
5
manually configured with network and security settings; then they are essentially left alone to serve
clients until they can no longer function. Thin APs allow remote configuration using a controller.
Since thin clients do not need to be manually configured, they can be easily reconfigured and
monitored. Access points can also be controller-based or stand-alone.
Conclusion: Having a solid understanding of the types of network devices available can help you
design and built a network that is secure and serves your organization well. However, to ensure the
ongoing security and availability of your network, you should carefully monitor your network
devices and activity around them, so you can quickly spot hardware issues, configuration issues and
attacks.
On the host computer, follow these steps to share the Internet connection:
8. Under Internet Connection Sharing, select the Allow other network users to
Connect through this computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up
connection whenever a computer on my network attempts to access the Internet
check box if you want to permit your computer to automatically connect to the
Internet.
When Internet Connection Sharing is enabled, your LAN adapter will be set to use IP
address
192.168.0.1. Your computer may lose connectivity with other computers on your network.
If
6
these other computers have static IP addresses, it is a good idea to set them to obtain their IP
addresses automatically. Are you sure you want to enable Internet Connection Sharing?
To connect to the Internet by using the shared connection, you must confirm the LAN
adapter IP configuration, and then configure the client computer. To confirm the LAN
adapter IP configuration, follow these steps:
Note: You can also assign a unique static IP address in the range of 192.168.0.2
to 192.168.0.254. For example, you can assign the following static IP
address, subnet mask, and default gateway:
8. IP Address 192.168.31.202
9. Subnet mask 255.255.255.0
1. Default gateway 192.168.31.1
7
EXPERIMENT NO: 2
(2a)
SOURCE CODE:
// BIT Stuffing
program
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("Enter frame
length:"); scanf("%d",&n);
printf("Enter input frame (0's & 1's
only):"); for(i=0;i<n;i++)
scanf("%d",&a[i])
; i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 && k<n &&count<5;k++)
{
j++;
b[j]=a[k]; count+
+; if(count==5)
8
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
} i+
+;
j++;
}
printf("After stuffing the frame
is:"); for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}
OUTPUT:
Viva questions:
1. What is Stuffing?
2. What is use of Stuffing?
3. With bit stuffing the boundary between two frames can be unambiquously recognize
9
by?
4. is a analogous to character stuffing?
5. The senders data link layer encounters......no of 1’s consecutively
10
EXPERIMENT NO: 2
2(b)
SOURCE CODE:
//PROGRAM FOR CHARACTER STUFFING
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;char
a[20],b[50],ch; clrscr();
printf("enter string\
n"); scanf("%s",&a);
n=strlen(a);
printf("enter position\
n"); scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again
:"); scanf("%d",&pos);
}
printf("enter the character\
n"); ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
11
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
getch();
}
12
OUTPUT:
Viva Questions:
1. What is Character stuffing?
2. What is the use of character stuffing?
3. _ _ _ _ _ _are the delimiters for the character stuffing?
4. Expand DLE STX?
5. Expand DLE ETX?
13
EXPERIMENT NO: 3
NAME OF THE EXPERIMENT: Program to implement data link layer framing method checksum.
OBJECTIVE:The Checksum is an error detection method that detected errors in data/message
while it is transmitted from sender to receiver. This method is used by the higher layer protocols
and makes use of the Checksum Generator on the Sender side and Checksum Checker on the
Receiver side.
RESOURCE: Turbo C
PROGRAM LOGIC or APPROACH : The given problem can be divided into two
following parts:
Generating the Checksum value of the sender’s message can be done using the following
steps:
Divide the message into the binary strings of the given block size.
All the binary strings are added together to get the sum.
The One’s Complement of the binary string representing the sum is the required
checksum value.
Check if the value of the received message (i.e, rec_message + senders_checksum) is
equal to 0.
The checksum of the received message can be calculated similarly to the checksum
calculated in the above process.
If the checksum value is 0, the message is transmitted properly with no errors
otherwise, some error has occurred during the transmission.
Below is the implementation of the above approach:
14
// C++ implementation of the above approach
#include <bits/stdc++.h>
using namespace std;
return data;
}
No Error
Time Complexity: O(N)
Auxiliary Space: O(block_size)
EXPERIMENT NO: 4
NAME OF THE EXPERIMENT: Write a program for Hamming Code generaion for Error
detection and correction
OBJECTIVE: Hamming Code generaion for Error detection and correction.
RESOURCE: Turbo C
PROGRAM LOGIC:
. #include<stdio.h>
. #include<conio.h>
. void main() {
. int data[7],rec[7],i,c1,c2,c3,c;
. printf("this works for message of 4bits in size \nenter message bit
. one by one: ");
. scanf("%d%d%d%d",&data[0],&data[1],&data[2],&data[4]);
. data[6]=data[0]^data[2]^data[4];
. data[5]=data[0]^data[1]^data[4];
. data[3]=data[0]^data[1]^data[2];
. printf("\nthe encoded bits are given below: \n");
. for (i=0;i<7;i++) {
. printf("%d ",data[i]);
. }
. printf("\nenter the received data bits one by one: ");
. for (i=0;i<7;i++) {
. scanf("%d",&rec[i]);
. }
. c1=rec[6]^rec[4]^rec[2]^rec[0];
. c2=rec[5]^rec[4]^rec[1]^rec[0];
. c3=rec[3]^rec[2]^rec[1]^rec[0];
. c=c3*4+c2*2+c1 ;
. if(c==0) {
. printf("\ncongratulations there is no error: ");
. } else {
. printf("\nerron on the postion: %d\nthe correct message is \n",c);
. if(rec[7-c]==0)
. rec[7-c]=1; else
16
. rec[7-c]=0;
. for (i=0;i<7;i++) {
. printf("%d ",rec[i]);
. }
. }
. getch();
. }
Output
17
EXPERIMENT NO: 5
SOURCE CODE:
//PROGRAM FOR CYCLIC REDUNDENCY CHECK
#include<stdio.h>
#include<conio.h>
int
gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
clrscr();
frl=8;
genl=4;
printf("enter
frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("enter
18
generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
remainder(dupfr);
for(i=0;i<frl;i++)
{
recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}
remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{
if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame received correctly");
}
Else
{
printf("the received frame is wrong");
}
getch();
}
remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k; for(i=0,j=k;i<genl;i+
+,j++)
{
rem[i]=fr[j]^gen[i];
}
19
for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}
20
OUTPUT:
Viva Questions:
1. What is CRC?
2. What is the use of the CRC?
3. Name the CRC standards?
4. Define Checksum?
5. Define generator polynomial?
21
EXPERIMENT NO: 6
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if (sent = = windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack = = windowsize)
break;
else
sent = ack;
}
return 0;
}
22
OUTPUT:-
** ** **
23
EXAMPLE-2 :
#include<stdio.h>
#include<conio.h>
void main()
{
char sender[50],receiver[50];
int i,winsize;
printf("\n ENTER THE WINDOWS SIZE : ");
scanf("%d",&winsize);
printf("\n SENDER WINDOW IS EXPANDED TO STORE MESSAGE OR
WINDOW \n");
printf("\n ENTER THE DATA TO BE SENT: ");
fflush(stdin);
gets(sender);
for(i=0;i<winsize;i++)
receiver[i]=sender[i];
receiver[i]=NULL;
printf("\n MESSAGE SEND BY THE SENDER:\n");
puts(sender);
printf("\n WINDOW SIZE OF RECEIVER IS EXPANDED\n");
printf("\n ACKNOWLEDGEMENT FROM RECEIVER \n");
for(i=0;i<winsize;i++);
printf("\n ACK:%d",i);
printf("\n MESSAGE RECEIVED BY RECEIVER IS : ");
puts(receiver);
printf("\n WINDOW SIZE OF RECEIVER IS SHRINKED \n");
getch();
}
------------------------------------------------------------------------------------------------------------------
Output.…
24
EXPERIMENT NO: 7
25
The sending and receiving window may not have the same size or any upper or lower
limits.
Selective Repeat Protocol :
The selective repeat protocol is an implementation of the sliding window protocol. In the
selective repeat protocol, both the sender and the receiver maintain a window of outstanding
and acceptable sequence numbers.
In SRP, the sender's window size starts at 0 and it grows to some predefined maximum.
The receiver's window is always fixed in size and equal to the predetermined maximum.
The receiver has the buffer reserved for each sequence number within its fixed window.
The sender and the receiver maintain a buffer of their window size.
If there is an error, the receiver checks the lower edge to the last sequence number before
the lost frame sequence number.
The receiver continues to receive and acknowledge incoming frames.
The sender maintains a timeout clock for the unacknowledged frame number and
retransmits that frame after the timeout.
The acknowledgment will be piggybacked to the sender. But when there is no traffic in the
reverse direction, piggyback is impossible, a special timer will time out for the ACK so
that the ACK is sent back as an independent packet. If the receiver suspects that the
transmission has an error, it immediately sends back a negative acknowledgment (NAK) to
the sender.
26
Note − SRP works better when the link is very unreliable. Because in this case, retransmission tends
to happen more frequently, selectively retransmitting frames is more efficient than retransmitting all
of them. In selective repeat protocol, the size of the sender and receiver windows must be at most
one-half of 2.
EXPERIMENT NO: 10
29
given graph.
RESOURCE: Turbo C
PROGRAM LOGIC: Dijkstra's algorithm is very similar to Prim's algorithm for
minimum spanning tree. Like Prim's MST, we generate a SPT (shortest path tree) with given
source as root. We maintain two sets, one set contains vertices included in shortest path tree,
and other set includes vertices not yet included in shortest path tree.
SOURCE CODE:
// .PROGRAM FOR FINDING SHORTEST PATH FOR A GIVEN GRAPH//
#include<stdio.h>
#include<conio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index; clrscr();
printf("enter the cost matrix\n");
for(i=1;i<=5;i++) for(j=1;j<=5;j++)
scanf("%d",&a[i][j]); printf("enter
the paths\n"); scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++) for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{ t[i]=0
;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
30
}min=t[st];
index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
getch();
}
31
Output:
Viva questions:
32
EXPERIMENT NO: 11
RESOURCE: Turbo C
SOURCE CODE:
#include<stdio.h>
#include<conio.h
> struct node
{
unsigned dist[20];
unsigned
from[20];
}rt[10];
int main()
33
{
int dmat[20][20];
int n,i,j,k,count=0;
clrscr();
printf("\nEnter the number of nodes : ");
scanf("%d",&n);printf("Enter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
Do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;count++;
}
}while(count!=0);
for(i=0;i<n;i++)
{
printf("\nState value for router %d is \
n",i+1); for(j=0;j<n;j++)
{
printf("\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf(“\n”);
}
34
Output:
Viva Questions:
1. What is routing?
2. What is best algorithm among all routing algorithms?
3. What is static routing?
4. Differences between static and dynamic?
5. What is optimality principle?
35
EXPERIMENT No :12
Else
{
t[i][0]=-1;t[i][1]=-1;
}
min=99;
}
printf("Minimum cost is %d\n Minimum spanning tree is\n"
,mincost); for(i=0;i<n;i++)
if(t[i][0]!=-1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0],65+t[i][1],edge[t[i][0]][t[i][1]]);printf("\n");
}
getch();
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>0)
i=parent[i];
return i;
37
Output:
Viva questions:
38
EXPERIMENT No :13
13 ( i )
It can capture, dissect, and decode various protocols. This helps Linux sysadmin to
troubleshoot network issues.
Apart from using wirehshark as a standlone application for debugging network packets, you
can also write your own extension or plugin using wireshark libraries for your custom
application.
This tutorial explains how to use wireshark libraries to write custom code to debug network
packets using a C example program.
The code explains two parts. First, to capture network packets. Second, to decode packets
using libwireshark.
As a prerequisite, your system should have both libpcap and wireshark libraries installed.
To capture a packet, refer to How to Perform Packet Sniffing Using Libpcap with C Example
Code.
You can also open an existing pcap file using the following api inside your C program:
pd = pcap_open_offline(pcap_path, errbuf);
Wireshark code uses its own dissection engine (epan module library) to dissect the network
packets.
The functions mentioned below are from the wireshark open source code, which will initialize
the packet dissection engine, required data structures, variables, GUID mapping, memory
allocation subsystem, registering all the protocol dissector handles, host name lookup, that are
necessary for dissection process.
39
An example
The code below makes use of the libpcap functions to achieve a basic packet capture. After
capturing the packets, inside the callback function, the length of each packet is printed on
stdout.
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <string.h>
41
// fetch the network address and network mask
pcap_lookupnet(dev, &pNet, &pMask, errbuf);
Output:
The function pcap_findalldevs() is used to fetch a list of all available interface devices. This list
can be shown to the user so that the intended interface can be selected to sniff packets on. Please
note that these is exists a function pcap_lookupdev() that also returns an interface device but the
42
problem with this function is that it returns the first available non loop-back device. So in case I
am using wireless network connection and the interface device for my connection is ‘wlan0’ but
pcap_lookupdev() function would still return ‘eth0’ as it encounters this interface first. So using
pcap_findalldevs() is a better option as it produces a list of interface devices to choose from.
The list returned by the function pcap_findalldevs() is given to user and the user’s input is
taken from stdin.
Then the function pcap_lookupnet() is used to fetch the ip address and network mask.
Through the function pcap_open_live() the pcap library is initialized with the interface device
selected.
Through pcap_compile() function , we can compile any filter on protocol etc set by the user.
Through pcap_setfilter(), this filter is applied.
Finally through function pcap_loop() the library starts packet capture on the selected device
with the filter applied and with every relevant packet captured, the callback function is called.
Enter the interface name on which you want to run the packet sniffer : wlan0
43
Packet number [8], length of this packet is: 66
If you are not executing the above program as root, you should use sudo to run the program as the
actions done by libpcap library requires super user privileges.
44
EXPERIMENT No : 13
13 ( i i )
$ wireshark -i eth0 -k
This will start Wireshark capturing on interface eth0. More details can be found at Section 11.2,
“Start Wireshark from the command line”.
45
EXPERIMENT No : 13
13 ( i ii )
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 Figure 6.1, “Wireshark with a TCP packet
selected for viewing”. It also has the Acknowledgment number in the TCP header selected,
which
shows up
in the byte
view as
the
selected
bytes.
Figure 6
.1 . Wiresh
ar k with a
TCP
packet
selected
for
viewing
You can
also
select
and view
packets
the same
way
while
46
Wireshark is capturing if you selected “Update list of packets in real time” in the “Capture
Preferences” dialog box.
In addition you can view individual packets in a separate window as shown in Figure 6.2,
“Viewing a packet in a separate window”. You can do this by double-clicking on an item in the
packet list or by selecting the packet in which you are interested in the packet list pane and
selecting View → Show Packet in New Window. This allows you to easily compare two or
more packets, even across multiple files.
Along with double-clicking the packet list and using the main menu there are a number of other
ways to open a new packet window:
47
EXPERIMENT No : 13
13 ( i v)
The Wireshark Statistics menu contains the fields shown in Table 3.9, “Statistics menu items”.
Each
menu item
brings up
a new
window
showing
specific
statistics.
Table 3.9
. Statistics
menu
items
48
Menu Item Accelerator Description
49
BACnet See Section 8.15, “BACnet”
EXPERIMENT No : 14
1. Download the Nmap installer. This can be found for free from the developer’s website. It
is highly recommended that you download directly from the developer to avoid any potential
viruses or fake files. Downloading the Nmap installer includes Zenmap, the graphical interface
for Nmap which makes it easy for newcomers to perform scans without having to learn
command lines.
The Zenmap program is available for Windows, Linux, and Mac OS X. You can find the
installation files for all operating systems on the Nmap website.
50
.
51
2. Install Nmap. Run the installer once it is finished downloading. You will be asked which
components you would like to install. In order to get the full benefit of Nmap, keep all of these
checked. Nmap will not install any adware or spyware.
52
3. Run the "Nmap – Zenmap" GUI program. If you left your settings at default during
installation, you should be able to see an icon for it on your desktop. If not, look in your
Start menu. Opening Zenmap will start the program.
.
53
4. Enter in the target for your scan. The Zenmap program makes scanning a fairly simple
process. The first step to running a scan is choosing your target. You can enter a domain
(example.com), an IP address (127.0.0.1), a network (192.168.1.0/24), or a combination of
those.
Depending on the intensity and target of your scan, running an Nmap scan may be
against the terms of your internet service provider, and may land you in hot water.
Always check your local laws and your ISP contract before performing Nmap scans on
targets other than your own network.
54
5.Choose your Profile. Profiles are preset groupings of modifiers that change what is scanned.
The profiles allow you to quickly select different types of scans without having to type in the
modifiers on the command line. Choose the profile that best fits your needs:[1]
55
6. Click Scan to start scanning. The active results of the scan will be displayed in the Nmap
Output tab. The time the scan takes will depend on the scan profile you chose, the physical
distance to the target, and the target’s network configuration.
7. Read your results. Once the scan is finished, you’ll see the message "Nmap done" at the
bottom of the Nmap Output tab. You can now check your results, depending on the type of
scan you performed. All of the results will be listed in the main Nmap Output tab, but you can
use the other tabs to get a better look at specific data.[2]
Ports/Hosts - This tab will show the results of your port scan, including the services
for those ports.
Topology - This shows the traceroute for the scan you performed. You can see how
many hops your data goes through to reach the target.
Host Details - This shows a summary of your target learned through scans, such as
the number of ports, IP addresses, hostnames, operating systems, and more.
Scans - This tab stores the commands of your previously-run scans. This allows
you to quickly re-scan with a specific set of parameters.
56
METHOD-2
1. Install Nmap. Before using Nmap, you will need to install it so that you can run it from the
command line of your operating system. Nmap is small and available for free from the
developer. Follow the instructions below for your operating system:
.
Linux - Download and install Nmap from your repository. Nmap is available through
most of the major Linux repositories. Enter in the command below based on your
distribution:
Red Hat, Fedora, SUSE
rpm -vhU http://nmap.org/dist/nmap-6.40-1.i386.rpm (32-bit) OR
rpm -vhU http://nmap.org/dist/nmap-6.40-1.x86_64.rpm (64-bit)
Debian, Ubuntu
sudo apt-get install nmap
Windows - Download the Nmap installer. This can be found for free from the
developer’s website. It is highly recommended that you download directly from the
57
developer to avoid any potential viruses or fake files. Using the installer allows you to
quickly install the command line Nmap tools without having to worry about extracting to
the right folder.
If you don’t want the Zenmap graphical user interface, you can uncheck it during the
installation process.
Mac OS X – Download the Nmap disk image. This can be found for free from the
developer’s website. It is highly recommended that you download directly from the
developer to avoid any potential viruses or fake files. Use the included installer to install
Nmap on your system. Nmap requires OS X 10.6 or later.
58
2. Open your command line. Nmap commands are run from the command line, and the
results are displayed beneath the command. You can use variables to modify the scan.
You can run the scan from any directory on the command line.
Linux - Open the terminal if you are using a GUI for your Linux distribution. The
location of the terminal varies by distribution
Windows - This can be accessed by pressing the Windows key + R and then typing
"cmd" into the Run field. Windows 8 users can press Windows key + X and select
Command Prompt from the menu. You can run an Nmap scan from any directory.
Mac OS X - Open the Terminal application located in the Utility subfolder of your
Applications folder.
59
.
60
3. Run a scan of you target’s ports. To start a basic scan, type nmap <target>. This will
ping the target and scan the ports. This is an easily-detected scan. The results will be
displayed on your screen. You may need to scroll back up to see all of the results.
.
Depending on the intensity and target of your scan, running an Nmap scan may be
against the terms of your internet service provider, and may land you in hot water.
Always check your local laws and your ISP contract before performing Nmap scans on
targets other than your own network.
61
4. Run a modified scan. You can use command line variables to change the parameters
of the scan, resulting in more detailed or less detailed results. Changing the scan
variables will change the intrusiveness of the scan. You can add multiple variables by
placing a space between each one. Variables come before the target: nmap <variable>
<variable> <target>[3]
.
-sS - This is a SYN stealth scan. It is less detectable than a standard scan, but may
take longer. Many modern firewalls can detect an –sS scan.
-sn - This is a ping scan. This will disable port scanning, and will only check to see
if the host is online.
-O - This is an operating system scan. The scan will attempt to determine the
operating system of the target.
-A - This variable enables several of the most commonly used scans: OS detection,
version detection, script scanning, and traceroute.
-F - This enables fast mode, and will reduce the number of ports scanned.
-v - This will show more information in your results, making them easier to read.
.
62
5. Output the scan to an XML file. You can set your scan results to be outputted as an
XML file so that you can easily read them in any web browser. To do this, you will need to
use the -oX variable, as well as set a filename for the new XML file. A completed command
would look similar to nmap –oX Scan Results.xml <target>.
The XML file will be saved to whatever your current working location is.
63
EXPERIMENT No : 15
One of Nmap's best-known features is remote OS detection using TCP/IP stack fingerprinting.
Nmap sends a series of TCP and UDP packets to the remote host and examines practically
every bit in the responses. After performing dozens of tests such as TCP ISN sampling, TCP
options support and ordering, IP ID sampling, and the initial window size check, Nmap
compares the results to its nmap-os-db database of more than 2,600 known OS fingerprints and
prints out the OS details if there is a match. Each fingerprint includes a freeform textual
description of the OS, and a classification which provides the vendor name (e.g. Sun),
underlying OS (e.g. Solaris), OS generation (e.g. 10), and device type (general purpose, router,
switch, game console, etc). Most fingerprints also have a Common Platform Enumeration
(CPE) representation, like cpe:/o:linux:linux_kernel:2.6.
If Nmap is unable to guess the OS of a machine, and conditions are good (e.g. at least one open
port and one closed port were found), Nmap will provide a URL you can use to submit the
fingerprint if you know (for sure) the OS running on the machine. By doing this you contribute
to the pool of operating systems known to Nmap and thus it will be more accurate for
everyone.
OS detection enables some other tests which make use of information that is gathered during
the process anyway. One of these is TCP Sequence Predictability Classification. This measures
approximately how hard it is to establish a forged TCP connection against the remote host. It is
useful for exploiting source-IP based trust relationships (rlogin, firewall filters, etc) or for
hiding the source of an attack. This sort of spoofing is rarely performed any more, but many
machines are still vulnerable to it. The actual difficulty number is based on statistical sampling
and may fluctuate. It is generally better to use the English classification such as “worthy
challenge” or “trivial joke”. This is only reported in normal output in verbose (-v) mode. When
verbose mode is enabled along with -O, IP ID sequence generation is also reported. Most
machines are in the “incremental” class, which means that they increment the ID field in the IP
header for each packet they send. This makes them vulnerable to several advanced information
gathering and spoofing attacks.
Another bit of extra information enabled by OS detection is a guess at a target's uptime. This
uses the TCP timestamp option (RFC 1323) to guess when a machine was last rebooted. The
guess can be inaccurate due to the timestamp counter not being initialized to zero or the
counter overflowing and wrapping around, so it is printed only in verbose mode.
-O (Enable OS detection)
Enables OS detection, as discussed above. Alternatively, you can use -A to enable OS
detection along with other things.
Specifying a lower --max-os-tries value (such as 1) speeds Nmap up, though you miss out on
retries which could potentially identify the OS. Alternatively, a high value may be set to allow
even more retries when conditions are favorable. This is rarely done, except to generate better
fingerprints for submission and integration into the Nmap OS database.
Introduction
While Nmap has supported OS detection since 1998, this chapter describes the 2nd generation
system released in 2006.
While some benefits of discovering the underlying OS and device types on a network are
obvious, others are more obscure. This section lists the top reasons I hear for discovering this
extra information.
65
OS detection can help reduce these false positives. For example, the Rwho daemon on
unpatched Sun Solaris 7 through 9 may be remotely exploitable (Sun alert #57659). Remotely
determining vulnerability is difficult, but you can rule it out by finding that a target system is
running Solaris 10.
Taking this from the perspective of a systems administrator rather than a pen-tester, imagine
you run a large Sun shop when alert #57659 comes out. Scan your whole network with OS
detection to find machines which need patching before the bad guys do.
Tailoring exploits
Even after you discover a vulnerability in a target system, OS detection can be helpful in
exploiting it. Buffer overflows, format-string exploits, and many other vulnerabilities often
require custom-tailored shellcode with offsets and assembly payloads generated to match the
target OS and hardware architecture. In some cases, you only get one try because the service
crashes if you get the shellcode wrong. Use OS detection first or you may end up sending
Linux shellcode to a FreeBSD server.
While it isn't as exciting as busting root through a specially crafted format string exploit, there
are many administrative reasons to keep track of what is running on your network. Before you
renew that IRIX support contract for another year, scan to see if anyone still uses such
machines. An inventory can also be useful for IT budgeting and ensuring that all company
equipment is accounted for.
With the ubiquity of mobile devices and cheap commodity networking equipment, companies
are increasingly finding that employees are extending their networks in undesirable ways.
They may install a $20 wireless access point (WAP) in their cubicle without realizing (or
caring) that they just opened up the protected corporate network to potential attackers in the
parking lot or nearby buildings. WAPs can be so dangerous that Nmap has a special category
for detecting them, as demonstrated in the section called “SOLUTION: Detect Rogue Wireless
Access Points on an Enterprise Network”. Users may also cause sysadmins grief by connecting
insecure and/or worm-infected laptops to the corporate network. Regular scanning can detect
unauthorized devices for investigation and containment.
Social engineering
Another possible use is social engineering. Lets say that you are scanning a target company
and Nmap reports a “Datavoice TxPORT PRISM 3000 T1 CSU/DSU 6.22/2.06”. You could
call up the target pretending to be Datavoice support and discuss some issues with their
PRISM 3000. Tell them you are about to announce a big security hole, but are first providing
the patch to valued customers. Some naive administrators might assume that only an
authorized engineer from Datavoice would know so much about their CSU/DSU. Of course the
patch you send them is a Trojan horse that gives you remote access to sniff and traipse through
66
their network. Be sure to read the rest of this chapter for detection accuracy and verification
advice before trying this. If you guess the target system wrong and they call the police, that
will be an embarrassing story to tell your cellmates.
The inner workings of OS detection are quite complex, but it is one of the easiest features to
use. Simply add -O to your scan options. You may want to also increase the verbosity with -
v for even more OS-related details. This is shown in Example 8.1.
# nmap -O -v scanme.nmap.org
Including the -O -v options caused Nmap to generate the following extra line items:
Device type
All fingerprints are classified with one or more high-level device types, such
as router, printer, firewall, or (as in this case) general purpose. These are further described
in the section called “Device and OS classification (Class lines)”. Several device types may be
shown, in which case they will be separated with the pipe symbol as in “Device Type:
router|firewall”.
67
Running
This field is also related to the OS classification scheme described in the section called
“Device and OS classification (Class lines)”. It shows the OS Family (Linux in this case) and
OS generation (2.6.X) if available. If there are multiple OS families, they are separated by
commas. When Nmap can't narrow down OS generations to one specific choice, options are
separated by the pipe symbol ('|') Examples include OpenBSD 3.X, NetBSD 3.X|
4.X and Linux 2.4.X|2.5.X|2.6.X.
If Nmap finds too many OS families to print concisely, it will omit this line. When there are no
perfect matches, Nmap changes the field to Running (JUST GUESSING) and adds an accuracy
percentage (100% is a perfect match) in parentheses after each candidate family name. If no
fingerprints are close matches, the line is omitted.
OS CPE
This shows a Common Platform Enumeration (CPE) representation of the operating system
when available. It may also have a CPE representation of the hardware type. OS CPE begins
with cpe:/o and hardware CPE begins with cpe:/h. For more about CPE see the section called
“Common Platform Enumeration (CPE)”.
OS details
This line gives the detailed description for each fingerprint that matches. While the Device
type and Running lines are from predefined enumerated lists that are easy to parse by a
computer, the OS details line contains free-form data which is useful to a human reading the
report. This can include more exact version numbers, device models, and architectures specific
to a given fingerprint. In this example, the only matching fingerprint was Linux 2.6.20-1
(Fedora Core 5). When there are multiple exact matches, they are comma-separated. If there
aren't any perfect matches, but some close guesses, the field is renamed Aggressive OS
guesses and fingerprints are shown followed by a percentage in parentheses which specifies
how close each match was.
Uptime guess
As part of OS detection, Nmap receives several SYN/ACK TCP packets in a row and checks
the headers for a timestamp option. Many operating systems use a simple counter for this
which starts at zero at boot time then increments at a constant rate such as twice per second.
By looking at several responses, Nmap can determine the current values and rate of increase.
Simple linear extrapolation determines boot time. The timestamp algorithm is used for OS
detection too (see the section called “TCP timestamp option algorithm (TS)”) since the
increment rate on different systems varies from 2 Hz to 1,000 Hz.
The uptime guess is labeled a “guess” because various factors can make it completely
inaccurate. Some operating systems do not start the timestamp counter at zero, but initialize it
with a random value, making extrapolation to zero meaningless. Even on systems using a
simple counter starting at zero, the counter eventually overflows and wraps around. With a
1,000 Hz counter increment rate, the counter resets to zero roughly every 50 days. So a host
that has been up for 102 days will appear to have been up only two days. Even with these
caveats, the uptime guess is accurate much of the time for most operating systems, so it is
printed when available, but only in verbose mode. The uptime guess is omitted if the target
gives zeros or no timestamp options in its SYN/ACK packets, or if it does not reply at all. The
68
line is also omitted if Nmap cannot discern the timestamp increment rate or it seems suspicious
(like a 30-year uptime).
Network Distance
A side effect of one of the OS detection tests allows Nmap to compute how many routers are
between it and a target host. The distance is zero when you are scanning localhost, and one for
a machine on the same network segment. Each additional router on the path adds one to the
hop count. The Network Distance line is not printed in this example, since Nmap omits the line
when it cannot be computed (no reply to the relevant probe).
Many systems unwittingly give away sensitive information about their traffic levels based on
how they generate the lowly 16-bit ID field in IP packets. This can be abused to spoof a port
scan against other systems and for other mischievous purposes discussed in the section called
“TCP Idle Scan (-sI)”. This field describes the ID generation algorithm that Nmap was able to
discern. More information on how it classifies them is available in the section called “IP ID
sequence generation algorithm (TI, CI, II)”. Note that many systems use a different IP ID
space for each host they communicate with. In that case, they may appear vulnerable (such as
showing the Incremental class) while still being secure against attacks such as the idle scan.
For this reason, and because the issue is rarely critical, the IP ID sequence generation line is
only printed in verbose mode. If Nmap does not receive sufficient responses during OS
detection, it will omit the whole line. The best way to test whether a host is vulnerable to being
an idle scan zombie is to test it with -sI.
69
While TCP fingerprinting is a powerful method for OS detection, interrogating open ports for
clues is another effective approach. Some applications, such as Microsoft IIS, only run on a
single platform (thus giving it away), while many other apps divulge their platform in overly
verbose banner messages. Adding the -sV option enables Nmap version detection, which is
trained to look for these clues (among others). In Example 8.2, Nmap catches the platform
details from an FTP server.
In this example, the line “No exact OS matches for host” means that TCP/IP fingerprinting
failed to find an exact match. Fortunately, the Service Info field a few lines down discloses that
the OS is HP-UX. If several operating systems were detected (which can happen with NAT
gateway boxes that redirect ports to several different machines), the field would be OSs and
the values would be comma separated. The Service Info line can also contain hostnames and
device types found during the version scan. The focus of this chapter is on TCP/IP
fingerprinting though, since version detection was covered in Chapter 7, Service and
Application Version Detection.
With two effective OS detection methods available, which one should you use? The best
answer is usually both. In some cases, such as a proxy firewall forwarding to an application on
another host, the answers may legitimately differ. TCP/IP fingerprinting will identify the proxy
while version scanning will generally detect the server running the proxied application. Even
when no proxying or port forwarding is involved, using both techniques is beneficial. If they
come out the same, that makes the results more credible. If they come out wildly different,
investigate further to determine what is going on before relying on either. Since OS and
version detection go together so well, the -A option enables them both.
OS detection is far more effective if at least one open and one closed TCP port are found. Set
the --osscan-limit option and Nmap will not even try OS detection against hosts which do not
70
meet this criteria. This can save substantial time, particularly on -Pn scans against many hosts.
You still need to enable OS detection with -O (or -A) for the --osscan-limit option to have any
effect.
When Nmap performs OS detection against a target and fails to find a perfect match, it usually
repeats the attempt. By default, Nmap tries five times if conditions are favorable for OS f
ingerprint submission, and twice when conditions aren't so good. The --max-os-tries option lets
you change this maximum number of OS detection tries. Lowering it (usually to 1) speeds
Nmap up, though you miss out on retries which could potentially identify the OS.
Alternatively, a high value may be set to allow even more retries when conditions are favorable. This
is rarely done, except to generate better fingerprints for submission and integration into the Nmap
OS database.
Like just about every other part of Nmap, results ultimately come from the target machine
itself. While rare, systems are occasionally configured to confuse or mislead Nmap. Several
programs have even been developed specifically to trick Nmap OS detection (see the section
called “OS Spoofing”). Your best bet is to use numerous reconnaissance methods to explore a
network, and don't trust any one of them.
TCP/IP fingerprinting requires collecting detailed information about the target's IP stack. The
most commonly useful results, such as TTL information, are printed to Nmap output whenever
they are obtained. Slightly less pertinent information, such as IP ID sequence generation and
TCP sequence prediction difficulty, is only printed in verbose mode. But if you want all of the
IP stack details that Nmap collected, you can find it in a compact form called a subject
fingerprint. Nmap sometimes prints this (for user submission purposes) when it doesn't
recognize a host. You can also force Nmap to print it (in normal, interactive, and XML
formats) by enabling debugging with (-d). Then read the section called “Understanding an
Nmap Fingerprint” to interpret it.
71