Skip to main content
Glama
passive-subdomain-mcp

passive-subdomain-mcp

by N-Next
README.md
# passive-subdomain-mcp

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/)

免 Key、零目标触碰的被动子域名收集 MCP Server。  
把 13 个免费公开数据源(证书透明度、被动 DNS、网页存档、情报聚合)打包成一个极简 stdio MCP 服务,让 AI Agent 在授权侦察的第一步就能直接拿到干净的子域名和来源账本。

### 为什么做这个工具(核心优势)

- **真免 Key,开箱即用**:不依赖 FOFA / Shodan / VirusTotal / GitHub Token,装好就能直接给 Claude Desktop、Cursor、Antigravity、Codex 调用。
- **零目标触碰(严格被动)**:所有请求都是发往第三方数据集的 HTTPS GET——**不解析目标 DNS、不扫端口、不发包探测目标 Web**,适合前期纯情报梳理。
- **极简单依赖,不拉全家桶**:运行时只依赖 `httpx`,连官方 `mcp` SDK 都不强制拉取(标准库 ~200 行实现完整 MCP stdio JSON-RPC 2.0),也不需要 MongoDB / Redis。
- **失败不装瞎,单源不连坐**:大多数脚本遇到某个免费源 503 或超时就直接跳过或当成“没子域名”。这里把 `success` / `empty` / `failed` / `skipped` 分开记账;某个源连续挂掉只熔断它自己,后面还活着的源照常跑。
- **不被本机代理坑**:默认 `trust_env=False` 直连,防止本地代理变量把不通或超时返回成假状态;需要走代理时通过 `PASSIVE_SUBDOMAIN_MCP_TRUST_ENV=1` 显式打开。
- **每条结果可溯源**:返回去重后的 `subdomains` 的同时,附带 `provenance`(每个子域名具体是从哪几个源捞出来的)和各源耗时/状态明细。

---

## 中文说明

### 功能

| 工具 | 作用 |
| --- | --- |
| `passive_subdomain_list_sources()` | 列出全部 13 个免 Key 源、默认超时、权重与端点(不联网)。 |
| `passive_subdomain_collect(domain, sources?, timeout_s?, interval_s?, limit?)` | 对根域执行被动子域收集,返回 `{domain, subdomains, count, total_found, truncated, sources_status, provenance}`。 |

### 13 个免 Key 数据源

| 源 | 类型 | 默认超时 | 权重 | 端点(示意) |
| --- | --- | --- | --- | --- |
| `crtsh` | 证书透明度 | 20s | 3 | `crt.sh/?q=%.{domain}&output=json` |
| `certspotter` | 证书透明度 | 20s | 3 | `api.certspotter.com/v1/issuances` |
| `anubis` | 被动子域 API | 15s | 2 | `anubisdb.com/anubis/subdomains/{domain}` |
| `hackertarget` | Hostsearch CSV | 20s | 2 | `api.hackertarget.com/hostsearch/` |
| `rapiddns` | 被动 DNS 页面 | 20s | 2 | `rapiddns.io/subdomain/{domain}` |
| `robtex` | 被动 DNS(NDJSON) | 20s | 2 | `freeapi.robtex.com/pdns/forward/{domain}` |
| `otx` | AlienVault OTX | 20s | 2 | `otx.alienvault.com/.../passive_dns` |
| `urlscan` | urlscan.io 搜索 | 20s | 2 | `urlscan.io/api/v1/search/` |
| `wayback` | Wayback CDX | 20s | 1 | `web.archive.org/cdx/search/cdx` |
| `commoncrawl` | CommonCrawl 索引 | 20s | 1 | `index.commoncrawl.org` |
| `subdomaincenter` | 免费子域 API | 15s | 2 | `api.subdomain.center/?domain={domain}` |
| `myssl` | MySSL 证书/子域 | 20s | 2 | `myssl.com/api/v1/discover_sub_domain` |
| `hudsonrock` | 情报 URL 聚合 | 20s | 2 | `cavalier.hudsonrock.com/api/json/v2/...` |

