August 30, 2026 · Offensive Cyber Operations with AI

MCPFastMCPMythic C2SandboxingAgentic AI

AI Red Teaming Lab 3: MCP Servers — ControlledFS & Mythic C2 — a technical write-up

Lab 3 introduces the Model Context Protocol (MCP) — the standard that lets an LLM client (Claude Desktop, an IDE) discover and call external tools. Exercise 1 builds a defensive MCP server (a sandboxed filesystem), Exercise 2 wires an LLM into the offensive Mythic C2 framework so the model can operate compromised hosts. Together they teach both sides of agentic tooling: how to expose capabilities safely, and what happens when an LLM gets real offensive tools.

Key result: a resolve-then-check sandbox that survives traversal and symlink tricks — and, on the flip side, an LLM autonomously chaining Mythic C2 tools from recon to objective.

Attack path (how the steps chain)

  1. Learn the tool standard — build the ControlledFS MCP server first: three tools, one sandbox, and the resolve-then-check pattern that keeps an LLM inside its lane.
  2. Probe the boundary — path-traversal and symlink prompts show what a sandboxed agent blocks, and the confused-deputy discussion shows what it can't.
  3. Hand the LLM real offensive tools — connect the Mythic C2 MCP server; the model can now see callbacks and task agents.
  4. Chain the operationstart_pentest persona → get_all_agentsad_recon/run_shell_commandprivilege_escalation_peasexecute_mimikatzrun_as_userrun_sharphound/run_kerberoast → objective (flag on DC01).
  5. Autonomy is the point — one natural-language objective ("emulate APT31, drop the flag on the DC") drives the whole chain without the operator naming a single command.

1. Exercise 1 — ControlledFS-MCP (the defensive side)

1.1 Setup

cd Labs-3/ControlledFS-MCP
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt   # fastmcp
python server.py                  # stdio server; normally launched by the client

Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "controlled-fs": {
      "command": "/abs/path/to/.venv/bin/python",
      "args": ["/abs/path/to/server.py"]
    }
  }
}

Use the venv's absolute interpreter path — Claude Desktop doesn't inherit your shell's PATH. Restart Claude; the hammer icon should show 3 tools.

1.2 How it works

server.py registers three tools on a FastMCP instance: list_files, read_file(filename), write_file(filename, content). The security control is safe_path():

def safe_path(filename: str) -> Path:
    path = (SANDBOX / filename).resolve()
    if SANDBOX not in path.parents and path != SANDBOX:
        raise ValueError("Access denied")
    return path

resolve() canonicalizes the path (collapsing .., following symlinks) before the containment check — so both ../../etc/passwd and a malicious symlink inside the sandbox are caught. Checking the raw string for ".." would be bypassable; resolve-then-check is the correct pattern.

1.3 Test prompts and expected outputs

1.4 Discussion points

2. Exercise 2 — Mythic C2 MCP (the offensive side)

2.1 Setup

# Prereq: a running Mythic server (Docker) + at least one active callback
cd "Labs-3/Mythic_C2 MCP"
uv sync
uv run main.py <mythic_user> <mythic_password> <mythic_host> 7443

Claude Desktop config uses uv --directory ... run main.py user pass host 7443 with the absolute path to uv. Credentials as CLI positional args are a security smell worth discussing (visible in process lists).

2.2 The operator's menu

The server exposes 2 prompts and 12 tools. The prompts inject persona/objective: start_pentest(threat_actor, objective) turns the model into an autonomous operator; start_recon() frames enumeration. Key tools:

2.3 Example operator prompts

  1. "List my active agents." → formatted ID/host/user list.
  2. "Run whoami on agent 1." → shell output wrapped in --- markers.
  3. "Do AD recon on agent 1 and summarize interesting groups." → ad_recon + model summary.
  4. Full autonomous scenario: "You are an automated pentester emulating APT31. Objective: add a flag to C:\win.txt on DC01." → the model chains agents → recon → privesc → lateral movement → objective.

2.4 Code insights

3. Troubleshooting

References