daedalus/ai-vuln-harness

GitHub: daedalus/ai-vuln-harness

基于 LLM 多 Agent 架构的自动化漏洞发现与验证框架,通过 15 阶段流水线在代码库中大规模搜寻、验证并生成 zero-day 漏洞 PoC。

Stars: 2 | Forks: 0

# ai-vuln-harness [![Python](https://img.shields.io/pypi/pyversions/ai-vuln-harness.svg)](https://pypi.org/project/ai-vuln-harness/) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/master/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/daedalus/ai-vuln-harness) 多 Agent 漏洞研究框架 —— 遵循 Project Glasswing / Cloudflare 方法论的 15 阶段 pipeline,涵盖从代码库接收到结构化安全报告的全过程。 ## 安装说明 ``` pip install ai-vuln-harness # 支持 search/embeddings pip install "ai-vuln-harness[search]" ``` ## 使用方法 ``` python -m ai_vuln_harness --mode full --repo /path/to/repo ``` ``` from ai_vuln_harness import run, run_all # Single 模式 report = run("full", "/path/to/repo") # 所有模式合并 report = run_all("/path/to/repo") ``` ## Pipeline ``` INGESTOR → RECON → COORDINATOR → HUNT → LOCALIZATION → VALIDATE → FUZZ_ORCHESTRATOR → GAPFILL → VOTING → SHIELD → SUPPRESSIONS → CHAINS → POC → TRACE → EXPOSURE → FEEDBACK → REPORT ``` 只有 HUNT 和 VALIDATE 阶段会调用 LLM —— 所有其他阶段均为确定性逻辑。 ## 设计默认值 - **库目标加固**:默认目录排除与目标感知标签 - **Recon 驱动的 Coordinator**:除非指定 `--allow-full-db-fallback`,否则不回退至全量 DB - **严格契约**:schema 验证 + 有限的修复轮次 - **可靠性**:默认同步路径,hunt/validate 池互斥,JSON 缓存,SQLite 状态 DB - **Validate/Trace 策略**:针对库目标的 code-in-prompt 和 trace-required 晋升机制 - **Validate 运行时检查**:C/C++ 代码片段可被重新编译并执行(可选通过 container/qemu wrapper 以及 fuzz orchestrator 中的 valgrind),以捕获真实的 PoC 信号 ## CVE 语料库与语义抑制 该 harness 会构建一个已知 CVE 的语料库,作为负样本。与已知 CVE 匹配的发现会被自动抑制 —— 它们不是 zero day。 ### 来源 1. **手动语料库** — 通过 `--cve-corpus path/to/cves.json` 传入的 JSON 文件 2. **OSV.dev 自动获取** — 扫描 manifest 文件以查找已知漏洞 3. **Git 历史扫描** — 扫描 commit 以查找 CVE 引用 ### 语义抑制(6 层) `suppress_known_cves()` 函数使用 embedding 余弦相似度来检测与已知 CVE 描述相同漏洞的发现,即使措辞不同也是如此: | 层级 | 内容 | 方式 | |-------|------|-----| | 1. 精确 CVE ID | 快速路径 | 字符串匹配,不使用 embedding | | 2. 两轮匹配 | 类别预筛选 → 语义 | 构建 class→indices 映射,在类内使用 FAISS | | 3. 类别匹配提升 | 同类 = 更易匹配 | 阈值 0.45(相同)vs 0.85(不同)| | 4. 丰富编码 | CWE + file + function | 包含所有用于 embedding 的字段 | | 5. 困难负样本 | 不同 file/function → 跳过 | 防止错误的抑制 | | 6. 置信度评分 | 0.0–1.0 带有加成 | 自动抑制 ≥0.9,标记审查 ≥0.7 | ### 控制标志 | 标志 | 效果 | |------|--------| | `--cve-corpus PATH` | 加载手动语料库 JSON 文件 | | `--no-fetch-cves` | 跳过 OSV.dev 自动获取 | | `--no-scan-git-cves` | 跳过 git 历史扫描 | ## Zero-day 搜寻模式 优化 pipeline 以发现新漏洞: ``` python -m ai_vuln_harness --mode full --repo /path/to/repo --zero-day ``` `--zero-day` 会禁用那些偏向已知 bug 或会增加噪音的功能: | 禁用项 | 原因 | |----------|-----| | 暴露追踪 | 修复时间与漏洞发现无关 | | 反馈循环 | 跨运行的回归是针对已知 bug 的 | | RAG KB 扩充 | CWE 模式匹配 → 已知弱点 | | 证据收集 | 产生元数据开销,对发现率无影响 | `--zero-day` **保留**:gapfill、chains、shield、抑制机制、CVE 语料库(作为负样本)。 用于精细控制的独立标志: | 标志 | 效果 | |------|--------| | `--no-gapfill` | 跳过 gapfill 循环 | | `--no-chains` | 跳过 chain 合成 | | `--no-exposure` | 跳过暴露追踪 | | `--no-feedback` | 跳过反馈循环 | | `--no-cve-corpus` | 跳过 CVE 语料库加载 | | `--no-rag-kb` | 跳过 RAG KB 扩充 | | `--no-evidence` | 跳过证据收集 | ## 投票中的语义去重 当设置了 `--enable-embeddings` 时,VOTING 阶段会使用 embedding 余弦相似度来合并跨 hunter 运行的语义相似发现: ``` python -m ai_vuln_harness --mode full --repo /path --enable-embeddings ``` 描述同一漏洞但位于不同行的两个发现会被合并为一个,即使它们的表面键不同。 ## 基于 FTS5 的抑制 启用模糊匹配以实现能够抵御行号偏移的抑制: ``` python -m ai_vuln_harness --mode full --repo /path --enable-fts-suppressions ``` ## 发现数据库 用于跨运行搜索的持久化、可查询发现 DB: ``` python -m ai_vuln_harness --mode full --repo /path \ --enable-findings-db output/findings.db \ --persist-findings --historical-context ``` ## 输出内容审查门控 阻止可武器化的漏洞利用内容(shellcode、reverse shell、ROP 链)进入报告: ``` python -m ai_vuln_harness --mode full --repo /path --enable-output-review python -m ai_vuln_harness --mode full --repo /path --enable-output-review --output-review-risk-level strict ``` ## CVE 到 exploit 的合成 根据 CVE ID 生成 exploit 模板: ``` from ai_vuln_harness.stages.cve_exploit_synthesis import synthesize_and_write from pathlib import Path record = synthesize_and_write( "CVE-2024-12345", Path("output/exploit"), cwe="CWE-120", severity="HIGH", ) ``` 支持的类别:buffer overflow、format string、command injection、SQL injection、path traversal 等。 ## 模型拒绝处理 该 harness 会检测 LLM 的拒绝行为并进行重试: - **检测**:16 种正则表达式模式,涵盖 OpenAI、Anthropic、通用以及中文模型的拒绝行为 - **重试**:最多重试 2 次,并带有指数退避(5秒、10秒) - **Prompt 变异**:每次重试都会使用安全研究框架的前言重写 prompt - **日志记录**:以 WARNING 级别记录拒绝行为,并按模型进行计数 ## 基准回归门控 ``` python -m ai_vuln_harness.run \ --mode benchmark \ --repo /path/to/repo \ --benchmark-corpus src/ai_vuln_harness/config/benchmark_corpus.json \ --benchmark-baseline src/ai_vuln_harness/config/benchmark_baselines.json \ --benchmark-thresholds src/ai_vuln_harness/config/benchmark_thresholds.json \ --benchmark-output output/benchmark_regression_report.json ``` ## 可选依赖组 | 组 | 包 | 用途 | |-------|----------|---------| | `search` | sentence-transformers, faiss-cpu, scikit-learn | 语义去重、模糊抑制、CVE 抑制 | | `solver` | z3-solver | VALIDATE 中的形式化验证 | | `sandbox` | llm-sandbox[mcp-docker] | Docker 隔离的 PoC 执行 | | `cst` | tree-sitter + language grammars | 多语言 AST 解析 | | `pbt` | hypothesis | 基于属性的测试 | ## 开发说明 ``` git clone https://github.com/daedalus/ai-vuln-harness.git cd ai-vuln-harness pip install -e ".[test]" # 运行测试 pytest # 格式化 ruff format src/ tests/ # lint + type check prospector --with-tool ruff --with-tool mypy --with-tool pylint src/ai_vuln_harness/ semgrep --config=auto --severity=ERROR src/ai_vuln_harness/ # dead code 检测 vulture --min-confidence 90 src/ai_vuln_harness/ --exclude src/ai_vuln_harness/.vulture_whitelist.py ``` ## API | 符号 | 描述 | |--------|------------| | `run(mode, repo, **kwargs)` | 运行单个 pipeline 模式 | | `run_all(repo, **kwargs)` | 运行所有模式并合并报告 | | `main()` | CLI 入口点 | ## Skill 元数据发现 ``` from ai_vuln_harness.skill_loader import discover_skills, load_skill_metadata meta = load_skill_metadata() skills = discover_skills() custom = load_skill_metadata(name="my-skill") ``` `discover_skills()` 返回内置 skill 以及在 `~/.ai-vuln-harness/skills/**/SKILL.md` 下找到的任何用户自定义 skill。`load_skill_metadata(name=...)` 根据 front matter 的 `name` 加载已发现的 skill。 ## CLI ``` python -m ai_vuln_harness --help ```
标签:AI智能体, C2, CISA项目, DLL 劫持, Python, 大语言模型, 安全, 对称加密, 无后门, 自动化审计, 请求拦截, 超时处理, 身份验证强制, 逆向工具