Network sec lab
Network sec lab
AIM:
To apply Data Encryption Standard (DES) Algorithm for a practical application like
User Message Encryption.
ALGORITHM:
1. Create a DES Key.
2. Create a Cipher instance from Cipher class, specify the following information
and separated by a slash (/).
Algorithm name
Mode (optional)
Padding scheme (optional)
3. Convert String into Byte[] array format.
4. Make Cipher in encrypt mode, and encrypt it with Cipher.doFinal() method.
5. Make Cipher in decrypt mode, and decrypt it with Cipher.doFinal() method.
PROGRAM:
import javax.swing.*;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Random;
class DES
{
byte[] skey=new byte[1000];
String skeystring;
static byte[] raw;
String inputmessage,encryptedata,decryptedmessage;
public DES()
{
try
{
generatesymmetrickey();
inputmessage=JOptionPane.showInputDialog(null,"Enter message to
encrypt:");
byte[] ibyte =inputmessage.getBytes();
byte[] ebyte=encrypt(raw, ibyte);
String encrypteddata=new String(ebyte);
System.out.println("Encrypted message:"+encrypteddata);
JOptionPane.showMessageDialog(null,"Encrypted Data"+"\
n"+encrypteddata);
byte[] dbyte=decrypt(raw,ebyte);
String decryptedmessage=new String(dbyte);
System.out.println("Decrypted message:"+decryptedmessage);
JOptionPane.showMessageDialog(null,"Decrypted Data "+"\
n"+decryptedmessage);
}
catch(Exception e)
{
System.out.println(e);
}
}
void generatesymmetrickey()
{
try
{
Random r = new Random();
int num=r.nextInt(10000);
String knum=String.valueOf(num);
byte[] knumb=knum.getBytes();
skey=getRawKey(knumb);
skeystring=new String(skey);
System.out.println("DES
SymmerticKey="+skeystring);
}
catch(Exception e)
{
System.out.println(e);
}
}
OUTPUT:
RESULT:
Thus the java program for applying Data Encryption Standard (DES) Algorithm for a
practical application of User Message Encryption is written and executed successfully.
Ex.No. : 2 AES ALGORITHM
Date :
AIM:
To apply Advanced Encryption Standard (AES) Algorithm for a practical application
like URL Encryption.
ALGORITHM:
1. AES is based on a design principle known as a substitution–permutation.
2. AES does not use a Feistel network like DES, it uses variant of Rijndael.
3. It has a fixed block size of 128 bits, and a key size of 128, 192, or 256 bits.
4. AES operates on a 4 × 4 column- major order array of bytes, termed the state
PROGRAM:
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
OUTPUT:
C:\Security Lab New\programs>java AES
Enter the secret key:
annaUniversity
Enter the original URL:
www.annauniv.edu
URL Encryption Using AES Algorithm
Original URL : www.annauniv.edu
Encrypted URL : vibpFJW6Cvs5Y+L7t4N6YWWe07+JzS1d3CU2h3mEvEg=
Decrypted URL : www.annauniv.edu
RESULT:
Thus the java program for applying Advanced Encryption Standard (AES) Algorithm
for a practical application of URL encryption is written and executed successfully.
Ex.No. : 3 ASYMMETRIC KEY ALGORITHM
Date : RSA ALGORITHM
AIM:
To implement a RSA algorithm using HTML and Javascript.
ALGORITHM:
1. Choose two prime number p and q.
2. Compute the value of n and t.
3. Find the value of public key e.
4. Compute the value of private key d.
5. Do the encryption and decryption
a. Encryption is given as,
c = te mod n
b. Decryption is given
as, t = c d mod n
PROGRAM:
rsa.html
<html>
<head>
<title>RSA Encryption</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<h1>RSA Algorithm</h1>
<h2>Implemented Using HTML & Javascript</h2>
<hr>
<table>
<tr>
<td>Enter First Prime Number:</td>
<td><input type="number" value="53" id="p"></td>
</tr>
<tr>
<td>Enter Second Prime Number:</td>
<td><input type="number" value="59" id="q"></p> </td>
</tr>
<tr>
<td>Enter the Message(cipher text):<br>[A=1, B=2,...]</td>
<td><input type="number" value="89" id="msg"></p> </td>
</tr>
<tr>
<td>Public Key:</td>
<td><p id="publickey"></p> </td>
</tr>
<tr>
<td>Exponent:</td>
<td><p id="exponent"></p> </td>
</tr>
<tr>
<td>Private Key:</td>
<td><p id="privatekey"></p></td>
</tr>
<tr>
<td>Cipher Text:</td>
<td><p id="ciphertext"></p> </td>
</tr>
<tr>
<td><button onclick="RSA();">Apply RSA</button></td>
</tr>
</table> </center>
</body>
<script type="text/javascript">
function RSA()
{
var gcd, p, q, no, n, t, e, i, x;
gcd = function (a, b) { return (!b) ? a : gcd(b, a % b); };
p = document.getElementById('p' ).value;
q = document.getElementById('q').value;
no = document.getElementById('msg').value;
n = p * q;
t = (p - 1) * (q - 1);
for (e = 2; e < t; e++)
{
if (gcd(e, t) == 1)
{
break;
}
}
for (i = 0; i < 10; i++)
{
x=1+i*t
if (x % e == 0)
{
d = x / e;
break;
}
}
ctt = Math.pow(no,
e).toFixed(0); ct = ctt % n;
dtt = Math.pow(ct, d).toFixed(0);
dt = dtt % n;
document.getElementById('publickey').innerHTML = n;
document.getElementById('exponent').innerHTML = e;
document.getElementById('privatekey').innerHTML = d;
document.getElementById('ciphertext').innerHTML = ct;
}
</script>
</html>
OUTPUT:
RESULT:
Thus the RSA algorithm was implemented using HTML and Javascript and executed
successfully.
Ex.No. : 4 DIFFIE-HELLMAN KEY EXCHANGE ALGORITHM
Date :
AIM:
To implement a Diffie-Hellman Key Exchange algorithm.
ALGORITHM:
1. Sender and receiver publicly agree to use a modulus p and base g which is a primitive
root modulo p.
2. Sender chooses a secret integer x then sends Bob R1 = gx mod p
3. Receiver chooses a secret integer y, then sends Alice R2 = gy mod p
4. Sender computes k1 = Bx mod p
5. Receiver computes k2 = Ay mod p
6. Sender and Receiver now share a secret key.
PROGRAM:
import java.io.*;
import java.math.BigInteger;
class dh
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter prime number:");
BigInteger p=new BigInteger(br.readLine());
BigInteger k1=R2.modPow(x,p);
System.out.println("Key calculated at Sender's
side:"+k1); BigInteger k2=R1.modPow(y,p);
System.out.println("Key calculated at Receiver's side:"+k2);
System.out.println("Diffie-Hellman secret key was calculated.");
}
}
OUTPUT
C:\Security Lab New\programs>javac dh.java
RESULT:
Thus the Diffie-Hellman key exchange algorithm was implemented and executed
successfully.
Ex.No. : 5 DIGITAL SIGNATURE SCHEME
Date :
AIM:
To implement the signature scheme - Digital Signature Standard.
ALGORITHM:
1. Declare the class and required variables.
2. Create the object for the class in the main program.
3. Access the member functions using the objects.
4. Implement the SIGNATURE SCHEME - Digital Signature Standard.
5. It uses a hash function.
6. The hash code is provided as input to a signature function along with a random
number K generated for the particular signature.
7. The signature function also depends on the sender„s private key.
8. The signature consists of two components.
9. The hash code of the incoming message is generated.
10. The hash code and signature are given as input to a verification function.
PROGRAM:
import java.util.*;
import
java.math.BigInteger; class
dsaAlg {
final static BigInteger one = new BigInteger("1");
final static BigInteger zero = new
BigInteger("0"); public static BigInteger
getNextPrime(String ans)
{
BigInteger test = new BigInteger(ans);
while (!test.isProbablePrime(99))
e:
{
test = test.add(one);
}
return test;
}
public static BigInteger findQ(BigInteger n)
{
BigInteger start = new BigInteger("2");
while (!n.isProbablePrime(99))
{
while (!((n.mod(start)).equals(zero)))
{
start = start.add(one);
}
n = n.divide(start);
}
return n;
}
public static BigInteger getGen(BigInteger p, BigInteger q,
Random r)
{
BigInteger h = new BigInteger(p.bitLength(), r);
h = h.mod(p);
return h.modPow((p.subtract(one)).divide(q), p);
}
public static void main (String[] args) throws
java.lang.Exception
{
Random randObj = new Random();
BigInteger p = getNextPrime("10600"); /* approximate
prime */
BigInteger q = findQ(p.subtract(one));
BigInteger g = getGen(p,q,randObj);
System.out.println(" \n simulation of Digital Signature Algorithm \n");
System.out.println(" \n global public key components are:\n");
System.out.println("\np is: " + p);
System.out.println("\nq is: " + q);
System.out.println("\ng is: " + g);
BigInteger x = new BigInteger(q.bitLength(), randObj);
x = x.mod(q);
BigInteger y = g.modPow(x,p);
BigInteger k = new BigInteger(q.bitLength(), randObj);
k = k.mod(q);
BigInteger r = (g.modPow(k,p)).mod(q);
BigInteger hashVal = new BigInteger(p.bitLength(),
randObj);
BigInteger kInv = k.modInverse(q);
BigInteger s = kInv.multiply(hashVal.add(x.multiply(r)));
s = s.mod(q);
System.out.println("\nsecret information are:\n");
System.out.println("x (private) is:" + x);
System.out.println("k (secret) is: " + k);
System.out.println("y (public) is: " + y);
System.out.println("h (rndhash) is: " + hashVal);
System.out.println("\n generating digital signature:\n");
System.out.println("r is : " + r);
System.out.println("s is : " + s);
BigInteger w = s.modInverse(q);
BigInteger u1 = (hashVal.multiply(w)).mod(q);
BigInteger u2 = (r.multiply(w)).mod(q);
BigInteger v = (g.modPow(u1,p)).multiply(y.modPow(u2,p));
v = (v.mod(p)).mod(q);
System.out.println("\nverifying digital signature (checkpoints)\n:");
System.out.println("w is : " + w);
System.out.println("u1 is : " +
u1); System.out.println("u2 is : "
+ u2); System.out.println("v is : "
+ v);
if (v.equals(r))
{
System.out.println("\nsuccess: digital signature is verified!\n " + r);
}
else
{
System.out.println("\n error: incorrect digital signature\n ");
}
}
}
OUTPUT:
RESULT:
Thus the Digital Signature Standard Signature Scheme has been implemented and
executed successfully.
Ex. No. : 6 INTRUSION DETECTION SYSTEM (IDS)
Date:
AIM:
To demonstrate Intrusion Detection System (IDS) using Snort software tool.
6. Copy “snort.conf” file from the “etc” folder of the extracted folder. You must paste it into
“C:\Snort\etc” folder. Overwrite any existing file. Remember if you modify your
snort.conf file and download a new file, you must modify it for Snort to work.
7. Open a command prompt (cmd.exe) and navigate to folder “C:\Snort\bin” folder. ( at the
Prompt, type cd\snort\bin)
8. To start (execute) snort in sniffer mode use following command:
snort -dev -i 3
-i indicates the interface number. You must pick the correct interface number. In my case, it
is 3.
-dev is used to run snort to capture packets on your network.
You can tell which interface to use by looking at the Index number and finding Microsoft.
As you can see in the above example, the other interfaces are for VMWare. My interface is
3.
9. To run snort in IDS mode, you will need to configure the file “snort.conf” according to
your network environment.
10. To specify the network address that you want to protect in snort.conf file, look for the
following line.
var HOME_NET 192.168.1.0/24 (You will normally see any here)
11. You may also want to set the addresses of DNS_SERVERS, if you have some on your
network.
Example:
example snort
12. Change the RULE_PATH variable to the path of rules folder.
var RULE_PATH c:\snort\rules
path to rules
13. Change the path of all library files with the name and path on your system. and you
must change the path of snort_dynamicpreprocessorvariable. C:\Snort\lib\
snort_dynamiccpreprocessor
You need to do this to all library files in the “C:\Snort\lib” folder. The old path might be:
“/usr/local/lib/…”. you will need to replace that path with your system path. Using C:\
Snort\lib
14. Change the path ofthe “dynamicengine” variable value in the “snort.conf” file..
Example:
dynamicengine C:\Snort\lib\snort_dynamicengine\sf_engine.dll
15 Add the paths for “include classification.config” and “include reference.config” files.
include c:\snort\etc\classification.config
include c:\snort\etc\reference.config
16. Remove the comment (#) on the line to allow ICMP rules, if it is commented with a #.
include $RULE_PATH/icmp.rules
17. You can also remove the comment of ICMP-info rules comment, if it is
commented. include $RULE_PATH/icmp- info.rules
18. To add log files to store alerts generated by snort, search for the “output log” test in
snort.conf and add the following line:
output alert_fast: snort-alerts.ids
19. Comment (add a #) the whitelist $WHITE_LIST_PATH/white_list.rules and
the blacklist
Ifa log is created, select the appropriate program to open it. You can use WordPard or
NotePad++ to read the file.
To generate Log files in ASCII mode, you can use following command while running snort in
IDS mode:
snort -A console - i3 -c c:\Snort\etc\snort.conf -l c:\Snort\log -K ascii
23. Scan the computer that is running snort from another computer by using PING or NMap
(ZenMap).
After scanning or during the scan you can check the snort-alerts.ids file in the log folder to
insure it is logging properly. You will see IP address folders appear.
AIM:
Objectives
Firewall in Windows 7
Windows 7 comes with two firewalls that work together. One is the
Windows Firewall, and the other is Windows Firewall with
Advanced Security (WFAS). The main difference between them is
the complexity of the rules configuration. Windows Firewall uses
simple rules that directly relate to a program or a service. The rules in
WFAS can be configured based on protocols, ports, addresses and
authentication. By default, both firewalls come with predefined set of
rules that allow us to utilize network resources. This includes things
like browsing the web, receiving e-mails, etc. Other standard firewall
exceptions are File and Printer Sharing, Network Discovery,
Performance Logs and Alerts, Remote Administration, Windows
Remote Management, Remote Assistance, Remote
Desktop, Windows Media Player, Windows Media Player Network
Sharing Service
With firewall in Windows 7 we can configure inbound and outbound
rules. By default, all outbound traffic is allowed, and inbound responses
to that traffic are also allowed. Inbound traffic initiated from external
sources is automatically blocked.
Exceptions
To change settings in this window we have to click the "Change
settings" button. As you can see, here we have a list of predefined
programs and features that can be allowed to communicate on private
or public networks. For example, notice that the Core Networking
feature is allowed on both private and public networks, while the File
and Printer Sharing is only allowed on private networks. We can also
see the details of the items in the list by selecting it and then clicking
the Details button.
Details
If we have a program on our computer that is not in this list, we can
manually add it by clicking on the "Allow another program" button.
Add a Program
Here we have to browse to the executable of our program and then click
the Add button. Notice that we can also choose location types on which
this program will be allowed to communicate by clicking on the
"Network location types" button.
Network Locations
Many applications will automatically configure proper exceptions in
Windows Firewall when we run them. For example, if we enable
streaming from Media Player, it will automatically configure firewall
settings to allow streaming. The same thing is if we enable Remote
Desktop feature from the system properties window. By enabling
Remote Desktop feature we actually create an exception in Windows
Firewall.
Firewall Customization
Note that we can modify settings for each type of network location
(private or public). Interesting thing here is that we can block all
incoming connections, including those in the list of allowed programs.
Warning
The Windows Firewall with Advanced Security is a tool which gives you
detailed control over the rules that are applied by the Windows
Firewall. You can view all the rules that are used by the Windows Firewall,
change their properties, create new rules or disable existing ones. In this
tutorial we will share how to open the Windows Firewall with Advanced
Security, how to find your way around it and talk about the types of rules
that are available and what kind of traffic they filter.
The Windows Firewall with Advanced Security looks and works the same
both in Windows 7 and Windows 8.1. To continue our tutorial, we will use
screenshots that were made in Windows 8.1.
In order to provide the security you need, the Windows Firewall has a
standard set of inbound and outbound rules, which are enabled
depending on the location of the network you are connected to.
Inbound rules are applied to the traffic that is coming from the network
and the Internet to your computer or device. Outbound rules apply to
the traffic from your computer to the network or the Internet.
These rules can be configured so that they are specific to: computers,
users, programs, services, ports or protocols. You can also specify to
which type of network adapter (e.g. wireless, cable, virtual private
network) or user profile it is applied to.
In the Windows Firewall with Advanced Security, you can access all rules
and edit their properties. All you have to do is click or tap the appropriate
unit in the left-side panel.
The rules used by the Windows Firewall can be enabled or disabled.
The ones which are enabled or active are marked with a green check-
box in the Name column. The ones that are disabled are marked with a
gray check-box.
If you want to know more about a specific rule and learn its properties,
right click on it and select Properties or select it and press Properties
in the column on right, which lists the actions that are available for
your selection.
In the Properties window, you will find complete information about the
selected rule, what it does and in when it is applied. You will also be
able to edit its properties and change any of the available parameters.
What Are The Connection Security Rules?
Unlike the inbound or outbound rules, which are applied only to one
computer, connection security rules require that both computers have
the same rules defined and enabled.
If you want to see if there are any such rules on your computer, click or
tap "Connection Security Rules" on the panel on the left. By default,
there are no such rules defined on Windows computers and devices.
They are generally used in business environments and such rules are
set by the network administrator.
What Does the Windows Firewall with Advanced Security
Monitor?
You should note that the Monitoring section shows only the active
rules for the current network location.
Ex.No.8 Client Server communication by using UDP
DATE :
Algorithm :
PROGRAM:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
InetAddress ip = InetAddress.getLocalHost();
byte buf[] = null;
System.out.println("Client:-" + data(receive));
OUTPUT :
Client:- Hello
Client:- I am client.
...Client:- bye
Client sent bye.....EXITING
RESULT:
Thus the client server communication by using UDPDatagram has been implemented
successfully.
EX.NO.9 NETWORK MONITORING TOOLS
DATE :
Aim :
Network monitoring tools are software that you can use to evaluate network connections.
These software programs can help you monitor a network connection and identify network
issues, which may include failing network components, slow connection speed, network
outage or unidentifiable connections.
Network management and monitoring tools can also help you resolve these issues or
establish solutions that prevent specific issues from occurring in the future.
2.Auvik
Datadog Network Monitoring offers services for on-premises devices and cloud networks. A
highlighting feature of this tool is the visualisations. It offers various graphical
representations of all the network connections on a system. It also allows users to track key
metrics like network latency, connection churn and transmission control protocol (TCP)
retransmits. Users can monitor the health of a network connection at different endpoints at
the application, IP address, port or process ID layers. Other prominent features include
automated log collection and user interface monitoring.
4. Paessler PRTG Network Monitor
Paessler's network connection monitoring tool provides a clean user interface and network
visibility on multiple devices. Users can track the health of different connection types like
local area networks (LAN), wide area network (WAN), servers, websites, applications and
services. The tools also integrate with various technologies, which makes it easier to use it
for different types of applications. It provides distribute monitoring, allowing users to track
network connections on devices in different locations. The tool also provides apps for
mobile platforms that can help users to track network health on mobile phones.
5. ManageEngine OpManager
ManageEngine OpManager is a good network monitoring and managing tool for users that
prefer in-depth view of network health and issues. This tool provides over 2000 network
performance monitors that allow users to track and monitor their connections and perform
detailed analyses on issues. It also provides over 200 dashboard widgets that can help users
customise their dashboard to their own suitability. Other features include CPU, memory and
disk utilisation monitoring on local and virtual machines. It also allows setting network
performance threshold and notifies the user in case of a violation.
6. Domotz
Domotz is an expansive tool that provides a list of features for monitoring network
connections. It allows users to customise their network monitoring preferences. Users can
write scripts the retrieve the data they wish to evaluate. It also allows connection to open
ports on remote devices while ensuring network security. Users can also scan and monitor
network connections globally. Domotz also allows to backup and restore network
configuration for switches, firewalls and access points and alerts when there is a change in
the configuration.
7. Checkmk
Checkmk is a tool that allows users to automate it completely. You can customise its
operations and enable it to perform tasks automatically. It also identifies network and
security components without the user requiring manual set up. For example, the tool can
identify a firewall even if the user has not set it up. Its Agent Bakery feature enables users to
manage agents and automate agent updating. This reduces manual effort to monitor network
connections. The tool also includes over 2000 plug-ins for enhancing network monitoring.
Progress Whatsup Gold is a basic network monitoring software. It provides a minimal user
interface with essential features like device monitoring, application monitoring, analysing
network traffic and managing configurations. The tool allows users to monitor cloud
devices, inspect suspicious connections, automate configuration backups and identify, and
resolve bandwidth issues.
RESULT : Thus the Network monitoring tools has been explored successfully.
Ex.No.10 MITM ATTACK BY USING ARP POISONING
Date :
INTRODUCTION:
1. ARPSpoofing:
ARP Stands for Address Resolution Protocol. This protocol is used for
resolving IP addresses to machine MAC addresses. All the devices
which want to communicate in the network, broadcast ARP-queries in
the system to find out the MAC addresses of other machines. ARP
Spoofing is also known as ARP Poisoning. In this, ARP poisoning, ARP
packets are forced to send data to the attacker’s machine. ARP Spoofing
constructs a huge number of forced ARP requests and replies packets to
overload the switch. The intention of the attacker all the network packets
and switch set in forwarding mode.
2. DNSSpoofing :
Similar to ARP, DNS resolves domain names to IP addresses. DNS
spoofing is very dangerous because in this case a hacker will be able to
hijack and spoof any DNS request made by the user and can serve the
user fake web pages, fake websites, fake login pages, fake updates, and
so on.
Step-2:
To run this attack we need two things Victim machine’s IP address & the IP of Gateway.
In this example, we are using a Windows Machine as our victim and Kali Machine to run
the attack. To know the victim machines IP address and gateway IP by running the
following command in both the Windows machine and Linux Machine as follows.
arp –a
OUTPUT:
RESULT :
Thus the MITM ATTACK by using ARP Poisoning has been implemented.