CNS Lab Manual
CNS Lab Manual
LAB MANUAL
OF
Computer Network
Security Lab
(2019 Course)
Department
Of
Information Technology
Department of Information Technology
VISION
To build versatile human resources in Information Technology professionally competent and capable of
MISSION
* To Explore IT Innovations through Collaborative learning and Partnerships with Institutions and Industries.
1
PROGRAM OUTCOME (PO)
Students are expected to know and be able to–
Engineering An ability to apply knowledge of mathematics, computing, science,
PO1 knowledge engineering and technology.
Problem An ability to define a problem and provide a systematic solution with the
PO2 analysis help of conducting experiments, analyzing the problem and interpreting
the data.
Design / An ability to design, implement, and evaluate software or a software
PO3 Developmentof /hardware system, component, or process to meet desired needs
Solutions within realistic constraints.
Conduct An ability to identify, formulate, and provide essay schematic solutionsto
Investigation of complex engineering /Technology problems.
PO4 Complex
Problems
Modern Tool An ability to use the techniques, skills, and modern engineering
PO5 Usage technology tools, standard processes necessary for practice as a IT
professional.
The An ability to apply mathematical foundations, algorithmic principles, and
Engineer computer science theory in the modeling and design of computer- based
PO6 and Society systems with necessary constraints and assumptions.
Environment An ability to analyze and provide solution for the local and global
PO7 and impactof information technology on individuals, organizations and
Sustainability society.
Ethics An ability to understand professional, ethical, legal, security and
PO8 social issues and responsibilities.
Individual and An ability to function effectively as an individual or as a team memberto
PO9 Team Work accomplish a desired goal(s).
Communication An ability to engage in life-long learning and continuing professional
Skills development to cope up with fast changes in the technologies /tools with
PO10 the help of electives, profession along animations and extra- curricular
activities.
Project An ability to communicate effectively in engineering community at large
Management by means of effective presentations, report writing, paper publications,
PO11 and demonstrations.
Finance
Life-long An ability to understand engineering, management, financial aspects,
PO12 Learning performance, optimizations and time complexity necessaryfor
professional practice.
Student should submit term work in the form of handwritten journal based
on specified list of assignments.
Practical Examination will be based on the term work.
Candidate is expected to know the theory involved in the experiment.
The practical examination should be conducted if and only if the journal of
the candidate is complete in all respect.
List of Assignments
Page
Sr. No. Tile of Assignment
no.
Group A: Computer Network
Using a Network Simulator (e.g. packet tracer) Configure Router
for…
a) Configure a router using router commands and Configure Routing
1 Information Protocol (RIP). 4-9
b) Configure Access Control lists – Standard & Extended.
c) Network Address Translation: Static, Dynamic & PAT (Port Address
Translation)
Using a Network Simulator (e.g. packet tracer) Configure Routing
Protocols,
a) Configure EIGRP – Explore Neighbor-ship Requirements and
Conditions, its K Values Metrics Assignment and Calculation.
2 10-12
b) OSPF – Explore Neighbor-ship Condition and Requirement, Neighbor-
ship states, OSPF Metric Cost Calculation.
c) WLAN with static IP addressing and DHCP with MAC security and
filters.
Socket Programming in C/C++ on Linux.
3 a) TCP Client, TCP Server 13-24
b) UDP Client, UDP Server
Introduction to server administration (server administration commands
and their applications) and configuration of below Server:
4 19-25
(Study/Demonstration Only)
a) FTP b) Web Server
Group B: Network Security
Implement a client and a server on different computers using python.
5 Perform the communication between these two entities by using RSA 26-32
cryptosystem.
Implement a client and a server on different computers using python.
6 Perform the authentication of sender between these two entities by using 33-38
RSA digital signature cryptosystem.
Implement a client and a server on different computers using python.
Perform the encryption of message of sender between these two entities
7 by using DES Algorithm and use Diffie Hellman method for exchange
39-42
of
keys.
Use the snort intrusion detection package to analyze traffic and create a
43-46
8 signature to identify problem traffic.
Extra Assignment
1.Attendance with Passive Very little Good Individual Individual and self -
Involvement of observer involvement Involvement in Involvement in Involvement in
Student (5M ) performing performing performing experiment
experiment
experiment
2. Viva
Assessment Poor (1) Satisfactory(2) Good (3) Very Good Excellent (5)
Outcome (4)
Dimensions
3. Presentation
Assessment Poor (1) Good (3) Very Good Excellent (5)
Outcome Satisfactory(2) (4)
Dimensions
Journal Presentation (5M) Not Completed well Very well
Prepared Incomplete documentation docum documented
ented
Outcome: Student will be able to
Apply knowledge to real life examples and develop practical approach
Design Basic Application.
TITLE
Using a Network Simulator (e.g. packet tracer) Configure Router for…
PROBLEM STATEMENT
a) Configure a router using router commands and Configure Routing Information Protocol (RIP).
OBJECTIVES
To understand various networking commands
To design and implement small size network
To Configure Routing Information Protocol (RIP).
THEORY
2. Go to the desktop
3. Select IP Configuration
Assigning IP address to PC
PING COMMAND:
CONFIGURING THE ROUTING INFORMATION PROTOCOL (RIP)
Routing Information Protocol (RIP) is a dynamic routing protocol that uses hop count as a routing
metric to find the best path between the source and the destination network. It is a distance-vector
routing protocol that has an AD value of 120 and works on the Network layer of the OSI model. RIP
uses port number 520.
Hop Count
Hop count is the number of routers occurring in between the source and destination network. The
path with the lowest hop count is considered as the best route to reach a network and therefore
placed in the routing table. RIP prevents routing loops by limiting the number of hops allowed in a
path from source and destination. The maximum hop count allowed for RIP is 15 and a hop count of
16 is considered as network unreachable.
Features of RIP
1. Updates of the network are exchanged periodically.
Router 1
R1(config)#
R1(config)#int fa0/0
R1(config-if)#no shut
R1(config-if)#
R1(config-if)#no shut
CNS Lab
Router 2
R2(config)#
R2(config)#int fa0/0
R2(config-if)#no shut
R2(config-if)#
R2(config-if)#no shut
IP configuration on PCs
And now:
Router 1(Output)
R1(config)#
R1(config)#router rip
R1(config-router)#network 10.0.0.0
R1(config-router)#network 192.168.1.0
R1(config-router)#Ctrl+Z
CNS Lab
Router 2(Output)
R2(config)#
R2(config)#router rip
R2(config-router)#network 10.0.0.0
R2(config-router)#network 192.168.2.0
R2(config-router)#Ctrl+Z
Now Ping PC2 from PC1 to further confirm that connectivity is really established between the two
subnets.
CNS Lab
PROBLEM STATEMENT
b) Configure a Access Control lists – Standard & Extended.
THEORY
Standard Access-list –
These are the Access-list which are made using the source IP address only. These ACLs permit or
deny the entire protocol suite. They don’t distinguish between the IP traffic such as TCP, UDP,
HTTPS, etc. By using numbers 1-99 or 1300-1999, the router will understand it as a standard ACL
and the specified address as the source IP address.
Features –
Note – Standard Access-list are less used as compared to extended access-list as the entire IP
protocol suite will be allowed or denied for the traffic as it can’t distinguish between the different IP
protocol traffic.
CNS Lab
Configuration –
Here is a small topology in which there are 3 departments namely sales, finance, and marketing. The
sales department has a network of 172.16.40.0/24, the Finance department has a network of
172.16.50.0/24, and the marketing department has a network of 172.16.60.0/24. Now, want to deny
connection from the sales department to the finance department and allow others to reach that
network.
Now, first configuring numbered standard access – list for denying any IP connection from sales to
finance department.
Now, as you already know there is an implicit deny at the end of every access list which means that
if the traffic doesn’t match any of the rules of the access list then the traffic will be dropped.
By specifying any means that source having any IP address traffic will reach the finance department
except the traffic which it matches the above rules that you have made.
Now, you have to apply the access list on the interface of the router:
Extended Access-list –
It is one of the types of Access-list which is mostly used as it can distinguish IP traffic therefore the
whole traffic will not be permitted or denied like in standard access-list. These are the ACL that uses
both source and destination IP addresses and also the port numbers to distinguish IP traffic. In this
type of ACL, we can also mention which IP traffic should be allowed or denied. These use range
100-199 and 2000-2699.
Features –
1. Extended access-list is generally applied close to the source but not always.
2. In the Extended access list, packet filtering takes place on the basis of source IP address,
destination IP address, port numbers.
3. In an extended access list, particular services will be permitted or denied.
4. Extended ACL is created from 100 – 199 & extended range 2000 – 2699.
5. If numbered with extended Access-list is used then remember rules can’t be deleted. If one of the
rules is deleted then the whole access list will be deleted.
6. If named with extended Access-list is used then we have the flexibility to delete a rule from the
access list.
CNS Lab
Configuration –
Here is a small topology in which there are 3 departments namely sales, finance, and marketing. The sales
department has a network of 172.16.10.40/24, the Finance department has a network of
172.16.50.0/24, and the marketing department has a network of 172.16.60.0/24. Now, we want to
deny the FTP connection from the sales department to the finance department and deny telnet to the
Finance department from both the sales and marketing departments.
Now, first configuring numbered extended access – list for denying FTP connection from sales to
finance department.
Note – Here, as FTP uses TCP and port number 21. Therefore, we have to specify the permit or deny
the condition according to the need. Also, after eq, we have to use the port number for the specified
application layer protocol.
Now, we have to deny telnet connection to finance department from both sales and Marketing
department which means no one should telnet to finance department. Configuring for the same.
By specifying any means that source having any IP address traffic will reach finance department
except the traffic which it matches the above rules that we have made. Now, we have to apply the
access-list on the interface of the router:
Outputs
CNS Lab
PROBLEM STATEMENT
c) Configure a Network Address Translation: Static, Dynamic & PAT (Port Address Translation)
THEORY
To access the Internet, one public IP address is needed, but we can use a private IP address in our
private network. The idea of NAT is to allow multiple devices to access the Internet through a single
public address. To achieve this, the translation of a private IP address to a public IP address is
required. Network Address Translation (NAT) is a process in which one or more local IP address
is translated into one or more Global IP address and vice versa in order to provide Internet access to
the local hosts. Also, it does the translation of port numbers i.e. masks the port number of the host
with another port number, in the packet that will be routed to the destination. It then makes the
corresponding entries of IP address and port number in the NAT table. NAT generally operates on a
router or firewall.
Network Address Translation (NAT) working –
Generally, the border router is configured for NAT i.e the router which has one interface in the local
(inside) network and one interface in the global (outside) network. When a packet traverse outside
the local (inside) network, then NAT converts that local (private) IP address to a global (public) IP
address. When a packet enters the local network, the global (public) IP address is converted to a
local (private) IP address.
If NAT runs out of addresses, i.e., no address is left in the pool configured then the packets will be
dropped and an Internet Control Message Protocol (ICMP) host unreachable packet to the
destination is sent.
Inside local address – An IP address that is assigned to a host on the Inside (local) network. The
address is probably not an IP address assigned by the service provider i.e., these are private IP
addresses. This is the inside host seen from the inside network.
Inside global address – IP address that represents one or more inside local IP addresses to the
outside world. This is the inside host as seen from the outside network.
Outside local address – This is the actual IP address of the destination host in the local network
after translation.
Outside global address – This is the outside host as seen from the outside network. It is the IP
address of the outside destination host before translation.
1. Static NAT – In this, a single unregistered (Private) IP address is mapped with a legally
registered (Public) IP address i.e one-to-one mapping between local and global addresses. This is
generally used for Web hosting. These are not used in organizations as there are many devices
that will need Internet access and to provide Internet access, a public IP address is needed.
Suppose, if there are 3000 devices that need access to the Internet, the organization has to buy
3000 public addresses that will be very costly.
In this, a single private IP address is mapped with a single Public IP address, i.e., a private IP
address is translated to a public IP address. It is used in Web hosting.
Configuration –
Here is a small topology in which there is PC having IP address 192.168.1.1/24, Router R1 having
IP address 192.168.1.2/24 on interface fa0/0, 12.1.1.1/24 on fa0/1, and server having IP address
73.1.1.2/24.
Now, inside local and inside global are shown in the figure. Configuring the static NAT through
command IP nat inside source static INSIDE_LOCAL_IP_ADDRESS
INSIDE_GLOBAL_IP_ADDRESS.
They are:
1. Creating a mapping between the private internal address and public global address using the ip
nat inside source static [private-address] [public-address] global configuration command.
2. After the mapping is made, the interfaces taking part in the NAT translation are configured
as either inside or outside with respect to NAT.
The router interface associated within the LAN is assigned the inside interface using the ip nat
inside interface mode command.
Similarly, the router interface associated with the internet is assigned the outside interface using the ip
nat inside interface mode command.
To configure a static NAT between the private address 172.31.1.2 and publicaddress 200.100.100.2:
Map the server’s private address 172.31.1.2 to the public routable address 200.100.100.2
using the command ip nat inside source static 172.31.1.2 200.100.100.2.
Enter the “interface serial s0/0/0/” command and identify the interface as the outside interface
using the command ip nat outside.
Enter the “interface gigabitethernet g0/0” command and identify it as the inside interface
relative to NAT using the ip nat inside command.
CNS Lab
Outputs
2. Dynamic NAT – In this type of NAT, an unregistered IP address is translated into a registered
(Public) IP address from a pool of public IP addresses. If the IP address of the pool is not free,
then the packet will be dropped as only a fixed number of private IP addresses can be translated
to public addresses.
Suppose, if there is a pool of 2 public IP addresses then only 2 private IP addresses can be
translated at a given time. If 3rd private IP address wants to access the Internet then the packet
will be dropped therefore many private IP addresses are mapped to a pool of public IP addresses.
NAT is used when the number of users who want to access the Internet is fixed. This is also very
costly as the organization has to buy many global IP addresses to make a pool.
CNS Lab
In this type of NAT, multiple private IP addresses are mapped to a pool of public IP addresses. It
is used when we know the number of fixed users who want to access the Internet at a given point
in time.
Configuration –
Dynamic NAT still requires that both the inside and the outside interfaces be configured.
For allocation, it uses an access control list (ACL) to specify which private addresses are subject to
translation and a NAT pool of registered IP addresses.
1. Create an ACL using the access-list 1 permit address wildcard mask command.
2. Create a NAT pool using the ip nat pool [name] [first-address] [last-address] [netmask]
[subnet mask] global configuration command.
This pool will contain the public addresses for the translation. Because, ISP assigns the public
addresses contiguous to the organizations.
The first address is the least in the given address range. And, the last address is the highest address of
that range.
The netmask identifies the network to which of these addresses belong to, using the ip nat inside
source list [access-list] [number] pool [name] command to bind the ACL and the NAT Pool created.
In this case, the ACL number is 1, and the NAT POOL is LAN.
NOTE: Different ACL numbers and pool names can be created and used, but ACL 1 and pool
name LAN will be used throughout this tutorial for simplicity.
1. Use the ip nat inside interface command to enable the inside interface for NAT translation
2. Use the ip nat outside interface command to enable the outside interface for NAT translation.
An organization is assigned with two public addresses: 200.100.100.1 and 200.100.100.2. It wants to
allow its inernal hosts, in the private network 172.31.1.0 and 255.255.255.0 to reach the internet using
dynamic NAT.
CNS Lab
Create an access list that will specify the private addresses that are allowed to be
translated using the access-list 1 permit 172.31.1.0 0.0.0.255.
Creates a pool that will contain the public addresses to be utilized for translation using the ip
nat pool LAN 200.100.100.1 200.100.100.1 netmask 255.255.255.0.
Bind the access list and the pool together using the ip inside source list 1 pool LAN. This
allows for the dynamic translation of the private addresses and the public addresses in a
NAT pool named LAN.
Enter the interface serial 0/0/0/ command and identify it as an outside interface using the ip nat
outside command.
Enter the interface gigabitethernet g0/0 command and identify it as the inside interface using
the ip nat inside command.
Outputs
CNS Lab
3. Port Address Translation (PAT) – This is also known as NAT overload. In this, many local
(private) IP addresses can be translated to a single registered IP address. Port numbers are used to
distinguish the traffic i.e., which traffic belongs to which IP address. This is most frequently used
as it is cost-effective as thousands of users can be connected to the Internet by using only one real
global (public) IP address.
This is also known as NAT overload. In this, many local (private) IP addresses can be translated
to a single public IP address. Port numbers are used to distinguish the traffic, i.e., which traffic
belongs to which IP address. This is most frequently used as it is cost-effective as thousands of
users can be connected to the Internet by using only one real global (public) IP address.
Configuration –
Taking the same topology, There is PC1 having IP address 192.168.1.1/24, Router R1 has IP address
192.168.1.2/24 on interface fa0/0, 12.1.1.1/24 on fa0/1, and the server has IP address 73.1.1.2/24.
Now, first configuring the access-list:
Here, note that the nat pool is shrunk to one IP address only and the IP address used is the outside
interface IP address of the router. If you have additional IP then you can use that also.
CNS Lab
-It requires every incoming packet of information to have been asked for by a device. if a malicious
data packet isn’t on the list of expected communications it gets rejected.
-Some firewalls can use whitelisting to block unauthorized outgoing traffic so if you do contract a
piece of malware your firewall may prevent it from communicating with your device.
Advantages of NAT –
NAT conserves legally registered IP addresses.
It provides privacy as the device’s IP address, sending and receiving the traffic, will be hidden.
Eliminates address renumbering when a network evolves.
Disadvantage of NAT –
Translation results in switching path delays.
Certain applications will not function while NAT is enabled.
Complicates tunneling protocols such as IPsec.
CNS Lab
Also, the router being a network layer device, should not tamper with port numbers(transport
layer) but it has to do so because of NAT.
PAT topology
To configure PAT for the network topology above, the following steps are applied:
1. Create an ace list that will specify which private addresses are allowed to be translated
using the access-list 1 permit 172.31.1.0 0.0.0.255
2. ip nat pool LAN 200.100.100.1 200.100.100.1 [netmask] 255.255.255.0 creates a pool that
contains the public addresses to be used for translation.
3. Bind the access list and the pool together using the ip inside source list 1 pool LAN overload.
This allows for the dynamic mapping of the private addresses and the public address in the
NAT pool named LAN. The overload keyword used here is the only configuration
difference between PAT and dynamic NAT.
4. Enter the interface serial 0/0/0/ to identify the interface as the outside interface using the ip nat
outside command.
CNS Lab
5. Enter gigabitethernet g0/0 using the interface gigabitethernet g0/0 command and identify it as
the inside interface relative to NAT with the ip nat inside command.
Outputs
If an organization is assigned a single public address by an ISP. Then, PAT can be configured with a
little changes when compared to PAT with multiple addresses.
In this situation, a NAT pool is not created, but an outside interface used for the translation is used in
place of the NAT pool as mentioned in step 3 above.
An organization is assigned one public address 200.100.100.1, and it wants to allow its internal hosts
in the private network 172.31.1.0 - 255.255.255.0 to reach the internet using PAT.
To configure PAT for the topology above, the following steps will be applied:
1. Create an ace list that will specify which private addresses are allowed to be translated,
using the access-list 1 permit 172.31.1.0 0.0.0.255 command.
2. Bind the access list and the outside interface together using the ip inside source list 1 interface
s0/0/0 overload.
3. Enter the interface serial 0/0/0/ command to identify it as an outside interface relative to NAT
using the: ip nat outside command.
4. Enter the interface gigabitethernet g0/0 command and identify it as an inside interface relative
to NAT using the ip nat inside command.
CNS Lab
Outputs
ASSIGNMENT NO.2
TITLE
Using a Network Simulator (e.g. packet tracer) Configure Routing Protocols
PROBLEM STATEMENT
Enhanced Interior Gateway Routing Protocol (EIGRP) is an hybrid routing protocol possessing
characteristics of both distance-vector and and link-state routing protocols. It was a proprietary Cisco
routing protocol but Cisco decided to convert it to an open standard in 2013.
For EIGRP, routing metric is calculated using bandwidth, delay, reliability and load.
CNS Lab
Before exchanging routing information, routers that run EIGRP must first become neighbors. EIGRP
Routers send hello packets to the multicast address of 224.0.0.10 to dynamically discover
neighbors on directly attached networks.
They must be configured with the same ASN (Autonomous System Number). An autonomous system
number is a group of EIGRP-enabled routers that should become EIGRP neighbors and exchange
routes.
The routers must also be using the same parameters to calculate metric. These parameters are
called K values (components of metric). Just as we’ve seen, the K values are bandwidth, delay,
reliability and load.
By default, the only parameters used to calculate EIGRP metric are bandwith and delay.The other
two parameters are disabled by default; so the network admin has to enable them on the router when
desired for use.
Neighborhood table -which stores information about EIGRP neighbors? Remember we said that
routers need first to become neighbors before they can exchange routing information. A neighborhood
table is thus used to keep neighborhood information such as the IP address of the neighbor, the local
interface on which hellos were received; the hold down timer and others neighbor information.
Topology table– stores routing information learnt from neighbor routing tables. Every EIGRP
route inside the autonomous system is stored here.The topology table also holds the metrics for each
of the listed EIGRP routes, the feasible successor and the successor routes.
Routing table -Stores only the best routes to reach a remote network.
CNS Lab
1. (config) router eigrp ASN – This command starts EIGRP on the router. In order to become EIGRP
neighbors, routers must be configured with the same AS number. You can use any number between 1
and 65,535
Router1
R1(config)#
R1(config)#int fa0/0
R1(config-if)#no shut
R1(config-if)#int fa0/1
R1(config-if)#no shut
Router 2
R2(config)#
R2(config)#int fa0/0
R2(config-if)#no shutdown
R2(config-if)#int fa0/1
R2(config-if)#no shutdown
PC IP configuration
PC1
PC2
3. Configure EIGRP on the routers. Remember to use the same ASN number on both routers. Once
configured, the routers become EIGRP neighbors.
CNS Lab
Router 1:
R1(config)#
R1(config)#router eigrp 1
R1(config-router)#network 10.0.0.0
R1(config-router)#network 20.0.0.0
R1(config-router)#Ctrl + Z
Router 2:
R2(config)#
R2(config)#router eigrp 1
R2(config-router)#network 20.0.0.0
R2(config-router)#network 30.0.0.0
R2(config-router)#Ctrl + Z
You can see that we’re simply enabling EIGRP on the routers, then advertising networks directly
connected to each router. Simple!
do this on Router 1
R1#
In the picture above, you can see that R1 has a single neighbor with the IP address of 20.0.0.2
Secondly, we’ll verify whether R1 has received a route to reach the 30.0.0.0/8 network. We can use
the show ip route eigrp command.
Lastly, let’s ping PC2 from PC1. Ping should succeed because. R1 has learnt the route
to 30.0.0.0/8 through EIGRP as denoted by letter D.
Outputs
CNS Lab
PROBLEM STATEMENT
b) OSPF – Explore Neighbor-ship Condition and Requirement, Neighbor-ship states,
OSPF Metric Cost Calculation
THEORY
Open Shortest Path First(OSPF) is one of the dynamic routing protocols amongst others such
as EIGRP, BGP and and RIP. It is perhaps one of the most popular link state routing protocols. It is
an open standard, so it can be run on routers from different vendors.
Classless routing
OSPF has a default administrative distance of 110. It uses cost as the parameter for determining route
metric. It uses the multicast address of 224.0.0.5 and 224.0.0.6 for communication between OSPF-
enabled neighbors
Routers running OSPF need to establish a neighbor relationship before exchanging routing updates.
Each OSPF router runs the SFP algorithm to calculate the best routes and adds them to the routing
table.
Routers running OSPF need to establish a neighbor relationship before exchanging routing updates.
OSPF neighbors are dynamically discovered by sending Hello packets out each OSPF-enabled
interface on a router. Hello packets are sent to the multicast address of 224.0.0.5.
OSPF areas
An area is simply a logical grouping of adjacent networks and routers. All routers in the same area
have the same topology table and don’t know about routers in other areas. The main benefits of
using areas in an OSPF network are:
Each area in an OSPF network must be connected to the backbone area ( also known as area 0 ). All
routers inside an area must have the same area ID .
A router that has interfaces in more than one area (for example area 0 and area 1) is known as an Area
Border Router (ABR). A router that connects an OSPF network to other routing networks (for
example, to an EIGRP network) is called an Autonomous System Border Router (ASBR).
Router 1
R1(config)#int fa 0/0
R1(config-if)#no shut
R1(config-if)#
R1(config-if)#no shut
Router 2
R2(config-if)#int fa0/0
R2(config-if)#no shut
R2(config-if)#
R2(config-if)#int serial0/0/0
R2(config-if)#no shut
CNS Lab
The configuration is pretty simple and requires only two major steps:
1. Enable OSPF on a router using the router ospf PROCESS_ID in the global configuration mode.
2.Define on which interfaces OSPF will run and what networks will be advertised using
network IP_ADDRESS WILCARD_MASK AREA command in the OSPF configuration mode.
Note that the OSPF process ID doesn’t have to be the same on all routers in order for the routers to
establish a neighbor relationship, but the area parameter has to be the same on all neighboring routers
in order for the routers to become neighbors.
Router 1
R1(config)#
R1(config)#router ospf 1
Router 2
R2(config)#
R2(config)#router ospf 2
As you can see from the above picture,we just need to enable OSPF on the routers which then
advertise the networks directly connected to each of them.
Have in mind: The OSPF process IDs used for the two routers have been made optionally different
but their area numbers must be the same.
CNS Lab
First, let’s verify that the routers have established a neighbor relationship by typing the show ip ospf
neighbor command on R1:
Next, to verify that R1 has learnt the route to 30.0.0.0/8 network, we’ll use show ip route
ospf command on R1:
Lastly, verify connectivity. Ping PC2 from PC1. Ping should be successful.
Outputs
CNS Lab
PROBLEM STATEMENT
c) WLAN with static IP addressing and DHCP with MAC security and filters.
THEORY
In our network set up, we have two laptops and a PC which should connect to a LAN provided by one
wireless router. The PC is is used by the network Admin and connects to the LAN via an Ethernet port
of wireless router. The laptops should connect to the same LAN by wireless means, and for this reason
we’ll install wireless adapters on them. Still, we’ll need to connect the LAN to the internet via an ISP
router.
First get into Cisco Packet Tracer and in the physical mode, pick a wireless router and two laptops,a
PC, a generic server and a 2800-series router(or just any other router other than wireless).
For the laptops, replace the already-installed wired LAN module with a wireless adapter module
(WMP 300N) .
Make sure that you first power off each laptop before you make any replacement then restore the
power back after replacement. That’s easy to do!
Once you have the wireless modules in place, you’ll see the wireless connections come up between the
laptops and the wireless router as shown below.
CNS Lab
Next, we’re going to do some settings on the wireless router to create a LAN then connect it to the
internet.
To do any configuration on the wireless router, we’ll use its GUI(Graphical User Interface) which we
can access either by:
We’ll access the router from the PC or the laptops using the router’s LAN interface. The LAN
interface is simply the default gateway of the LAN.
So now, on the ADMIN PC browser, type the IP address of the LAN interface of the wireless router.
(192.168.0.1 by default ), then hit Go.
A login prompt appears. Provide the username (admin) and password (admin) to be allowed into the
GUI of the router.You can always change these settings later.
CNS Lab
You should now be in the GUI of the router, whichever approach you chose to access it. Just examine
it closely for a moment. On it, you can see several tabs like Setup, Wireless, Security, Access
Restrictions, Application & Gaming, Administration and WRT 300N status.
For this tutorial we’ll focus on setup, wireless and administration tabs. Notice that once you click on
one major tab, other ‘sub-tabs’ will appear.
We’ll begin with Administration in the GUI. Here we’ll simply change the router’s username and
password.
On the browser of Admin PC, type the IP address of the LAN interface of the wireless
router(192.168.0.1, by default). Hit Go to access the GUI of the router. Provide the
default username(admin) and password(admin). Click OK. You’re now on the GUI of the router.
See it on the figure below.
CNS Lab
Click on the Administration tab and set a new password for administrative access. Scroll down
and Save settings. You will be prompted for a username and the new password you just set.Type them
and click OK. Wait a bit. A new screen appears confirming settings are successful. You can click
on continue to continue with configurations.
CNS Lab
To test for the new password entered, close the browser of Admin PC and try to to access the GUI
again using the browser. You’ll now provide the new password you’ve just set.
The admin username and password are important, as only a network admin(or a user with admin
rights) is able to log into the router and manage its settings.
To configure addresses for the LAN and internet connectivity, we’ll use Setup tab.
Network Setup
Network setup means LAN setup. Already, we have a PC and three laptops in the LAN.We’ll assign
the them IP addresses either statically or dynamically (using a DHCP pool set up in the wireless
router).
The default LAN network address given here is 192.168.0.0 with a subnet mask of 255.255.255.0
.The first address in this network (192.168.0.1 by default) has been assigned to the LAN interface of
the router. It has just been named IP address. Obviously, all the PCs in the LAN will use the LAN
interface as their default interface(to communicate to hosts in outside networks).
Now, in the router’s network settings, you may choose to enable DHCP to dynamically assign IP
addresses to the PCs. On the other hand, if you choose to disable DHCP, then obviously, you’ll have
to configure static IP addresses on the PCs.
When you choose to enable DHCP, set the start address for the LAN pool, maximum hosts to be
allowed in your LAN and the DNS server for the LAN. The PCs will receive addresses automatically
from the pool.
You can leave the DNS server entry as it is (0.0.0.0) or specify the address of a DNS server of your
choice.
Scroll down and Save settings.
Moving on, let’s enable DHCP on each PC for dynamic configuration. Go to the IP
configuration tab for each PC and enable DHCP. Each PC should automatically obtain an IP
address from the router.
Try also to ping the LAN interface of the router from one of the PCs ,say, PC1 . It should be
successful.
That was pretty easy! Let’s now move on and add wireless security for the wireless LAN access.
The LAN network we have just setup has no wireless security features enabled. If this a was a
production network, this would mean an obvious security threat since this makes the network
accessible to unauthorized users. So let’s implement some level of wireless security to our LAN.
Access the GUI of wireless router (either by clicking on Router icon or from Admin PC browser),
then click on Wireless tab. Under the Basic Wireless Settings sub tab, change the default
wireless SSID to any name of your choice. I have named mine ‘myLAN‘. After this, don’t forget
to Save settings.
CNS Lab
The acronym SSID stands for Service Set Identifier, and its the name of your wireless
network(wireless LAN).
Still, in the Wireless tab, under the Wireless security sub tab, change security mode
to WPA personal , then set passphrase field to a password of your choice. Scroll down and Save
settings
CNS Lab
The LAN network is now secured for wireless access. To test whether its really protected,
click Laptop1->Desktop->Wireless.
A new window appears that shows the now secured wireless network. Click connect. You can now
see the name of the wireless network( myWIFI , in my case) and its signal strength. Site features
listed include WPA1 PSK security feature.
CNS Lab
Again, click connect, then provide the security pre-shared key for the WiFi that you set,
then connect. Laptop 1 is now connected to the WiFi network. You can see at the bottom right of the
screen that the wireless network adapter on the laptop is active.Repeat this process for the Laptop2.
Now, you can change the wireless security mode to any other from the available options. You may
choose WEP security feature for our wireless network, for example. For WEP, provide a 40-bit (10
hexadecimal digits e.g. A123B456C789) or 64 -bit key(16 hex characters). WEP and WPA
configurations look almost alike.
Lastly, let’s see how to set up internet configurations on the wireless Router so that the PC and
laptops in the LAN can access the internet. So move on to the next section.
Internet Setup
For this part, we’ll configure the internet interface on the router so as to connect our LAN to the
internet. Note that for different routers (from different vendors), the internet interface may be named
CNS Lab
differently; in some routers, for example, the interface may have the name ‘WAN interface‘, suitably
because its the interface that allows devices in our LAN to access the internet.
Here, we’ll connect the internet interface to an ISP router which then connects to an internet server
(example.com, as an example).
So now, access the Internet Setup tab on the GUI of the wireless router (either by clicking on its
icon or from admin PC browser). Actually, in a real life router configuration, you’ll use a PC browser.
In this case you should remember the username name and the new password you set.
To Set internet connectivity , we’ll need to set a static IP address on the interface or set interface as a
DHCP client so that it will be assigned an address dynamically by the ISP router. Alternatively, you
may use PPPoE to provide WAN connectivity to the internet.
Now, if you choose to configure a static IP address for the internet interface, you can specify also
the default gateway and a DNS server of your choice.
And, if you’d rather like to have the internet interface address configured by DHCP, you’ll then set the
internet interface as a DHCP client. A DHCP server will be configured on another device, such as
the ISP router (in our topology here!).
CNS Lab
Otherwise, if you choose PPPoE for internet connectivity, then set up the username and password for
PPPoE authentication. The internet interface will then become a PPPoE client and will negotiate for
connection with a PPPoE server running on an ISP device so as to achieve internet
connectivity.Usually the username and password will be provided by your ISP.
For now, we’ll set the internet interface to act as a DHCP client (with the DHCP server configured on
the ISP router)
So then :
ISP_ROUTER(config)#int fa0/0
ISP_ROUTER(config-if)#no shut
ISP_ROUTER(config-if)#
ISP_ROUTER(config-if)#int fa0/1
ISP_ROUTER(config-if)#no shut
ISP_ROUTER(config-if)#exit
ISP_ROUTER(dhcp-config)#default-router 155.21.21.1
ISP_ROUTER(dhcp-config)#dns-server 0.0.0.0
Now make the internet interface a DHCP client by enabling DHCP on it.
CNS Lab
To verify DHCP configuration, click on the wireless router icon, then go to Config
tab. Pick DHCP. The interface is now configured with an IP address from the pool set in the ISP
router.
Next,we have to configure static or dynamic routes in the ISP router for the devices in the wireless
LAN to gain access the internet server:
255.255.255.0 fa0/0
Lastly, assign an IP address to the internet server (if you hadn’t done so), then try to reach the server
from a host in the LAN.
For example, you can ping the server from Laptop1. Ping should succeed.
CNS Lab
Outputs
CNS Lab
ASSIGNMENT NO.3
TITLE
Socket Programming using Python
PROBLEM STATEMENT
a) TCP Client, TCP Server
OBJECTIVES
To understand Socket Programming using Python between TCP Client and Server
THEORY
What is socket?
Sockets act as bidirectional communications channel where they are endpoints of it. Sockets may
communicate within the process, between different process and also process on different places.
Socket programming is a way of connecting two nodes on a network to communicate with each
other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the
other to form a connection. The server forms the listener socket while the client reaches out to the
server.
Socket Module- s.socket.socket(socket_family, socket_type)
socket_family-AF_UNIX or AF_INET
socket_type-SOCK_STREAM or SOCK_DGRAM
Once socket object is created as mentioned above, now we can use functions below to create client
server programs.
Socket methods
Server socket methods
Socket programming is started by importing the socket library and making a simple socket.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Here we made a socket instance and passed it two parameters. The first parameter is AF_INET and
the second one is SOCK_STREAM. AF_INET refers to the address-family ipv4. The
SOCK_STREAM means connection-oriented TCP protocol.
A simple server-client program :
Server :
A server has a bind() method which binds it to a specific IP and port so that it can listen to incoming
requests on that IP and port. A server has a listen() method which puts the server into listening
mode. This allows the server to listen to incoming connections. And last a server has an accept() and
close() method. The accept method initiates a connection with the client and the close method closes
the connection with the client
tcpServer.py
import socket
server = socket.socket(socket.AF_INET,
socket.SOCK_STREAM) print("Socket Created Successfully
............................................................")
server.bind(('localhost', 9999))
server.listen(10)
print("Server Waiting for connection..")
while True:
c, addr = server.accept()
print("Connected with", addr)
c.send('Thank you for connecting'.encode())
c.close()
tcpClient,py
import socket
c = socket.socket()
c.connect(('localhost', 9999))
print(c.recv(1024).decode())
c.close()
CNS Lab
Program code
//TCP Client
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#define SERVER_PORT 8080
#define SERVER_IP "127.0.0.1"
int main() {
int sock;
struct sockaddr_in server_addr;
char message[] = "Hello from client!";
char buffer[1024];
// Create socket
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVER_PORT);
if (inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr) <= 0) {
perror("Invalid address");
exit(EXIT_FAILURE);
}
// Connect to the server
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("Connection failed");
exit(EXIT_FAILURE);
}
// Send message to server
send(sock, message, strlen(message), 0);
CNS Lab
//TCP Server
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
exit(EXIT_FAILURE);
}
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
// Bind socket to address and port
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("Bind failed");
exit(EXIT_FAILURE);
}
// Listen for incoming connections
if (listen(server_fd, MAX_CLIENTS) < 0) {
perror("Listen failed");
exit(EXIT_FAILURE);
}
printf("Server is listening on port %d...\n", PORT);
client_len = sizeof(client_addr);
// Accept a client connection
if ((client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_len)) < 0) {
perror("Accept failed");
exit(EXIT_FAILURE);
}
printf("Client connected\n");
// Receive data from client
int bytes_received = recv(client_fd, buffer, sizeof(buffer), 0);
if (bytes_received > 0) {
buffer[bytes_received] = '\0';
printf("Received: %s\n", buffer);
}
// Send response to client
CNS Lab
Program Output
}
CNS Lab
CNS Lab
PROBLEM STATEMENT
b) UDP Client, UDP Server
OBJECTIVES
To understand Socket Programming using Python between UDP Client and Server
THEORY
What is socket?
Sockets act as bidirectional communications channel where they are endpoints of it. Sockets may
communicate within the process, between different process and also process on different places.
Socket programming is a way of connecting two nodes on a network to communicate with each
other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the
other to form a connection. The server forms the listener socket while the client reaches out to the
server.
Socket Module- s.socket.socket(socket_family, socket_type)
socket_family-AF_UNIX or AF_INET
socket_type-SOCK_STREAM or SOCK_DGRAM
Once socket object is created as mentioned above, now we can use functions below to create client
server programs.
Socket methods
Server socket methods
s.b ind – This method binds address hostname, port number to socket
Client socket methods
s.c onnect – This method actively initiates TCP server connection
Socket programming is started by importing the socket library and making a simple socket.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Here we made a socket instance and passed it two parameters. The first parameter is AF_INET and
the second one is SOCK_STREAM. AF_INET refers to the address-family ipv4. The
SOCK_STREAM means connection-oriented TCP protocol.
A simple server-client program :
Server :
A server has a bind() method which binds it to a specific IP and port so that it can listen to incoming
requests on that IP and port. A server has a listen() method which puts the server into listening
mode. This allows the server to listen to incoming connections. And last a server has an accept() and
close() method. The accept method initiates a connection with the client and the close method closes
the connection with the client
udpServer.py
import socket
s = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM) print("Socket Created
Successfully......................................................")
s.bind(('localhost', 12345))
print("UDP Server is up and waiting.......")
while True:
data, addr1 = s.recvfrom(4096)
print(str(data))
msg = bytes("Hello I am UDP server...",encoding='utf-8')
s.sendto(msg,addr1)
udpClient,py
import socket
client = socket.socket(socket.AF_INET,
client.sendto(msg.encode('utf-8'),('localhost',
print(str(data))
client.close()
CNS Lab
Program Code
//UDP Client
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int sock;
struct sockaddr_in server_addr;
char message[] = "Hello from UDP client!";
char buffer[MAX_BUF_SIZE];
// Create socket
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("Socket failed");
exit(EXIT_FAILURE);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVER_PORT);
inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr);
//UDP Server
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
Program Output
CNS Lab
ASSIGNMENT NO. 4
TITLE
PROBLEM STATEMENT
a) FTP Server
OBJECTIVES
To Configure FTP Services on Server.
To Upload a File into the FTP Server from Remote PC.
To Download a File from the FTP Server from Remote PC.
THEORY
The File Transfer Protocol is a standard network protocol used for the transfer of computer files
between a client and server on a computer network. FTP is built on a client-server model architecture
using separate control and data connections between the client and the server.
First of all, we take two computers and take their IP address.then we take server and swich and
connect them with the help of cable.
CNS Lab
after that we have to click on the server and after clicking on the sevice name option, we will close all
the services open, and then click on FTP service and turn on.
we
have to create user name and password by going to FTP service and then we will give read-write-
delete-rename-list permission to the user and add it
CNS Lab
after that we will go to one of the computers and open the command prompt it and type ( ipconfig )
inside
it so that we will know which IP we login with on which computer?
CNS Lab
after entering the FTP sever IP address, we will see it. there, the user name, we have to enter the
name of the user with which we have created the user and the password to which we have given it.
after that we will operate the FTP sever so you can configure FTP server in packet tracer.
Now try using an FTP client built in the Laptop to send files to an FTP server configured in the
Server.
From the Laptop’s command prompt, FTP the server using the server IP address by typing:
ftp 192.168.1.2
Provide the username(cisco) and password(cisco) [which are the defaults] for ftp login.
PC0 has an FTP client which can be used to read, write, delete and rename files present in the FTP
server.
The FTP server can be used to read and write configuration files as well as IOS images. Additionally,
the FTP server also supports file operations such rename, delete and listing directory.
4. Create a file in the Laptop then upload it to the server using FTP.
To do this, open the Text Editor in the Laptop, create a file and give it your name of choice.
Type any text in the editor then save your file. e.g. myFile.txt.
5. Now upload the file from the Laptop to the server using FTP. (An FTP connection has to be started
first. But this is what we’ve done in step 3)
put MyFile.txt
6. Once file upload is successful, go to the Server FTP directory to verify if the file sent has been
received . To do this, go to Server-> Services->FTP. Here look for MyFile.txt sent from the laptop.
CNS Lab
Something extra: To check other FTP commands supported by the FTP client running on the
Laptop(or PC), you can use a question mark (?) on the Laptop’s command prompt as shown below:
You can see the put command that we used to upload our file to the FTP server. Other commands listed
include:
delete– to delete a file in the FTP directory with the server For
For example, we can open an HTTP directory in the server by typing: cd /http. This will change the
current directory from FTP directory to HTTP directory
Once the http directory is open, you can upload a file to the HTTP server. You’re now uploading a file
to an HTTP folder(directory) using FTP.
To see this working, let’s open an HTTP directory and upload(put) a file to it using FTP:
You can now check up in the HTTP directory in the server and verify that the file uploaded from the
Laptop(MyFile.txt) is well received:
CNS Lab
Notice that we are uploading files to an HTTP Server directory using File Transfer Protocol.(FTP).
This is what actually happens when you use an FTP client such as FileZilla client to upload files to a
website. In our case here, we are using an FTP client built-in the Laptop.
The first FTP client applications were command-line programs developed before operating
systems had graphical user interfaces, and are still shipped with most Windows and Linux operating
systems. (Actually this is what we have been using this far). Many FTP clients(e.g. FileZilla) and
automation utilities have since been developed for desktops, servers, mobile devices, and hardware.
FTP has also been incorporated into productivity applications, such as HTML editors.
Well done for reading this topic up to this point! You now have more than a foundation regarding
working with FTP to upload, download, delete, rename…files.
We’ll create an html file in our Laptop, upload it to HTTP server directory using FTP, then try
to access the file from the Laptop’s browser.
On the Laptop, open the text editor, then type some markup(html) and save the file with the
extension .html. See all this below:
CNS Lab
Now upload the file( File2.html) to the HTTP server using FTP. This is easy. We’ve already done it
previously!
If you’re already in the HTTP directory, you just need to type: put File2.html. If no, first ftp the
server(ftp 192.168.1.2), provide the login username(cisco) and password(cisco); change the current
directory to HTTP(cd /http) , and finally upload the html file onto the HTTP directory(put File2.html)
CNS Lab
Moving on…
Check whether the html file uploaded has been received in the HTTP directory:
Go to Server->Services-> HTTP. Then look up for the file in the File Manager.
Now edit index.html file in the HTTP directory so as to include a link to File2 that we’ve just
uploaded. This will make File2 accessible from the Laptop’s browser. To do this,
CNS Lab
locate index.html then click edit. Proceed to edit it as shown below. Then save and accept overwrite.
Finally, try to access the newly uploaded file from the Laptop’s browser.
So go to the Laptop’s browser and access the server using the server’s IP address. By doing this, the
browser is making an http request to the server. The server will respond to the Laptop with
the index.html file containing a link to File2 which we’ve uploaded from the Laptop using FTP.
CNS Lab
Click File2 link to view the contents of the file in the browser.
Outputs
CNS Lab
PROBLEM STATEMENT
b) Web Server
THEORY
When we search anything on Google, Bing, Mozila, safari or any web browser. Its result comes
on web page that appears on screen.
So we are taking few PCs and one web server and one switch for connecting all devices. Make
sure all devices should be connected by straight through cable because for connecting different
devices, straight through cable is required. Assign IPs to each end device (server and PCs) of
single network (192.168.1.0) with subnet mask 255.255.255.0 It can different as per your choice.
If you want to create your own webpage then it is very simple. Just follow path
Go to on server>services>HTTP>new file>just write you html code whatsoever you want as I coded
here.
Outputs
CNS Lab
ASSIGNMENT NO. 5
PROBLEM STATEMENT
Implement a client and a server on different computers using python. Perform the communication
between these two entities by using RSA cryptosystem.
OBJECTIVES
To implement a client and server communication.
To understand communication between two entities by using RSA
THEORY
RSA algorithm is a public key encryption technique and is considered as the most secure way of
encryption. It was invented by Rivest, Shamir and Adleman in year 1978 and hence
name RSA algorithm.
The idea of RSA is based on the fact that it is difficult to factorize a large integer. The public key
consists of two numbers where one number is multiplication of two large prime numbers. And
private key is also derived from the same two prime numbers. So if somebody can factorize the large
number, the private key is compromised. Therefore encryption strength totally lies on the key size
and if we double or triple the key size, the strength of encryption increases exponentially. RSA keys
can be typically 1024 or 2048 bits long, but experts believe that 1024 bit keys could be broken in the
near future. But till now it seems to be an infeasible task.
How it works
The RSA algorithm ensures that the keys, in the above illustration, are as secure as possible. The
following steps highlight how it works:
1. Select two large prime numbers, x and y. The prime numbers need to be large so that
they will be difficult for someone to figure out.
2. Calculate n=x x y.
3. Calculate the totient function; ϕ(n)=(x−1)(y−1).
CNS Lab
4. Select an integer e, such that e is co-prime to ϕ(n) and 1<e<ϕ(n). The pair of
numbers (n,e) makes up the public key.
Note: Two integers are co-prime if the only positive integer that divides them is 1.
d can be found using the extended euclidean algorithm. The pair (n,d) makes up the private key.
2. Encryption
C=Pemod n.
3. Decryption
Using the private key (n,d), the plaintext can be found using:
Rsa.py
import rsa
def generate_keys():
pubKey =
rsa.pubKey()
with open('keys/pubkey.pem','wb') as
f:
f.write(pubKey.save_pkcs1('PEM')
)
with open('keys/prikey.pem','wb') as
f:
f.write(priKey.save_pkcs1('PEM')
)
def load_keys():
with open('keys/pubkey.pem','rb') as f:
pubKey = rsa.PublicKey.load_pkcs1(f.read())
with open('keys/prikey.pem','rb') as f:
priKey = rsa.PrivateKey.load_pkcs1(f.read())
try:
return rsa.decrypt(ciphertext,key).decode('ascii')
except:
return False
generate_keys()
pubKey, priKey = load_keys()
if plaintext:
print(f'Plain Text: {plaintext}')
else:
print('Could not decrypt the message')
Outputs
CNS Lab
ASSIGNMENT NO. 6
PROBLEM STATEMENT
Implement a client and a server on different computers using python. Perform the authentication of
sender between these two entities by using RSA digital signature cryptosystem.
OBJECTIVES
To implement a client and server communication.
To understand communication between two entities by using RSA digital signature cryptosystem
THEORY
RSA algorithm is an asymmetric cryptography algorithm. Asymmetric actually means that it works
on two different keys i.e. Public Key and Private Key. As the name describes that the Public Key is
given to everyone and the Private key is kept private.
Digital signatures are used to verify the authenticity of the message sent electronically. A digital
signature algorithm uses a public key system. The intended transmitter signs his/her message with
his/her private key and the intended receiver verifies it with the transmitter’s public key. A digital
signature can provide message authentication, message integrity and non-repudiation services.
Digisign.py
import rsa
def generate_keys():
pubKey = rsa.pubKey()
with open('keys/pubkey.pem','wb') as f:
f.write(pubKey.save_pkcs1('PEM'))
with open('keys/prikey.pem','wb') as f:
f.write(priKey.save_pkcs1('PEM'))
def load_keys():
with open('keys/pubkey.pem','rb') as f:
pubKey = rsa.PublicKey.load_pkcs1(f.read())
with open('keys/prikey.pem','rb') as f:
priKey = rsa.PrivateKey.load_pkcs1(f.read())
generate_keys()
pubKey, priKey = load_keys()
if plaintext:
print(f'Plain Text: {plaintext}')
else:
print('Could not decrypt the message')
Outputs
CNS Lab
ASSIGNMENT NO. 7
PROBLEM STATEMENT
Implement a client and a server on different computers using python. Perform the encryption of
message of sender between these two entities by using DES Algorithm and use Diffie Hellman
method for exchange of keys.
OBJECTIVES
To implement a client and server communication.
To understand DES algorithm and Diffie Hellman method of key exchange.
THEORY
Data encryption standard (DES) has been found vulnerable against very powerful attacks and
therefore, the popularity of DES has been found slightly on the decline.
DES is a block cipher and encrypts data in blocks of size of 64 bits each, which means 64 bits of
plain text goes as the input to DES, which produces 64 bits of ciphertext. The same algorithm and
key are used for encryption and decryption, with minor differences. The key length is 56 bits. The
basic idea is shown in the figure.
DES is based on the two fundamental attributes of cryptography: substitution (also called
confusion) and transposition (also called diffusion). DES consists of 16 steps, each of which is
called a round. Each round performs the steps of substitution and transposition. Let us now
discuss the broad-level steps in DES.
1. In the first step, the 64-bit plain text block is handed over to an initial Permutation (IP) function.
CNS Lab
Diffie-Hellman algorithm
The Diffie-Hellman algorithm is being used to establish a shared secret that can be used for secret
communications while exchanging data over a public network using the elliptic curve to generate
points and get the secret key using the parameters.
For the sake of simplicity and practical implementation of the algorithm, we will consider only 4
variables, one prime P and G (a primitive root of P) and two private values a and b.
P and G are both publicly available numbers. Users (say Alice and Bob) pick private values a and
b and they generate a key and exchange it publicly. The opposite person receives the key and that
generates a secret key, after which they have the same secret key to encrypt.
Step by Step Explanation
CNS Lab
Example:
Step 1: Alice and Bob get public numbers P = 23, G
= 9
DES.py
CNS Lab
Outputs
CNS Lab
ASSIGNMENT NO. 8
PROBLEM STATEMENT
Use the snort intrusion detection package to analyze traffic and create a signature to identify
problem traffic
OBJECTIVES
To focus on writing snort rules to detect real world attacks based on inspecting ans analyzing
malicious traffic.
THEORY
Snort is one of the best known and widely used network intrusion detection systems (NIDS). It has
been called one of the most important open-source projects of all time.
Snort analyzes network traffic in real-time and flags up any suspicious activity. In particular, it looks
for anything that might indicate unauthorized access attempts and other attacks on the network. A
comprehensive set of rules define what counts as “suspicious” and what Snort should do if a rule is
triggered.
Installation Steps:
2. Read through Snort's configuration guide and edit /etc/snort/snort.conf as needed for your machine
3. When you run snort you'll see many errors/warnings in the output. Warnings about duplicate
rules are okay, but others aren't.
Once triggered, view the alert in /var/log/snort. It will be in binary, so you'll need to convert it from
Snort's unified2 format into human readable using:
ASSIGNMENT NO. 9
PROBLEM STATEMENT
Write a Java program to perform encryption and decryption using the following algorithms:
a) Ceaser Cipher
b) Substitution Cipher
c) Hill Cipher
OBJECTIVES
To understand the concept of encryption and Decryption using various cipher algorithms
THEORY
Ceaser Cipher:
The Caesar cipher (or Caesar code) is a monoalphabetic substitution cipher, where each letter is replaced
by another letter located a little further in the alphabet (therefore shifted but always the same for given
cipher message). The shift distance is chosen by a number called the offset, which can be right (A to
B) or left (B to A).
PROGRAM:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class CeaserCipher {
static Scanner sc=new Scanner(System.in);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public
static void main(String[] args) throws IOException {
// TODO code application logic here
System.out.print("Enter any String: ");
String str = br.readLine();
System.out.print("\nEnter the Key: ");
int key = sc.nextInt();
String encrypted = encrypt(str, key); System.out.println("\
nEncrypted String is: " +encrypted); String decrypted =
decrypt(encrypted, key); System.out.println("\nDecrypted
String is: "
+decrypted); System.out.println("\n");
}
public static String encrypt(String str, int key)
if (c > 'Z')
c = c - 26;
}
else if (Character.isLowerCase(c)) {
c = c + (key % 26);
if (c > 'z')
c = c - 26;
}
encrypted += (char) c;
}
return encrypted;
}
public static String decrypt(String str, int key)
{ String decrypted = "";
for(int i = 0; i < str.length(); i++)
{ int c = str.charAt(i);
if (Character.isUpperCase(c)) {
c = c - (key % 26);
if (c < 'A')
c = c + 26;
}
else if (Character.isLowerCase(c)) {
c = c - (key % 26);
if (c < 'a')
c = c + 26;
}
decrypted += (char) c;
}
return decrypted;
}
}
Output:
Enter any String: Hello World
Enter the Key: 5
Encrypted String is: MjqqtBtwqi
Decrypted String is: Hello World
Substitution Cipher:
Substitution ciphers encrypt the plaintext by swapping each letter or symbol in the plaintext by a
different symbol as directed by the key. Perhaps the simplest substitution cipher is the Caesar cipher,
named after the man who used it. To modern readers, the Caesar cipher is perhaps better known
through the Captain Midnight Code-O-Graph and secret decoder rings that even came inside Kix
cereal boxes. Technically speaking, the Caesar cipher may be differentiated from other, more complex
substitution ciphers by terming it either a shift cipher or a mono-alphabetic cipher; both are correct.
CNS Lab
PROGRAM:
import java.io.*;
import java.util.*;
public class SubstitutionCipher {
static Scanner sc = new Scanner(System.in);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
// TODO code application logic here
String a = "abcdefghijklmnopqrstuvwxyz";
String b = "zyxwvutsrqponmlkjihgfedcba";
System.out.print("Enter any string: ");
String str = br.readLine();
String decrypt = "";
char c;
for(int i=0;i<str.length();i++)
{
c = str.charAt(i);
int j = a.indexOf(c);
decrypt = decrypt+b.charAt(j);
}
System.out.println("The encrypted data is: " +decrypt);
}
}
Output:
Enter any string: aceho
The encrypted data is: zxvsl
Hill Cipher:
Hill cipher is a polygraphic substitution cipher based on linear algebra.Each letter is represented by a
number modulo 26. Often the simple scheme A = 0, B = 1, …, Z = 25 is used, but this is not an
essential feature of the cipher. To encrypt a message, each block of n letters (considered as an n-
component vector) is multiplied by an invertible n × n matrix, against modulus 26. To decrypt the
message, each block is multiplied by the inverse of the matrix used for encryption.
PROGRAM:
import java.io.*;
import java.util.*;
import java.io.*;
public class HillCipher
{
static float[][] decrypt = new float[3][1];
static float[][] a = new float[3][3]; static
float[][] b = new float[3][3]; static float[]
[] mes = new float[3][1]; static float[][]
res = new float[3][1];
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in)); static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws IOException {
// TODO code application
logic here getkeymes();
CNS Lab
Output: