用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/brucesongs/kali-claw --skill mcp-server-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | mcp-server-patterns |
| description | Building and security-testing MCP (Model Context Protocol) servers for Kali Linux security tools. |
| origin | openclaw |
| version | 0.2.0.2 |
| compatibility | ["openclaw","claude-code","cursor","windsurf"] |
| allowed-tools | ["Bash","Read","Write","Edit","WebSearch","WebFetch","Agent"] |
| defense_triple_required | false |
| metadata | {"domain":"infrastructure","tool_count":5,"guide_count":5,"last_reviewed":"2026-07-26"} |
Supplementary Files:
payloads.md— Complete Python code templates, tool wrapping scaffolds, input validation snippets, auth middleware, rate limiting patterns, and MCP security testing commandstest-cases.md— Structured test cases covering tool wrapping verification, input validation enforcement, authentication testing, rate limiting, and full MCP security auditguides/security-mcp-server-design.md— Deep-dive guide on tool selection, protocol fundamentals, secure wrapping principles, implementation walkthrough, testing, and deployment
Mcp Server Patterns skill domain covering infrastructure operations.
Tools: Tools, Resources, Prompts, stdio, HTTP/SSE
Domain: infrastructure
Building and security-testing MCP (Model Context Protocol) servers for Kali Linux security tools. Covers wrapping tools as structured APIs with input validation, subprocess safety, authentication, and rate limiting, plus auditing MCP server implementations for authentication weakness, command injection, schema abuse, and information disclosure.
An MCP server exposes three primitive types:
| Primitive | Purpose | Example |
|---|---|---|
| Tools | Functions the AI calls to take actions | run_nmap, check_url, parse_output |
| Resources | Data the AI reads (like files or DB records) | scan_results, target_list |
| Prompts | Templated instructions the AI can request | pentest_report_template |
For security tool wrapping, tools are the primary primitive. A tool definition has four fields:
name — unique identifier the AI uses to invoke the tool
description — natural language explanation of what the tool does and when to use it
inputSchema — JSON Schema describing required/optional parameters and their types
handler — the Python function that executes when the AI calls the tool
The AI (Claude) reads the tool list, decides which tool to call, constructs a JSON argument object matching the inputSchema, and sends it to the server. The server validates the arguments, executes the handler, and returns a structured result.
The canonical wrapping pattern follows this sequence:
AI tool call (JSON args)
↓
Input validation (schema + allowlist checks)
↓
Subprocess construction (shlex.split, no shell=True)
↓
Subprocess execution (timeout enforced)
↓
Output parsing (structured JSON from raw stdout)
↓
Error sanitization (no stack traces, no internal paths)
↓
Structured response returned to AI
Each step is a mandatory gate. Skipping input validation before subprocess construction is the primary attack surface in MCP servers that wrap shell tools.
| Mode | How It Works | Security Implications |
|---|---|---|
| stdio | Server communicates over stdin/stdout; launched as child process | Default for Claude Desktop; no network exposure; authentication handled by OS-level process isolation |
| HTTP/SSE | Server runs as HTTP service; AI sends POST requests; Server-Sent Events for streaming | Exposed to network; requires explicit authentication (API key, OAuth); TLS mandatory for remote deployment |
For penetration testing use cases, HTTP/SSE transport introduces a real attack surface — the server becomes a network service accepting arbitrary JSON from callers.
inputSchema with type, description, and constraints (enum for allowed values, pattern for format, minimum/maximum for ranges).shell=True: Construct subprocess arguments as a list (["nmap", "-sV", target]), never as a shell string. shell=True with any user-controlled input is command injection.timeout parameter. Unbounded execution enables denial of service.IP/CIDR validation — regex match + ipaddress module parse
URL validation — urllib.parse.urlparse + scheme allowlist
Port range — integer cast + 1-65535 bounds check
File path — os.path.realpath + prefix allowlist
Target scope — ip_network.supernet_of check against authorized_ranges
Tool flags — set intersection against ALLOWED_FLAGS constant
For HTTP/SSE transport, implement token-based authentication on every request:
X-API-Key header on every incoming request before processing{"error": "unauthorized"} body — no detail about why the key was rejectedPer-client limits prevent abuse and limit blast radius if credentials are compromised:
{"error": "rate_limit_exceeded", "retry_after": N} — never silently dropretry_after field for repeated violationsMCP server errors are a significant information disclosure vector:
{"error": "tool_execution_failed", "detail": "nmap returned non-zero exit code"}| Surface | Attack Vector | Goal |
|---|---|---|
| Tool input parameters | Injection strings (;, &&, ` | , $()`) |
| Input schema | Send wrong types, missing required fields | Schema bypass, unexpected code path |
| Authentication | Missing header, wrong key, replayed token | Unauthorized tool access |
| Rate limiting | Rapid sequential requests | Exhaust tool execution, DoS |
| Error messages | Trigger tool failures deliberately | Information disclosure (paths, versions) |
| Scope validation | Submit out-of-scope targets | Execute tools against unauthorized hosts |
Step 1 — Schema Fuzzing: Send tool calls with wrong parameter types (string where int expected), missing required fields, extra undeclared fields, and boundary values (empty string, very long string, null).
Step 2 — Injection Testing: For every string input, test: semicolons (; id), shell metacharacters ($(whoami), `id`), path traversal (../../etc/passwd), newlines (\n), and null bytes (\x00).
Step 3 — Auth Bypass: Test: missing X-API-Key header, empty key, key with extra whitespace, key from a different server, expired/rotated key. Verify all return 401 with no partial data.
Step 4 — Rate Limit Bypass: Send requests faster than the limit. Try: different client IPs (X-Forwarded-For spoofing), different API keys per request, large batch requests vs many small ones.
Step 5 — Error Analysis: Trigger failures by passing valid-format-but-broken inputs (unreachable IPs, nonexistent files, malformed URLs). Examine every error response for internal path leakage, version strings, or exception class names.
Step 6 — Scope Bypass: Submit targets just outside the authorized CIDR (adjacent IPs, neighboring subnets). Verify rejection. Test CIDR notation edge cases (host bits set, /0, /32).
| Tool / SDK | Purpose |
|---|---|
mcp Python SDK | Official MCP server implementation library (pip install mcp) |
fastmcp | FastAPI-style high-level MCP server framework for rapid development |
httpx / requests | HTTP client for testing HTTP/SSE transport MCP servers |
ipaddress (stdlib) | IP and CIDR validation in tool handlers |
shlex (stdlib) | Safe subprocess argument construction |
subprocess (stdlib) | Tool execution with timeout and output capture |
| Custom Python scripts | Security testing automation (schema fuzzer, injection tester) |
read_file.index=mcp server.tool="read_file" | where match(params.path, "\.\./\.\./")filesystem, git); inherit trust.ECC Loop Pattern: Sequential Pipeline
Rationale: MCP server development follows a strict build-test-secure-deploy sequence. Each phase gates the next: schema design must precede implementation, implementation must precede security testing, security testing must pass before deployment. Skipping phases or running them in parallel introduces unvetted code into production.
Integration:
terminal-ops (MCP server enables structured tool execution replacing ad-hoc shell commands), autonomous-loops (MCP tools called within agent autonomy loops), multi-agent-collaboration (shared MCP server exposes tools across multiple agent sessions)security-review (audit the MCP server implementation itself before deployment), verification-loop (confirm tool outputs are correct and reproducible)Cross-Skill Pipeline:
[Identify security tools to wrap]
↓
mcp-server-patterns → [Design tool schemas + input validation rules]
↓
mcp-server-patterns → [Implement server: handlers, auth, rate limiting]
↓
security-review → [Audit the MCP server implementation itself]
↓
verification-loop → [Confirm tool outputs are correct and consistent]
↓
[Deploy + integrate with agent workflows]
Quality Gate: Before deploying any MCP server:
shell=True in any subprocess call — verified by grep基于 SOC 职业分类