Nslab Print
Nslab Print
No : 1a
Implementation of symmetric key algorithm
Date :
using DES Algorithm
AIM:
To use 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 thefollowing
information and separated by a slash(/).
a. Algorithm name
b. Mode(optional)
c. Padding scheme(optional)
3. Convert String into Byte[] arrayformat.
4. Make Cipher in encrypt mode, and encrypt it with [Link]()method.
5. Make Cipher in decrypt mode, and decrypt it with [Link]()method.
PROGRAM:
[Link]
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link] ;
class DES1 {
byte[] skey = new byte[1000];
String skeyString;
static byte[] raw;
String inputMessage,encryptedData,decryptedMessage;
public DES1() {
try {
generateSymmetricKey();
inputMessage=[Link](null,"Enter message
to encrypt");
byte[] ibyte = [Link]();
byte[] ebyte=encrypt(raw, ibyte);
String encryptedData = new String(ebyte);
[Link]("Encrypted message "+encryptedData);
[Link](null,"Encrypted Data
"+"\n"+encryptedData);
[Link](null,"Decrypted Data
"+"\n"+decryptedMessage);
}
catch(Exception e) {
[Link](e);
}
}
void generateSymmetricKey() {
try {
Random r = new Random();
int num = [Link](10000);
String knum = [Link](num);
byte[] knumb = [Link]();
skey=getRawKey(knumb);
skeyString = new String(skey);
[Link]("DES Symmetric key = "+skeyString);
}
catch(Exception e) {
[Link](e);
}
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = [Link]("DES");
SecureRandom sr = [Link]("SHA1PRNG");
[Link](seed);
[Link](56, sr);
SecretKey skey = [Link]();
raw = [Link]();
return raw;
}
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");
Cipher cipher = [Link]("DES");
[Link](Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = [Link](clear);
return encrypted;
}
OUTPUT:
DES Symmetric key = R�]Q�TC1
Encrypted message �0�=�)��������
Decrypted message SECURITYLAB
RESULT:
Thus the java program for DES Algorithm has been implemented and the
output verified successfully.
Apply AES algorithm for practical applications
[Link].b Date:
AIM:
To use Advanced Encryption Standard (AES) Algorithm for a practical
application like URL Encryption.
ALGORITHM:
1. AES is based on a design principle known as asubstitution–permutation.
2. AES does not use a Feistel network like DES, it uses variant ofRijndael.
3. It has a fixed block size of 128 bits, and a key size of 128, 192, or 256bits.
4. AES operates on a 4 × 4 column-major order array of bytes, termed thestate
PROGRAM:
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
import [Link];
public class AES {
private static SecretKeySpec secretKey;
private static byte[] key;
public static void setKey(String myKey)
{
MessageDigest sha = null;
try {
key = [Link]("UTF-8");
sha = [Link]("SHA-1");
key = [Link](key);
key = [Link](key, 16);
secretKey = new SecretKeySpec(key, "AES");
}
catch (NoSuchAlgorithmException e)
{
[Link]();
} catch (UnsupportedEncodingException e)
{
[Link]();
}
}
public static String encrypt(String strToEncrypt, String secret)
{
try {
setKey(secret);
Cipher cipher = [Link]("AES/ECB/PKCS5Padding");
[Link](Cipher.ENCRYPT_MODE, secretKey);
Return
[Link]().encodeToString([Link]([Link]("UTF -
8")));
} catch (Exception e)
{
[Link]("Error while encrypting: " + [Link]());
}
return null; }
public static String decrypt(String strToDecrypt, String secret)
{
try {
setKey(secret);
Cipher cipher = [Link]("AES/ECB/PKCS5PADDING");
[Link](Cipher.DECRYPT_MODE, secretKey);
return new String([Link]([Link]().decode(strToDecrypt))); }
catch (Exception e) {
[Link]("Error while decrypting: " + [Link]());
}
return null;
}
public static void main(String[] args)
{
final String secretKey = "annaUniversity";
String originalString = "[Link]";
String encryptedString = [Link](originalString, secretKey);
String decryptedString = [Link](encryptedString, secretKey);
[Link]("URL Encryption Using AES Algorithm\n------------");
[Link]("Original URL : " + originalString);
[Link]("Encrypted URL : " + encryptedString);
[Link]("Decrypted URL : " + decryptedString);
}
}
OUTPUT:
C:\jdk1.7\bin>javac [Link]
C:\jdk1.7\bin>java AESEncryption
RESULT:
Thus the java program for AES Algorithm has been implemented for URL
Encryption and the output verified successfully.
Ex. No : 2a
Implementation of Asymmetric Encryption
Date :
algorithm using RSA Techniques
AIM:
To implement RSA (Rivest–Shamir–Adleman) algorithm by using HTML
and Javascript.
ALGORITHM:
1. Choose two prime number p andq
2. Compute the value of n andp
3. Find the value of e (publickey)
4. Compute the value of d (private key) usinggcd()
5. Do the encryption and decryption
a. Encryption is givenas,
c = te mod n
b. Decryption is givenas,
t = cd mod n
PROGRAM:
[Link]
<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 =[Link]('p').value;
q =[Link]('q').value;
no = [Link]('msg').value;
n = p * q;
t = (p - 1) * (q - 1);
ctt = [Link](no,e).toFixed(0);
ct = ctt % n;
dtt = [Link](ct,d).toFixed(0);
dt = dtt % n;
[Link]('publickey').innerHTML = n;
[Link]('exponent').innerHTML = e;
[Link]('privatekey').innerHTML = d;
[Link]('ciphertext').innerHTML = ct;
}
</script>
</html>
OUTPUT:
RESULT:
Thus the RSA algorithm has been implemented using HTML & CSS and the
output has been verified successfully.
Ex. No : 2b
AsymmetricAgorithm- Diffie Hellamn key
Date :
exchange algorithm
AIM:
To implement the Diffie-Hellman Key Exchange algorithm for a given
problem .
ALGORITHM:
1. Alice and Bob publicly agree to use a modulus p = 23 and base g = 5(which is a
primitive root modulo23).
2. Alice chooses a secret integer a = 4, then sends Bob A = ga modp
o A = 54mod 23 =4
3. Bob chooses a secret integer b = 3, then sends Alice B = gb modp
o B = 53mod 23 =10
4. Alice computes s = Ba modp
o s = 104mod 23 =18
5. Bob computes s = Ab mod p
o s = 43mod 23 =18
6. Alice and Bob now share a secret (the number18).
PROGRAM:
[Link]
class DiffieHellman {
public static void main(String args[]) {
int p = 23; /* publicly known (prime number) */ int
g = 5; /* publicly known (primitive root) */ int x =
4; /* only Alice knows this secret*/
int y = 3; /* only Bob knows this secret */
double aliceSends = ([Link](g, x)) %p;
double bobComputes = ([Link](aliceSends, y)) % p; double
bobSends = ([Link](g, y)) % p;
double aliceComputes = ([Link](bobSends, x)) % p; double
sharedSecret = ([Link](g, (x * y))) % p
OUTPUT:
RESULT:
Thus the Diffie-Hellman key exchange algorithm has been implemented using
Java Program and the output has been verified successfully.
Ex. No : 3 Implement the SIGNATURE SCHEME - Digital Signature
Date : Standard
AIM:
To implement the SIGNATURE SCHEME - Digital Signature Standard.
ALGORITHM:
1. Create a KeyPairGeneratorobject.
2. Initialize the KeyPairGeneratorobject.
3. Generate the KeyPairGenerator....
4. Get the private key from thepair.
5. Create a signatureobject.
6. Initialize the Signatureobject.
7. Add data to the Signatureobject
8. Calculate theSignature
PROGRAM:
import [Link].*;
import [Link];
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
() e:
{
test = [Link](one);
}
return test;
}
public static BigInteger findQ(BigInteger n)
{
BigInteger start = new BigInteger("2"); while
() {
while (!(([Link](start)).equals(zero)))
{
start = [Link](one);
}
n = [Link](start);
}
return n;
}
public static BigInteger getGen(BigInteger p, BigInteger q,
Random r)
{
BigInteger h = new BigInteger([Link](), r); h = [Link](p);
return [Link](([Link](one)).divide(q), p);
}
public static void main (String[] args) throws
[Link]
{
Random randObj = new Random();
BigInteger p = getNextPrime("10600");
BigInteger q = findQ([Link](one));
BigInteger g = getGen(p,q,randObj);
if ([Link](r))
{
[Link]("\nsuccess: digital signature is verified!\n " + r);
}
else
{
[Link]("\n error: incorrect digital signature\n ");
}
}
}
OUTPUT:
simulation of Digital Signature Algorithm
p is: 10601
q is: 53
g is: 1992
secret information are:
x (private) is:48
k (secret) is: 26
y (public) is: 9106
h (rndhash) is: 1717
r is : 31
s is : 3
w is : 18
u1 is : 7
u2 is : 28
v is : 31
RESULT:
Thus the Digital Signature Standard Signature Scheme has been
implemented and the output has been verified successfully.
Ex. No : 4 a
Installation of Wire shark using TCP/UDP
Date :
AIM:
PROCEDURE:
Thus the installation of wire shark for capturing packets using TCP/UDP
was installed successfully.
Ex. No : 4 b
Installation of tcp dump and observe data transferred
Date :
in client-server communication using UDP/TCP and
identify the UDP/TCP datagram.
AIM:
PROCEDURE:
RESULT
Thus the installation of Tcp dump for capturing packets using TCP/UDP
was installed and studied successfully.
Ex. No : 5
Date : Check message integrity and confidentiality using SSL
AIM
PROCEDURE:
RESULT:
Thus the integrity and confidentiality of the given message was verified successfully.
Ex. No : 6 Experiment Eavesdropping, Dictionary attacks, MITM attacks
Date :
AIM
To perform the eavesdropping dictionary attacks and MITM attacks using Kali
Linux.
PROCEDURE
sudo hydra
3. To access the GUI version of hydra using the following command as “root”
user:
sudo xhydra
4. Type “hydra -h” to get the help menu and see what kind of attacks can run
using Hydra.
Navigate to the tab called “Network”. reload the page by pressing ctrl +
F5. several GET requests will appear.
7. Now enter a random username and password into the login page and click
login.
A new POST request pop up in the Network tab. This is our machine
sending the data to the server.
8. Right click on the POST request and select “Edit and Resend”.
9. A page will open to the right of the Network header, with information regarding
the POST request. Scroll down to the Request Body section and copy the tfUName and
tfUPass Parameters. Hydra will need this information.
10. for this attack, It will be attempting to login as admin. It will need to choose a
wordlist to guess passwords to login as this account. Open the terminal and type:
“locate wordlists” to see all the different wordlists Kali has installed. We will use the
[Link] wordlist for this attack. Type “locate [Link]” to see the path to this
wordlist.
11. To do this, change directory to the wordlist directory using the following
command:
cd /usr/share/wordlists
Then use the following command to extract the file:
gunzip [Link]
Type ls into the terminal after this and you will see that the [Link] file is now
available.
12. Let’s begin the attack by submitting the following command to hydra:
Once you press enter, the attack will begin and Hydra will start guessing a lot of
passwords for the username admin in an attempt to login.
Thus the eavesdropping dictionary attacks and MITM attacks using Kali Linux was
performed and verified successfully.
Ex. No : 7 Experiment with Sniff Traffic using ARP Poisoning
Date :
AIM
PROCEDURE
1. Install the VMware workstation and install the Kali Linux operating system.
2. Login into the Kali Linux using username pass “root, toor”.
3. Make sure you are connected to local LAN and check the IP address by typing the
command ifconfig in the terminal.
4. Open up the terminal and type “Ettercap –G” to start the graphical version of
Ettercap.
5. Now click the tab “sniff” in the menu bar and select “unified sniffing” and click
OK to select the interface. To use “eth0” this means Ethernet connection.
6. Now click the “hosts” tab in the menu bar and click “scan for hosts”. It will
start scanning the whole network for the alive hosts.
7. Next, click the “hosts” tab and select “hosts list” to see the number of hosts
available in the network. This list also includes the default gateway address. We have
to be careful when we select the targets.
8. In MITM, the target is the host machine, and the route will be the router address
to forward the traffic. In an MITM attack, the attacker intercepts the network and sniffs
the packets. So, it will add the victim as “target 1” and the router address as “target 2.”
In VMware environment, the default gateway will always end with “2” because “1” is
assigned to the physical machine.
11. Click “start” and select “start sniffing”. This will start ARP poisoning in the
network which means we have enabled the network card in “promiscuous
mode” and now the local traffic can be sniffed.
Note – It will allowed only HTTP sniffing with Ettercap, so don’t expect
HTTPS packets to be sniffed with this process.
12. Now it’s time to see the results; if our victim logged into some websites. You
can see the results in the toolbar of Ettercap.
Result:
Thus the sniff traffic using ARP Poisoning attack was performed successfully.
Ex. No : 8
Demonstration of Intrusion Detection System(IDS)
Date :
AIM:
To demonstrate Intrusion Detection System (IDS) using Snort software tool.
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“[Link]”
according to your networkenvironment.
10. To specify the network address that you want to protect in [Link] file,look
for the followingline.
var HOME_NET [Link]/24 (You will normally see any here)
11. You may also want to set the addresses ofDNS_SERVERS, if you have some
on yournetwork.
Example:
example snort
12. Change the RULE_PATH variable to the path of rulesfolder.
var RULE_PATHc:\snort\rules
path to rules
13. Change the path of all library files with the name and path on your [Link]
you must changethepath 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 willneedto replace that path with yoursystem
path. Using C:\Snort\lib
14. Change the path of the “dynamicengine” variable value in the“[Link]”
file..
Example:
dynamicengine C:\Snort\lib\snort_dynamicengine\sf_engine.dll
If a 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\[Link] -l c:\Snort\log -K ascii
23. Scan the computer that is running snort from another computer by usingPING
or NMap (ZenMap).
After scanning or during the scan you can check the [Link] file in the log
folder to insure it is logging properly. You will see IP address folders appear.
AIM:
To install a rootkit hunter and find the malwares in a computer.
ROOTKIT HUNTER:
rkhunter (Rootkit Hunter) is a Unix-based tool that scans for rootkits,
backdoors and possible localexploits.
It does this by comparing SHA-1 hashes of important files with knowngood
ones in online databases, searching for default directories (of rootkits),
wrong permissions, hidden files, suspicious strings in kernel modules, and
special tests for Linux andFreeBSD.
rkhunter is notable due to its inclusion in popular operating systems (Fedora,
Debian,etc.)
The tool has been written in Bourne shell, to allow for portability. It canrun
on almost all UNIX-derivedsystems.
Click the "Download EXE" button to download the program with a random file
name, as some rootkits will close “[Link]” before you can open it.
Step 2
Click the "Scan" button in the lower-right corner of the dialog box. Allow the
program to scan your entire hard drive.
Step 3
When the program completes its scan, select any program or file listed in red.
Right-click it and select "Delete."
If the red item is a service, it may be protected. Right-click the service and select
"Disable." Reboot your computer and run the scan again, this time selecting "Delete"
when that service is detected.
When your computer is free of Rootkits, close the program and restart your PC.
RESULT:
In this experiment a rootkit hunter software tool has been installed and the rootkits
have been detected.
Ex. No : 10 Study to configure Firewall, VPN
Date :
AIM:
it is also configured to block all connections to programs that are not on the list of
allowed [Link] configure exceptions we can go to the menu on the left and
select "Allow a program or feature trough Windows Firewall" option.
To change settings in this window we have to click the "Change settings" [Link]
Core Networking feature is allowed on both private and public networks, while the
File and Printer Sharing is only allowed on private networks.
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.
Windows Firewall can be turned off completely. To do that selects the "Turn Windows
Firewall on or off" option from the menu on the left.
Windows Firewall is actually a Windows service. As you know, services can be
stopped and started. If the Windows Firewall service is stopped, the Windows Firewall
will not work.
RESULT
[Link]: 11 Date:
AIM:
To download the N-Stalker Vulnerability Assessment Tool and exploring the
features.
EXPLORING N-STALKER:
1 L‹mdt&e*›etm
Once the scan is completed, the NStalker scanner will show details like severity
level, vulnerability class, why is it an issue, the fix for the issue and the URL
which is vulnerable to the particular vulnerability?
RESULT:
Thus the N-Stalker Vulnerability Assessment tool has been downloaded, installed
and the features has been explored by using a vulnerable website.