· 7 years ago · Oct 21, 2018, 06:22 PM
1Dharmapuri – 636 703
2PREPARED BY
3B.THENMOZHI
4AP/CSE
5Regulation : 2013
6Branch : B.E – CSE
7Year / Semester : IV/ VII
8Varuvan Vadivelan
9Institute of Technology
10LABORATORY MANUAL
11CS6711 – SECURITY LABORATORY
12Computer Science
13&
14Engineering
15CS6711 SECURITY LABORATORY
16VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 2
17ANNA UNIVERSITY CHENNAI
18REGULATION-2013
19CS6711 SECURITY LABORATORY
20OBJECTIVES:
21The student should be made to:
22 Learn to implement the algorithms DES, RSA,MD5,SHA-1
23 Learn to use network security tools like GnuPG, KF sensor, Net Strumbler
24LIST OF EXPERIMENTS:
251. Implement the following SUBSTITUTION & TRANSPOSITION TECHNIQUES
26concepts:
27a) Caesar Cipher
28b) Playfair Cipher
29c) Hill Cipher
30d) Vigenere Cipher
31e) Rail fence – row & Column Transformation
322. Implement the following algorithms
33a) DES
34b) RSA Algorithm
35c) Diffiee-Hellman
36d) MD5
37e) SHA-1
383. Implement the Signature Scheme - Digital Signature Standard
394. Demonstrate how to provide secure data storage, secure data transmission and for
40creating digital signatures (GnuPG)
415. Setup a honey pot and monitor the honeypot on network (KF Sensor)
426. Installation of rootkits and study about the variety of options
437. Perform wireless audit on an access point or a router and decrypt WEP and WPA.
44( Net Stumbler)
458. Demonstrate intrusion detection system (ids) using any tool (snort or any other s/w)
46TOTAL: 45 PERIODS
47CS6711 SECURITY LABORATORY
48VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 3
49OUTCOMES:
50At the end of the course, the student should be able to:
51 Implement the cipher techniques
52 Develop the various security algorithms
53 Use different open source tools for network security and analysis
54LIST OF HARDWARE REQUIREMENTS & SOFTWARE REQUIREMENTS
55SOFTWARE REQUIREMENTS
56 C
57 C++
58 Java or equivalent compiler GnuPG
59 KF Sensor or Equivalent
60 Snort
61 Net Stumbler or Equivalent
62HARDWARE REQUIREMENTS
63 Standalone desktops (or) Server supporting 30 terminals or more
64CS6711 SECURITY LABORATORY
65VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 4
66INDEX
67S.No.
68Name of the Program
69Page No.
70Staff Signature
71Remarks
721(A) Caesar Cipher
731(B) Playfair Cipher
741(C) Hill Cipher
751(D) Vigenere Cipher
761(E) Rail fence – row & Column
77Transformation
782(A) Data Encryption Standard(DES)
792(B) RSA Algorithm
802(C) Diffiee-Hellman Algorithm
812(D) MD5
822(E) SHA-1
833 Implement the Signature Scheme
84for Digital Signature Standard
854 Demonstrate how to provide secure
86data storage, secure data
87transmission and for
88creating digital signatures (GnuPG)
895 Setup a honey pot and monitor the
90honeypot on network (KF Sensor)
916 Installation of rootkits and study
92about the variety of options
937 Perform wireless audit on an access
94point or a router and decrypt WEP
95and WPA
96( Net Stumbler)
978 Demonstrate intrusion detection
98system (ids) using any tool
99(snort or any other s/w)
100CS6711 SECURITY LABORATORY
101EX. NO: 1(A)
102IMPLEMENTATION OF CAESAR CIPHER
103AIM:
104To implement the simple substitution technique named Caesar cipher using C language.
105DESCRIPTION:
106To encrypt a message with a Caesar cipher, each letter in the message is changed
107using a simple rule: shift by three. Each letter is replaced by the letter three letters ahead in
108the alphabet. A becomes D, B becomes E, and so on. For the last letters, we can think of
109alphabet as a circle and "wrap around". W becomes Z, X becomes A, Y becomes B, and Z
110becomes C. To change a message back, each letter is replaced by the one three before it.
111EXAMPLE:
112ALGORITHM:
113STEP-1: Read the plain text from the user.
114STEP-2: Read the key value from the user.
115STEP-3: If the key is positive then encrypt the text by adding the key with each
116character in the plain text.
117STEP-4: Else subtract the key from the plain text.
118STEP-5: Display the cipher text obtained above.
119PROGRAM: (Caesar Cipher)
120#include <stdio.h>
121#include <string.h>
122#include<conio.h>
123#include <ctype.h>
124void main()
125ipher)
126the
127CS6711 SECURITY LABORATORY
128VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 6
129{
130char plain[10], cipher[10];
131int key,i,length;
132int result;
133clrscr();
134printf("\n Enter the plain text:");
135scanf("%s", plain);
136printf("\n Enter the key value:");
137scanf("%d", &key);
138printf("\n \n \t PLAIN TEXt: %s",plain);
139printf("\n \n \t ENCRYPTED TEXT: ");
140for(i = 0, length = strlen(plain); i < length; i++)
141{
142cipher[i]=plain[i] + key;
143if (isupper(plain[i]) && (cipher[i] > 'Z'))
144cipher[i] = cipher[i] - 26;
145if (islower(plain[i]) && (cipher[i] > 'z'))
146cipher[i] = cipher[i] - 26;
147printf("%c", cipher[i]);
148}
149printf("\n \n \t AFTER DECRYPTION : ");
150for(i=0;i<length;i++)
151{
152plain[i]=cipher[i]-key;
153if(isupper(cipher[i])&&(plain[i]<'A'))
154plain[i]=plain[i]+26;
155if(islower(cipher[i])&&(plain[i]<'a'))
156plain[i]=plain[i]+26;
157printf("%c",plain[i]);
158}
159getch();
160}
161CS6711 SECURITY LABORATORY
162VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 7
163OUTPUT:
164RESULT:
165Thus the implementation of Caesar cipher had been executed successfully.
166CS6711 SECURITY LABORATORY
167VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 8
168EX. NO: 1(B)
169IMPLEMENTATION OF PLAYFAIR CIPHER
170AIM:
171To write a C program to implement the Playfair Substitution technique.
172DESCRIPTION:
173The Playfair cipher starts with creating a key table. The key table is a 5×5 grid of
174letters that will act as the key for encrypting your plaintext. Each of the 25 letters must be
175unique and one letter of the alphabet is omitted from the table (as there are 25 spots and 26
176letters in the alphabet).
177To encrypt a message, one would break the message into digrams (groups of 2 letters)
178such that, for example, "HelloWorld" becomes "HE LL OW OR LD", and map them out on
179the key table. The two letters of the diagram are considered as the opposite corners of a
180rectangle in the key table. Note the relative position of the corners of this rectangle. Then
181apply the following 4 rules, in order, to each pair of letters in the plaintext:
1821. If both letters are the same (or only one letter is left), add an "X" after the first letter
1832. If the letters appear on the same row of your table, replace them with the letters to
184their immediate right respectively
1853. If the letters appear on the same column of your table, replace them with the letters
186immediately below respectively
1874. If the letters are not on the same row or column, replace them with the letters on the
188same row respectively but at the other pair of corners of the rectangle defined by the
189original pair.
190EXAMPLE:
191CS6711 SECURITY LABORATORY
192VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 9
193ALGORITHM:
194STEP-1: Read the plain text from the user.
195STEP-2: Read the keyword from the user.
196STEP-3: Arrange the keyword without duplicates in a 5*5 matrix in the row order and
197fill the remaining cells with missed out letters in alphabetical order. Note that
198‘i’ and ‘j’ takes the same cell.
199STEP-4: Group the plain text in pairs and match the corresponding corner letters by
200forming a rectangular grid.
201STEP-5: Display the obtained cipher text.
202PROGRAM: (Playfair Cipher)
203#include<stdio.h>
204#include<conio.h>
205#include<string.h>
206#include<ctype.h>
207#define MX 5
208void playfair(char ch1,char ch2, char key[MX][MX])
209{
210int i,j,w,x,y,z;
211FILE *out;
212if((out=fopen("cipher.txt","a+"))==NULL)
213{
214printf("File Currupted.");
215}
216for(i=0;i<MX;i++)
217{
218for(j=0;j<MX;j++)
219{
220if(ch1==key[i][j])
221{
222w=i;
223x=j;
224}
225else if(ch2==key[i][j])
226{
227y=i;
228z=j;
229}}}
230//printf("%d%d %d%d",w,x,y,z);
231if(w==y)
232{
233x=(x+1)%5;z=(z+1)%5;
234printf("%c%c",key[w][x],key[y][z]);
235fprintf(out, "%c%c",key[w][x],key[y][z]);
236}
237else if(x==z)
238{
239CS6711 SECURITY LABORATORY
240VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 10
241w=(w+1)%5;y=(y+1)%5;
242printf("%c%c",key[w][x],key[y][z]);
243fprintf(out, "%c%c",key[w][x],key[y][z]);
244}
245else
246{
247printf("%c%c",key[w][z],key[y][x]);
248fprintf(out, "%c%c",key[w][z],key[y][x]);
249}
250fclose(out);
251}
252void main()
253{
254int i,j,k=0,l,m=0,n;
255char key[MX][MX],keyminus[25],keystr[10],str[25]={0};
256char
257alpa[26]={'A','B','C','D','E','F','G','H','I','J','K','L'
258,'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
259;
260clrscr();
261printf("\nEnter key:");
262gets(keystr);
263printf("\nEnter the plain text:");
264gets(str);
265n=strlen(keystr);
266//convert the characters to uppertext
267for (i=0; i<n; i++)
268{
269if(keystr[i]=='j')keystr[i]='i';
270else if(keystr[i]=='J')keystr[i]='I';
271keystr[i] = toupper(keystr[i]);
272}
273//convert all the characters of plaintext to uppertext
274for (i=0; i<strlen(str); i++)
275{
276if(str[i]=='j')str[i]='i';
277else if(str[i]=='J')str[i]='I';
278str[i] = toupper(str[i]);
279}
280j=0;
281for(i=0;i<26;i++)
282{
283for(k=0;k<n;k++)
284{
285if(keystr[k]==alpa[i])
286break;
287else if(alpa[i]=='J')
288break;
289}
290if(k==n)
291{
292keyminus[j]=alpa[i];j++;
293}
294}
295CS6711 SECURITY LABORATORY
296VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 11
297//construct key keymatrix
298k=0;
299for(i=0;i<MX;i++)
300{
301for(j=0;j<MX;j++)
302{
303if(k<n)
304{
305key[i][j]=keystr[k];
306k++;}
307else
308{
309key[i][j]=keyminus[m];m++;
310}
311printf("%c ",key[i][j]);
312}
313printf("\n");
314}
315printf("\n\nEntered text :%s\nCipher Text :",str);
316for(i=0;i<strlen(str);i++)
317{
318if(str[i]=='J')str[i]='I';
319if(str[i+1]=='\0')
320playfair(str[i],'X',key);
321else
322{
323if(str[i+1]=='J')str[i+1]='I';
324if(str[i]==str[i+1])
325playfair(str[i],'X',key);
326else
327{
328playfair(str[i],str[i+1],key);i++;
329}}
330}
331getch();
332}
333CS6711 SECURITY LABORATORY
334VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 12
335OUTPUT:
336RESULT:
337Thus the Playfair cipher substitution technique had been implemented successfully.
338CS6711 SECURITY LABORATORY
339EX. NO: 1(C)
340IMPLEMENTATION OF HILL CIPHER
341AIM:
342To write a C program to implement the hill cipher substitution techniques.
343DESCRIPTION:
344Each letter is represented by a number
345= 1... Z = 25, is used, but this is not an essential feature of the cipher. To encrypt a message,
346each block of n letters is multiplied by an invertible
347decrypt the message, each block is multiplied by the inverse of the matrix used for
348encryption. The matrix used for encryption is the cipher
349randomly from the set of invertible
350EXAMPLE:
351ALGORITHM:
352STEP-1: Read the plain text and key from the user.
353STEP-2: Split the plain text into groups of
354STEP-3: Arrange the keyword in a 3*3 matrix.
355STEP-4: Multiply the two matrices to obtain the cipher text of length three.
356STEP-5: Combine all these groups to get the complete cipher text.
357PROGRAM: (Hill Cipher)
358#include<stdio.h>
359#include<conio.h>
360#include<string.h>
361int main(){
362unsigned int a[3][3]={{6,24,1},{13,16,10},{20,17,15}};
363unsigned int b[3][3]={{8,5,10},{21,8,21},{21,12,8}};
364int i,j, t=0;
365unsigned int c[20],d[20];
366char msg[20];
367clrscr();
368printf("Enter plain text
369scanf("%s",msg);
370for(i=0;i<strlen(msg);i++)
371{ c[i]=msg[i]-65;
372modulo 26. Often the simple scheme A = 0, B
373ltiplied n × n matrix, against modulus
374sage, key, and it should be chosen
375n × n matrices (modulo 26).
376length three.
377text\n ");
37826. To
379,
380CS6711 SECURITY LABORATORY
381VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 14
382printf("%d ",c[i]);
383}
384for(i=0;i<3;i++)
385{ t=0;
386for(j=0;j<3;j++)
387{
388t=t+(a[i][j]*c[j]);
389}
390d[i]=t%26;
391}
392printf("\nEncrypted Cipher Text :");
393for(i=0;i<3;i++)
394printf(" %c",d[i]+65);
395for(i=0;i<3;i++)
396{
397t=0;
398for(j=0;j<3;j++)
399{
400t=t+(b[i][j]*d[j]);
401}
402c[i]=t%26;
403}
404printf("\nDecrypted Cipher Text :");
405for(i=0;i<3;i++)
406printf(" %c",c[i]+65);
407getch();
408return 0;
409}
410OUTPUT:
411RESULT:
412Thus the hill cipher substitution technique had been implemented successfully in C.
413CS6711 SECURITY LABORATORY
414EX. NO: 1(D)
415IMPLEMENTATION OF VIGENERE CIPHER
416AIM:
417To implement the Vigenere C
418DESCRIPTION:
419To encrypt, a table of alphabets can be used, termed a
420or Vigenère table. It consists of the alphabet written out 26 times in different rows, each
421alphabet shifted cyclically to the left compared to the prev
42226 possible Caesar ciphers. At different points in the encryption process, the cipher uses a
423different alphabet from one of the rows. The alphabet used at each point depends on a
424repeating keyword.
425Each row starts with a key letter. The remainder of the row holds the letters A to Z.
426Although there are 26 key rows shown, you will only use as many keys as there are unique
427letters in the key string, here just 5 keys, {L, E, M, O, N}. For successive letters of the
428message, we are going to take successive letters of the key string, and encipher each message
429letter using its corresponding key row. Choose the next letter of the key, go along that row to
430find the column heading that matches the message character; the letter at the
431[key-row, msg-col] is the enciphered letter.
432EXAMPLE:
433Cipher substitution technique using C program.
434tabula recta, Vigenère square,
435previous alphabet, corresponding to the
436intersection of
437ipher ious
438CS6711 SECURITY LABORATORY
439VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 16
440ALGORITHM:
441STEP-1: Arrange the alphabets in row and column of a 26*26 matrix.
442STEP-2: Circulate the alphabets in each row to position left such that the first letter is
443attached to last.
444STEP-3: Repeat this process for all 26 rows and construct the final key matrix.
445STEP-4: The keyword and the plain text is read from the user.
446STEP-5: The characters in the keyword are repeated sequentially so as to match with
447that of the plain text.
448STEP-6: Pick the first letter of the plain text and that of the keyword as the row indices
449and column indices respectively.
450STEP-7: The junction character where these two meet forms the cipher character.
451STEP-8: Repeat the above steps to generate the entire cipher text.
452PROGRAM: (Vigenere Cipher)
453#include <stdio.h>
454#include<conio.h>
455#include <ctype.h>
456#include <string.h>
457void encipher();
458void decipher();
459void main()
460{
461int choice;
462clrscr();
463while(1)
464{
465printf("\n1. Encrypt Text");
466printf("\t2. Decrypt Text");
467printf("\t3. Exit");
468printf("\n\nEnter Your Choice : ");
469scanf("%d",&choice);
470if(choice == 3)
471exit(0);
472else if(choice == 1)
473encipher();
474else if(choice == 2)
475decipher();
476else
477printf("Please Enter Valid Option.");
478}
479}
480void encipher()
481{
482unsigned int i,j;
483char input[50],key[10];
484printf("\n\nEnter Plain Text: ");
485CS6711 SECURITY LABORATORY
486VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 17
487scanf("%s",input);
488printf("\nEnter Key Value: ");
489scanf("%s",key);
490printf("\nResultant Cipher Text: ");
491for(i=0,j=0;i<strlen(input);i++,j++)
492{
493if(j>=strlen(key))
494{ j=0;
495}
496printf("%c",65+(((toupper(input[i])-65)+(toupper(key[j])-
49765))%26));
498}}
499void decipher()
500{
501unsigned int i,j;
502char input[50],key[10];
503int value;
504printf("\n\nEnter Cipher Text: ");
505scanf("%s",input);
506printf("\n\nEnter the key value: ");
507scanf("%s",key);
508for(i=0,j=0;i<strlen(input);i++,j++)
509{
510if(j>=strlen(key))
511{ j=0; }
512value = (toupper(input[i])-64)-(toupper(key[j])-64);
513if( value < 0)
514{ value = value * -1;
515}
516printf("%c",65 + (value % 26));
517}}
518CS6711 SECURITY LABORATORY
519VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 18
520OUTPUT:
521RESULT:
522Thus the Vigenere Cipher substitution technique had been implemented successfully.
523CS6711 SECURITY LABORATORY
524VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 19
525EX. NO: 1(E)
526IMPLEMENTATION OF RAIL FENCE – ROW & COLUMN
527TRANSFORMATION TECHNIQUE
528AIM:
529To write a C program to implement the rail fence transposition technique.
530DESCRIPTION:
531In the rail fence cipher, the plain text is written downwards and diagonally on
532successive "rails" of an imaginary fence, then moving up when we reach the bottom rail.
533When we reach the top rail, the message is written downwards again until the whole plaintext
534is written out. The message is then read off in rows.
535EXAMPLE:
536ALGORITHM:
537STEP-1: Read the Plain text.
538STEP-2: Arrange the plain text in row columnar matrix format.
539STEP-3: Now read the keyword depending on the number of columns of the plain text.
540STEP-4: Arrange the characters of the keyword in sorted order and the corresponding
541columns of the plain text.
542STEP-5: Read the characters row wise or column wise in the former order to get the
543cipher text.
544CS6711 SECURITY LABORATORY
545VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 20
546PROGRAM: (Rail Fence)
547#include<stdio.h>
548#include<conio.h>
549#include<string.h>
550void main()
551{
552int i,j,k,l;
553char a[20],c[20],d[20];
554clrscr();
555printf("\n\t\t RAIL FENCE TECHNIQUE");
556printf("\n\nEnter the input string : ");
557gets(a);
558l=strlen(a);
559/*Ciphering*/
560for(i=0,j=0;i<l;i++)
561{
562if(i%2==0)
563c[j++]=a[i];
564}
565for(i=0;i<l;i++)
566{
567if(i%2==1)
568c[j++]=a[i];
569}
570c[j]='\0';
571printf("\nCipher text after applying rail fence :");
572printf("\n%s",c);
573/*Deciphering*/
574if(l%2==0)
575k=l/2;
576else
577k=(l/2)+1;
578for(i=0,j=0;i<k;i++)
579{
580d[j]=c[i];
581j=j+2;
582}
583for(i=k,j=1;i<l;i++)
584{
585d[j]=c[i];
586j=j+2;
587}
588d[l]='\0';
589printf("\nText after decryption : ");
590printf("%s",d);
591getch();
592}
593CS6711 SECURITY LABORATORY
594VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 21
595OUTPUT:
596RESULT:
597Thus the rail fence algorithm had been executed successfully.
598CS6711 SECURITY LABORATORY
599VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 22
600EX. NO: 2(A) IMPLEMENTATION OF DES
601AIM:
602To write a C program to implement Data Encryption Standard (DES) using C
603Language.
604DESCRIPTION:
605DES is a symmetric encryption system that uses 64-bit blocks, 8 bits of which are
606used for parity checks. The key therefore has a "useful" length of 56 bits, which means that
607only 56 bits are actually used in the algorithm. The algorithm involves carrying out
608combinations, substitutions and permutations between the text to be encrypted and the key,
609while making sure the operations can be performed in both directions. The key is ciphered on
61064 bits and made of 16 blocks of 4 bits, generally denoted k1 to k16. Given that "only" 56 bits
611are actually used for encrypting, there can be 256 different keys.
612The main parts of the algorithm are as follows:
613 Fractioning of the text into 64-bit blocks
614 Initial permutation of blocks
615 Breakdown of the blocks into two parts: left and right, named L and R
616 Permutation and substitution steps repeated 16 times
617 Re-joining of the left and right parts then inverse initial permutation
618EXAMPLE:
619CS6711 SECURITY LABORATORY
620VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 23
621ALGORITHM:
622STEP-1: Read the 64-bit plain text.
623STEP-2: Split it into two 32-bit blocks and store it in two different arrays.
624STEP-3: Perform XOR operation between these two arrays.
625STEP-4: The output obtained is stored as the second 32-bit sequence and the original
626second 32-bit sequence forms the first part.
627STEP-5: Thus the encrypted 64-bit cipher text is obtained in this way. Repeat the same
628process for the remaining plain text characters.
629PROGRAM:
630DES.java
631import javax.swing.*;
632import java.security.SecureRandom;
633import javax.crypto.Cipher;
634import javax.crypto.KeyGenerator;
635import javax.crypto.SecretKey;
636import javax.crypto.spec.SecretKeySpec;
637import java.util.Random ;
638class DES {
639byte[] skey = new byte[1000];
640String skeyString;
641static byte[] raw;
642String inputMessage,encryptedData,decryptedMessage;
643public DES()
644{
645try
646{
647generateSymmetricKey();
648inputMessage=JOptionPane.showInputDialog(null,"Enter
649message to encrypt");
650byte[] ibyte = inputMessage.getBytes();
651byte[] ebyte=encrypt(raw, ibyte);
652String encryptedData = new String(ebyte);
653System.out.println("Encrypted message "+encryptedData);
654JOptionPane.showMessageDialog(null,"Encrypted Data
655"+"\n"+encryptedData);
656byte[] dbyte= decrypt(raw,ebyte);
657String decryptedMessage = new String(dbyte);
658System.out.println("Decrypted message
659"+decryptedMessage);
660JOptionPane.showMessageDialog(null,"Decrypted Data
661"+"\n"+decryptedMessage);
662}
663catch(Exception e)
664{
665System.out.println(e);
666}
667}
668CS6711 SECURITY LABORATORY
669VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 24
670void generateSymmetricKey() {
671try {
672Random r = new Random();
673int num = r.nextInt(10000);
674String knum = String.valueOf(num);
675byte[] knumb = knum.getBytes();
676skey=getRawKey(knumb);
677skeyString = new String(skey);
678System.out.println("DES Symmetric key = "+skeyString);
679}
680catch(Exception e)
681{
682System.out.println(e);
683}
684}
685private static byte[] getRawKey(byte[] seed) throws Exception
686{
687KeyGenerator kgen = KeyGenerator.getInstance("DES");
688SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
689sr.setSeed(seed);
690kgen.init(56, sr);
691SecretKey skey = kgen.generateKey();
692raw = skey.getEncoded();
693return raw;
694}
695private static byte[] encrypt(byte[] raw, byte[] clear) throws
696Exception {
697SecretKeySpec skeySpec = new SecretKeySpec(raw,
698"DES");
699Cipher cipher = Cipher.getInstance("DES");
700cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
701byte[] encrypted = cipher.doFinal(clear);
702return encrypted;
703}
704private static byte[] decrypt(byte[] raw, byte[] encrypted)
705throws Exception
706{
707SecretKeySpec skeySpec = new SecretKeySpec(raw,
708"DES");
709Cipher cipher = Cipher.getInstance("DES");
710cipher.init(Cipher.DECRYPT_MODE, skeySpec);
711byte[] decrypted = cipher.doFinal(encrypted);
712return decrypted;
713}
714public static void main(String args[]) {
715DES des = new DES();
716}
717}
718CS6711 SECURITY LABORATORY
719VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 25
720OUTPUT:
721CS6711 SECURITY LABORATORY
722VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 26
723RESULT:
724Thus the data encryption standard algorithm had been implemented successfully
725using C language.
726CS6711 SECURITY LABORATORY
727VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 27
728EX. NO: 2(B) IMPLEMENTATION OF RSA
729AIM:
730To write a C program to implement the RSA encryption algorithm.
731DESCRIPTION:
732RSA is an algorithm used by modern computers to encrypt and decrypt messages. It
733is an asymmetric cryptographic algorithm. Asymmetric means that there are two different
734keys. This is also called public key cryptography, because one of them can be given to
735everyone. A basic principle behind RSA is the observation that it is practical to find three
736very large positive integers e, d and n such that with modular exponentiation for all
737integer m:
738(me)d = m (mod n)
739The public key is represented by the integers n and e; and, the private key, by the
740integer d. m represents the message. RSA involves a public key and a private key. The public
741key can be known by everyone and is used for encrypting messages. The intention is that
742messages encrypted with the public key can only be decrypted in a reasonable amount of
743time using the private key.
744EXAMPLE:
745CS6711 SECURITY LABORATORY
746VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 28
747ALGORITHM:
748STEP-1: Select two co-prime numbers as p and q.
749STEP-2: Compute n as the product of p and q.
750STEP-3: Compute (p-1)*(q-1) and store it in z.
751STEP-4: Select a random prime number e that is less than that of z.
752STEP-5: Compute the private key, d as e * mod-1(z).
753STEP-6: The cipher text is computed as messagee * mod n.
754STEP-7: Decryption is done as cipherdmod n.
755PROGRAM: (RSA)
756#include<stdio.h>
757#include<conio.h>
758#include<stdlib.h>
759#include<math.h>
760#include<string.h>
761long int
762p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
763char msg[100];
764int prime(long int);
765void ce();
766long int cd(long int);
767void encrypt();
768void decrypt();
769void main()
770{
771clrscr();
772printf("\nENTER FIRST PRIME NUMBER\n");
773scanf("%d",&p);
774flag=prime(p);
775if(flag==0)
776{
777printf("\nWRONG INPUT\n");
778getch();
779}
780printf("\nENTER ANOTHER PRIME NUMBER\n");
781scanf("%d",&q);
782flag=prime(q);
783if(flag==0||p==q)
784{
785printf("\nWRONG INPUT\n");
786getch();
787}
788printf("\nENTER MESSAGE\n");
789fflush(stdin);
790scanf("%s",msg);
791for(i=0;msg[i]!=NULL;i++)
792m[i]=msg[i];
793n=p*q;
794CS6711 SECURITY LABORATORY
795VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 29
796t=(p-1)*(q-1);
797ce();
798printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
799for(i=0;i<j-1;i++)
800printf("\n%ld\t%ld",e[i],d[i]);
801encrypt();
802decrypt();
803getch();
804}
805int prime(long int pr)
806{
807int i;
808j=sqrt(pr);
809for(i=2;i<=j;i++)
810{
811if(pr%i==0)
812return 0;
813}
814return 1;
815}
816void ce()
817{
818int k;
819k=0;
820for(i=2;i<t;i++)
821{
822if(t%i==0)
823continue;
824flag=prime(i);
825if(flag==1&&i!=p&&i!=q)
826{
827e[k]=i;
828flag=cd(e[k]);
829if(flag>0)
830{
831d[k]=flag;
832k++;
833}
834if(k==99)
835break;
836} } }
837long int cd(long int x)
838{
839long int k=1;
840while(1)
841{
842k=k+t;
843if(k%x==0)
844return(k/x);
845} }
846void encrypt() {
847long int pt,ct,key=e[0],k,len;
848i=0;
849len=strlen(msg);
850CS6711 SECURITY LABORATORY
851VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 30
852while(i!=len) {
853pt=m[i];
854pt=pt-96;
855k=1;
856for(j=0;j<key;j++)
857{ k=k*pt;
858k=k%n;
859}
860temp[i]=k;
861ct=k+96;
862en[i]=ct;
863i++;
864}
865en[i]=-1;
866printf("\nTHE ENCRYPTED MESSAGE IS\n");
867for(i=0;en[i]!=-1;i++)
868printf("%c",en[i]);
869}
870void decrypt()
871{
872long int pt,ct,key=d[0],k;
873i=0;
874while(en[i]!=-1)
875{
876ct=temp[i];
877k=1;
878for(j=0;j<key;j++)
879{
880k=k*ct;
881k=k%n;
882}
883pt=k+96;
884m[i]=pt;
885i++;
886}
887m[i]=-1;
888printf("\nTHE DECRYPTED MESSAGE IS\n");
889for(i=0;m[i]!=-1;i++)
890printf("%c",m[i]);
891}
892CS6711 SECURITY LABORATORY
893VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 31
894OUTPUT:
895RESULT:
896Thus the C program to implement RSA encryption technique had been implemented
897successfully
898CS6711 SECURITY LABORATORY
899VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 32
900EX. NO: 2(C)
901IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE
902ALGORITHM
903AIM:
904To implement the Diffie-Hellman Key Exchange algorithm using C language.
905DESCRIPTION:
906Diffie–Hellman Key Exchange establishes a shared secret between two parties that
907can be used for secret communication for exchanging data over a public network. It is
908primarily used as a method of exchanging cryptography keys for use in symmetric encryption
909algorithms like AES. The algorithm in itself is very simple. The process begins by having the
910two parties, Alice and Bob. Let's assume that Alice wants to establish a shared secret with
911Bob.
912EXAMPLE:
913ALGORITHM:
914STEP-1: Both Alice and Bob shares the same public keys g and p.
915STEP-2: Alice selects a random public key a.
916STEP-3: Alice computes his secret key A as ga mod p.
917STEP-4: Then Alice sends A to Bob.
918CS6711 SECURITY LABORATORY
919VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 33
920STEP-5: Similarly Bob also selects a public key b and computes his secret key as B
921and sends the same back to Alice.
922STEP-6: Now both of them compute their common secret key as the other one’s secret
923key power of a mod p.
924PROGRAM: (Diffie Hellman Key Exchange)
925#include<stdio.h>
926#include<conio.h>
927long long int power(int a, int b, int mod)
928{
929long long int t;
930if(b==1)
931return a;
932t=power(a,b/2,mod);
933if(b%2==0)
934return (t*t)%mod;
935else
936return (((t*t)%mod)*a)%mod;
937}
938long int calculateKey(int a, int x, int n)
939{
940return power(a,x,n);
941}
942void main()
943{
944int n,g,x,a,y,b;
945clrscr();
946printf("Enter the value of n and g : ");
947scanf("%d%d",&n,&g);
948printf("Enter the value of x for the first person : ");
949scanf("%d",&x);
950a=power(g,x,n);
951printf("Enter the value of y for the second person : ");
952scanf("%d",&y);
953b=power(g,y,n);
954printf("key for the first person is :
955%lld\n",power(b,x,n));
956printf("key for the second person is :
957%lld\n",power(a,y,n));
958getch();
959}
960CS6711 SECURITY LABORATORY
961VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 34
962OUTPUT:
963RESULT:
964Thus the Diffie-Hellman key exchange algorithm had been successfully implemented
965using C.
966CS6711 SECURITY LABORATORY
967EX. NO: 2(D)
968IMPLEMENTATION OF MD5
969AIM:
970To write a C program to implement the MD5 hashing technique.
971DESCRIPTION:
972MD5 processes a variable
973input message is broken up into chunks of 512
974length is divisible by 512. The padding works as follows: first a single bit, 1, is appended to
975the end of the message. This is followed by as many zeros as are required to bring the length
976of the message up to 64 bits less than a multiple of 512. The remaining bits are filled up
97764 bits representing the length of the original message, modulo 2
978operates on a 128-bit state, divided into four 32
979initialized to certain fixed constants. The main algorithm then u
980block in turn to modify the state.
981EXAMPLE:
982ALGORITHM:
983STEP-1: Read the 128-bit plain text.
984STEP-2: Divide into four blocks of 32
985variable-length message into a fixed-length output of 128 bits. The
986p 512-bit blocks. The message is padded
9872. 64.The main MD5 algorithm
98832-bit words, denoted A, B, C, and
989uses each 512
99032-bits named as A, B, C and D.
991so that its
992with
993, D. These are
994ses 512-bit message
995CS6711 SECURITY LABORATORY
996VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 36
997STEP-3: Compute the functions f, g, h and i with operations such as, rotations,
998permutations, etc,.
999STEP-4: The output of these functions are combined together as F and performed
1000circular shifting and then given to key round.
1001STEP-5: Finally, right shift of ‘s’ times are performed and the results are combined
1002together to produce the final output.
1003PROGRAM:( MD5)
1004#include <stdlib.h>
1005#include <stdio.h>
1006#include <string.h>
1007#include <math.h>
1008#include<conio.h>
1009typedef union uwb
1010{
1011unsigned w;
1012unsigned char b[4];
1013} MD5union;
1014typedef unsigned DigestArray[4];
1015unsigned func0( unsigned abcd[] ){
1016return ( abcd[1] & abcd[2]) | (~abcd[1] & abcd[3]);}
1017unsigned func1( unsigned abcd[] ){
1018return ( abcd[3] & abcd[1]) | (~abcd[3] & abcd[2]);}
1019unsigned func2( unsigned abcd[] ){
1020return abcd[1] ^ abcd[2] ^ abcd[3];}
1021unsigned func3( unsigned abcd[] ){
1022return abcd[2] ^ (abcd[1] |~ abcd[3]);}
1023typedef unsigned (*DgstFctn)(unsigned a[]);
1024unsigned *calctable( unsigned *k)
1025{
1026double s, pwr;
1027int i;
1028pwr = pow( 2, 32);
1029for (i=0; i<64; i++)
1030{
1031s = fabs(sin(1+i));
1032k[i] = (unsigned)( s * pwr );
1033}
1034return k;
1035}
1036unsigned rol( unsigned r, short N )
1037{
1038unsigned mask1 = (1<<N) -1;
1039return ((r>>(32-N)) & mask1) | ((r<<N) & ~mask1);
1040}
1041CS6711 SECURITY LABORATORY
1042VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 37
1043unsigned *md5( const char *msg, int mlen)
1044{
1045static DigestArray h0 = { 0x67452301, 0xEFCDAB89,
10460x98BADCFE, 0x10325476 };
1047static DgstFctn ff[] = { &func0, &func1, &func2, &func3};
1048static short M[] = { 1, 5, 3, 7 };
1049static short O[] = { 0, 1, 5, 0 };
1050static short rot0[] = { 7,12,17,22};
1051static short rot1[] = { 5, 9,14,20};
1052static short rot2[] = { 4,11,16,23};
1053static short rot3[] = { 6,10,15,21};
1054static short *rots[] = {rot0, rot1, rot2, rot3 };
1055static unsigned kspace[64];
1056static unsigned *k;
1057static DigestArray h;
1058DigestArray abcd;
1059DgstFctn fctn;
1060short m, o, g;
1061unsigned f;
1062short *rotn;
1063union
1064{
1065unsigned w[16];
1066char b[64];
1067}mm;
1068int os = 0;
1069int grp, grps, q, p;
1070unsigned char *msg2;
1071if (k==NULL) k= calctable(kspace);
1072for (q=0; q<4; q++) h[q] = h0[q]; // initialize
1073{
1074grps = 1 + (mlen+8)/64;
1075msg2 = malloc( 64*grps);
1076memcpy( msg2, msg, mlen);
1077msg2[mlen] = (unsigned char)0x80;
1078q = mlen + 1;
1079while (q < 64*grps){ msg2[q] = 0; q++ ; }
1080{
1081MD5union u;
1082u.w = 8*mlen;
1083q -= 8;
1084memcpy(msg2+q, &u.w, 4 );
1085}
1086}
1087for (grp=0; grp<grps; grp++)
1088{
1089memcpy( mm.b, msg2+os, 64);
1090CS6711 SECURITY LABORATORY
1091VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 38
1092for(q=0;q<4;q++) abcd[q] = h[q];
1093for (p = 0; p<4; p++)
1094{
1095fctn = ff[p];
1096rotn = rots[p];
1097m = M[p]; o= O[p];
1098for (q=0; q<16; q++)
1099{
1100g = (m*q + o) % 16;
1101f = abcd[1] + rol( abcd[0]+ fctn(abcd)+k[q+16*p]
1102+ mm.w[g], rotn[q%4]);
1103abcd[0] = abcd[3];
1104abcd[3] = abcd[2];
1105abcd[2] = abcd[1];
1106abcd[1] = f;
1107}}
1108for (p=0; p<4; p++)
1109h[p] += abcd[p];
1110os += 64;
1111}
1112return h;}
1113void main()
1114{
1115int j,k;
1116const char *msg = "The quick brown fox jumps over
1117the lazy dog";
1118unsigned *d = md5(msg, strlen(msg));
1119MD5union u;
1120clrscr();
1121printf("\t MD5 ENCRYPTION ALGORITHM IN C \n\n");
1122printf("Input String to be Encrypted using MD5 :
1123\n\t%s",msg);
1124printf("\n\nThe MD5 code for input string is: \n");
1125printf("\t= 0x");
1126for (j=0;j<4; j++){
1127u.w = d[j];
1128for (k=0;k<4;k++) printf("%02x",u.b[k]);
1129}
1130printf("\n");
1131printf("\n\t MD5 Encyption Successfully
1132Completed!!!\n\n");
1133getch();
1134system("pause");
1135getch();}
1136CS6711 SECURITY LABORATORY
1137VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 39
1138OUTPUT:
1139RESULT:
1140Thus the implementation of MD5 hashing algorithm had been implemented
1141successfully using C.
1142CS6711 SECURITY LABORATORY
1143VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 40
1144EX. NO: 2(E) IMPLEMENTATION OF SHA-I
1145AIM:
1146To implement the SHA-I hashing technique using C program.
1147DESCRIPTION:
1148In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function.
1149SHA-1 produces a 160-bit hash value known as a message digest. The way
1150this algorithm works is that for a message of size < 264 bits it computes a 160-bit condensed
1151output called a message digest. The SHA-1 algorithm is designed so that it is practically
1152infeasible to find two input messages that hash to the same output message. A hash function
1153such as SHA-1 is used to calculate an alphanumeric string that serves as the cryptographic
1154representation of a file or a piece of data. This is called a digest and can serve as a digital
1155signature. It is supposed to be unique and non-reversible.
1156EXAMPLE:
1157ALGORITHM:
1158STEP-1: Read the 256-bit key values.
1159STEP-2: Divide into five equal-sized blocks named A, B, C, D and E.
1160STEP-3: The blocks B, C and D are passed to the function F.
1161STEP-4: The resultant value is permuted with block E.
1162STEP-5: The block A is shifted right by ‘s’ times and permuted with the result of step-4.
1163CS6711 SECURITY LABORATORY
1164VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 41
1165STEP-6: Then it is permuted with a weight value and then with some other key pair and
1166taken as the first block.
1167STEP-7: Block A is taken as the second block and the block B is shifted by ‘s’ times and
1168taken as the third block.
1169STEP-8: The blocks C and D are taken as the block D and E for the final output.
1170PROGRAM: (Secure Hash Algorithm)
1171import java.security.*;
1172public class SHA1 {
1173public static void main(String[] a) {
1174try {
1175MessageDigest md = MessageDigest.getInstance("SHA1");
1176System.out.println("Message digest object info: ");
1177System.out.println(" Algorithm = " +md.getAlgorithm());
1178System.out.println(" Provider = " +md.getProvider());
1179System.out.println(" ToString = " +md.toString());
1180String input = "";
1181md.update(input.getBytes());
1182byte[] output = md.digest();
1183System.out.println();
1184System.out.println("SHA1(\""+input+"\") =
1185+bytesToHex(output));
1186input = "abc";
1187md.update(input.getBytes());
1188output = md.digest();
1189System.out.println();
1190System.out.println("SHA1(\""+input+"\") = "
1191+bytesToHex(output));
1192input = "abcdefghijklmnopqrstuvwxyz";
1193md.update(input.getBytes());
1194output = md.digest();
1195System.out.println();
1196System.out.println("SHA1(\"" +input+"\") = "
1197+bytesToHex(output));
1198System.out.println(""); }
1199catch (Exception e) {
1200System.out.println("Exception: " +e);
1201}
1202}
1203public static String bytesToHex(byte[] b)
1204{
1205char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6',
1206'7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
1207StringBuffer buf = new StringBuffer();
1208for (int j=0; j<b.length; j++) {
1209CS6711 SECURITY LABORATORY
1210VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 42
1211buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
1212buf.append(hexDigit[b[j] & 0x0f]); }
1213return buf.toString(); }
1214}
1215OUTPUT:
1216RESULT:
1217Thus the SHA-1 hashing technique had been implemented successfully.
1218CS6711 SECURITY LABORATORY
1219VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 43
1220EX. NO: 3
1221IMPLEMENTATION OF DIGITAL SIGNATURE STANDARD
1222AIM:
1223To write a C program to implement the signature scheme named digital signature
1224standard (Euclidean Algorithm).
1225ALGORITHM:
1226STEP-1: Alice and Bob are investigating a forgery case of x and y.
1227STEP-2: X had document signed by him but he says he did not sign that document
1228digitally.
1229STEP-3: Alice reads the two prime numbers p and a.
1230STEP-4: He chooses a random co-primes alpha and beta and the x’s original signature
1231x.
1232STEP-5: With these values, he applies it to the elliptic curve cryptographic equation to
1233obtain y.
1234STEP-6: Comparing this ‘y’ with actual y’s document, Alice concludes that y is a
1235forgery.
1236PROGRAM: (Digital Signature Standard)
1237import java.util.*;
1238import java.math.BigInteger;
1239class dsaAlg {
1240final static BigInteger one = new BigInteger("1");
1241final static BigInteger zero = new BigInteger("0");
1242public static BigInteger getNextPrime(String ans)
1243{
1244BigInteger test = new BigInteger(ans);
1245while (!test.isProbablePrime(99))
1246e:
1247{
1248test = test.add(one);
1249}
1250return test;
1251}
1252public static BigInteger findQ(BigInteger n)
1253{
1254BigInteger start = new BigInteger("2");
1255while (!n.isProbablePrime(99))
1256{
1257while (!((n.mod(start)).equals(zero)))
1258{
1259start = start.add(one);
1260CS6711 SECURITY LABORATORY
1261VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 44
1262}
1263n = n.divide(start);
1264}
1265return n;
1266}
1267public static BigInteger getGen(BigInteger p, BigInteger q,
1268Random r)
1269{
1270BigInteger h = new BigInteger(p.bitLength(), r);
1271h = h.mod(p);
1272return h.modPow((p.subtract(one)).divide(q), p);
1273}
1274public static void main (String[] args) throws
1275java.lang.Exception
1276{
1277Random randObj = new Random();
1278BigInteger p = getNextPrime("10600"); /* approximate
1279prime */
1280BigInteger q = findQ(p.subtract(one));
1281BigInteger g = getGen(p,q,randObj);
1282System.out.println(" \n simulation of Digital Signature
1283Algorithm \n");
1284System.out.println(" \n global public key components
1285are:\n");
1286System.out.println("\np is: " + p);
1287System.out.println("\nq is: " + q);
1288System.out.println("\ng is: " + g);
1289BigInteger x = new BigInteger(q.bitLength(), randObj);
1290x = x.mod(q);
1291BigInteger y = g.modPow(x,p);
1292BigInteger k = new BigInteger(q.bitLength(), randObj);
1293k = k.mod(q);
1294BigInteger r = (g.modPow(k,p)).mod(q);
1295BigInteger hashVal = new BigInteger(p.bitLength(),
1296randObj);
1297BigInteger kInv = k.modInverse(q);
1298BigInteger s = kInv.multiply(hashVal.add(x.multiply(r)));
1299s = s.mod(q);
1300System.out.println("\nsecret information are:\n");
1301System.out.println("x (private) is:" + x);
1302System.out.println("k (secret) is: " + k);
1303System.out.println("y (public) is: " + y);
1304System.out.println("h (rndhash) is: " + hashVal);
1305System.out.println("\n generating digital signature:\n");
1306System.out.println("r is : " + r);
1307System.out.println("s is : " + s);
1308BigInteger w = s.modInverse(q);
1309BigInteger u1 = (hashVal.multiply(w)).mod(q);
1310BigInteger u2 = (r.multiply(w)).mod(q);
1311BigInteger v = (g.modPow(u1,p)).multiply(y.modPow(u2,p));
1312v = (v.mod(p)).mod(q);
1313System.out.println("\nverifying digital signature
1314(checkpoints)\n:");
1315System.out.println("w is : " + w);
1316CS6711 SECURITY LABORATORY
1317VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 45
1318System.out.println("u1 is : " + u1);
1319System.out.println("u2 is : " + u2);
1320System.out.println("v is : " + v);
1321if (v.equals(r))
1322{
1323System.out.println("\nsuccess: digital signature is
1324verified!\n " + r);
1325}
1326else
1327{
1328System.out.println("\n error: incorrect digital
1329signature\n ");
1330}
1331}
1332}
1333OUTPUT:
1334RESULT:
1335Thus the simple Code Optimization techniques had been implemented successfully.
1336CS6711 SECURITY LABORATORY
1337EX. NO: 04
1338SECURE DATA STORAGE, SECURE DATA TRANSMISSION AND FOR
1339CREATING
1340AIM:
1341Demonstrate how to provide secure data storage, secure data transmission and for
1342creating digital signatures (GnuPG).
1343INTRODUCTION:
1344 Here’s the final guide in my PGP basics series, this time focusing on Windows
1345 The OS in question will be Windows 7, but it should work for Win8 and Win8.1 as
1346well
1347 Obviously it’s not recommended to be using Windows to access the DNM, but I
1348won’t go into the reasons here.
1349 The tool well be using is GPG4Win
1350INSTALLING THE SOFTWARE
13511. Visit www.gpg4win.org
1352DIGITAL SIGNATURES (GNUPG)
1353SOFTWARE:
1354org. Click on the “Gpg4win 2.3.0†button
1355CS6711 SECURITY LABORATORY
1356VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 47
13572. On the following screen, click the “Download Gpg4win†button.
13583. When the “Welcome†screen is displayed, click the “Next†button
1359CS6711 SECURITY LABORATORY
1360VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 48
13614. When the “License Agreement†page is displayed, click the “Next†button
13625. Set the check box values as specified below, then click the “Next†button
1363CS6711 SECURITY LABORATORY
1364VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 49
13656. Set the location where you want the software to be installed. The default location
1366is fine. Then, click the “Next†button.
13677. Specify where you want shortcuts to the software placed, then click the “Nextâ€
1368button.
1369CS6711 SECURITY LABORATORY
1370VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 50
13718. If you selected to have a GPG shortcut in your Start Menu, specify the folder in
1372which it will be placed. The default “Gpg4win†is OK. Click the “Install†button
1373to continue
13749. A warning will be displayed if you have Outlook or Explorer opened. If this
1375occurs, click the “OK†button.
1376CS6711 SECURITY LABORATORY
1377VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 51
137810. The installation process will tell you when it is complete. Click the “Nextâ€
1379button
138011. Once the Gpg4win setup wizard is complete, the following screen will be
1381displayed. Click the “Finish†button
1382CS6711 SECURITY LABORATORY
1383VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 52
138412. If you do not uncheck the “Show the README file†check box, the README
1385file will be displayed. The window can be closed after you’ve reviewed it.
1386CREATING YOUR PUBLIC AND PRIVATE KEYS
1387GPG encryption and decryption is based upon the keys of the person who will be
1388receiving the encrypted file or message. Any individual who wants to send the person an
1389encrypted file or message must possess the recipient’s public key certificate to encrypt the
1390message. The recipient must have the associated private key, which is different than the
1391public key, to be able to decrypt the file. The public and private key pair for an individual is
1392usually generated by the individual on his or her computer using the installed GPG program,
1393called “Kleopatra†and the following procedure:
1394CS6711 SECURITY LABORATORY
1395VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 53
13961. From your start bar, select the “Kleopatra†icon to start the Kleopatra certificate
1397management software
13982. The following screen will be displayed
1399CS6711 SECURITY LABORATORY
1400VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 54
14013. From the “File†dropdown, click on the “New Certificate†option
14024. The following screen will be displayed. Click on “Create a personal OpenGPG key
1403pair†and the “Next†button
1404CS6711 SECURITY LABORATORY
1405VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 55
14065. The Certificate Creation Wizard will start and display the following:
14076. Enter your name and e-mail address. You may also enter an optional comment. Then,
1408click the “Next†button
1409CS6711 SECURITY LABORATORY
1410VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 56
14117. Review your entered values. If OK, click the “Create Key†button
14128. You will be asked to enter a passphrase
1413CS6711 SECURITY LABORATORY
1414VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 57
14159. The passphrase should follow strong password standards. After you’ve entered your
1416passphrase, click the “OK†button.
141710. You will be asked to re-enter the passphrase
1418CS6711 SECURITY LABORATORY
1419VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 58
142011. Re-enter the passphrase value. Then click the “OK†button. If the passphrases match,
1421the certificate will be created.
142212. Once the certificate is created, the following screen will be displayed. You can save a
1423backup of your public and private keys by clicking the “Make a backup Of Your Key
1424Pair†button. This backup can be used to copy certificates onto other authorized
1425computers.
1426CS6711 SECURITY LABORATORY
1427VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 59
142813. If you choose to backup your key pair, you will be presented with the following
1429screen:
143014. Specify the folder and name the file. Then click the “OK†button.
1431CS6711 SECURITY LABORATORY
1432VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 60
143315. After the key is exported, the following will be displayed. Click the “OK†button.
143416. You will be returned to the “Key Pair Successfully Created†screen. Click the
1435“Finish†button.
1436CS6711 SECURITY LABORATORY
1437VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 61
143817. Before the program closes, you will need to confirm that you want to close the
1439program by clicking on the “Quit Kleopatra†button
1440DECRYPTING AN ENCRYPTED E-MAIL THAT HAS BEEN SENT TO YOU:
14411. Open the e-mail message
1442CS6711 SECURITY LABORATORY
1443VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 62
14442. Select the GpgOL tab
14453. Click the “Decrypt†button
1446CS6711 SECURITY LABORATORY
1447VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 63
14484. A command window will open along with a window that asks for the Passphrase to
1449your private key that will be used to decrypt the incoming message.
14505. Enter your passphrase and click the “OK†button
1451CS6711 SECURITY LABORATORY
1452VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 64
14536. The results window will tell you if the decryption succeeded. Click the “Finish†button
1454top close the window
14557. Your unencrypted e-mail message body will be displayed.
1456CS6711 SECURITY LABORATORY
1457VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 65
14588. When you close the e-mail you will be asked if you want to save the e-mail message in
1459its unencrypted form. For maximum security, click the “No†button. This will keep the
1460message encrypted within the e-mail system and will require you to enter your
1461passphrase each time you reopen the e-mail message
1462RESULT:
1463Thus the secure data storage, secure data transmission and for creating digital
1464signatures (GnuPG) was developed successfully.
1465CS6711 SECURITY LABORATORY
1466VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 66
1467EX. NO: 05
1468WORKING WITH KF SENSOR TOOL FOR CREATING AND
1469MONITORING HONEYPOT
1470AIM:
1471Honey Pot is a device placed on Computer Network specifically designed to capture
1472malicious network traffic. KF Sensor is the tool to setup as honeypot when KF Sensor is
1473running it places a siren icon in the windows system tray in the bottom right of the screen. If
1474there are no alerts then green icon is displayed.
1475INTRODUCTION:
1476HONEY POT:
1477A honeypot is a computer system that is set up to act as a decoy to lure cyber
1478attackers, and to detect, deflect or study attempts to gain unauthorized access to information
1479systems. Generally, it consists of a computer, applications, and data that simulate the
1480behavior of a real system that appears to be part of a network but is actually isolated and
1481closely monitored. All communications with a honeypot are considered hostile, as there's no
1482reason for legitimate users to access a honeypot. Viewing and logging this activity can
1483provide an insight into the level and types of threat a network infrastructure faces while
1484distracting attackers away from assets of real value. Honeypots can be classified based on
1485their deployment (use/action) and based on their level of involvement.
1486Based on deployment, honeypots may be classified as:
14871. Production honeypots
14882. Research honeypots
1489Production honeypots are easy to use, capture only limited information, and are used
1490primarily by companies or corporations. Production honeypots are placed inside the
1491production network with other production servers by an organization to improve their overall
1492state of security. Normally, production honeypots are low-interaction honeypots, which are
1493easier to deploy. They give less information about the attacks or attackers than research
1494honeypots.
1495Research honeypots are run to gather information about the motives and tactics of the Black
1496hat community targeting different networks. These honeypots do not add direct value to a
1497specific organization; instead, they are used to research the threats that organizations face and
1498to learn how to better protect against those threats.
1499CS6711 SECURITY LABORATORY
1500VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 67
1501KF SENSOR:
1502KFSensor is a Windows based honeypot Intrusion Detection System (IDS). It acts as
1503a honeypot to attract and detect hackers and worms by simulating vulnerable system services
1504and trojans. By acting as a decoy server it can divert attacks from critical systems and
1505provide a higher level of information than can be achieved by using firewalls and NIDS
1506alone. KFSensor is a system installed in a network in order to divert and study an attacker’s
1507behavior. This is a new technique that is very effective in detecting attacks.
1508The main feature of KFSensor is that every connection it receives is a suspect hence it
1509results in very few false alerts. At the heart of KFSensor sits a powerful internet daemon
1510service that is built to handle multiple ports and IP addresses. It is written to resist denial of
1511service and buffer overflow attacks. Building on this flexibility KFSensor can respond to
1512connections in a variety of ways, from simple port listening and basic services (such as
1513echo), to complex simulations of standard system services. For the HTTP protocol KFSensor
1514accurately simulates the way Microsoft’s web server (IIS) responds to both valid and invalid
1515requests. As well as being able to host a website it also handles complexities such as range
1516requests and client side cache negotiations. This makes it extremely difficult for an attacker
1517to fingerprint, or identify KFSensor as a honeypot.
1518PROCEDURE:
1519STEP-1: Download KF Sensor Evaluation Setup File from KF Sensor Website.
1520STEP-2: Install with License Agreement and appropriate directory path.
1521STEP-3: Reboot the Computer now. The KF Sensor automatically starts during windows
1522boot.
1523STEP-4: Click Next to setup wizard.
1524STEP-5: Select all port classes to include and Click Next.
1525STEP-6: “Send the email and Send from emailâ€, enter the ID and Click Next.
1526STEP-7: Select the options such as Denial of Service[DOS], Port Activity, Proxy Emulsion,
1527Network Port Analyzer, Click Next.
1528STEP-8: Select Install as System service and Click Next.
1529STEP-9: Click finish.
1530CS6711 SECURITY LABORATORY
1531VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 68
1532SCREENSHOTS:
1533CS6711 SECURITY LABORATORY
1534VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 69
1535RESULT:
1536Thus the study of setup a hotspot and monitor the hotspot on network has been
1537developed successfully.
1538CS6711 SECURITY LABORATORY
1539VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 70
1540EX. NO: 06
1541INSTALLATION OF ROOTKITS
1542AIM:
1543Rootkit is a stealth type of malicious software designed to hide the existence of
1544certain process from normal methods of detection and enables continued privileged access to
1545a computer.
1546INTRODUCTION:
1547Breaking the term rootkit into the two component words, root and kit, is a useful way
1548to define it. Root is a UNIX/Linux term that's the equivalent ofAdministrator in Windows.
1549The word kit denotes programs that allow someone to obtain root/admin-level access to the
1550computer by executing the programs in the kit — all of which is done without end-user
1551consent or knowledge.
1552A rootkit is a type of malicious software that is activated each time your system boots
1553up. Rootkits are difficult to detect because they are activated before your system's Operating
1554System has completely booted up. A rootkit often allows the installation of hidden files,
1555processes, hidden user accounts, and more in the systems OS. Rootkits are able to intercept
1556data from terminals,network connections, and the keyboard.
1557Rootkits have two primary functions: remote command/control (back door) and
1558software eavesdropping. Rootkits allow someone, legitimate or otherwise, to administratively
1559control a computer. This means executing files, accessing logs, monitoring user activity, and
1560even changing the computer's configuration. Therefore, in the strictest sense, even versions
1561of VNC are rootkits. This surprises most people, as they consider rootkits to be solely
1562malware, but in of themselves they aren't malicious at all.
1563The presence of a rootkit on a network was first documented in the early 1990s. At
1564that time, Sun and Linux operating systems were the primary targets for a hacker looking to
1565install a rootkit. Today, rootkits are available for a number of operating systems, including
1566Windows, and are increasingly difficult to detect on any network.
1567CS6711 SECURITY LABORATORY
1568VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 71
1569PROCEDURE:
1570STEP-1: Download Rootkit Tool from GMER website www.gmer.net.
1571STEP-2: This displays the Processes, Modules, Services, Files, Registry, RootKit /
1572Malwares, Autostart, CMD of local host.
1573STEP-3: Select Processes menu and kill any unwanted process if any.
1574STEP-4: Modules menu displays the various system files like .sys, .dll
1575STEP-5: Services menu displays the complete services running with Autostart, Enable,
1576Disable, System, Boot.
1577STEP-6: Files menu displays full files on Hard-Disk volumes.
1578STEP-7: Registry displays Hkey_Current_user and Hkey_Local_Machine.
1579STEP-8: Rootkits / Malwares scans the local drives selected.
1580STEP-9: Autostart displays the registry base Autostart applications.
1581STEP-10:CMD allows the user to interact with command line utilities or Registry
1582SCREENSHOTS:
1583CS6711 SECURITY LABORATORY
1584VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 72
1585CS6711 SECURITY LABORATORY
1586VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 73
1587RESULT:
1588Thus the study of installation of Rootkit software and its variety of options were
1589developed successfully.
1590CS6711 SECURITY LABORATORY
1591VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 74
1592EX. NO: 07
1593WORKING WITH NET STUMBLER TO PERFORM WIRELESS
1594AUDIT ON A ROUTER
1595AIM:
1596To perform wireless audit on an access point or a router and decrypt WEP and WPA
1597(Net Stumbler).
1598INTRODUCTION:
1599NET STUMBLER:
1600NetStumbler (Network Stumbler) is one of the Wi-Fi hacking tool which only
1601compatible with windows, this tool also a freeware. With this program, we can search for
1602wireless network which open and infiltrate the network. Its having some compatibility and
1603network adapter issues. NetStumbler is a tool for Windows that allows you to detect Wireless
1604Local Area Networks (WLANs) using 802.11b, 802.11a and 802.11g. It runs on Microsoft
1605Windows operating systems from Windows 2000 to Windows XP. A trimmed-down version
1606called MiniStumbler is available for the handheld Windows CE operating system.
1607It has many uses:
1608 Verify that your network is set up the way you intended
1609 Find locations with poor coverage in your WLAN.
1610 Detect other networks that may be causing interference on your network
1611 Detect unauthorized "rogue" access points in your workplace
1612 Help aim directional antennas for long-haul WLAN links.
1613 Use it recreationally for WarDriving.
1614PROCEDURE:
1615STEP-1: Download and install Netstumbler.
1616STEP-2: It is highly recommended that the PC should have wireless network card in order to
1617access wireless router.
1618STEP-3: Now Run Netstumbler in record mode and configure wireless card.
1619STEP-4: There are several indicators regarding the strength of the signal, such as GREEN
1620indicates Strong, YELLOW and other color indicates a weaker signal, RED
1621indicates a very weak and GREY indicates a signal loss.
1622STEP-5: Lock symbol with GREEN bubble indicates the Access point has encryption
1623enabled.
1624CS6711 SECURITY LABORATORY
1625VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 75
1626STEP-6: MAC assigned to Wireless Access Point is displayed on right hand pane.
1627STEP-7: The next column displays the Access points Service Set Identifier[SSID] which is
1628useful to crack the password.
1629STEP-8: To decrypt use WireShark tool by selecting Edit preferences IEEE 802.11.
1630STEP-9: Enter the WEP keys as a string of hexadecimal numbers as A1B2C3D4E5.
1631SCREENSHOTS:
1632CS6711 SECURITY LABORATORY
1633VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 76
1634Adding Keys: Wireless Toolbar
1635 If the system is having the Windows version of Wireshark and have an
1636AirPcap adapter, then we can add decryption keys using the wireless toolbar.
1637 If the toolbar isn't visible, you can show it by selecting View Wireless
1638Toolbar.
1639 Click on the Decryption Keys button on the toolbar:
1640CS6711 SECURITY LABORATORY
1641VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 77
1642 This will open the decryption key management window. As shown in the window you
1643can select between three decryption modes: None, Wireshark and Driver:
1644RESULT:
1645Thus the wireless audit on an access point or a router and decrypt WEP and WPA
1646(Net Stumbler) was done successfully.
1647CS6711 SECURITY LABORATORY
1648VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 78
1649EX. NO: 08
1650WORKING WITH SNORT TOOL TO DEMONSTRATE INTRUSION
1651DETECTION SYSTEM
1652AIM:
1653Snort is an open source network intrusion detection system (NIDS) and it is a packet
1654sniffer that monitors network traffic in real time.
1655INTRODUCTION:
1656INTRUSION DETECTION SYSTEM :
1657Intrusion detection is a set of techniques and methods that are used to detect
1658suspicious activity both at the network and host level. Intrusion detection systems fall into
1659two basic categories:
1660 Signature-based intrusion detection systems
1661 Anomaly detection systems.
1662Intruders have signatures, like computer viruses, that can be detected using software.
1663You try to find data packets that contain any known intrusion-related signatures or anomalies
1664related to Internet protocols. Based upon a set of signatures and rules, the detection system is
1665able to find and log suspicious activity and generate alerts.
1666Anomaly-based intrusion detection usually depends on packet anomalies present in
1667protocol header parts. In some cases these methods produce better results compared to
1668signature-based IDS. Usually an intrusion detection system captures data from the network
1669and applies its rules to that data or detects anomalies in it. Snort is primarily a rule-based
1670IDS, however input plug-ins are present to detect anomalies in protocol headers.
1671SNORT TOOL:
1672Snort is based on libpcap (for library packet capture), a tool that is widely used in
1673TCP/IPtraffic sniffers and analyzers. Through protocolanalysis and content searching and
1674matching, Snort detects attack methods, including denial of service, buffer overflow, CGI
1675attacks, stealthport scans, and SMB probes. When suspicious behavior is detected, Snort
1676sends a real-time alert to syslog, a separate 'alerts' file, or to apop-up window.
1677Snort is currently the most popular free network intrusion detection software. The
1678advantages of Snort are numerous. According to the snort web site, “It can perform protocol
1679CS6711 SECURITY LABORATORY
1680VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 79
1681analysis, content searching/matching, and can be used to detect a variety of attacks and
1682probes, such as buffer overflow, stealth port scans, CGI attacks, SMB probes, OS
1683fingerprinting attempts, and much more†(Caswell).
1684One of the advantages of Snort is its ease of configuration. Rules are very flexible,
1685easily written, and easily inserted into the rule base. If a new exploit or attack is found a rule
1686for the attack can be added to the rule base in a matter of seconds. Another advantage of
1687snort is that it allows for raw packet data analysis.
1688SNORT can be configured to run in three modes:
16891. Sniffer mode
16902. Packet Logger mode
16913. Network Intrusion Detection System mode
16921. Sniffer mode
1693 Snort –v Print out the TCP/IP packets header on the screen
1694 Snort –vd show the TCP/IP ICMP header with application data in transmit
16952. Packet Logger mode
1696 snort –dev –l c:\log [create this directory in the C drive] and snort will
1697automatically know to go into packet logger mode, it collects every packet it
1698sees and places it in log directory.
1699 snort –dev –l c:\log –h ipaddress/24:This rule tells snort that you want to
1700print out the data link and TCP/IP headers as well as application data into the
1701log directory. snort –l c:\log –b This is binary mode logs everything into a
1702single file.
17033. Network Intrusion Detection System mode
1704 snort –d c:\log –h ipaddress/24 –c snort.conf This is a configuration file
1705applies rule to each packet to decide it an action based upon the rule type in
1706the file.
1707 Snort –d –h ipaddress/24 –l c:\log –c snort.conf This will cnfigure snort to
1708run in its most basic NIDS form, logging packets that trigger rules specifies in
1709the snort.conf.
1710PROCEDURE:
1711STEP-1: Sniffer mode snort –v Print out the TCP/IP packets header on the screen.
1712STEP-2: Snort –vd Show the TCP/IP ICMP header with application data in transit.
1713CS6711 SECURITY LABORATORY
1714VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 80
1715STEP-3: Packet Logger mode snort –dev –l c:\log [create this directory in the C drive]
1716and snort will automatically know to go into packet logger mode, it collects every
1717packet it sees and places it in log directory.
1718STEP-4: snort –dev –l c:\log –h ipaddress/24 This rule tells snort that you want to print
1719out the data link and TCP/IP headers as well as application data into the log
1720directory.
1721STEP-5: snort –l c:\log –b this binary mode logs everything into a single file.
1722STEP-6: Network Intrusion Detection System mode snort –d c:\log –h ipaddress/24 –c
1723snort.conf This is a configuration file that applies rule to each packet to decide
1724it an action based upon the rule type in the file.
1725STEP-7: snort –d –h ip address/24 –l c:\log –c snort.conf This will configure snort to run
1726in its most basic NIDS form, logging packets that trigger rules specifies in the
1727snort.conf.
1728STEP-8: Download SNORT from snort.org. Install snort with or without database support.
1729STEP-9: Select all the components and Click Next. Install and Close.
1730STEP-10: Skip the WinPcap driver installation.
1731STEP-11: Add the path variable in windows environment variable by selecting new
1732classpath.
1733STEP-12: Create a path variable and point it at snort.exe variable name path and variable
1734value c:\snort\bin.
1735STEP-13: Click OK button and then close all dialog boxes. Open command prompt and type
1736the following commands:
1737CS6711 SECURITY LABORATORY
1738VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 81
1739INSTALLATION PROCESS :
1740CS6711 SECURITY LABORATORY
1741VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 82
1742CS6711 SECURITY LABORATORY
1743VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 83
1744RESULT:
1745Thus the demonstration of the instruction detection using Snort tool was done
1746successfully.