xFreed0m/ghosttype
GitHub: xFreed0m/ghosttype
从 Cursor、ChatGPT、Claude Code 等 AI 编码助手的本地对话存储中自动化提取泄露凭证的 Python 取证扫描工具。
Stars: 49 | Forks: 4
# ghosttype
本地取证扫描器,用于从 AI 工具的对话历史中提取凭证和敏感信息。
## 功能介绍
ghosttype 会扫描 AI 工具的对话文件,查找其中暴露的凭证和机密信息,然后生成一份报告,将每项发现与其源对话文件关联起来。
**支持的 AI 工具:**
| 工具 | 数据来源 |
|------|------------|
| Claude Code CLI | `~/.claude/projects/**/*.jsonl` + history |
| Cursor IDE | `state.vscdb` (SQLite,全局 + 工作区) |
| Codex CLI | `~/.codex/state_5.sqlite` + 日志 |
| ChatGPT Desktop | Keychain 支持的 `.data` 文件 (AES-128-CBC) |
| Claude Desktop | 桩模块 (已检测到路径;提取功能开发中) |
**检测到的凭证类型 (40+ 种模式):**
AWS 访问/密钥、OpenAI token、Anthropic API 密钥、GitHub PAT (6 种格式)、Stripe 密钥、Slack token、HashiCorp Vault token、Linear、Databricks、npm、Telegram、Hugging Face、DigitalOcean、Docker Hub、Pulumi、Doppler、PyPI、SendGrid、GCP 服务账号/API 密钥、JWT token、PEM 私钥、数据库连接字符串,以及更多——外加 10 种启发式上下文信号模式 (API 密钥赋值、密码、JWT 密钥、Azure 凭证、Supabase 密钥等)。
## 快速开始
```
git clone https://github.com/xFreed0m/ghosttype
cd ghosttype
python3 -m venv .venv && source .venv/bin/activate
pip install -e .
# 扫描所有检测到的 AI tools
ghosttype scan
# 仅限高置信度发现(无启发式噪音)
ghosttype scan --min-confidence high
# 通过管道传递至 jq 进行过滤
ghosttype scan --format json --output - --quiet | jq '.[] | select(.severity == "critical")'
# 显示此机器上检测到哪些工具
ghosttype list-tools
```
**环境要求:** Python 3.11+,macOS (Linux/Windows:需更新扫描器中的路径)
## 输出
默认输出:`./ghosttype_report/findings.json` + `findings.csv`
每项发现包含:
| 字段 | 描述 |
|-------|-------------|
| `tool` | 源 AI 工具 |
| `secret_type` | 凭证类别 (例如 `aws_access_key`) |
| `severity` | `critical` / `high` / `medium` |
| `secret_value` | 明文值 (使用 `--redact` 进行掩码处理) |
| `file_path` | 源对话文件 |
| `confidence` | `high` (正则表达式匹配) 或 `medium` (启发式匹配) |
| `context` | 匹配项周围 200 个字符的上下文窗口 |
## 所有选项
```
ghosttype scan [OPTIONS]
--tool TEXT Scan one tool: cursor, chatgpt, codex, claude, claude_code
--format [json|csv|both] Output format (default: both)
--output TEXT Output dir, or - for stdout JSON (default: ./ghosttype_report)
--redact Mask secret values in output
--min-confidence Filter: high or medium (default: medium)
--max-age-days N Only scan files modified within last N days
--copy-sources Copy source conversation files to output/sources/
--allow-list PATH Suppress known-safe values (one value per line)
--stats-only Print summary statistics only
--quiet / -q Suppress banner for scripting
--context-window N Context chars around match (default: 200)
ghosttype list-tools Show detected AI tools on this machine
ghosttype version Print version
```
## 检测设计
带有误报 (FP) 消除机制的双层引擎:
1. **正则表达式 (高置信度)** — 针对已知凭证精确结构的 30 种匹配模式
2. **启发式 (中等置信度)** — 使用变量名上下文信号 (`API_KEY=`、`JWT_SECRET=` 等) 的 10 种匹配模式
误报消除:信息熵阈值 (≥3.0 比特/字符)、占位符/示例值过滤器、已知文档示例排除列表。
## 项目文档
- [ARCHITECTURE.md](ARCHITECTURE.md) — 模块设计、数据流、模式引擎
- [RESEARCH.md](RESEARCH.md) — 各工具的存储位置研究结果 (已在 macOS 15.x 上验证)
- [DECISIONS.md](DECISIONS.md) — 关键技术决策及其依据
- [ROADMAP.md](ROADMAP.md) — 计划开发的工作
- [THREAT-MODEL.md](THREAT-MODEL.md) — 预期用例及超出范围的使用情况
标签:AI对话历史提取, Anthropic API密钥, API密钥扫描, AWS凭证, ChatGPT Desktop, Claude Code CLI, Claude Desktop, Codex CLI, Cursor IDE, DevSecOps, DLP(数据防泄漏), GitHub PAT, HTTP工具, macOS安全, Mistral, OpenAI密钥, Python安全工具, StruQ, 上游代理, 凭证提取, 启发式扫描, 安全助手, 提示注入防御, 数字取证, 数据泄露, 本地取证扫描器, 本地安全, 源代码安全, 秘密检测, 端点安全, 网络安全审计, 自动化脚本, 补丁管理, 逆向工具