# FofaMap MCP server (v2.0.0) — tool reference
## Global notes from server code
- `FastMCP("Fofamap-Platinum-Full-Expert")` defines the MCP app name.
- Logging/print is redirected to stderr via a “MCP 协议防污染补丁” (prints forced to `sys.stderr`).
- `generate_nuclei_command` explicitly **generates only** commands; it does **not execute** scans inside MCP.
---
## Tool 1: `search_assets`
**Signature**: `search_assets(query: str, fields: str = None, pages: int = 1, full: bool = False, display_rows: int = 25)`
**Purpose**: Execute a FOFA query and return a Markdown table.
**Parameters**
- `query` (required): FOFA query syntax (examples shown in docstring):
- `(app="xxx" || app="yyy") && country="CN"`
- `app="ThinkPHP" && country="CN"`
- `fields` (optional): comma-separated FOFA fields to return.
- If not set, server selects defaults based on login VIP level.
- To include cert/body/fid/icon_hash etc., explicitly add those fields (examples: `"host,ip,cert,body"`).
- `pages` (default `1`): query page count.
- `full` (default `False`): whether to search historical data.
- `display_rows` (default `25`): max rows displayed in returned Markdown table.
- If user asks for more, can be increased, but not “too high” to avoid output limits.
**Default field selection logic (server-side)**
- Base defaults always include:
- `"host", "ip", "port", "protocol", "title", "server", "domain", "country_name"`
- Additional defaults added when `vip_level >= 12` OR `vip_level == 2` OR `vip_level == 5`:
- `"product", "lastupdatetime"`
**Returns (string)**
- On exception: `❌ FOFA 请求异常: {error}`
- If no results: `🔍 未发现资产,实际查询字段: `{effective_fields}``
- Otherwise: `### 🔍 FOFA 检索结果: `{query}`\n` + Markdown table
- Table headers are derived from `target_fields` and each header is truncated to 10 chars (`h[:10]`).
- Each cell is cleaned: newline to space and `|` escaped; long cells truncated (over 50 chars -> keep first 47 + `...`).
**FOFA syntax gotchas (as stated in docstring)**
- Geographic values must use pinyin (server warns):
- ❌ `city="上海"`
- ✅ `city="Shanghai"`, `region="Zhejiang"`
---
## Tool 2: `get_host_aggregation`
**Signature**: `get_host_aggregation(host: str)`
**Purpose**: Get a single target (IP/domain) “aggregation/portrait”, including open ports and products.
**Parameters**
- `host` (required): an IP or domain.
**Returns (string)**
- On exception: `❌ 查询异常: {e}`
- If data missing or `data.get('error')`: `❌ 查询失败: {data.get('errmsg', '目标不存在')}`
- Otherwise:
- Header section including:
- `data.get('host', host)`
- `- **基本信息**: `{data.get('ip')}` | {data.get('country_name')} | {data.get('org')}`
- `- **ASN**: {data.get('asn')} | **更新时间**: {data.get('update_time')}`
- If ports exist:
- Ports are sorted by `port`.
- A table `Port | Protocol | Products` where `Products` is `", ".join([x.get('product','') for x in p.get('products', [])])`.
---
## Tool 3: `get_stats_aggregation`
**Signature**: `get_stats_aggregation(query: str, fields: str = "country,title,org")`
**Purpose**: Perform a FOFA stats aggregation and return Top-N tables.
**Parameters**
- `query` (required): FOFA query for stats aggregation.
- `fields` (optional): must be one of the fields listed below.
- Supported fields (as stated):
- `protocol`, `domain`, `port`, `title`, `os`, `server`, `country`, `asn`, `org`, `asset_type`, `fid`, `icp`
**Returns (string)**
- If exception: `❌ 统计异常: {e}`
- If no data: `⚠️ 无统计数据。`
- Otherwise:
- `### 📊 资产统计分布 (总量: {data.get('size', 0)})\n`
- For each aggregated field with items:
- `#### 🏆 {field.upper()} Top 10`
- table `名称 | 数量` using `i.get('name')` and `i.get('count')`.
---
## Tool 4: `calculate_icon_hash`
**Signature**: `calculate_icon_hash(url: str)`
**Purpose**: Extract favicon from the target website and compute `icon_hash`.
**Parameters**
- `url` (required): website URL.
**Returns (string)**
- On success: `✅ 计算成功!\n请使用: `{hash_query}``
- If favicon fetch fails: `❌ 获取 favicon 失败。`
- On exception: `❌ 异常: {e}`
---
## Tool 5: `ai_security_consultant`
**Signature**: `ai_security_consultant(user_intent: str)`
**Purpose**: Produce an AI tactical plan (query suggestions, routing, and whether to run nuclei).
**Parameters**
- `user_intent` (required): user’s intent (free text).
**Returns (string)**
- If AI plan fails: `⚠️ AI 思考失败。`
- Otherwise a formatted block:
- `### 🧠 AI 专家战术规划`
- `- **推荐查询语句**: `{plan.get('queries')}``
- `- **动作路由**: `{plan.get('action')}``
- `- **扫描决策**: ✅ 建议开启` if `plan.get('run_nuclei')` else `❌ 不建议执行`
**Stated AI decision logic (docstring highlights)**
- “拼音优先”: converts Chinese locations (e.g., “上海”) to pinyin (e.g., `Shanghai`).
- “权限感知”: strictly limits fields based on VIP level.
- Lists example categories of fields it might choose, including high-risk fields such as:
- `body`, `icon_hash`, `fid`, `icon`, `structinfo`
---
## Tool 6: `check_assets_alive`
**Signature**: `check_assets_alive(hosts: list[str])`
**Purpose**: HTTP/HTTPS liveness check.
**Parameters**
- `hosts` (required list): list of host URLs/targets to check.
**Hard-coded behavior in docstring/code**
- Uses `FastChecker.check_alive(hosts, timeout=5)`.
**Returns (string)**
- On exception: `❌ 检测异常: {e}`
- Otherwise:
- `### 🟢 存活资产 ({len(alive_data)}/{len(hosts)})\n`
- table headers: `URL | 状态码`
- Includes entries where status code is digit (`str(code).isdigit()`).
---
## Tool 7: `generate_nuclei_command`
**Signature**: `generate_nuclei_command(targets: list[str], severity: str = "medium,high,critical")`
**Purpose**: Generate a Nuclei command string and a `targets.txt` payload. **Does not execute scans**.
**Parameters**
- `targets` (required list[str]): targets to be written into `targets.txt`.
- `severity` (optional): defaults to `"medium,high,critical"`.
**Returns (string)**
- If `targets` empty: `❌ 目标列表为空。`
- Otherwise:
- Shows `targets.txt 内容` in a code block.
- Provides a bash snippet:
- `cat > targets.txt << 'EOF'`
- then each target line
- then scan command using variables:
- `nuclei -l targets.txt -severity {severity} -stats -o result.txt`
**Docstring decision rules (used to craft recommendations)**
- Technical stack identification based on Title/Server/Header/Port.
- For specific vulnerabilities (example: “Log4j”), recommends including tags or `-id CVE-2021-44228`.
- For broad probing, recommends `-as` and `-severity critical,high` (though the returned command shown in code is: it only includes `-severity`, `-stats`, `-o`, and `-l targets.txt`).
- For target count tuning:
- fewer important targets: add `-bs 25 -rl 150`
- many mixed targets: add `-tags cves,misconfig`
(Warning: The returned command in this version does not visibly incorporate those extra tuning flags; it only uses `-severity {severity} -stats -o result.txt`.)
FOFA scan workflow (prepare vulnerability/PoC commands)
Description
Creates an agentic workflow that searches FOFA for exposed assets, aggregates and verifies liveness, identifies likely technology via metadata/icon hashes, then prepares vulnerability scanning commands (e.g., Nuclei command-only) and guides exploit-Picture hunting. Use when user asks to scan FOFA, enumerate FOFA assets, find vulnerable targets, or generate nuclei commands. Trigger on: "fofa scan", "scan fofo", "fofa-scan", "search_assets", "FOFA query", "enumerate FOFA", "find vulnerable", "prepare nuclei command", "generate nuclei command", "nuclei command only", "icon hash", "calculate_icon_hash", "check assets alive", "liveness check", "exploit pics". Never trigger if user asks to actually exploit systems or run exploit payloads; require explicit consent for any exploitation step.
When to Use
When the user explicitly asks for an agent workflow to scan FOFA, find vulnerable targets, or generate Nuclei commands (command-only) and exploit-picture leads.
Use Cases
1) Enumerate FOFA-exposed hosts for a given product/tech stack and verify which are alive. 2) Prepare command-only Nuclei scans to assess common vulnerabilities. 3) Use icon hash and metadata to guide exploit research ("exploit pics") without executing exploits.
Bundle Explorer
2 files across 1 folder. Click a file to inspect its contents.
---
name: fofa-scan
description: "Creates an agentic workflow that searches FOFA for exposed assets, aggregates and verifies liveness, identifies likely technology via metadata/icon hashes, then prepares vulnerability scanning commands (e.g., Nuclei command-only) and guides exploit-Picture hunting. Use when user asks to scan FOFA, enumerate FOFA assets, find vulnerable targets, or generate nuclei commands. Trigger on: \"fofa scan\", \"scan fofo\", \"fofa-scan\", \"search_assets\", \"FOFA query\", \"enumerate FOFA\", \"find vulnerable\", \"prepare nuclei command\", \"generate nuclei command\", \"nuclei command only\", \"icon hash\", \"calculate_icon_hash\", \"check assets alive\", \"liveness check\", \"exploit pics\". Never trigger if user asks to actually exploit systems or run exploit payloads; require explicit consent for any exploitation step."
---
FOFA scan + prepare vulnerability scanning and exploit-picture leads (command-only)
Workflow
1) Collect scan intent and scope
- Extract: country/org keywords, product/app names, tech names (e.g., ThinkPHP), ports/services, and desired volume (pages). If missing, ask the user for: FOFA query intent + country/region + approximate pages (default 1).
- Determine whether the user wants only preparation (default) vs any active exploitation (default: no).
2) Generate FOFA query
- Use the user’s keywords to build a FOFA query string.
- Enforce pinyin for locations in the query (e.g., Shanghai not 上海). If user provides Chinese locations, convert to pinyin.
3) Execute FOFA asset search
- Call `search_assets(query, fields, pages, full=false)`.
- Set `fields` to include: "host,ip,port,protocol,title,server,domain,country_name" plus risk-enabling fields only when appropriate: include "body,cert,fid,icon_hash" if the user asks for tech fingerprinting or exploit-picture hunting.
- If results are empty or an error string is returned, stop and ask for a narrower/broader query.
4) Aggregate likely candidates
- From returned rows, select up to 10 unique hosts/targets (prefer those with explicit server/product/title matches to the intent).
- For each selected target, call `get_host_aggregation(host)` and record: host, open ports/products.
5) Liveness check
- Call `check_assets_alive(hosts)` with URLs/targets derived from protocol/port if available; otherwise use host.
- Keep only alive entries.
6) Fingerprint via icon hash when URL is available
- For each alive web target with a usable URL/hostname, call `calculate_icon_hash(url)` to get an `icon_hash`-query suggestion.
- Use the suggestion to refine targeting or to guide which exploit-pic/tech family to look for.
- Read [references/mcp-fofamap-tools.md](references/mcp-fofamap-tools.md) when selecting which tool parameters/fields are supported.
7) AI tactical planning (decision + query suggestions)
- Call `ai_security_consultant(user_intent)` using the user’s original request + your current candidate list summary.
- Follow its “扫描决策”: only proceed with command generation steps when it indicates scanning is recommended.
8) Prepare vulnerability scanning commands (DO NOT EXECUTE)
- Call `generate_nuclei_command(targets, severity)` where `targets` are the alive hosts (and optionally specific ports) and `severity` defaults to "medium,high,critical".
- Return the generated command text and the `targets.txt` contents/location as provided by the tool output.
- Read [references/mcp-fofamap-tools.md](references/mcp-fofamap-tools.md) when confirming that this tool generates commands only.
9) Exploit-picture hunting guidance (no exploitation)
- Create a shortlist of “likely tech families” from: server/title/products, plus icon_hash hints, plus any available `body`/`fid` metadata.
- Ask the user what exploit confirmation level they want, and require explicit consent before any exploitation attempt.
Exploitation consent rule (hard requirement)
- Never execute exploits without consent.
- If the user asks to exploit: ask for explicit confirmation (what targets, what payload type, and confirmation that exploitation is allowed). If not provided, only provide preparation (scan commands, verification steps, and exploit research leads).
Outputs
- Always output:
a) The FOFA query used
b) Candidate list (hosts/ports/products) and which are alive
c) The generated Nuclei command(s) (command-only)
d) Exploit-picture lead shortlist (tech-family hypotheses + why)
Example I/O
- Input: "fofa scan ThinkPHP CN, find vulnerable, prepare nuclei command"
Output: FOFA query built → top candidates aggregated → alive checked → nuclei command generated (command-only) → exploit-pic tech shortlist for ThinkPHP.
- Input: "exploit pic and run exploit against 1.2.3.4 now"
Output: request explicit consent; if not granted, refuse exploitation and provide only scanning/verification commands.
Constraints / edge cases
- If user requests more than safe output volume, cap pages/default display_rows via tool behavior (prefer pages=1 unless asked).
- If FOFA location is provided in Chinese characters, convert to pinyin in the query.
- If the user requests execution of exploits or vulnerability scans, clarify that the skill only prepares commands and that exploits require explicit consent.
SKILL.md Content
---
name: fofa-scan
description: "Creates an agentic workflow that searches FOFA for exposed assets, aggregates and verifies liveness, identifies likely technology via metadata/icon hashes, then prepares vulnerability scanning commands (e.g., Nuclei command-only) and guides exploit-Picture hunting. Use when user asks to scan FOFA, enumerate FOFA assets, find vulnerable targets, or generate nuclei commands. Trigger on: \"fofa scan\", \"scan fofo\", \"fofa-scan\", \"search_assets\", \"FOFA query\", \"enumerate FOFA\", \"find vulnerable\", \"prepare nuclei command\", \"generate nuclei command\", \"nuclei command only\", \"icon hash\", \"calculate_icon_hash\", \"check assets alive\", \"liveness check\", \"exploit pics\". Never trigger if user asks to actually exploit systems or run exploit payloads; require explicit consent for any exploitation step."
---
FOFA scan + prepare vulnerability scanning and exploit-picture leads (command-only)
Workflow
1) Collect scan intent and scope
- Extract: country/org keywords, product/app names, tech names (e.g., ThinkPHP), ports/services, and desired volume (pages). If missing, ask the user for: FOFA query intent + country/region + approximate pages (default 1).
- Determine whether the user wants only preparation (default) vs any active exploitation (default: no).
2) Generate FOFA query
- Use the user’s keywords to build a FOFA query string.
- Enforce pinyin for locations in the query (e.g., Shanghai not 上海). If user provides Chinese locations, convert to pinyin.
3) Execute FOFA asset search
- Call `search_assets(query, fields, pages, full=false)`.
- Set `fields` to include: "host,ip,port,protocol,title,server,domain,country_name" plus risk-enabling fields only when appropriate: include "body,cert,fid,icon_hash" if the user asks for tech fingerprinting or exploit-picture hunting.
- If results are empty or an error string is returned, stop and ask for a narrower/broader query.
4) Aggregate likely candidates
- From returned rows, select up to 10 unique hosts/targets (prefer those with explicit server/product/title matches to the intent).
- For each selected target, call `get_host_aggregation(host)` and record: host, open ports/products.
5) Liveness check
- Call `check_assets_alive(hosts)` with URLs/targets derived from protocol/port if available; otherwise use host.
- Keep only alive entries.
6) Fingerprint via icon hash when URL is available
- For each alive web target with a usable URL/hostname, call `calculate_icon_hash(url)` to get an `icon_hash`-query suggestion.
- Use the suggestion to refine targeting or to guide which exploit-pic/tech family to look for.
- Read [references/mcp-fofamap-tools.md](references/mcp-fofamap-tools.md) when selecting which tool parameters/fields are supported.
7) AI tactical planning (decision + query suggestions)
- Call `ai_security_consultant(user_intent)` using the user’s original request + your current candidate list summary.
- Follow its “扫描决策”: only proceed with command generation steps when it indicates scanning is recommended.
8) Prepare vulnerability scanning commands (DO NOT EXECUTE)
- Call `generate_nuclei_command(targets, severity)` where `targets` are the alive hosts (and optionally specific ports) and `severity` defaults to "medium,high,critical".
- Return the generated command text and the `targets.txt` contents/location as provided by the tool output.
- Read [references/mcp-fofamap-tools.md](references/mcp-fofamap-tools.md) when confirming that this tool generates commands only.
9) Exploit-picture hunting guidance (no exploitation)
- Create a shortlist of “likely tech families” from: server/title/products, plus icon_hash hints, plus any available `body`/`fid` metadata.
- Ask the user what exploit confirmation level they want, and require explicit consent before any exploitation attempt.
Exploitation consent rule (hard requirement)
- Never execute exploits without consent.
- If the user asks to exploit: ask for explicit confirmation (what targets, what payload type, and confirmation that exploitation is allowed). If not provided, only provide preparation (scan commands, verification steps, and exploit research leads).
Outputs
- Always output:
a) The FOFA query used
b) Candidate list (hosts/ports/products) and which are alive
c) The generated Nuclei command(s) (command-only)
d) Exploit-picture lead shortlist (tech-family hypotheses + why)
Example I/O
- Input: "fofa scan ThinkPHP CN, find vulnerable, prepare nuclei command"
Output: FOFA query built → top candidates aggregated → alive checked → nuclei command generated (command-only) → exploit-pic tech shortlist for ThinkPHP.
- Input: "exploit pic and run exploit against 1.2.3.4 now"
Output: request explicit consent; if not granted, refuse exploitation and provide only scanning/verification commands.
Constraints / edge cases
- If user requests more than safe output volume, cap pages/default display_rows via tool behavior (prefer pages=1 unless asked).
- If FOFA location is provided in Chinese characters, convert to pinyin in the query.
- If the user requests execution of exploits or vulnerability scans, clarify that the skill only prepares commands and that exploits require explicit consent.