Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 37 ยท Meterpreter and Post-exploitation

Meterpreter Overview: Sessions and Staging

Understand what Meterpreter is, how staged and stageless payloads differ, and how sessions are tracked, from a defender's and an authorized tester's viewpoint.

Meterpreter is the most famous payload in the Metasploit Framework. Instead of handing a tester a bare command shell, it provides an in-memory agent with its own command set: browse files, list processes, collect system facts, route traffic. It was designed so that it leaves little on disk and talks to the framework over an encrypted channel.

This lesson explains the concepts, so you can use it in an authorized lab and, just as importantly, recognize what it looks like from the defender's side. Nothing here targets a real system: the stand-ins model session bookkeeping with plain Python. You met payload types in Exploits and Payloads; here we go one step further, into what happens once a payload connects back.

Only run Meterpreter against systems you own or have written permission to test. See Law, Ethics and Authorization before you build a lab.

What a Meterpreter session is

A session is a live connection between the framework (the handler) and an agent running on the target. The framework numbers each session and remembers which module created it, the target address, the payload and the tunnel.

TEXT
# Illustrative output of `sessions -l` (invented lab addresses)
Active sessions
===============

  Id  Name  Type                     Information            Connection
  --  ----  ----                     -----------            ----------
  1         meterpreter x64/windows  LAB\tester @ LAB-WIN10 192.0.2.10:4444 -> 192.0.2.20:49721
  2         shell linux              tester @ lab-ubuntu    192.0.2.10:4444 -> 192.0.2.30:51022

Meterpreter sessions differ from plain shell sessions in three ways:

  • Own protocol. Commands are TLV (type-length-value) packets, not text typed into cmd.exe.
  • Channels. Several streams (a process's input, a file transfer) are multiplexed over one connection.
  • Extensions. Features such as stdapi, priv or kiwi are loaded on demand into memory, keeping the initial payload small.

Staged versus stageless

A payload name such as windows/x64/meterpreter/reverse_tcp uses slashes between the pieces: platform, architecture, stage, stager. The stager is a tiny program whose only job is to connect back and download the larger stage (the Meterpreter agent) into memory. A stageless payload carries everything in one blob and is named with an underscore, windows/x64/meterpreter_reverse_tcp.

sequenceDiagram
    participant T as Target (lab)
    participant H as Handler
    T->>H: Stager connects back
    H-->>T: Sends the stage (agent)
    T->>H: Agent starts, encrypted session opens
    H->>T: Commands as TLV packets

A staged payload: a small stager first, the full agent second.

Why the two designs exist:

  • Staged payloads are small, which fits tight exploit buffers.
  • Stageless payloads need one network round trip, which is useful when the connection is flaky or heavily filtered.
  • For defenders, a staged download is a second chance to notice odd traffic, while stageless puts everything in the first file.
Python Model the staged payload name

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Session bookkeeping

The framework keeps a table of sessions and lets you interact with one at a time (sessions -i 1), background it (background, or Ctrl+Z), or close it (sessions -k 1). The stand-in below mimics that table so you can see the logic.

Python A tiny session table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The defender's view

An in-memory agent still leaves traces. Defenders watch for:

  • A process making a long-lived outbound connection to an unusual host and port, often with regular "beacon" timing.
  • Memory regions that are executable but not backed by a file on disk.
  • A short-lived program that spawns a new process and then exits.
  • Network sensors that match known stager byte patterns (covered in Detecting Metasploit Activity).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the stager in a staged payload do?

    The stager is tiny and exists only to fetch the full agent (the stage) so the exploit buffer can stay small.
  2. 2. Which payload name is stageless?

    An underscore between meterpreter and the transport marks a single, stageless blob; slashes mark separate stage and stager.
  3. 3. What does sessions -k 1 do?

    -k kills a session, -i interacts with it and -l lists them.
  4. 4. Which is a realistic defender signal for an in-memory agent?

    Regular beacons from an unexpected process are a classic network-level indicator.

Summary

  • Meterpreter is an in-memory agent with its own protocol, channels and loadable extensions.
  • Staged payloads fetch the agent after a tiny stager connects; stageless payloads carry everything.
  • The framework numbers sessions; you list, interact, background and kill them.
  • Defenders look for beacons, unbacked executable memory and unusual outbound connections.
  • Use it only with explicit authorization.

Next: Meterpreter Commands and File System Work