Cyber Security Lab Manual
Cyber Security Lab Manual
result = ""
if char.isalpha():
else:
result += char
return result
# Example usage:
shift_amount = 3
print(f"Plaintext: {plaintext}")
print(f"Ciphertext: {cipher_text}")
rail, direction = 0, 1
fence[rail][direction - 1] = char
rail += direction
direction *= -1
return encrypted_text
rail, direction = 0, 1
fence[rail][direction - 1] = 'X'
rail += direction
direction *= -1
index = 0
for i in range(num_rails):
for j in range(len(encrypted_text)):
if fence[i][j] == 'X':
fence[i][j] = encrypted_text[index]
index += 1
rail, direction = 0, 1
decrypted_text = ''
for _ in range(len(encrypted_text)):
decrypted_text += fence[rail][direction - 1]
RIET, Jaipur COURSE FILE Year : 4th
rail += direction
direction *= -1
return decrypted_text
# Example usage:
num_rails = 3
print(f"Plaintext: {plaintext}")
2. Implement the Diffie-Hellman Key Exchange mechanism using HTML and JavaScript.
Consider the end user as one of the parties (Alice) and the JavaScript application as other
party (bob).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
RIET, Jaipur COURSE FILE Year : 4th
<div>
</div>
<div>
</div>
<div>
</div>
<script>
function performKeyExchange() {
// Choose a common base and modulus (these are typically agreed upon values)
const base = 5;
document.getElementById('alice-public-key').innerText = alicePublicKey;
document.getElementById('bob-public-key').innerText = bobPublicKey;
? sharedSecretAlice
</script>
</body>
</html>
a) Dictionary Attack:
A dictionary attack is a type of password attack where an attacker uses a predefined list of
words (dictionary) to try to gain unauthorized access to user accounts. The attacker
typically uses common passwords, words, phrases, or variations thereof. The idea is to
systematically try each entry in the dictionary as a password until the correct one is found.
if login_attempt(username, password):
# Function to simulate a login attempt (replace this with your actual authentication
mechanism)
# For the sake of example, let's assume the correct password is "password123"
# Example usage
username = "user123"
print(result)
A brute force attack involves trying all possible combinations of passwords systematically
until the correct one is found. This method is time-consuming and resource-intensive,
especially for strong and complex passwords. Brute force attacks may involve trying all
possible character combinations, starting from the shortest to the longest passwords.
import itertools
password = ''.join(password_attempt)
if login_attempt(username, password):
# Example usage
username = "user123"
max_password_length = 4
character_set = "abcdefghijklmnopqrstuvwxyz0123456789"
print(result)
4. Installation of Wire shark, tcpdump, etc and observe data transferred in client server
communication using UDP/TCP and identify the UDP/TCP datagram
Below are the steps to install the Wireshark software on the computer:
RIET, Jaipur COURSE FILE Year : 4th
On the network and Internet settings option, we can check the interface connected to our
computer.
If you are Linux users, then you will find Wireshark in its package repositories.
By selecting the current interface, we can get the traffic traversing through that interface.
The version used here is 3.0.3. This version will open as:
The Wireshark software window is shown above, and all the processes on the network are
carried within this screen only.
AD
The options given on the list are the Interface list options. The number of interface options
will be present. Selection of any option will determine all the traffic. For example, from the
above fig. select the Wi-Fi option. After this, a new window opens up, which will show all
the current traffic on the network. Below is the image which tells us about the live capture
of packets and our Wireshark will look like:
RIET, Jaipur COURSE FILE Year : 4th
The above arrow shows the packet content written in hexadecimal or the ASCII format.
And the information above the packet content, are the details of the packet header.
It will continue listening to all the data packets, and you will get much data. If you want to
see a particular data, then you can click on the red button. The traffic will be stationary, and
you can note the parameters like time, source, destination, the protocol being used, length,
and the Info. To view in-depth detail, you can click on that particular address; a lot of the
information will be displayed below that.
There will be detailed information on HTTP packets, TCP packets, etc. The red button is
shown below:
AD
o First part contains a menu bar and the options displayed below it. This part is at the
top of the window. File and the capture menus options are commonly used in
Wireshark. The capture menu allows to start the capturing process. And the File
menu is used to open and save a capture file.
RIET, Jaipur COURSE FILE Year : 4th
o The second part is the packet listing window. It determines the packet flow or the
captured packets in the traffic. It includes the packet number, time, source,
destination, protocol, length, and info. We can sort the packet list by clicking on the
column name.
o Next comes the packet header- detailed window. It contains detailed information
about the components of the packets. The protocol info can also be expanded or
minimized according to the information required.
o The bottom window called the packet contents window, which displays the content
in ASCII and hexadecimal format.
o At last, is the filter field which is at the top of the display. The captured packets on
the screen can be filtered based on any component according to your requirements.
For example, if we want to see only the packets with the HTTP protocol, we can
apply filters to that option. All the packets with HTTP as the protocol will only be
displayed on the screen, shown below:
You can also select the connection to which your computer is connected. For example, in
this PC, we have chosen the current network, i.e., the ETHERNET.
In view option on the menu bar, we can also change the view of the interface. You can
change the number of things in the view menu. You can also enable or disable any option
according to the requirements.
There is a filter block below the menu bar, from where a large amount of data can be
filtered. For example, if we apply a filter for HTTP, only the interfaces with the HTTP will
be listed.
RIET, Jaipur COURSE FILE Year : 4th
If you want to filter according to the source, right-click on the source you want to filter and
select 'Apply as Filter' and choose '...and filter.'
Steps for the permanent colorization are: click on the 'View' option on the menu bar and
select 'Coloring Rules.' The table will appear like the image shown below:
RIET, Jaipur COURSE FILE Year : 4th
For the network administrator job, advanced knowledge of Wireshark is considered as the
requirements. So, it is essential to understand the concepts of the software. It contains these
20 default coloring rules which can be added or removed according to the requirements.
Select the option 'View' and then choose 'Colorize Packet List,' which is used to toggle the
color on and off.
INTRODUCTION:
Breaking the term rootkit into the two component words, root and kit, is
a useful way to define it. Root is a UNIX/Linux term that's the equivalent
ofAdministrator in Windows. The word kit denotes programs that allow
someone to obtain root/admin-level access to the computer by executing the
programs in the kit — all of which is done without end-user consent or
knowledge.
early 1990s. At that time, Sun and Linux operating systems were the primary
targets for a hacker looking to install a rootkit. Today, rootkits are available for
a number of operating systems, including Windows, and are increasingly
difficult to detect on any network.
PROCEDURE:
STEP-10:CMD allows the user to interact with command line utilities or Registry
RIET, Jaipur COURSE FILE Year : 4th
SCREENSHOTS:
RIET, Jaipur COURSE FILE Year : 4th
RESULT:
When one machine needs to communicate with another, it looks up its ARP
table.
If the MAC address is not found in the table, the ARP_request is broadcasted
over the network.
All machines on the network will compare this IP address to MAC address.
If one of the machines in the network identifies this address, then it will respond
to the ARP_request with its IP and MAC address.
The requesting computer will store the address pair in its ARP table and
communication will take place.
ARP spoofing constructs a large number of forged ARP request and reply
packets to overload the switch.
The switch is set in forwarding mode and after the ARP table is flooded with
spoofed ARP responses, the attackers can sniff all network packets.
Attackers flood a target computer ARP cache with forged entries, which is also known
as poisoning. ARP poisoning uses Man-in-the-Middle access to poison the network.
What is MITM?
The Man-in-the-Middle attack (abbreviated MITM, MitM, MIM, MiM, MITMA) implies
an active attack where the adversary impersonates the user by creating a connection
between the victims and sends messages between them. In this case, the victims think
that they are communicating with each other, but in reality, the malicious actor controls
the communication.
RIET, Jaipur COURSE FILE Year : 4th
A third person exists to control and monitor the traffic of communication between two
parties. Some protocols such as SSL serve to prevent this type of attack.
VMware workstation
Kali Linux or Linux Operating system
Ettercap Tool
LAN connection
Note − This attack is possible in wired and wireless networks. You can perform this
attack in local LAN.
Step 1 − Install the VMware workstation and install the Kali Linux operating system.
Step 2 − Login into the Kali Linux using username pass “root, toor”.
Step 3 − Make sure you are connected to local LAN and check the IP address by typing
the command ifconfig in the terminal.
RIET, Jaipur COURSE FILE Year : 4th
Step 4 − Open up the terminal and type “Ettercap –G” to start the graphical version of
Ettercap.
Step 5 − Now click the tab “sniff” in the menu bar and select “unified sniffing” and
click OK to select the interface. We are going to use “eth0” which means Ethernet
connection.
RIET, Jaipur COURSE FILE Year : 4th
Step 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.
Step 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.
RIET, Jaipur COURSE FILE Year : 4th
Step 8 − Now we have to choose the targets. In MITM, our 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, we 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.
Step 10 − Now click on “MITM” and click “ARP poisoning”. Thereafter, check the
option “Sniff remote connections” and click OK.
RIET, Jaipur COURSE FILE Year : 4th
Step 11 − Click “start” and select “start sniffing”. This will start ARP poisoning in the
network which means we have enabled our network card in “promiscuous mode” and
now the local traffic can be sniffed.
Note − We have allowed only HTTP sniffing with Ettercap, so don’t expect HTTPS
packets to be sniffed with this process.
Step 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.
This is how sniffing works. You must have understood how easy it is to get the HTTP
credentials just by enabling ARP poisoning.
ARP Poisoning has the potential to cause huge losses in company environments. This is
the place where ethical hackers are appointed to secure the networks.
Like ARP poisoning, there are other attacks such as MAC flooding, MAC spoofing,
DNS poisoning, ICMP poisoning, etc. that can cause significant loss to a network.
In the next chapter, we will discuss another type of attack known as DNS poisoning.
7. Demonstrate intrusion detection system using any tool (snort or any other
RIET, Jaipur COURSE FILE Year : 4th
7. Demonstrate intrusion detection system using any tool (snort or any other s/w)
Installation Steps:
In Linux:
1. Sniffer Mode –
To print TCP/IP header use command ./snort -v
To print IP address along with header use command ./snort -vd
2. Packet Logging –
To store packet in disk you need to give path where you want to store the logs. For
this command is./snort -dev -l ./SnortLogs.
3. Activate network intrusion detection mode –
To start this mode use this command ./snort -dev -l ./SnortLogs -h 192.127.1.0/24 -c
snort.conf
Basic Usages:
Packet Sniffing: The way traffic is being transmitted can be thoroughly examined
by gathering the individual packets that travel to and from devices on the network.
Generates Alerts: It generates warnings based on the configuration file’s rules when
it discovers unusual or malicious activity, the possibility of a vulnerability being
exploited, or a network threat that compromises the organization’s security policy.
Debug Traffic: After the traffic has been logged, any malicious packets and
configuration problems are checked.
RIET, Jaipur COURSE FILE Year : 4th
8. Demonstrate how to provide secure data storage, secure data transmission and for
creating digital signatures.
# Example usage
secret_key = get_random_bytes(16) # 128-bit key for AES
data_to_encrypt = "This is sensitive information."
encrypted_data = encrypt_data(data_to_encrypt, secret_key)
decrypted_data = decrypt_data(encrypted_data, secret_key)
For secure data transmission, using protocols like HTTPS is essential. Below is an
example using Python's requests library, which supports HTTPS:
import requests
RIET, Jaipur COURSE FILE Year : 4th
url = "https://example.com/api"
data_to_send = {"username": "user", "password": "pass"}
Make sure the server is configured to use HTTPS with a valid SSL/TLS certificate.
# Example usage
private_key = """-----BEGIN RSA PRIVATE KEY-----
... (your private key here)
-----END RSA PRIVATE KEY-----"""
print(f"Data: {data_to_sign}")
print(f"Signature: {signature}")
print(f"Signature Verification Result: {verification_result}")
Ensure that you replace (your private key here) and (your public key here) with your
actual private and public keys.