Practical - Manual - BMSF
Practical - Manual - BMSF
BMSF Laboratory
Practical 5
Use msfvenom to exploit windows system and get the meterpreter session.
CSE- Page 1 of 55
Enrolment No. BMSF Laboratory
Practical-5
Use msfvenom to exploit windows system and get the meterpreter session.
Description: This practical session focuses on the steps to exploit the Windows system and
get the meterpreter session. Meterpreter is an advanced, powerful payload within the
Metasploit Framework, specifically designed for exploitation and post-exploitation activities
during penetration testing and ethical hacking engagements.
Tools:
Virtual Machine: Use a virtual machine environment with Kali Linux installed with
Metasploit for a controlled and safe learning environment.
Msfvenom - msfvenom is a versatile tool within the Metasploit Framework used for
generating payloads. Use this tool to create custom payload.
Steps:
We need to set a listener on our attacker machine, to listen to the connection of the
target machine. For that, use the following commands:
use exploit/multi/handler – It will open a multi-handler to set the required
parameters.
CSE- Page 2 of 55
Enrolment No. BMSF Laboratory
Now we need to set our payload to open the listener. For that, use the following
command:
Now we will set lport i.e. local port on which we will listen the victim
machine.
Use the command – set LPORT 4040
CSE- Page 3 of 55
Enrolment No. BMSF Laboratory
To deliver our payload to the target system, we can use different delivery
mechanisms.
For this practical demo, we will use a Python server to deliver our payload to the
target system.
Open the Python server in the same directory where, our payload is saved. To run
the Python server, use the command:
python3 -m http.server
Now go to the victim machine and type the IP address and port number of the
attacker machine in the form of a URL.
CSE- Page 4 of 55
Enrolment No. BMSF Laboratory
Let’s execute the payload by double click on it and click on run option.
Check the present working directory of target machine typing pwd command in
meterpreter.
CSE- Page 5 of 55
Enrolment No. BMSF Laboratory
Conclusion:
Through this practical exercise, we've successfully exploited a Windows system to gain
a Meterpreter session. This process enabled us to gather valuable information for our
practice. It highlights the critical importance of cybersecurity measures in protecting
systems against unauthorized access and underscores the need for continuous learning
and vigilance in the ever-evolving landscape of digital security threats.
CSE- Page 6 of 55
Enrolment No. BMSF Laboratory
Practical 6
Use already created meterpreter session to perform post exploitation.
CSE- Page 7 of 55
Enrolment No. BMSF Laboratory
Practical-6
Use already created meterpreter session to perform post exploitation.
Description:
During the post-exploitation phase of our practical exercise, we delved deeper into the
compromised Windows system to explore methods for escalating privileges and
establishing persistence. This phase is crucial in understanding how attackers can
maintain access and control over a compromised system, even after initial access has
been gained.
Privileges escalation:
Persistence:
Tools:
Virtual Machine: Use a virtual machine environment with Kali Linux installed with
Metasploit for a controlled and safe learning environment.
Msfvenom: msfvenom is a versatile tool within the Metasploit Framework used for
generating payloads. Use this tool to create custom payload.
Steps:
1. Privileges escalation: -
CSE- Page 8 of 55
Enrolment No. BMSF Laboratory
As a result, we have only user-level access on the target system, and we can perform
only limited activities.
To perform high-priority activities, we need to escalate our privileges.
To use another exploit to escalate privileges, we need to background this active
session, Use the command background to send this active session in background.
Use the back command to exit from multi/handler
Now search for another exploit to bypass the UAC of target system.
For that, use the command – search exploit/windows/local/bypassuac
CSE- Page 9 of 55
Enrolment No. BMSF Laboratory
We are done with all the setup, run the payload by using run command.
The output is username only means we only have user level privileges on target
system.
Use getsystem command to get admin access on target system.
We have access to the system32 directory, and it is now confirmed that, we have
admin-level access on the target system.
2. Persistence: -
CSE- Page 10 of
Enrolment No. BMSF Laboratory
Before using any exploit on the target system, take a snapshot of the target system so,
we can revert it back.
To take a snapshot, navigate to Oracle Virtual Box and select the took option.
CSE- Page 11 of
Enrolment No. BMSF Laboratory
CSE- Page 12 of
Enrolment No. BMSF Laboratory
The above command will execute all commands present in this script, and we will get a
meterpreter session if we have made persistence on the target system. Otherwise, it will
just open a new meterpreter listener.
Here we have successfully gotten the meterpreter session of the target machine, which
means we have made persistence in the target system.
CSE- Page 13 of
Enrolment No. BMSF Laboratory
Conclusion:
CSE- Page 14 of
Enrolment No. BMSF Laboratory
Practical 7
Perform windows hash dump using mimikatz module in metasploit.
CSE- Page 15 of
Enrolment No. BMSF Laboratory
Practical-7
Performing a Windows hash dump using the Mimikatz module in Metasploit involves
leveraging the powerful capabilities of both Mimikatz and Metasploit to extract
password hashes from a compromised Windows system
Tools:
Virtual Machine: Use a virtual machine environment with Kali Linux installed with
Metasploit for a controlled and safe learning environment.
Msfvenom: msfvenom is a versatile tool within the Metasploit Framework used for
generating payloads. Use this tool to create custom payload.
Steps:
As per the result of getuid command, we have only user level access on target
system.
To dump the hash values of target system we required admin level access.
To get admin access, we need to bypass UAC of target system.
Use background command to send this active session to background.
CSE- Page 16 of
Enrolment No. BMSF Laboratory
Now search for another exploit to bypass the UAC of target system.
For that, use the command – search exploit/windows/local/bypassuac
We are done with all the setup, run the payload by using run command.
CSE- Page 17 of
Enrolment No. BMSF Laboratory
Check user id
CSE- Page 18 of
Enrolment No. BMSF Laboratory
Use lsa_dump_sam command to dump all windows user passwors hash values.
To brute force this hash we will use john the ripper tool.
John the ripper required wordlist to brute force this hash value, we will
use rockyou.txt wordlist present in kali linux.
rockyou.txt is present in /usr/share/wordlists directory.
Copy this rockyou.txt into your working directory.
Now use following command as shown in below diagram to perform brute force.
CSE- Page 19 of
Enrolment No. BMSF Laboratory
If this hash was cracked before then it will give us, error as above.
To see cracked password use following command.
Here, we successfully cracked NTLM hash and got windows user password.
Conclusion:
CSE- Page 20 of
Enrolment No. BMSF Laboratory
Practical 8
1. Create a malicious .docx/.xlsx using Metasploit.
CSE- Page 21 of
Enrolment No. BMSF Laboratory
Practical-8
2. Use malicious .docx/.xlsx file to exploit windows system and gain the
meterpreter session.
Description:
In this practical demonstration, we showcase the threat posed by malicious documents by
crafting a .docx or .xlsx file embedded with a payload using Metasploit. Through social
engineering, we entice a user to open the file, triggering the payload execution upon opening.
This exploit establishes a reverse TCP connection back to our attacker machine, granting us a
Meterpreter session.
Tools:
Virtual Machine: Use a virtual machine environment with Kali Linux installed with
Metasploit for a controlled and safe learning environment.
Steps:
Choose exploit –
Here, we will use exploit number 30.
CSE- Page 22 of
Enrolment No. BMSF Laboratory
It will start server and create payload i.e. malicious document into
/home/project/.msf4/local/ directory.
CSE- Page 23 of
Enrolment No. BMSF Laboratory
Change the directory to desktop and make script by using nano editor with
all essential commands as follow.
CSE- Page 24 of
Enrolment No. BMSF Laboratory
Conclusion:
By successfully executing the payload embedded within the document, we highlighted the
critical importance of identifying and addressing security flaws to prevent unauthorized
access and data breaches. This exercise serves as a valuable reminder of the necessity for
robust cybersecurity measures, proactive vulnerability management, and continuous testing to
bolster defences against potential threats. Through penetration testing and simulated attacks,
organizations can uncover weaknesses in their systems and implement targeted security
measures to mitigate risks effectively, ultimately enhancing overall resilience in the face of
cyber threats.
CSE- Page 25 of
Enrolment No. BMSF Laboratory
Practical 9
Implement the following private key cryptography algorithm:
1. Ceaser Cipher
2. DES algorithm
CSE- Page 26 of
Enrolment No. BMSF Laboratory
Practical-9
Implement the following private key cryptography algorithm:
1. Ceaser Cipher
2. DES algorithm
Description:
In implementing the Caesar Cipher algorithm, we'll define functions for encryption and
decryption, shifting characters in the plaintext by a fixed number of positions. This will
illustrate basic substitution cipher principles. Similarly, for the DES algorithm, we'll create
functions for key generation, encryption, and decryption, following the DES algorithm's
permutation and substitution operations. These implementations will provide practical insight
into private key cryptography.
Ceaser Cipher:
The Caesar Cipher, also known as the shift cipher, is one of the simplest and most
widely known encryption techniques. It is a substitution cipher where each letter in
the plaintext is shifted a certain number of places down or up the alphabet.
DES algorithm:
Data Encryption Standard, is a symmetric-key block cipher algorithm used for
encryption and decryption of electronic data. It was developed in the 1970s by IBM
and adopted as a standard by the National Institute of Standards and Technology
(NIST) in 1977. DES became widely used for securing electronic communications
and data transmission until it was eventually replaced by more secure algorithms
like AES (Advanced Encryption Standard). Its 56-bit key size is considered
insufficient for modern security standards due to advances in computing power and
cryptanalysis techniques.
Tools:
Anaconda Navigator:
Anaconda Navigator is a graphical user interface (GUI) included with the Anaconda
distribution for Python. It provides an easy-to-use interface to manage packages,
environments, and applications associated with Anaconda.
Jupyter Notebook:
Jupyter Notebook provides an interactive interface where you can create and edit notebooks.
Notebooks consist of cells that can contain code, Markdown text, equations, or raw text.
CSE- Page 27 of
Enrolment No. BMSF Laboratory
Steps:
Code: -
This code defines a function called Caesar cipher that performs Caesar cipher encryption
on a given text input with a specified shift value.
import tkinter as tk: This line imports the Tkinter module and aliases it as tk.
def caesar_cipher(text, shift): This line defines the function caesar_cipher which
takes two parameters:
text: The text to be encrypted.
shift: The number of positions to shift each character in the text.
encrypted_text = "": Initializes an empty string to store the encrypted text.
for char in text:: Iterates over each character in the input text.
if char.isalpha():: Checks if the character is an alphabet.
shifted = ord(char) + shift: Calculates the shifted value of the character by adding
the shift value to its ASCII code.
if char.islower():: Checks if the character is a lowercase letter.
if shifted > ord('z'): shifted -= 26: If the shifted value exceeds the ASCII code for
lowercase 'z', it wraps around by subtracting 26.
if char.isupper():: Checks if the character is an uppercase letter.
if shifted > ord('Z'): shifted -= 26: If the shifted value exceeds the ASCII code for
uppercase 'Z', it wraps around by subtracting 26.
encrypted_text += chr(shifted): Converts the shifted ASCII code back to a character
and appends it to the encrypted_text string.
else: encrypted_text += char: If the character is not an alphabet (e.g., punctuation or
whitespace), it is left unchanged and added to the encrypted_text.
return encrypted_text: Returns the encrypted text.
CSE- Page 28 of
Enrolment No. BMSF Laboratory
These functions are part of a GUI application using Tkinter for Caesar cipher encryption
and decryption:
encrypt_text(): Encrypts input text using a Caesar cipher with a user-specified shift
value. Retrieves input from a text widget, gets the shift value from another widget,
calls the caesar_cipher() function, and displays the encrypted text in an output widget.
decrypt_text(): Decrypts input text using a Caesar cipher with a user-specified
negative shift value (to reverse encryption). Performs similar steps as encrypt_text()
but with a negated shift value.
Both functions rely on input entry and shift entry widgets for user input and output entry
widget to display results.
This code creates a Tkinter window for a Caesar Cipher application with the
following components:
A window with the title "Caesar Cipher".
A label "Enter Text:" and a text entry widget (input_entry) for inputting text.
A label "Shift Value:" and an entry widget (shift_entry) for specifying the shift value.
The pack() method is used to display these widgets in the window in the order
they are defined.
CSE- Page 29 of
Enrolment No. BMSF Laboratory
This code adds buttons for encryption and decryption, as well as an output text entry
field. The encrypt_button and decrypt_button widgets trigger the encrypt_text() and
decrypt_text() functions when clicked, respectively. The output_entry widget displays the
encrypted or decrypted text. Finally, window.mainloop() starts the Tkinter event loop,
allowing the GUI to be interactive.
Output –
Encryption -
CSE- Page 30 of
Enrolment No. BMSF Laboratory
Decryption -
Code- –
This code creates a GUI application using Tkinter for encrypting and decrypting text using
the DES algorithm. It imports necessary modules from tkinter and Cryptodome, defines
functions for encryption and decryption, and sets up the GUI layout with labels, entry fields,
and buttons for user interaction. When the user enters a key and plaintext, clicks the
"Encrypt" button, the plaintext is encrypted using DES and displayed as ciphertext. Clicking
the "Decrypt" button decrypts the ciphertext and displays the original plaintext. The code
then runs the Tkinter event loop to keep the GUI application running.
CSE- Page 31 of
Enrolment No. BMSF Laboratory
CSE- Page 32 of
Enrolment No. BMSF Laboratory
Output –
Conclusion:
CSE- Page 33 of