# Metasploit

> Use when msfconsole/msfvenom/meterpreter is the chosen exec vehicle (DB recon, module search, handler shells, post-ex, pivoting). Console-pitfall ledger + delegate hand-off. Consumes a foothold/vector; hands shells to hunt-windows/hunt-ad.

- Skill: `encod3d-sec/metasploit-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx get-skill add encod3d-sec/metasploit-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/encod3d-sec/metasploit-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: Encod3d-Sec (https://skillmd.com/u/encod3d-sec)
- Updated: 2026-11-16
- Page: https://skillmd.com/skills/encod3d-sec/metasploit-2

---


# Metasploit: framework driver

Drive msfconsole for recon, exploit, reverse shells, and post-ex.
Syntax lives in `[[metasploit]]`; this skill is the workflow that
strings it together - plus the console-pitfall ledger that only
survives if it stays in one place.

## Wiki

Hub: [[exploit-dev-moc]] - Primary page: [[metasploit]]
Anchors: [[pivoting-tunneling]], [[windows-privesc]], [[password-cracking]]
**REFS:** [[metasploit]]

qmd on hint only: "msfconsole handler meterpreter msfvenom autoroute"
- the metasploit page first, wiki-arsenal for module picks.

## Paths (binding - define once at the top of the run notes)

    # seat side (Windows) - engagement tree is DOUBLE-NESTED in VMshare:
    ENG_DIR=/mnt/c/Users/Lenovo/Desktop/VMshare/<eng>/<eng>
    # VM side (WHERE msfconsole + handlers run, same tree through the share):
    ENG_DIR=/mnt/VMshare/<eng>/<eng>

Sessions, loot, and creds stay in the msf DB workspace (scoped
`workspace -a <eng>`) + targets/<eng>/; never paste a real
host/cred/hashdump into wiki/ or session/* (client-data boundary).

## Transport

The console runs ON the VM inside a NAMED tmux tab (the operator must
watch sessions land live - never a blind background job); the seat
drives it through ONE documented transport:

    wsl.exe -d kali-linux -u root bash -c "cd /mnt/c/Users/Lenovo/Documents/ObisidianVaults/ZTorch/ZTorch && bash scripts/vm-ssh.sh '<command>'"

- vm-ssh lands as user tz (NOT root); one argument per call; quotes
  ship as base64 (`echo <b64> | base64 -d | bash`).
- Handler automation: `bash scripts/vm-handler.sh <lhost> [tmux] [payload]`
  (picks the first FREE egress-friendly LPORT 80/443/53/8000/8080,
  launches in tmux, prints the port to build payloads with).
- Stager channel: `bash scripts/stager.sh <lhost> [port] <payload>`
  (web_delivery pattern, integer-encoded IPv4 one-liner for
  length-capped sinks).
- Interactive session driving from the seat: `sessions -i` inside the
  tmux tab; `bash scripts/win-rsh.sh <eng> '<cmd>'` for Windows shells.

## Entry gate

All four must pass; each is falsifiable:

1. Active engagement exists (repo tree targets/<eng>/active.md) and
   the target is on targets/<eng>/scope.md in-scope. Scope-guard is
   the deny.
2. A VECTOR exists to drive: a fingerprinted version/CVE, a cred pair,
   or a shell already landed (loot.md / state.md row). Raw "run msf
   against the scope" with no vector = recon lane first.
3. Wiki query fired (MANDATORY pre-attack): `[[metasploit]]` for
   syntax + Skill(wiki-arsenal) for the module/payload pick. Never
   fire a module from memory when a targeted lookup would confirm it.
4. Toolchain preflight (fails LOUD; install-on-demand per the
   operator rule):

       command -v msfconsole >/dev/null \
         || { sudo apt-get install -y metasploit-framework 2>/dev/null; } \
         || echo "N/A: msfconsole absent on VM (install failed - needs apt/sudo) - manual exploit path (hunt-rce)"

## Checklist (mandatory)

Copy checklist.md (this skill's dir) to
`$ENG_DIR/msf-checklist.md` at run start. Unchecked at stop =
UNCHECKED lane, re-run from the first unchecked step. SKILL.md and the
checklist header agree byte-for-byte on that copy target.

## Nudge

Review-skill re-injection text (pinned; NOTE: completion-gate emits
its own generic nudge - both mean: resume at the first unchecked box):

    Your work was just reviewed by the review skill and it was found
    that you either missed a step of analysis, or didn't generate an
    artifact of sufficient proof. Look at the markdown based checklist
    and the output for each step, find what you missed, and complete
    that step.

## Confirmation gate

**NOT confirmation:** a module fired and "completed" in the log; a
session ID listed by `sessions`; a `getuid` that returns your own
attacker box (false-root: the session died back home); a check that
returns "The target is not exploitable" ignored because the run
succeeded anyway.

**IS confirmation:** a LIVE session verified against the actual
target - `getuid` + `sysinfo`/hostname match the target host, an
action the base context could not perform succeeds in-session
(protected read, privilege escalation observed via `getsystem`/local
exploit), reproduced from your own written steps. Post-ex claims ride
the same gate as manual shells (hunt-core).

## Methodology

### Setup / DB

`msfconsole -q` in a named tmux tab; `workspace -a <eng>`,
`db_status` (if down after an msf update: `msfdb reinit`), creds
captured with `creds add` so the workspace holds them alongside
state.md.

### Recon via msf

`db_nmap` writes straight to hosts/services; layer
`auxiliary/scanner/*` (smb/http/ssh version + vuln checks) on top.
Complements ctf-box Phase-1 basics - run both.

### Search / select / verify

`search <app> <ver>` / `search cve:<id>`, `use`, `info` (CVE refs +
target list), `check` before `run` whenever supported
(`search check:true` pre-filters). No local module for the version ->
searchsploit .rb import ([[metasploit]] 'Importing an Exploit-DB module' section); the
public-PoC sweep behind it is Skill(searchsploit).

### Reverse shells (ladder)

1. meterpreter first (`linux/x64/meterpreter/reverse_tcp`,
   `windows/x64/meterpreter/reverse_tcp`);
2. plain `shell_reverse_tcp` when meterpreter is blocked/unstable
   (hardened Windows/EDR);
3. AV reaps even the plain stager -> skip msf payloads: stage a
   minimal non-network stub over the existing webshell/file-write
   channel ([[wiki/cheatsheets/windows-privesc]]).

`set ExitOnSession false; run -j` to keep the handler catching.
Egress-test LPORT (80/443/53 before 4444) or use vm-handler.sh.

### Sessions / post-ex

`sessions -i <id>`; `run post/multi/recon/local_exploit_suggester` on
every fresh session (privesc reflex); targeted `post/*`; `getsystem`;
`post/multi/manage/shell_to_meterpreter` to upgrade.

### Driving the console from tmux (pitfall ledger - hard-won)

- Console health: the pane must render the `msf6 >` prompt. Event
  spam with no prompt = blocked input loop (blocking `run` under
  `-x`); keystrokes ECHO but never execute. Relaunch with `run -j`.
- `sessions -c <cmd>` is a SILENT NO-OP on plain cmd/unix shells -
  drive sessions one at a time (`sessions -i <id>` then `id`).
- NEVER C-z a session you plan to leave: the `Background session N?
  [y/N]` confirm eats the next typed line. `exit` a disposable shell
  or answer the prompt first.
- Command shells are pty-less: interactive sudo/GTFOBins tools see a
  non-tty and die. Stabilize FIRST (`script -qc /bin/bash /dev/null`),
  then `sudo less <file>` + `!sh` = root.

### Tunnel → Escalate → Pivot checklist

WIKI-FIRST GATE (hard, range-exercise lesson): before ANY tunneling/pivot work, query
the wiki - `[[pivoting-tunneling]]` via qmd/wiki-query (the range-repo
cheatsheet equivalent, when present, rides the same hub). The wiki carries
the full syntax + proxychains patterns this checklist assumes; skipping it
rediscovered them from scratch on one range exercise.

**T0 - Transport feasibility (BEFORE any upgrade):**
- [ ] What ports actually reach the handler? Map the callback path
  (front/DNAT/firewall): from a target-side shell run per-port probes.
  rc 1 (refused) = forwarded, rc 124 (timeout) = not.
- [ ] Meterpreter stage ports (4444 etc.) reachable? If the front forwards
  443 ONLY, `shell_to_meterpreter` will hang forever ("Upgrading session"
  never completes) - SKIP to pivot-by-command instead of waiting.
- [ ] Handler on 0.0.0.0 catch-all, ExitOnSession false - survives front
  rotation without rebinds.

**T1 - Escalate (in the session):**
- [ ] Stabilize the pty FIRST (`script -qc /bin/bash /dev/null`) - plain
  shells are pty-less; sudo/GTFOBins die without it.
- [ ] `getsystem` (Windows) / `sudo -n`, suid, sudo -S vectors (Linux).
- [ ] Move the shell OUT of the console: creds/key to a direct SSH path.
  A shell that only lives inside msf dies with the console - one range exercise
  lost ~25 sessions to a single console wedge.

**T2 - Tunnel (meterpreter available):**
- [ ] `run post/multi/manage/autoroute` -> `route print`
- [ ] `portfwd add -l <local> -p <port> -r <target>` per service
- [ ] `socks` + proxychains for tool-through-pivot

**T3 - Pivot (meterpreter BLOCKED - pivot-by-command):**
- [ ] Drive the root session directly: `timeout 2 bash -c "echo >
  /dev/tcp/<h>/<port>"` neighbor sweeps FROM the box.
- [ ] Fire callbacks from ON the box (its egress may work where the
  seat's is filtered); arm same-subnet relays (relay reach is
  same-SUBNET only behind range ACLs).
- [ ] SSH -J through the box for TCP the seat cannot reach.

**Anti-patterns (range-verified):**
- NEVER script-loop `sessions -i` + paste + C-z + y - the y-confirm merges
  with the next command and wedges the console. Manual, one at a time.
- `sessions -c <cmd>` is a silent no-op on plain command shells.
- A wedged console: SIGINT kills readline but ruby still holds the port -
  kill -9 the pid, relaunch, re-`exploit -j` AFTER the port frees.


### Interlock + anti-drift

The msfvenom->handler->escalation sequence is a prime Skill(delegate)
hand-off (mechanical, cheap-model-shaped). But DRIVE msf for every
load-bearing exploit/shell request so the operator watches sessions
land; once landed, WORK FROM THE SHELLS - relay/uploads re-arm a
broken channel, they do not drive post-ex you could run interactively.

## Chaining

- Module choice from a fingerprint: hunt-rce owns the CVE verdict;
  this skill owns execution once msf is the vehicle.
- Landed Windows shell: hunt-windows (local privesc ladder).
- Domain-joined foothold: hunt-ad (mapper dispatch).
- Cred reuse beyond the session: creds add + loot.md rows feed the
  mapper enum waves.

## Validation

- Proof = live session verified on-target (getuid + sysinfo match) +
  an in-session action the base context could not perform.
- Negative control: the same vector without the payload/exploit
  fails cleanly (module `check` or manual request).

## False Positives

- False-root: getuid shows the attacker box (dead session bouncing
  home) - delegate's guardrail applies here verbatim.
- "Session opened" that dies on first interaction (EDR kill, unstable
  transport) - a session that cannot ACT is not a foothold.
- check:false module fired blind on a hardened target and "succeeded"
  against a decoy service.
- meterpreter on a monitored host = telemetry bonfire; prefer plain
  shells there (AV/EDR ladder above).

## Severity

Inherits the finding's class severity (hunt-core/triage own rating);
msf is the vehicle, not the verdict.

## N/A escapes

- "N/A: msfconsole absent on VM (install failed - needs apt/sudo)"
  (manual exploit path via hunt-rce)
An N/A tick is a claim with a reason, never a silent pass. Identical
strings in SKILL.md and checklist.md.

## Bitter-pill variant

Freehand run: skip checklist + numbered steps, one freehand pass over
the vector, output ONLY $ENG_DIR/analysis/msf-bitter-pill.md (tried/
found/dismissed, every claim carries evidence). The on-target-session
gate survives freehand. Declare with a _requests.md row (lane =
msf-bitterpill).

## Exit artifact + handoff

$ENG_DIR/msf-checklist.md + $ENG_DIR/analysis/msf-bitter-pill.md (or
both), session log excerpt (tmux capture) into targets/<eng>/poc/,
`MSF-DONE sessions=<n> verified=<n>` appended to
$ENG_DIR/hunt-rce-<host>.md (or the owning class pointer). Consumer:
triage. Findings leave ONLY through G1. Distill console pitfalls:
`python3 scripts/wiki-stage.py --kind technique --slug <slug>
--target-page wiki/tools/metasploit.md`.

## Stop conditions

Console healthy or relaunched; every session either verified or
explicitly discarded with the WHY; no unchecked boxes above REVIEW;
hunt-core stop conditions fire unchanged.

