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:
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):
Start the Metasploit console:
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.version
: Shows the current version of Metasploit.search
: Searches for exploits, payloads, and modules.use
: Selects a module to use.show options
: Displays options for the selected module.
5. Scanning and Enumerating Targets
Before exploiting, gather information about the target.
Using Nmap within Metasploit
Run Nmap scan:
Replace
192.168.1.10
with the target IP address.View the scanned hosts:
List open services and ports:
6. Selecting and Configuring Exploits
Searching for Exploits
Use the
search
command with relevant keywords:
Selecting an Exploit
Choose an exploit module:
View exploit options:
Setting Exploit Options
Set the target IP address:
Confirm the options are set:
7. Choosing and Configuring Payloads
Listing Available Payloads
Show compatible payloads:
Selecting a Payload
Choose a payload (e.g., reverse TCP shell):
Set the local host IP (your machine's IP):
Replace
192.168.1.5
with your Kali Linux IP address.(Optional) Set the local port:
8. Executing the Exploit
Run the 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.getuid
: Shows user ID.shell
: Drops into a shell on the target system.screenshot
: Takes a screenshot of the target desktop.download
: Downloads a file from the target system.
Exiting Meterpreter
exit
: Closes the Meterpreter session.
10. Closing the Session and Exiting Metasploit
List active sessions:
Interact with a session:
Close a session:
Exit Metasploit:
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