> 权重只是置信度提示(证书类 > 被动 DNS > 网页抓取),不会丢弃低权重结果。
> 单源超时硬上限 20 秒;`timeout_s` 可覆盖但同样被限制在 1–20 秒。

### 安装

```bash
# 推荐:隔离安装并得到 console script
pipx install .

# 或 uv
uv tool install .

# 或开发模式
python -m venv .venv && .venv/bin/pip install -e .
```

不安装也可直接从源码运行(仅需当前环境有 `httpx`):

```bash
PYTHONPATH=src python -m passive_subdomain_mcp
```

### 客户端配置

无参数启动即为 MCP stdio 服务器。以下四种客户端都使用同样方式的
`command + args`;若已 `pipx install`,可把 `command` 直接写成
`passive-subdomain-mcp` 并省略 `args`。

**Claude Desktop** — `claude_desktop_config.json`
(macOS:`~/Library/Application Support/Claude/`,Windows:`%APPDATA%\Claude\`):

```json
{
  "mcpServers": {
    "passive-subdomain": {
      "command": "python",
      "args": ["-m", "passive_subdomain_mcp"]
    }
  }
}
```

**Cursor** — 项目内 `.cursor/mcp.json` 或全局 `~/.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "passive-subdomain": {
      "command": "passive-subdomain-mcp"
    }
  }
}
```

**Antigravity** — `~/.gemini/antigravity/mcp_config.json`:

```json
{
  "mcpServers": {
    "passive-subdomain": {
      "command": "python",
      "args": ["-m", "passive_subdomain_mcp"]
    }
  }
}
```

**Codex** — `~/.codex/config.toml`:

```toml
[mcp_servers.passive_subdomain]
command = "python"
args = ["-m", "passive_subdomain_mcp"]
```

> 若 `python` 不在客户端的环境变量 `PATH` 中,请填绝对路径
> (如 `"/Users/me/.local/share/pipx/venvs/passive-subdomain-mcp/bin/python"`)。
> 修改配置后重启客户端;首次调用前请确认客户端已信任该 MCP server。

### 命令行用法

```bash
# 列出 13 个源
passive-subdomain-mcp --list-sources

# 单次收集(人读)
passive-subdomain-mcp --domain example.com --sources crtsh,wayback,otx --limit 200

# 只测某个源、缩短超时、关闭限速间隔(快速排障)
passive-subdomain-mcp --domain example.com --sources crtsh --timeout-s 10 --interval-s 0

