Cs6711 Security Laboratory
Cs6711 Security Laboratory
AIM:
Develop a program to implement Message Digest Algorithm.
ALGORITHM DESCRIPTION:
PROGRAM:
import
java.util.*; class
md5Alg
int[64];
static
{
for (int i = 0; i < 64; i++) for (int i = 0; i < numBlks; i
++)
{
{
TABLE_T[i] = (int)(long)((1L << 32) * Math.abs(Math.sin(i +
1)));
}
}
/* compute message digest (hash value)
*/
public static byte[] computeMd5(byte[]
msg)
{
int msgLenBytes = /* msg length (bytes)
msg.length; */
long msgLenBits = (long)msgLenBytes << /* msg length (bits)
3; */
int numBlks = ((msgLenBytes + 8) >>> 6) /* number of
+ 1; blocks */
int totLen = numBlks << 6; /* total length */
byte[] padB = new byte[totLen -
msgLenBytes]; /* padding bytes */
/* pre-processing with padding */
padB[0] = (byte)0x80;
for (int i = 0; i < 8; i++)
{
padB[padB.length - 8 + i] =
(byte)msgLenBits;
msgLenBits >>>= 8;
}
int a = INIT_A;
int b = INIT_B;
int c = INIT_C;
int d = INIT_D;
int[] buf = new int[16];
int idx = i << 6;
case 0:
case 1:
break;
case 2:
{
f = b ^ c ^ d;
0x0F; break;
case 3:
f = c ^ (b | ~d);
0x0F; break;
/* left rotate */
a =
d; d
= c;
c =
b;
b = temp;
so far */ a += origA;
b +=
origB; c
+= origC;
d += origD; public static
void main
}
(String[] args)
byte[] md5 = new throws
java.lang.Except
byte[16]; int cnt = 0; ion
{ String msg =
"hello world";
int n = (i == 0) ? a : ((i == 1) ? b : ((i == 2) ? c :
md5[cnt++] =
(byte)n; n >>>= 8;
return md5;
StringBuilder sb = new
b.length; i++)
return sb.toString();
}
System.out.println("simulation of MD5
+ msg);
stdin:
stdout:
simulation of MD5
hello world
AIM:
ALGORITHM DESCRIPTION:
H0 = 0x67452301
H1 = 0xEFCDAB89
H2 = 0x98BADCFE
H3 = 0x10325476
H4 = 0xC3D2E1F0
Step 6: Processing Message in 512-bit blocks (L blocks in total message)….
This is the main task of SHA1 algorithm which loops through the
padded and appended message in 512-bit blocks.
Input and predefined functions: M[1, 2, ..., L]: Blocks of the padded and appended
message f(0;B,C,D), f(1,B,C,D), ..., f(79,B,C,D): 80 Processing
Functions K(0), K(1), ...,
K(79): 80 Processing Constant Words
H0, H1, H2, H3, H4, H5: 5 Word buffers with initial values
Output:
H0, H1, H2, H3, H4, H5: Word buffers with final message digest
PROGRAM :
import
java.security.*;
public class SHA1 {
public static void
main(String[] a) { try {
MessageDigest md =
MessageDigest.getInstance("SHA1");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = "
+md.getAlgorithm()); System.out.println(" Provider
= " +md.getProvider()); System.out.println("
ToString = " +md.toString());
String input = "";
md.update(input.getByte
s()); byte[] output =
md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = "
+bytesToHex(output)); input = "abc";
md.update(input.getByte
s()); output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = "
+bytesToHex(output)); input =
"abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output =
md.digest();
System.out.printl
n();
System.out.println("SHA1(\"" +input+"\") = "
+bytesToHex(output)); System.out.println(""); }
catch (Exception e) {
System.out.println("Exception:
" +e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F'}; StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) &
0x0f]); buf.append(hexDigit[b[j] &
0x0f]); } return buf.toString(); }
}
OUTPUT:
C:\Program Files\Java\jdk1.6.0_20\bin>javac
SHA1.java C:\Program
Files\Java\jdk1.6.0_20\bin>java SHA1 Message
digest object info:
Algorithm = SHA1
Provider = SUN version
1.6
ToString = SHA1 Message Digest from SUN, <initialized>
SHA1("") =
DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
SHA1("abc") =
A9993E364706816ABA3E25717850C26C9CD0D89D
SHA1("abcdefghijklmnopqrstuvwxyz") =
32D10C7B8CF96570CA04CE37F2A19D84240D3A89
RESULT:
Thus the program was executed and verified successfully.
EX.No.: 5 IMPLEMENT DIGITAL SIGNATURE SCHEME
AIM:
PROGRAM :
import java.util.*;
import
java.math.BigInteger;
class dsaAlg
BigInteger(ans); while
(!test.isProbablePrime(99))
test = test.add(one);
return test;
BigInteger("2"); while
(!n.isProbablePrime(99))
{
while (!((n.mod(start)).equals(zero)))
start = start.add(one);
n = n.divide(start);
return n;
getGen(BigInteger p, BigInteger q,
Random r)
h = h.mod(p);
BigInteger q = findQ(p.subtract(one));
BigInteger g =
getGen(p,q,randObj); /* public
key components */
s);
signature */ 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("u1 is : " +
u1); System.out.println("u2 is
: " + u2);
System.out.println("v is : " +
v); if (v.equals(r))
else
stdin:
Standard input is
empty stdout:
components are:
p is: 10601
q is: 53
g is: 3848
secret information
48
k (secret) is: 25
h (rndhash) is:
8794
generating digital
signature: r is : 4
s is : 16
(checkpoints): w is : 10
u1 is : 13
u2 is :
40 v is :
AIM:
DESCRIPTION :
Root kit is a stealth type of malicious software designed to hide the existence of
certain process from normal methods of detection and enables continued
privileged access to a computer.
AIM:
Honey Pot is a device placed on Computer Network specifically designed to
capture malicious network traffic. KF Sensor is the tool to setup as honeypot
when KF Sensor is running it places a siren icon in the windows system tray in
the bottom right of the screen. If there are no alerts then green icon is displayed.
STEPS:
5.You will get some logs about clients.And it will start working
KFSensor
Interprets all the data and alerts captured by server in graphical form.
Using it you can configure the KFSensor Server and monitor the events
generated by the KFSensor Server.
Sim Server
There are two types of Sim Server available; the Sim Banner and the
Sim Standard Server.
Setting Up a HoneyPot
• Install WinPCap
• Install KFSensor
KFSensor Monitor
Terminology
Visitor
Event
• Events are recorded in the log file and displayed in the KFSensor monitor.
Editing Scenario
Terminology – Rules
• All of the data that was produced was the result of KFSensor detecting
certain types of activity and then using a rule to determine what type of
action should be taken.
– either select a rule and click the Edit button to edit a rule, or you
can click the Add button to create a new rule.
Adding a rule
• Click the Add button and you will see the Add Listen dialog box.
– `The first thing that this dialog box asks for is a name. This is just a
name for the rule.
– Pick something descriptive though, because the name that you enter
is what will show up in the logs whenever the rule is triggered.
Download Link
• http://www.keyfocus.net/kfsensor/free-trial/
Installing KFSensor
install KFSensor
Setting up Server
• Go through the wizard, give fictitious mail ids when they are asked
and start the server running by pressing the finish button.
FTP Emulation
1. Open command prompt
2. Type
Ftp ipaddress
4. Right click KFSensor entry, select Event details, see the details captured by the
server
5. Create visitor rule by right clicking the FTP entry and check either ignore /
close under actions in the dialog box that opened.
6. Now redo the above said operations at the command prompt and see
how the emulation behaves.
7. You can see/ modify the created rules in Scenario->edit active visitor rules.
SMTP Emulation
2. Type
telnet
ipaddress 25
Helo
Mail from:<mail-id>
Rcpt to:<mail-id>
Data
type contents of mail end that with . in
captured information.
IIS emulation
2. Make sure index.html is in first place in the listed htm files in the
dialog box
3. Check the kfsensor for the captured information.
DOS attack
Ping ipaddress –t or
1. Check the kfsensor for the DOS attack alerts, open event details in right
click menu for further details.
RESULT:
Thus the program was executed and verified successfully.
PERFORM WIRELESS AUDIT ON AN ACCESS POINT OR A
EX.No.: 8
ROUTER AND DECRYPT WEP AND WPA
AIM:
NetStumbler (also known as Network Stumbler) aircrack on ubuntu is a
tool for windows that facilitates detection of Wireless LANs using the 802.11b,
802.11a and 802.11g WLAN standards. It is one of the Wi-Fi hacking tool which
only compatible with windows; this tool also a freeware. With this program, we
can search for wireless network which open and infiltrate the network. It’s
having some compatibility and network adapter issues.
DESCRIPTION :
If you are using the Windows version of Wireshark and you have an
AirPcap adapter you can add decryption keys using the wireless
toolbar.
If the toolbar isn't visible, you can show it by selecting
View->Wireless Toolbar. Click on the Decryption Keys. button on
the toolbar:
RESULT:
Thus the program was executed and verified successfully.
DEMONSTRATE INTRUSION DETECTION SYSTEM (IDs)
USING
EX.No.: 9
ANY TOOL (SNORT OR ANY OTHER S/W)
AIM:
Snort is an open source network intrusion detection system (NIDS) has the
ability to perform real-time traffic analysis and packet logging on internet
protocol (IP) networks. Snort performs protocol analysis, content searching and
matching. Snort can be configured in three main modes: sniffer, packet logger,
and network intrusion detection.
Description: