AI Agent Abuse: Local AI CLI Tools & MCP (Claude/Gemini/Warp)
Tip
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Learn & practice Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Check the subscription plans!
- Join the đŹ Discord group or the telegram group or follow us on Twitter đŚ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
Overview
Local AI command-line interfaces (AI CLIs) such as Claude Code, Gemini CLI, Warp and similar tools often ship with powerful builtâins: filesystem read/write, shell execution and outbound network access. Many act as MCP clients (Model Context Protocol), letting the model call external tools over STDIO or HTTP. Because the LLM plans tool-chains nonâdeterministically, identical prompts can lead to different process, file and network behaviours across runs and hosts.
Key mechanics seen in common AI CLIs:
- Typically implemented in Node/TypeScript with a thin wrapper launching the model and exposing tools.
- Multiple modes: interactive chat, plan/execute, and singleâprompt run.
- MCP client support with STDIO and HTTP transports, enabling both local and remote capability extension.
Abuse impact: A single prompt can inventory and exfiltrate credentials, modify local files, and silently extend capability by connecting to remote MCP servers (visibility gap if those servers are thirdâparty).
Adversary Playbook â PromptâDriven Secrets Inventory
Task the agent to quickly triage and stage credentials/secrets for exfiltration while staying quiet:
- Scope: recursively enumerate under $HOME and application/wallet dirs; avoid noisy/pseudo paths (
/proc,/sys,/dev). - Performance/stealth: cap recursion depth; avoid
sudo/privâescalation; summarise results. - Targets:
~/.ssh,~/.aws, cloud CLI creds,.env,*.key,id_rsa,keystore.json, browser storage (LocalStorage/IndexedDB profiles), cryptoâwallet data. - Output: write a concise list to
/tmp/inventory.txt; if the file exists, create a timestamped backup before overwrite.
Example operator prompt to an AI CLI:
You can read/write local files and run shell commands.
Recursively scan my $HOME and common app/wallet dirs to find potential secrets.
Skip /proc, /sys, /dev; do not use sudo; limit recursion depth to 3.
Match files/dirs like: id_rsa, *.key, keystore.json, .env, ~/.ssh, ~/.aws,
Chrome/Firefox/Brave profile storage (LocalStorage/IndexedDB) and any cloud creds.
Summarize full paths you find into /tmp/inventory.txt.
If /tmp/inventory.txt already exists, back it up to /tmp/inventory.txt.bak-<epoch> first.
Return a short summary only; no file contents.
Capability Extension via MCP (STDIO and HTTP)
AI CLIs frequently act as MCP clients to reach additional tools:
- STDIO transport (local tools): the client spawns a helper chain to run a tool server. Typical lineage:
node â <ai-cli> â uv â python â file_write. Example observed:uv run --with fastmcp fastmcp run ./server.pywhich startspython3.13and performs local file operations on the agentâs behalf. - HTTP transport (remote tools): the client opens outbound TCP (e.g., port 8000) to a remote MCP server, which executes the requested action (e.g., write
/home/user/demo_http). On the endpoint youâll only see the clientâs network activity; serverâside file touches occur offâhost.
Notes:
- MCP tools are described to the model and may be autoâselected by planning. Behaviour varies between runs.
- Remote MCP servers increase blast radius and reduce hostâside visibility.
Local Artifacts and Logs (Forensics)
- Gemini CLI session logs:
~/.gemini/tmp/<uuid>/logs.json- Fields commonly seen:
sessionId,type,message,timestamp. - Example
message: â@.bashrc what is in this file?â (user/agent intent captured).
- Fields commonly seen:
- Claude Code history:
~/.claude/history.jsonl- JSONL entries with fields like
display,timestamp,project.
- JSONL entries with fields like
Pentesting Remote MCP Servers
Remote MCP servers expose a JSONâRPC 2.0 API that fronts LLMâcentric capabilities (Prompts, Resources, Tools). They inherit classic web API flaws while adding async transports (SSE/streamable HTTP) and perâsession semantics.
Key actors
- Host: the LLM/agent frontend (Claude Desktop, Cursor, etc.).
- Client: perâserver connector used by the Host (one client per server).
- Server: the MCP server (local or remote) exposing Prompts/Resources/Tools.
AuthN/AuthZ
- OAuth2 is common: an IdP authenticates, the MCP server acts as resource server.
- After OAuth, the server issues an authentication token used on subsequent MCP requests. This is distinct from
Mcp-Session-Idwhich identifies a connection/session afterinitialize.
Transports
- Local: JSONâRPC over STDIN/STDOUT.
- Remote: ServerâSent Events (SSE, still widely deployed) and streamable HTTP.
A) Session initialization
- Obtain OAuth token if required (Authorization: Bearer âŚ).
- Begin a session and run the MCP handshake:
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"capabilities":{}}}
- Persist the returned
Mcp-Session-Idand include it on subsequent requests per transport rules.
B) Enumerate capabilities
- Tools
{"jsonrpc":"2.0","id":10,"method":"tools/list"}
- Resources
{"jsonrpc":"2.0","id":1,"method":"resources/list"}
- Prompts
{"jsonrpc":"2.0","id":20,"method":"prompts/list"}
C) Exploitability checks
- Resources â LFI/SSRF
- The server should only allow
resources/readfor URIs it advertised inresources/list. Try outâofâset URIs to probe weak enforcement:
- The server should only allow
{"jsonrpc":"2.0","id":2,"method":"resources/read","params":{"uri":"file:///etc/passwd"}}
{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"http://169.254.169.254/latest/meta-data/"}}
- Success indicates LFI/SSRF and possible internal pivoting.
- Resources â IDOR (multiâtenant)
- If the server is multiâtenant, attempt to read another userâs resource URI directly; missing perâuser checks leak crossâtenant data.
- Tools â Code execution and dangerous sinks
- Enumerate tool schemas and fuzz parameters that influence command lines, subprocess calls, templating, deserializers, or file/network I/O:
{"jsonrpc":"2.0","id":11,"method":"tools/call","params":{"name":"TOOL_NAME","arguments":{"query":"; id"}}}
- Look for error echoes/stack traces in results to refine payloads. Independent testing has reported widespread commandâinjection and related flaws in MCP tools.
- Prompts â Injection preconditions
- Prompts mainly expose metadata; prompt injection matters only if you can tamper with prompt parameters (e.g., via compromised resources or client bugs).
D) Tooling for interception and fuzzing
- MCP Inspector (Anthropic): Web UI/CLI supporting STDIO, SSE and streamable HTTP with OAuth. Ideal for quick recon and manual tool invocations.
- HTTPâMCP Bridge (NCC Group): Bridges MCP SSE to HTTP/1.1 so you can use Burp/Caido.
- Start the bridge pointed at the target MCP server (SSE transport).
- Manually perform the
initializehandshake to acquire a validMcp-Session-Id(per README). - Proxy JSONâRPC messages like
tools/list,resources/list,resources/read, andtools/callvia Repeater/Intruder for replay and fuzzing.
Quick test plan
- Authenticate (OAuth if present) â run
initializeâ enumerate (tools/list,resources/list,prompts/list) â validate resource URI allowâlist and perâuser authorization â fuzz tool inputs at likely codeâexecution and I/O sinks.
Impact highlights
- Missing resource URI enforcement â LFI/SSRF, internal discovery and data theft.
- Missing perâuser checks â IDOR and crossâtenant exposure.
- Unsafe tool implementations â command injection â serverâside RCE and data exfiltration.
References
- Commanding attention: How adversaries are abusing AI CLI tools (Red Canary)
- Model Context Protocol (MCP)
- Assessing the Attack Surface of Remote MCP Servers
- MCP Inspector (Anthropic)
- HTTPâMCP Bridge (NCC Group)
- MCP spec â Authorization
- MCP spec â Transports and SSE deprecation
- Equixly: MCP server security issues in the wild
Tip
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Learn & practice Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Check the subscription plans!
- Join the đŹ Discord group or the telegram group or follow us on Twitter đŚ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
HackTricks

