> For the complete documentation index, see [llms.txt](https://capcap-1.gitbook.io/capcap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://capcap-1.gitbook.io/capcap/readme/ctf-modules/vulnerability-assessment/msf/sessions.md).

# Sessions

**Sessions**

MSF can manage multiple active connections simultaneously. Each exploited target gets its own session with a dedicated control interface.

***

**Backgrounding a Session**

Two ways:

* **`[CTRL] + [Z]`** — works for any module
* **`background`** — used inside Meterpreter

Backgrounded sessions **keep running** and connection persists. They can die if the payload communication breaks.

***

**Key Session Commands**

```bash
sessions          # list all active sessions
sessions -i 1     # interact with session 1
```

**Typical flow:**

```bash
# exploit lands, you get meterpreter
meterpreter > background          # send to background
msf6 > sessions                   # confirm it's there
msf6 > use post/...               # load a post-exploit module
msf6 > set SESSION 1              # point it at your session
msf6 > run
```

> Post-exploitation modules (credential gatherers, local exploit suggesters, internal network scanners) are run this way — against an already-owned session.

***

**Jobs**

Jobs are modules/exploits running in the background. Different from sessions — a job is the **running task**, a session is the **resulting connection**.

**Why jobs matter:** If an exploit is holding a port open, you can't just `CTRL+C` — the port stays occupied. You need to kill it properly via jobs.

```bash
jobs -l           # list running jobs
jobs -i 0         # detailed info on job 0
jobs -k 0         # kill job by ID
jobs -K           # kill ALL jobs
jobs -p 0         # persist job across restarts
```

**Run an exploit as a background job:**

```bash
msf6 > exploit -j     # runs exploit in background, frees your console
```

***

**Sessions vs Jobs — Quick Distinction**

|                     | Session                     | Job                                   |
| ------------------- | --------------------------- | ------------------------------------- |
| What it is          | Active connection to target | Running module/task                   |
| Persists if killed? | Dies with connection        | Can be persisted with `-p`            |
| Use case            | Interacting with target     | Holding listeners, long-running tasks |

***

**Key takeaway:** Background sessions with `CTRL+Z`, manage with `sessions`. Use `exploit -j` to run listeners as jobs, kill them cleanly with `jobs -k` to free ports.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://capcap-1.gitbook.io/capcap/readme/ctf-modules/vulnerability-assessment/msf/sessions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