# 显式走系统代理(默认直连)
PASSIVE_SUBDOMAIN_MCP_TRUST_ENV=1 passive-subdomain-mcp --domain example.com
```

### 返回结构

```json
{
  "domain": "example.com",
  "subdomains": ["api.example.com", "www.example.com"],
  "count": 2,
  "total_found": 2,
  "truncated": false,
  "sources_status": [
    {"source": "crtsh", "status": "success", "reason": "", "count": 2,
     "timeout_s": 20, "duration_ms": 812},
    {"source": "wayback", "status": "failed", "reason": "http 503", "count": 0,
     "timeout_s": 20, "duration_ms": 190}
  ],
  "provenance": {
    "api.example.com": ["crtsh"],
    "www.example.com": ["crtsh", "wayback"]
  }
}
```

- `status`:`success` / `empty` / `failed` / `skipped`(该源自己的熔断已打开)。
- `failed` 一定代表请求层失败,**不会**被伪装成 `empty`。
- `provenance` 是「子域 → 命中它的源」多源合并结果。
- 只保留查询根域及其子域(后缀匹配,杜绝越界污染);`limit` 默认 1000,
  `0` 表示不截断,截断时 `truncated=true` 且 `total_found` 保留真实总数。

### 安全与合规声明

- 本工具**只做第三方被动查询**:CT 日志、被动 DNS、网页存档/索引。
- **绝不**对目标域做主动 DNS 解析、端口扫描、路径爆破或 Web 探测。
- 不做任何写操作,不创建项目/任务,不需要也不接受任何 API Key。
- 被动数据可能过期、缺失或含误报;结果需结合授权范围人工复核。
- 请仅对你**已获授权**的资产使用;使用者需自行遵守当地法律与第三方站点条款。

### 开发与测试

```bash
cd standalone/passive-subdomain-mcp
python -m pytest -q
```

测试覆盖:13 源解析、404/5xx → `failed`、成功空结果 → `empty`、前 3 源失败第 4
源照常执行、逐源熔断不连坐、域名归一化/去重/scope 过滤、`trust_env=False`、
MCP `initialize` / `tools/list` / `tools/call` 的真实 stdio 子进程往返,以及
「零主仓库依赖」的导入/路径扫描。

---

## English

### What it is

A standalone MCP stdio server that exposes 13 **key-free** passive subdomain
sources. It speaks JSON-RPC 2.0 over newline-delimited stdio using only the
Python standard library, and depends on `httpx` at runtime — no `mcp` SDK, no
database, no broker, no code from any other project.

### Tools

- `passive_subdomain_list_sources()` — catalogue of the 13 sources (offline).
- `passive_subdomain_collect(domain, sources?, timeout_s?, interval_s?, limit?)`
  — returns `{domain, subdomains, count, total_found, truncated,
  sources_status, provenance}`.

### Sources

`crtsh`, `certspotter`, `anubis`, `hackertarget`, `rapiddns`, `robtex`, `otx`,
`urlscan`, `wayback`, `commoncrawl`, `subdomaincenter`, `myssl`, `hudsonrock` — all HTTPS GET against
third-party datasets, each with its own timeout (1–20 s), rate-limit slot and
per-source circuit breaker.

### Install & configure

```bash
pipx install .          # or: uv tool install .
```

MCP client entries (`mcpServers` for Claude Desktop / Cursor / Antigravity,
`mcp_servers` in `~/.codex/config.toml` for Codex):

```json
{
  "mcpServers": {
    "passive-subdomain": {
      "command": "python",
      "args": ["-m", "passive_subdomain_mcp"]
    }
  }
}
```

```toml
# ~/.codex/config.toml
[mcp_servers.passive_subdomain]
command = "python"
args = ["-m", "passive_subdomain_mcp"]
```

Run from a checkout without installing:

```bash
PYTHONPATH=src python -m passive_subdomain_mcp
```

One-shot CLI:

```bash
passive-subdomain-mcp --list-sources
passive-subdomain-mcp --domain example.com --sources crtsh,wayback --limit 200
```

### Failure semantics

- `failed` — network error, non-200 response, or malformed provider payload.
- `empty` — the provider answered successfully with zero hostnames.
- `skipped` — that source's own consecutive-failure breaker is open; other
  sources keep running.
- A source is never retried inside one run, and failures are never silently
  converted into `empty`.

### Network policy

Requests use `trust_env=False` by default, so host `HTTP(S)_PROXY` /
`NO_PROXY` settings cannot reroute traffic. Opt in explicitly with
`PASSIVE_SUBDOMAIN_MCP_TRUST_ENV=1` or `--trust-env`.

### Safety

Passive, third-party data only. No DNS resolution, port scanning, path
brute-forcing, or web probing against the queried domain. Use only against
assets you are authorized to investigate. Results may be stale or contain false
positives and should be reviewed by a human.

### Development

```bash
cd standalone/passive-subdomain-mcp
python -m pytest -q
```

### License

MIT — see [LICENSE](LICENSE).

TDQS

A3.8/5.0

Scored across 2 tools

Disambiguation5/5

The two tools are clearly distinct: one is a zero-network metadata/introspection call listing built-in sources, the other performs the actual collection run. An agent can trivially tell which to call first and which to call to get data.

Naming Consistency5/5

Both names use the same `passive_subdomain_` namespace prefix followed by a clear verb/noun (`list_sources`, `collect`). The pattern is predictable and would scale cleanly if more tools were added.

Tool Count3/5

Two tools is thin even for a narrowly scoped passive-recon server; the source-listing tool is essentially documentation surfaced as a tool. It works, but a config/selection tool would make the surface feel less minimal.

Completeness4/5

The core lifecycle for passive collection is covered: inspect available sources, then run collection with per-source status and provenance. Minor gaps remain — no way to select a subset of sources, override timeouts/weights, or re-run/diff against prior results.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues