01. Metasploit The Basics Modules, Exploits & Payloads
The Metasploit Framework is a widely used tool for penetration testing, security research, and vulnerability assessments. It provides a comprehensive environment for exploiting vulnerabilities in systems and includes tools for reconnaissance, payload generation, and post-exploitation.
Key Features of Metasploit¶
- Modular Design:
- Modules for exploits, payloads, auxiliary functions, and post-exploitation.
- Exploitation:
- Automates the process of exploiting known vulnerabilities in systems or applications.
- Payloads:
- Delivers code or commands to the target system after a successful exploit.
- Post-Exploitation:
- Tools for maintaining access, privilege escalation, and data collection.
- Auxiliary Tools:
- Includes scanners, fuzzers, and other utilities for gathering information and testing vulnerabilities.
Common Components in Metasploit¶
-
Exploits:
- Code designed to take advantage of a vulnerability.
- Example:
exploit/windows/smb/ms17_010_eternalblue. -
Payloads:
-
Code executed after exploiting a system.
- Types include:
- Single Payloads: Perform one task (e.g., adding a user).
- Staged Payloads: Deliver large or complex code in smaller parts.
-
Encoders:
-
Obfuscate payloads to evade detection by antivirus software.
-
Auxiliary Modules:
-
Non-exploit functionalities such as scanners and fuzzers.
-
Post-Exploitation Modules:
-
Tools for privilege escalation, dumping credentials, or gathering additional system information.
Types of Payloads¶
-
Meterpreter:
- A powerful and extensible post-exploitation tool.
- Features:
- Command shell interaction.
- File transfer capabilities.
- Process management.
- Network pivoting.
-
Reverse Shell:
-
Connects back to the attacker’s machine to provide shell access.
-
Bind Shell:
-
Opens a listening port on the victim's system that the attacker can connect to.
-
Staged Payloads:
-
Breaks the payload into smaller parts to bypass network restrictions.
-
Inline Payloads:
-
A single, self-contained payload.
Metasploit Setup¶
1. Purpose¶
-
In real penetration testing, multiple targets are common.
-
Metasploit’s database feature helps:
-
Store and organize hosts, services, vulnerabilities.
-
Avoid confusion with multiple targets.
-
Reuse scan results in modules without manually retyping IPs.
-
2. Database Setup (Kali / Non-AttackBox Systems)¶
If you’re on TryHackMe AttackBox → already done.
If on Kali or local setup:
Note: Running
msfdb initas root will cause:
Please run msfdb as a non-root user.
Solution → use thepostgresaccount as above.
If you want to re-init:
3. Checking Database Status¶
In msfconsole:
Example:
4. Workspaces¶
Workspaces keep projects separate.
-
List:
-
Add:
-
Switch:
-
Delete:
Example:
(* marks the current workspace)
5. Database Backend Commands¶
Once DB is active, extra commands are available:
-
db_nmap – Run Nmap & save results
-
hosts – List stored hosts
-
services – List services on stored hosts
-
vulns – List found vulnerabilities
-
loot – Show collected loot (files/data)
-
notes – Show analyst notes
-
workspace – Switch projects
6. Example Workflow¶
Step 1 – Run Nmap and store results¶
-
-sV→ Service version detection -
-p-→ Scan all ports
Results are automatically saved in DB.
Step 2 – View Hosts¶
Example output:
Step 3 – View Services¶
Example:
Step 4 – Use Hosts in Modules¶
If you found a host with SMB:
Step 5 – Search Specific Services¶
Example: Find netbios services
Output:
7. Common “Low Hanging Fruits”¶
-
HTTP → Check for SQLi, RCE, file uploads.
-
FTP → Try anonymous login.
-
SMB → Look for MS17-010 (EternalBlue).
-
SSH → Test for weak/default passwords.
-
RDP → BlueKeep or weak credentials.
Example Mini Scenario¶
-
Create workspace:
-
Scan entire subnet:
-
Find SMB servers:
-
Test for MS17-010:
Metasploit Commands¶
1. help¶
- Displays a list of all available commands in Metasploit.
- Useful for beginners to understand the available functionalities.
2. search¶
- Searches for modules matching the criteria.
type:exploitspecifies the type of module (e.g., exploit, auxiliary, payload).platform:windowsfilters results for the Windows platform.<name>can be a specific keyword related to the target or exploit (e.g., "smb").
3. use¶
- Selects a specific module for use.
-
Example:
4. show¶
-
General Command
- Lists all available modules or options, depending on the current context.
- Show Options
- Displays configurable options for the selected module, such as RHOST (remote host) or LHOST (local host).
- Show Targets
- Lists all the operating systems or environments the exploit is compatible with.
- Show Info
- Provides detailed information about the selected module, including its purpose and requirements.
5. set¶
- Configures an option for the selected module.
-
Example:
-
6. back¶
- Exits the current module and returns to the main console.
7. exit¶
- Quits the Metasploit console.