Network Security Lab Manual
Network Security Lab Manual
LAB MANUAL
Regulation 2021
YEAR/SEMESTER:III/VI
Academic Year 2024-2025
CCS354 – NETWORK SECURITY LABORATORY
PRACTICAL EXERCISES:
PRACTICAL: 30 PERIODS
TABLE OF CONTENTS
PAGE
S.NO. DATE NAME OF THE EXPERIMENT MARKS SIGN.
NO
OUTPUT:
Key: lZ1+0bq2... (some random key)
Plain text: This is a secret message
IV: D1cnw3... (random IV)
Cipher text: a3cN5D... (encrypted text)
Decrypted text: This is a secret message
RESULT:
Thus the implementation and operation of symmetric key algorithms using AES for encrypting and
decrypting messages was Successfully verified.
2. IMPLEMENT ASYMMETRIC KEY ALGORITHMS AND KEY EXCHANGE
ALGORITHMS
AIM:
To implement asymmetric key algorithms (RSA for encryption and decryption) and key exchange
algorithms (Diffie-Hellman) in C, illustrating how secure key exchanges and data encryption work.
APPARATUS REQUIRED:
1.A computer with a C/C++ compiler (such as GCC)
2.Open SSL library for cryptographic functions
3.Basic text editor (like Notepad++, Visual Studio Code, etc.)
PROCEDURE:
1. Create the C source file
2. Include Necessary Libraries
3. Implement RSA Key Generation
4. Implement RSA Encryption and Decryption Functions
5. Implement Diffie-Hellman Key Exchange.
6.Write the Main Function
7. Compile the Program
8. Run the Program
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
// Function to handle errors
void handleErrors() {
ERR_print_errors_fp(stderr);
abort();
}
// RSA Encryption
int rsa_encrypt(RSA *rsa, unsigned char *plaintext, unsigned char *ciphertext) {
int result = RSA_public_encrypt(strlen((char *)plaintext), plaintext, ciphertext, rsa,
RSA_PKCS1_PADDING);
return result;
}
// RSA Decryption
int rsa_decrypt(RSA *rsa, unsigned char *ciphertext, unsigned char *plaintext) {
int result = RSA_private_decrypt(RSA_size(rsa), ciphertext, plaintext, rsa, RSA_PKCS1_PADDING);
return result;
}
int main() {
RSA *rsa = RSA_generate_key(2048, RSA_F4, NULL, NULL);
if (!rsa) handleErrors();
// Encryption
unsigned char *plaintext = (unsigned char *)"Hello, Asymmetric Cryptography!";
unsigned char ciphertext[256];
unsigned char decrypted[256];
int encrypted_length = rsa_encrypt(rsa, plaintext, ciphertext);
if (encrypted_length == -1) handleErrors();
printf("Encrypted message length: %d\n", encrypted_length);
// Decryption
int decrypted_length = rsa_decrypt(rsa, ciphertext, decrypted);
if (decrypted_length == -1) handleErrors();
decrypted[decrypted_length] = '\0'; // Null terminate
printf("Decrypted message: %s\n", decrypted);
// Free the RSA structure
RSA_free(rsa);
return 0;
}
OUTPUT:
Encrypted message length: 256
Decrypted message: Hello, Asymmetric Cryptography!
RESULT:
Thus, the above program was successfully completed and verified the implementation of asymmetric key
algorithms (RSA for encryption and decryption) and a simple framework for key exchange algorithms.
3.IMPLEMENT DIGITAL SIGNATURE SCHEMES
AIM:
To implement digital signature schemes using RSA, demonstrating how to create and verify
APPARATUS REQUIRED:
PROCEDURE:
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/sha.h>
void handleErrors() {
ERR_print_errors_fp(stderr);
abort();
}
// Sign the message
private_key) != 1) {
handleErrors();
return signature_length;
int verify_signature(RSA *public_key, unsigned char *message, unsigned char *signature, unsigned int
signature_length) {
public_key) != 1) {
int main() {
if (!private_key) handleErrors();
if (!public_key) handleErrors();
// Message to be signed
if (verification_result) {
} else {
RSA_free(private_key);
RSA_free(public_key);
return 0;
OUTPUT:
RESULT:
Thus, the above program was successfully completed and verified the implementation of
digital signature schemes using RSA. This shows how to create a digital signature for a message
AIM:
APPARATUS REQUIRED:
PROCEDURE:
1.Install Wireshark
2. Install TCPDump
5. Identify Datagrams
PROGRAM:
import socket
def tcp_server():
server_socket.bind(('localhost', 12345))
server_socket.listen(1)
conn.sendall(message.encode())
conn.close()
print("Connection closed.")
if __name__ == "__main__":
tcp_server()
import socket
def tcp_client():
client_socket.connect(('localhost', 12345))
data = client_socket.recv(1024)
client_socket.close()
if __name__ == "__main__":
tcp_client()
import socket
def udp_server():
server_socket.bind(('localhost', 12345))
while True:
if data.decode() == "exit":
print("Exiting server.")
break
server_socket.close()
if __name__ == "__main__":
udp_server()
import socket
def udp_client():
# client_socket.sendto("exit".encode(), server_address)
client_socket.close()
if __name__ == "__main__":
udp_client()
OUTPUT:
TCP
Server Output:
Connection closed.
Client Output:
For UDP:
Server Output:
RESULT:
The installation of Wireshark and TCPDump was successful, allowing for the capturing and
over TCP (or UDP, if using that protocol) can be identified by filtering in Wireshark,
AIM:
To demonstrate and verify the message integrity and confidentiality in data transmission
APPARATUS REQUIRED:
3.Python or any script language: for sending and receiving messages over a secure connection.
PROCEDURE:
PROGRAM:
import socket
import ssl
bindsocket = socket.socket()
bindsocket.bind(('localhost', 8443))
bindsocket.listen(5)
server_socket = ssl.wrap_socket(bindsocket,
keyfile="server.key",
certfile="server.crt",
server_side=True)
while True:
try:
data = newsocket.recv(1024)
print("Received:", data.decode('utf-8'))
finally:
newsocket.close()
import socket
import ssl
ssl_sock = ssl.wrap_socket(sock)
ssl_sock.connect(('localhost', 8443))
# Receive a response
response = ssl_sock.recv(1024)
ssl_sock.close()
OUTPUT:
RESULT:
Thus the message is encrypted and tamper-proof, ensuring the integrity and confidentiality
APPARATUS REQUIRED:
5.A sample application to transmit data (e.g., a web application or chat application)
PROCEDURE:
3.Start a communication session (e.g., send messages or browse a website) on one device.
5. On the second computer, install a password-cracking tool and attempt to crack weak passwords
6. Use the MITM tool to initiate ARP spoofing on the attacker device, intercepting traffic between
7. On the monitoring device, run Wireshark to capture and analyze the intercepted packets,
8. Modify (if possible) the intercepted data packets to show the potential impact of an MITM
attack.
9. Analyze the results and outcomes of each demonstration to highlight the risks and vulnerabilities
PROGRAM:
1.Eavesdropping
def packet_callback(packet):
if packet.haslayer(TCP) and packet.haslayer(Raw):
print("Payload:", packet[Raw].load.decode())
print("------------------------")
sniff(prn=packet_callback, store=False)
Output:
Destination Port: 80
Host: 192.168.1.1
Destination Port: 80
2. Dictionary Attack
import hashlib
word = line.strip()
if hashlib.sha256(word.encode()).hexdigest() == hash:
return word
return None
hash = "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
dictionary_file = "dictionary.txt"
if password:
else:
password123
123456
qwerty
password
Output:
ip = "192.168.1.100"
mac = "00:11:22:33:44:55"
arp_spoofing(ip, mac)
Output:
Sent 1 packets.
RESULT:
Thus the vulnerabilities in network security through eavesdropping, dictionary attacks, and
Man-in-the-Middle attacks, highlighting the ease with which sensitive information can be
intercepted.
7. EXPERIMENT WITH SNIFF TRAFFIC USING ARP POISONING
AIM:
To demonstrate how ARP (Address Resolution Protocol) poisoning can be used to intercept
APPARATUS REQUIRED:
1. Two computers or virtual machines (VMs) within the same local network.
3. Kali Linux or another penetration testing distribution (for the attacking machine).
PROCEDURE:
1. Ensure two devices are connected to the same local network (Device A and Device B).
arp -a
9. In a terminal, use the following command to poison the ARP cache, directing traffic from
11.Watch the traffic being captured in Wireshark for any sensitive data.
12.Close the terminals or stop the `arpspoof` processes when you're done capturing traffic.
PROGRAM:
#!/bin/bash
exit 1
fi
INTERFACE=$1
TARGET_IP=$2
GATEWAY_IP=$3
# Enable IP forwarding
# ARP spoofing
Wait
OUTPUT:
The captured packets displayed in Wireshark will show all data being transmitted
between the target device and the gateway, including potentially sensitive information such
RESULT:
allowing the attacker to intercept and analyze traffic on the local network. The results highlight
the importance of implementing security measures such as static ARP entries, using VPNs, and
APPARATUS REQUIRED:
1.Computer or virtual machine running a Linux distribution (e.g., Ubuntu).
PROCEDURE:
1.Install the chosen IDS tool on your Linux machine. For example, to install Snort, use
6. This command will start Snort in the console mode, displaying alerts directly in the terminal.
7. From another machine on the same network or from a local script, generate some malicious
traffic. For demonstration, you could use a simple ping flood or Nmap scan:
CopyReplit
8.Watch the Snort console for any alerts generated from the malicious activity.
9. Review the logs generated by Snort, typically found in the /var/log/snort/ directory (if logging is
def detect_http_get(packet):
# Check if the packet has a TCP layer and contains an HTTP GET request
if "GET" in payload:
def main():
if __name__ == "__main__":
main()
OUTPUT:
RESULT:
This demonstration highlights the capability of an IDS to provide real-time monitoring and
alerting of network activity, ensuring better security and detection of potentially malicious behavior.
9. EXPLORE NETWORK MONITORING TOOLS
AIM:
tools
to capture, analyze, and detect network traffic patterns, anomalies, and potential security threats.
APPARATUS REQUIRED:
1.Hardware:
2.Software:
PROCEDURE:
2. Set up a basic web server (e.g., Apache) to generate HTTP traffic by installing it as follows
3. Edit the Snort configuration file (/etc/snort/snort.conf) to set HOME_NET and include custom
rules.
curl http://localhost
6. Open Wireshark, select the interface (e.g., eth0), and start capturing packets.
7.Apply filters to display only HTTP traffic.
PROGRAM:
Snort Configuration
# File: /etc/snort/rules/local.rules
alert tcp any any -> any 80 (msg:"HTTP GET Request Detected"; content:"GET"; http_method;
sid:1000001;)
Run Snort
curl http://localhost
OUTPUT:
Snort Console Output
[**] [1:1000001:0] HTTP GET Request Detected [**]
[**] [Priority: 0] [192.168.1.10:12345 -> 192.168.1.20:80] [**]
Wireshark Capture-A list of captured HTTP packets showing request and response data when
RESULT:
APPARATUS REQUIRED:
1.Hardware:
2.Software:
Terminal/Shell access
PROCEDURE:
1. Install UFW.
6. Enable UFW
1. Install OpenVPN
PROGRAM:
client
dev tun
proto udp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
cipher AES-256-CBC
verb 3
OUTPUT:
The experiment effectively demonstrated the configuration of both a firewall (using UFW)
and a secure VPN (using OpenVPN). Implementing firewalls and VPNs significantly increases
network security, allowing for controlled access and secure remote connections.