Gleaming0427/cve-agent

GitHub: Gleaming0427/cve-agent

一个结合 AST 可达性分析与 Mistral AI 分类的开源漏洞扫描工具,用于精准识别代码中真正可利用的 CVE 并生成上下文修复建议。

Stars: 0 | Forks: 1

# 🔍 CVE Agent

Python 3.12 AGPL-3.0 CI tests 8/8 phases

## 为什么开发此项目 **Snyk、Dependabot 和 Trivy** 都在回答同一个问题:*“此依赖项存在已知的 CVE。”* **CVE Agent** 则会回答那些真正重要的问题:*“这个 CVE 在我的代码中可达吗?在我的上下文中重要吗?我该如何处理?”* 它的三个与众不同之处: 1. **可达性分析** — 解析你的 AST,检查易受攻击的函数是否被导入、调用,或通过 HTTP 路由暴露 2. **AI 驱动的分类** — Mistral 会过滤误报,并根据你的项目上下文用通俗易懂的语言解释每个发现 3. **欧盟数据主权** — 100% 使用 Mistral(法国 AI)。你的源代码永远不会离开你的机器。只有 CVE 元数据会被发送到 Mistral API。 ## 快速开始 ``` # 1. 克隆和安装 git clone https://github.com/Gleaming0427/cve-agent.git cd cve-agent uv sync # 2. 启动 Qdrant(向量数据库) docker compose up -d # 3. 交互式设置(API keys、数据库) uv run cve-agent init # 4. 填充 CVE 数据库(约 30 分钟,250K+ CVEs) uv run cve-agent ingest bootstrap # 5. 扫描 repository uv run cve-agent scan ./my-project -o report.md open report.md ``` 你会得到一份 **markdown 报告**,其中包含每个 CVE、其基于上下文的严重程度、通俗易懂的英文解释,以及用于修复它的精确命令。 ## 工作原理 ``` Git repo → Syft (SBOM) → CVE Matcher → Reachability (AST) → AI Triage → AI Analyze → AI Patch → Report ``` | 步骤 | 发生了什么 | 技术 | |---|---|---| | **1. SBOM** | 生成 CycloneDX 物料清单 | [Syft](https://github.com/anchore/syft) | | **2. 匹配** | 将每个包与已知的 CVE 进行匹配(精确 + 语义匹配) | SQLite + Qdrant | | **3. 可达性** | 检查易受攻击的函数是否被导入、调用,或通过 HTTP 暴露 | tree-sitter + Python AST | | **4. 分类** | AI 过滤误报 | Mistral Small | | **5. 分析** | AI 解释每个发现并分配基于上下文的严重程度 | Codestral | | **6. 修补** | AI 为你的生态系统生成精确的修复命令 | Codestral | | **7. 报告** | 将所有内容汇编成一份简洁的 markdown 报告 | 纯 Python | ### 可达性标签 基于 AST 分析,每个发现都会获得以下标签之一: | 标签 | 含义 | 风险 | |---|---|---| | `not_imported` | 包在 SBOM 中,但未在代码中导入 | 低 | | `imported_not_called` | 包已被导入,但其易受攻击的函数从未被调用 | 中 | | `called` | 易受攻击的函数在代码中的某处被实际调用 | 高 | | `called_from_entry_point` | 从 HTTP 路由处理器或 Lambda 入口点调用 | **严重** | ## CLI ``` # 首次设置 cve-agent init # 管理 API keys 和设置 cve-agent config cve-agent config --set MISTRAL_API_KEY=sk-xxx # 扫描 repository cve-agent scan ./my-project # Rich table output cve-agent scan ./my-project -o report.md # Save markdown report cve-agent scan ./my-project --format json # JSON output cve-agent scan ./my-project --no-agent # Skip AI (fast, table only) # 语义化 CVE 搜索 cve-agent search "prototype pollution lodash" cve-agent search "remote code execution" --limit 5 # 数据库操作 cve-agent ingest bootstrap # Full CVE import cve-agent ingest update # Incremental update cve-agent stats # Database statistics # Vector index cve-agent index build # Build Qdrant index cve-agent index bench # Benchmark search latency ``` ## GitHub Action 将以下内容添加到任何仓库的 `.github/workflows/security.yml` 中: ``` name: CVE Scan on: pull_request: branches: [main] jobs: scan: runs-on: ubuntu-latest steps: - uses: Gleaming0427/cve-agent@main with: fail-on: critical github-token: ${{ secrets.GITHUB_TOKEN }} ``` 该 action 会发布带有发现的 PR 评论,并在引入严重 CVE 时阻止合并。 ## 数据源 | 来源 | 提供的内容 | 刷新频率 | |---|---|---| | [MITRE CVE 列表 v5](https://github.com/CVEProject/cvelistV5) | 约 25 万条 CVE 描述 | 每周 | | [NVD API 2.0](https://nvd.nist.gov/developers/vulnerabilities) | CVSS 分数、CWE 分类 | 每日 | | [CISA KEV](https://www.cisa.gov/known-exploited-vulnerabilities-catalog) | 已知被积极利用的漏洞 | 每日 | | [EPSS](https://www.first.org/epss) | 漏洞利用预测评分 | 每日 | ## 架构 ``` cve-agent/ ├── src/cve_agent/ │ ├── agent/ # AI agent (LangGraph + Mistral) │ │ ├── prompts/ # Versioned system prompts (triage, analyze, patcher) │ │ └── nodes/ # LangGraph nodes: Triage → Analyze → Patcher → Report │ ├── ingestion/ # CVE data ingestion from MITRE, NVD, KEV, EPSS │ ├── indexing/ # Qdrant vector indexing + Mistral embeddings │ ├── scanner/ # SBOM generation (Syft) + CVE matching │ ├── reachability/ # AST-based reachability (tree-sitter + Python AST) │ └── cli/ # CLI (Typer + Rich) ├── tests/ # 164 tests (pytest) ├── action.yml # GitHub Action definition ├── Dockerfile # Action runtime image └── docker-compose.yml # Qdrant for local development ``` ## 开发 ``` uv sync --group dev # Install all dependencies docker compose up -d # Start Qdrant uv run cve-agent ingest bootstrap # Populate CVE database (one-time) # 代码质量 uv run ruff check src/ tests/ # Lint uv run ruff format src/ tests/ # Format uv run pytest # 164 tests make check # All of the above + security audit ``` Git hooks 已激活:每次 `git push` 都会在推送前运行 lint → 安全 → 测试。 ## 技术栈 Python 3.12 · FastAPI · LangGraph · Mistral (Small + Codestral) · LiteLLM · Qdrant · SQLite · Syft · tree-sitter · Typer · Rich ## 许可证 AGPL-3.0 — 参见 [LICENSE](LICENSE)。 在闭源 SaaS 中的商业使用需要公开其修改内容。如需获取专用许可证,请联系作者。
标签:AI智能体, Mistral AI, 逆向工具