Security Lab Manual PDF
Security Lab Manual PDF
Security Lab Manual PDF
PUDUVOYAL –
601206
IT6712–SECURITY LAB
MANUAL
4. Demonstrate how to provide secure data storage, secure data transmission and for
creating digital signatures (GnuPG).
7. Perform wireless audit on an access point or a router and decrypt WEP and WPA.(
Net Stumbler)
8. Demonstrate intrusion detection system (ids) using any tool (snort or any other
s/w)
TOTAL: 45
PERIODS
JDK 1.7/1.8
Gpg4Win
WinPcap
Snort
ViStumbler
KF Sensor
List of Contents
S.No. Name of the Experiment Page No.
1 Substitution & Transposition Ciphers
(a) Caesar Cipher 1
(b) Hill Cipher 4
(c) Vigenere Cipher 8
(d) Rail fence 12
2 Encryption & Authentication Algorithms
(a) DES 15
(b) RSA 19
(c) MD5/ SHA-1 24
(d) Diffie-Hellman 27
3 SIGNATURE SCHEME - Digital Signature Standard 31
Secure data storage, transmission and creating digital
4
35
signatures using GNU Privacy Guard (GnuPG)
5 Performing wireless audit using NetStumbler 40
Installation of rootkits and study about the variety of
6
41
options
7 Honeypot using KF Sensor 42
8 Intrusion Detection System using Snort 45
OMMAND 46
Appendix 1 – USING netsh C
Appendix 2 - DOWNLOAD LINKS 48
Ex. No: 1 (a) CAESAR CIPHER
Date :
AIM
ALGORITHM
1. Encryption:
C = E(k, p) = (p + k) mod 26
2. Decryption:
p = D(k, C) = (C - k) mod 26
D – Decryption Function
ii) Each character is converted into its appropriate ASCII character. So A = 65, B =
66 and Z = 90.
compensate for earlier subtraction. (Since ASCII for Upper case alphabets are
from 65-90)
1
/*Ceaser Cipher */
import java.util.Scanner;
plainText = plainText.toUpperCase();
//Encryption
System.out.println(cipherText);
plainTextChar = cipherText.toCharArray();
//Decryption
System.out.println(recoveredPlainText);
2
OUTPUT
RESULT
The Java program to perform encryption and decryption using Caesar Cipher was
successfully implemented.
3
Ex. No: 1 (b) HILL CIPHER
Date :
AIM
ALGORITHM
1. Encryption:
k11, k21, k31, k12, k22, k32, k13, k23 and k33 are key matrix elements
ii) Each character is converted into its appropriate ASCII character. So A = 65, B =
66 and Z = 90.
compensate for earlier subtraction. (Since ASCII for Upper case alphabets are
from 65-90)
4
/*HILL CIPHER*/
import java.util.Scanner;
class HillCipher {
char[] text=plainText.toCharArray();
int c1,c2,c3,p1,p2,p3;
p1=(int)text[0] - 65;
p2=(int)text[1] - 65;
p3=(int)text[2] - 65;
c1 = (key[0][0]*p1+key[0][1]*p2+key[0][2]*p3) % 26;
c2 = (key[1][0]*p1+key[1][1]*p2+key[1][2]*p3) % 26;
c3 = (key[2][0]*p1+key[2][1]*p2+key[2][2]*p3) % 26;
char[] cipherText=new char[3];
cipherText[0]=(char)(c1+65);
cipherText[1]=(char)(c2+65);
cipherText[2]=(char)(c3+65);
return String.valueOf(cipherText);
5
int[][] key=new int[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++){
key[i][j]= sc.nextInt();
}
}String cipherText = hillCipher.encrypt(plainText.toUpperCase(), key);
System.out.println("Cipher Text="+cipherText);
6
OUTPUT
/*Hill Cipher*/
RESULT
The Java program to perform encryption using Hill Cipher was successfully implemented.
7
Ex. No: 1 (c) VIGENERE CIPHER
Date :
AIM
ALGORITHM
1. Encryption
ii) Each character is converted into its appropriate ASCII character. So A = 65, B =
66 and Z = 90.
compensate for earlier subtraction. (Since ASCII for Upper case alphabets are
from 65-90)
8
/*VIGENERE CIPHER*/
import java.util.Arrays;
import java.util.Scanner;
String key=sc.nextLine();
char[] keyChar =
Arrays.copyOf(key.toUpperCase().toCharArray(),plainTextChar.length);
int i=0;
for(int j=key.toCharArray().length;j<keyChar.length;j++){
keyChar[j]=keyChar[i];
i++;
//Encryption
for(i=0;i<cipherTextChar.length;i++){
cipherTextChar[i]=(char)(int) ((plainTextChar[i]+keyChar[i]-130)%26+65);
}System.out.println("Cipher Text="+String.valueOf(cipherTextChar));
//Decryption
for(i=0;i<recoveredPlainTextChar.length;i++)
9
{
}System.out.println("Recovered Plain
Text="+String.valueOf(recoveredPlainTextChar).toLowerCase());
}
}
10
OUTPUT
/*Vigenere Cipher*/
RESULT
The Java program to perform encryption and decryption using Vigenere Cipher was
successfully implemented.
11
Ex. No: 1 (d) RAIL FENCE CIPHER
Date :
AIM
ALGORITHM
1. Encryption
The plaintext iswritten down as a sequence of diagonals and then read off as a sequence
of rows.
For example, to encipher the message “meet me after the toga party” with a
railfence of
m e ma t r h t g p r y
etefeteoaat
import java.util.Scanner;
int i, j = 0;
cipherTextChar[i] = plainTextChar[j];
j = j + 2;
}System.out.println("CipherText=" + String.valueOf(cipherTextChar));
j = 0;
recoveredPlainTextChar[i] = cipherTextChar[j];
j++;
13
OUTPUT
The Java program to perform encryption and decryption using Rail Fence Cipher was
successfully implemented.
14
Ex. No: 2 (a) DATA ENCRYPTION STANDARD
Date :
AIM
ALGORITHM
7. To recover the plain text message, perform decryption using appropriate method.
15
/*DES Demo*/
import com.sun.crypto.provider.SunJCE;
import java.util.Base64;
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.math.BigInteger;
importjava.security.Security;
importjavax.crypto.Cipher;
importjavax.crypto.KeyGenerator;
importjavax.crypto.SecretKey;
Security.addProvider(new SunJCE());
KeyGeneratorkeyGen = KeyGenerator.getInstance("DES");
SecretKey key=keyGen.generateKey();
16
//Base64 works in Java 8 only
//Encryption
cipher.init(Cipher.ENCRYPT_MODE, key);
//Decryption
cipher.init(Cipher.DECRYPT_MODE, key);
System.out.println();
}
17
OUTPUT
/*DES*/
RESULT
The Java program to perform encryption and decryption using DES was successfully
implemented.
18
Ex. No: 2 (b) RSA
Date :
AIM
ALGORITHM
Version 1:
7. To recover the plain text message, perform decryption using appropriate method.
Version 2:
2. Encryption
Memod n
C=
3. Decyption
Cdmod
M= n
19
/*RSA Demo */
import java.io.*;
importjava.math.BigInteger;
importjava.security.Security;
importjava.security.KeyPairGenerator;
importjava.security.Key;
importjava.security.KeyPair;
importjavax.crypto.Cipher;
importcom.sun.crypto.provider.SunJCE;
Security.addProvider(new SunJCE());
20
KeyPairGeneratorkpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPairkp = kpg.genKeyPair();
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
//Decryption
cipher.init(Cipher.DECRYPT_MODE, privateKey);
System.out.println();
21
/*RSA Version 2 */
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
BigInteger n = p.multiply(q);
BigInteger d = e.modInverse(phi);
22
OUTPUT
The Java program to perform encryption and decryption using RSA was successfully
implemented.
23
Ex. No: 2 (c) MD5/SHA-1
Date :
AIM
ALGORITHM
1. Using Java’s in-built packages, MD5/SHA-1 algorithm is implemented.
24
/*Message Digest Demo – MD5 and SHA-1*/
import java.io.*;
importjava.math.BigInteger;
importjava.security.Security;
importjava.security.MessageDigest;
importcom.sun.crypto.provider.SunJCE;
Security.addProvider(new SunJCE());
String message=br.readLine();
MessageDigest md = MessageDigest.getInstance("MD5");
//MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(input);
String hashValue=b.toString(16);
25
OUTPUT
/*MD5*/
/*SHA-1*/
RESULT
The Java program to generate message digest using MD5 and SHA-1 was successfully
implemented.
26
Ex. No: 2 (d) DIFFIE – HELLMAN KEY EXCHANGE
Date :
AIM
2. Get the prime number and one of its primitive root from the user.
6. Algorithm Formulae
XA
-U ser B’s Private Key User
ser A’s Private Key X B - U
A’s Public Key: YA = od q User
A m
αX B’s Public Key:YB =
od q Shared
αXB m Secret Key calculated by User A: K =
(YB ) X A m
od q Shared
Secret Key calculated by User B: K =
(YA ) X B m
od q
27
/*Diffie-Hellman Key Exchange*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.io.IOException;
28
} catch (ArithmeticException e) {
System.out.println(e);
} catch (IOException e) {
29
OUTPUT
30
Ex. No: 3 DIGITAL SIGNATURE STANDARD
Date :
AIM
ALGORITHM
import com.sun.crypto.provider.SunJCE;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
Security.addProvider(new SunJCE());
signature.update(message);
signature.initVerify(keyPair.getPublic());
signature.update(message);
if(signature.verify(sigBytes)==true)
System.out.println("Signature is verified");
}}
33
OUTPUT
The Java program to sign and verify digital signature using DSS was successfully
implemented.
34
Ex. No: 4 Using GNU Privacy Guard
Date :
AIM
using GnuPG.
1. Click File ->New Certificate -> A Certificate Creation Wizard appears as follows:
2. Choose and Click Create a personal OpenPGP key pair. It will prompt to enter
35
4. Click Next in the Certificate Creation Wizard. It will prompt to review certificate
5. The pinentry dialog box will appear and it will prompt to enter passphrase details.
After entering passphrase (use alphanumeric characters), it will prompt to re-enter the
passphrase. After re-entering, Key Pair Successfully Created message appears. Click
Finish
36
ENCRYPTING MESSAGE
37
3. Click File ->Sign/Encrypt Files and choose the text file containing plaintext
message.
4. Make sure that Encrypt radio button is checked and Click Next.
5. Choose receiver Certificate file details and click Add button. Details of selected file
DECRYPTING MESSAGE
1. Click File ->Decrypt/Verify Files and choose the file containing encrypted cipher
text
2. Click Decrypt/Verify button. Now the tool will prompt to enter receiver’s
3. Decryption succeeded message appears after saving the file in appropriate folder.
Click OK.
SIGNING A MESSAGE
1. Click File ->Sign/Encrypt Files and choose the text file containing plaintext
message.
2. Make sure that Sign radio button is checked and Click Next.
3. Choose the mail id of sender under OpenPGP Signing Certificate. Then click Sign
button.
38
4. Now the tool will prompt to enter passphrase of sender. Enter the passphrase. Now the
message is signed.
VERIFYING MESSAGE
1. Click File -> Decrypt/Verify File and choose the signature file.
2. Click Decrypt/Verify button. The following window appears. Click Show Details.
RESULT
Using Kleopatra
39
Ex. No: 5 Performing Wireless Audit Using ViStumbler
Date :
AIM
Using Vistumbler
1. Click Scan Aps button. You will see the following window.
2. Collapse and open the Channel panel on the left. The list of used channels and their
access points appear. If your channel has more access points, one can change to
channel with least access points by logging in to your default gateway address.
The Vistumbler tool was used to obtain wireless networks details like type of Authentication
used, Encryption algorithm used, channels used, SSID, signal strength etc.
40
Ex. No: 6 GMER – Rootkit Detection and Removal
Date :
AIM
PROCEDURE
The GMER application was installed and run for detection of rootkits. No rootkits were
found.
41
Ex. No: 7 SNORT
Date :
AIM
PROCEDURE
2. Install Snort
3. After installation, opensnort.confusing any text editor. (It is present in the location
C:\Snort\etc)
Environment Variables.
8. Sniffer Mode
snort -i 1 –v
43
10. Network IDS Mode
44
Ex. No: 8 KFSensor
Date :
AIM
PROCEDURE
45
APPENDIX 1 - USING netsh COMMAND
Netsh is a command-line scripting utility that allows you to, either locally or remotely,
display or modify the network configuration of a computer that is currently
running. Netsh also provides a scripting feature that allows you to run a group of commands
in batch mode against a specified computer.Netsh can also save a configuration script in a
text file for archival purposes or to help you configure other servers.
46
47
APPENDIX 2 – DOWNLOAD LINKS
1. GnuPG - Encryption software for files and emails (Supports OpenPGP and S/MIME)
https://www.gpg4win.org/
https://www.vistumbler.net/downloads.html
https://www.snort.org/downloads/snort/Snort_2_9_8_3_Installer.exe
http://www.gmer.net/
http://www.keyfocus.net/kfsensor/free-trial/
http://www.winpcap.org/install/default.htm
48