Table of Content
- Introduction to Metasploit - Overview - Main Components - Room Objectives
- Main Components of Metasploit - Core Concepts
- Msfconsole
- Launching msfconsole
- Console Functionality
- Limitations
- Contextual Configuration
- Module Selection and Context Switching
- Viewing Module Options
- Example: EternalBlue Exploit
- Example: Post-Exploitation Modules
- Showing Available Modules
- Illustrative Example
- Listing All Modules
- Module Information (
info
command) - Module Searching (
search
command):** - Exploit Ranking
Introduction to Metasploit
Overview
Metasploit is a widely used penetration testing framework, available in two versions:
- Metasploit Pro: Commercial, GUI-based, offering automation and management features.
- Metasploit Framework: Open-source, command-line interface (CLI), used in this room and commonly found on penetration testing Linux distributions. This room focuses on the Framework.
The Framework supports all phases of penetration testing: information gathering, scanning, exploitation, exploit development, and post-exploitation. It’s also valuable for vulnerability research and exploit development.
Main Components
msfconsole
: The primary CLI.- Modules: Exploits, scanners, payloads, and other supporting components.
- Tools: Standalone utilities aiding in vulnerability research, assessment, and penetration testing. Examples include:
msfvenom
: (Covered in this room) Used for creating payloads.pattern_create
andpattern_offset
: (Not covered in this room) Useful for exploit development.
Room Objectives
This room provides a foundation in using the Metasploit Framework CLI. Upon completion, users will be able to:
- Navigate the Metasploit command line.
- Find relevant exploits.
- Set parameters for exploits.
- Exploit vulnerable services.
Main Components of Metasploit
The Metasploit console (msfconsole
) is launched from the terminal using the command msfconsole
. This console serves as the primary interface for interacting with Metasploit’s modules.
graph LR
A[msfconsole] --> B(Modules);
A --> C(Tools);
B --> D{Exploits};
B --> E{Auxiliary};
B --> F{Payloads};
B --> G{Post-Exploitation};
B --> H{Encoders};
B --> I{Evasion};
B --> J{NOPs};
C --> K[msfvenom];
C --> L[pattern_create/offset];
Core Concepts
- Vulnerability: A flaw (design, coding, or logic) in a system that can be exploited. Exploitation can lead to information disclosure or code execution.
- Exploit: Code that leverages a system vulnerability.
- Payload: Code executed on the target system after successful exploitation. Payloads achieve the attacker’s objective (e.g., gaining a shell, executing commands, retrieving data).
Metasploit Modules
Modules are self-contained components within the Metasploit Framework, categorized as follows:
graph LR
A[Modules] --> B(Auxiliary);
A --> C(Encoders);
A --> D(Evasion);
A --> E(Exploits);
A --> F(NOPs);
A --> G(Payloads);
A --> H(Post-Exploitation);
B --> B1(Scanning);
B --> B2(Crawling);
B --> B3(Fuzzing);
B --> B4(Other);
G --> G1(Adapters);
G --> G2(Singles/Inline);
G --> G3(Stagers);
G --> G4(Stages);
A. Auxiliary Modules
These support various tasks, including
- Scanning: Identifying potential vulnerabilities.
- Crawling: Mapping web applications.
- Fuzzing: Testing application robustness by providing unexpected inputs.
- Other: Admin, analyze, bnat, client, cloud, docx, dos, fileformat, gather, parser, pdf, server, sniffer, spoof, sqli, voip, vsploit.
B. Encoders
These encode exploits and payloads to potentially evade signature-based antivirus detection. However, their effectiveness is limited as advanced antivirus solutions often employ additional detection methods.
C. Evasion Modules
These actively attempt to evade antivirus software, often with varying degrees of success. (Primarily focused on Windows systems).
D. Exploit Modules
These contain code to leverage specific vulnerabilities, organized by target operating system (e.g., Windows, Linux, Android).
E. NOP (No Operation) Modules
These modules insert “no operation” instructions (0x90
in x86) into payloads, creating padding to ensure consistent payload sizes. They are architecture-specific (x86, x64, ARM, etc.).
F. Payload Modules
These contain the code that will be executed on the target system after a successful exploit. They are categorized as:
- Adapters: Wrap single payloads into different formats (e.g., PowerShell).
- Singles (Inline): Self-contained payloads that don’t require additional components (e.g., launching an application). Indicated by ”_” between components in the name (e.g.,
generic/shell_reverse_tcp
). - Stagers: Establish a connection between Metasploit and the target, then download the remaining payload (stage). Used with staged payloads.
- Stages: The main part of the payload, downloaded by the stager. Allows for larger payloads. Indicated by ”/” between components in the name (e.g.,
windows/x64/shell/reverse_tcp
).
NOTE
Metasploit has a subtle way to help you identify single (also called “inline”) payloads and staged payloads.
- generic/shell_reverse_tcp
- windows/x64/shell/reverse_tcp Both are reverse Windows shells. The former is an inline (or single) payload, as indicated by the __ between “shell” and “reverse”. While the latter is a staged payload, as indicated by the “/” between “shell” and “reverse”.
G. Post-Exploitation Modules
These are used after initial access to extend the attack (Post modules). They are also organized by target operating system.
IV. Module Location:
On the AttackBox, Metasploit modules are located within /opt/metasploit-framework/embedded/framework/modules
. The directory structure mirrors the module categories described above.
Msfconsole
Launching msfconsole
The Metasploit console is launched using the command msfconsole
in the terminal. Upon launch, it displays a banner indicating the version and module counts. The prompt changes to msf6>
(or msf5>
depending on the version).
Console Functionality
-
Command Line Interface:
msfconsole
acts like a regular command-line shell. It supports many standard Linux commands likels
,ping
, andclear
. However, it does not support all features, such as output redirection (e.g.,command > file.txt
). -
Help System: The
help
command provides information on Metasploit commands and options. Usinghelp [command]
gives specific details about a command (e.g.,help set
). -
Command History: The
history
command displays previously executed commands. -
Tab Completion: Tab completion significantly speeds up command entry, auto-completing commands and options as you type.
-
Datastore Management: The
set
command allows modifying options within the Metasploit framework, operating on either the global or module-specific datastore.set [option] [value]
sets an option; omitting the value displays its current setting; omitting both lists currently set options. Using-g
with theset
command operates on the global datastore. Payload selection uses indexes fromshow payloads
.
Example Commands and Their Usage:
ls
: Lists files and directories in the current directory.ping -c 1 8.8.8.8
: Sends a single ping to Google’s DNS server. (The-c 1
limits the number of pings).help
: Displays general help information.help set
: Displays specific help for theset
command.history
: Shows the command history.set [option] [value]
: Sets a specific option to a value.show payloads
: Displays available payloads.
Limitations
- Output redirection (e.g.,
>
,>>
) is not supported.
Contextual Configuration
msfconsole
operates within a specific context. This means that settings made for a particular module (exploit, auxiliary, post-exploitation module, etc.) are not global. Changing modules resets the configuration to the defaults for the new module. Any parameters set for a previous module are lost unless they’re explicitly set as global variables (a more advanced topic).
Module Selection and Context Switching
Modules are selected using the use
command followed by the module path (e.g., use exploit/windows/smb/ms17_010_eternalblue
). The console prompt changes to reflect the current context: msf6 exploit(windows/smb/ms17_010_eternalblue) >
. This indicates you are now working within the context of the ms17_010_eternalblue
exploit.
Standard Linux commands (e.g., ls
) can still be used within a module context; however, they operate on the system’s filesystem, not within the Metasploit framework’s internal structure.
Viewing Module Options
The show options
command displays the configurable options for the currently selected module. These options are specific to the module’s functionality. Some options are required (Required: yes
), while others are optional. The output differs depending on the module type (exploit, payload, auxiliary, post-exploitation module, etc.).
Example: EternalBlue Exploit
The ms17_010_eternalblue
exploit, as shown in the example, requires settings like RHOSTS
(target IP address(es)) and RPORT
(target port). After selecting this exploit using use
, show options
reveals these and other relevant parameters. If you switch to a different module, you’ll need to reconfigure these settings for the new module.
Example: Post-Exploitation Modules
Post-exploitation modules operate on existing sessions (connections to compromised systems). Their options typically include a SESSION
parameter, specifying the session ID to use.
Showing Available Modules
The show
command, followed by a module type (e.g., show exploits
, show payloads
, show auxiliary
), lists the available modules of that type. This is useful for browsing and selecting appropriate tools. show payloads
within an exploit’s context only lists payloads compatible with that exploit.
Illustrative Example
use exploit/windows/smb/ms17_010_eternalblue
: Selects the EternalBlue exploit, establishing its context.show options
: Displays options specifically for the EternalBlue exploit (e.g.,RHOSTS
,RPORT
).set RHOSTS 192.168.1.100
: Sets the target IP address.use auxiliary/scanner/portscan/tcp
: Switches to a TCP port scanner module. TheRHOSTS
setting is lost.show options
: Displays options for the TCP port scanner, which will likely require different parameters than the EternalBlue exploit.
Listing All Modules
The show
command, when used without any arguments from the msfconsole
prompt, lists all available modules in the Metasploit database.
Module Context Management
-
use
command: Selects a specific module, changing the console context to that module. The prompt reflects the current module (e.g.,msf6 exploit(windows/smb/ms17_010_eternalblue)
). All subsequent commands, unless explicitly specified as global, apply only to the currently selected module. -
show options
command: Displays the configurable options for the selected module. Required and optional parameters are clearly indicated. This command’s output is specific to the module’s context. -
back
command: Exits the current module context, returning to the mainmsfconsole
prompt.
Module Information (info
command)
The info
command provides detailed information about a module. It can be used in two ways:
-
Within a module’s context:
info
displays comprehensive details, including author(s), description, relevant references (URLs, CVE numbers), licensing information, supported targets (if any), and basic options. -
From the main
msfconsole
prompt:info [module_path]
(e.g.,info exploit/windows/smb/ms17_010_eternalblue
) displays the same detailed information.
The info
command provides far more than a simple help menu; it provides rich contextual information about the module’s capabilities and background.
Module Searching (search
command):**
The search
command is a powerful tool for finding relevant modules within the Metasploit database. It supports various search parameters, including:
-
Keywords: Search for modules containing specific terms in their names or descriptions (e.g.,
search eternalblue
,search heartbleed
). -
CVE numbers: Find modules related to specific vulnerabilities (e.g.,
search CVE-2017-0143
). -
Module type: Filter results by module type (e.g.,
search type:auxiliary telnet
searches only for auxiliary modules related to Telnet). -
Platform: Filter results based on the target operating system (e.g.,
search platform:windows
).
The output of the search
command lists matching modules, including their name, disclosure date, rank (reliability), whether a check is available, and a brief description. Modules can be selected using either their index number or full path (e.g., use 4
or use exploit/windows/smb/smb_doublepulsar_rce
).
Exploit Ranking
Source: https://github.com/rapid7/metasploit-framework/wiki/Exploit-Ranking
Metasploit assigns a rank to exploits indicating their reliability. This helps penetration testers gauge the likelihood of success when using a given exploit. The ranking system is detailed in the Metasploit Framework’s official documentation. Note that even high-ranked exploits may not always be successful due to unpredictable target system behavior or unforeseen circumstances.