CodeAtCode/baco-scanner

GitHub: CodeAtCode/baco-scanner

一款结合静态分析与 LLM 的多阶段安全漏洞扫描器,能自动发现、验证漏洞并生成交叉引用报告。

Stars: 0 | Forks: 1

# BACO - Bug 分析与交叉引用编排器 [![License](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) 一款基于 CLI 的安全漏洞扫描器,结合了静态分析、基于 LLM 的发现以及工单系统交叉引用(由 Regolo.AI 生成)。 使用 [Regolo.AI](https://regolo.ai/) 模型在 [ins1gn1a/VulnServer-Linux](https://github.com/ins1gn1a/VulnServer-Linux) 上生成的[示例报告](example-report.html)。 代码覆盖率详见 [Codecov.io](https://app.codecov.io/gh/CodeAtCode/baco-scanner/tree/master)。 ## 功能 - **多阶段扫描**:包含 13 个以上的阶段,如 Indexing → Semgrep → LLM Static Analysis → LLM Discovery → LLM Verification → **SecurityAgent Verification** → Ticket Cross-Ref → Git Analysis → Cross-File Analysis → Confidence Scoring → AI Aggregation → Reporting → 高级 V3 功能(Threat Modeling、CVE Bootstrap、PoC Compilation、Variant Search) - **并行执行**:Semgrep 和 LLM discovery 并行运行;verification、ticket cross-ref 和 git analysis 并行运行 - **检查点/恢复**:在每个阶段后自动保存状态以进行崩溃恢复 - **多种输出格式**:JSON、HTML、SARIF - **配置驱动**:TOML 配置并支持环境变量覆盖 - **Prompt 自定义**:可通过 config 按阶段覆盖默认的 LLM prompt - **工单集成**:支持 GitHub、GitLab、Bugzilla、Jira - **跨文件分析**:追踪文件间的数据流以识别可利用的攻击链 - **综合置信度评分**:将多种信号结合为单一可靠性评分 ## 架构 ### Pipeline 阶段 **核心 Pipeline(11 个阶段):** 1. **Indexing**:构建文件列表和调用图 2. **Semgrep**:使用预定义规则进行静态分析 3. **LLM Static Analysis**:独立的基于 LLM 的代码分析(使用 discovery 配置) 4. **LLM Discovery**:多模型漏洞检测(所有已配置的模型均会分析每个发现) 5. **LLM Verification**:带有 PoC 生成和缓解代码的验证 6. **SecurityAgent Verification**:使用 file_read、pattern_search、file_write、run_test 的**基于工具的 agent 验证**,以确认是否为真阳性 7. **Ticket Cross-Ref**:在 GitHub/GitLab 上搜索现有的报告 8. **Git Analysis**:检查提交历史以寻找相关的修复 9. **Cross-File Analysis**:追踪文件间的数据流 10. **Confidence Scoring**:计算综合可靠性评分 11. **AI Aggregation**:生成执行摘要、语义去重以及 LLM 丰富的描述 12. **Reporting**:生成 JSON、HTML 和 SARIF 输出 13. **Threat Modeling**:生成包含攻击面分析的 THREAT_MODEL.md 14. **Root Cause Dedup**:根据根本原因而非位置对发现进行去重 15. **Multi-Verifier**:具有多数投票机制的多种验证方法 16. **Auto-Patching**:通过 staging 生成并验证补丁 17. **CVE Bootstrap**:使用 NVD/CISA KEV 数据丰富漏洞发现 18. **PoC Compiler**:验证 PoC 代码能否成功编译 19. **Variant Search**:搜索相关的漏洞变体 ### 数据流 ``` Config → Indexing → [Semgrep + LLM Static Analysis + LLM Discovery] → [LLM Verification + SecurityAgent Verification + Tickets + Git + Confidence] → Cross-File → AI Aggregation → Reporting → [Threat Modeling, CVE, PoC, Variants] → JSON/HTML/SARIF Output ↑ Checkpoint after each major stage ``` ## 安装 ``` cargo build --release ./target/release/baco --version ``` ## 用法 ### 1. 创建配置 ``` cp config.example.toml myproject.toml ``` 编辑 `myproject.toml`: - 设置 `project.path` 为目标目录 - 配置 LLM API 密钥(或使用环境变量) - 如有需要,设置工单系统凭证 ### 2. 运行扫描 ``` baco scan --config myproject.toml ``` **选项:** - `-c, --config ` - 配置文件(必填) - `-t, --target ` - 覆盖配置中的目标路径 - `-f, --force` - 强制重新扫描,忽略现有的检查点 **恢复之前的扫描:** ``` baco scan --config myproject.toml --force ``` 使用 `--force` 可重新开始并忽略检查点文件。 ### 3. 查看结果 ``` output/report.html ``` ## 配置 ### 项目设置 ``` [project] name = "my-project" path = "/path/to/target" languages = ["c", "cpp", "python"] ``` ### LLM 配置 BACO 在每个阶段支持单个或多个模型。当配置了多个模型时,它们将以轮询的方式运行,以在不同的模型/提供商之间分配负载。 **详细的错误日志**:当 LLM 请求失败时,BACO 会报告 HTTP 状态码、错误类型(超时、连接、请求、响应体、解码)以及实际的 URL,以便于调试。 **单个模型:** ``` [llm.phases.discovery] base_url = "https://api.mistral.ai/v1" api_key = "${MISTRAL_API_KEY}" # or set env var model = "mistral-small" ``` **多个模型:** ``` [llm.phases.discovery] base_url = "https://api.mistral.ai/v1" api_key = "${MISTRAL_API_KEY}" # 如果同时存在,'models' 优先于 'model' models = ["mistral-small", "mistral-medium", "codestral-latest"] [llm.phases.verification] base_url = "https://api.qwen.ai/v1" api_key = "${QWEN_API_KEY}" model = "qwen35" # single model [llm.phases.aggregation] base_url = "https://api.openai.com/v1" api_key = "${OPENAI_API_KEY}" models = ["gpt-4o", "gpt-4o-mini"] # multiple models for distributed load ``` **注意**:如果同时存在,`models` 数组将优先于 `model`。模型将以轮询的方式进行选择,以在不同的提供商之间分配负载。 ### Agent 模式 BACO 具有**两种不同的 agent 模式**: #### 1. Discovery Agent (`agent.enabled = true`) 启用后,LLM Discovery 阶段在分析发现之前会直接读取源文件: ``` [agent] enabled = true max_turns = 10 # Max conversation turns with tools tool_timeout_secs = 60 # Timeout for tool execution keep_artifacts = false # Keep generated test files ``` **优势:** - LLM 在丰富发现信息之前会读取实际的源代码 - 使用工具(file_read、pattern_search)进行更深入的分析 - 结合上下文提供更准确的漏洞描述 #### 2. SecurityAgent 验证(阶段 6) 一个**独立的验证阶段**,它使用带有工具的嵌入式安全 agent 来**证明或反驳**漏洞发现: - **file_read**:在上下文中检查易受攻击的代码 - **pattern_search**:查找相关的漏洞模式 - **file_write**:创建 PoC 测试用例 - **run_test**:执行测试以验证可利用性 当测试通过时,该 agent 会自动移除假阳性,从而减少最终报告中的噪音。此阶段运行在 LLM 验证**之后**、Ticket 交叉引用**之前**。 ### Prompt 自定义 BACO 在运行时会从 Markdown 文件中加载各阶段所使用的 prompt 模板。你可以通过配置覆盖它们: **默认 prompt** 作为 Markdown 文件存储在 `prompts/phases/` 中: - `prompts/phases/indexing.md` - `prompts/phases/semgrep.md` - `prompts/phases/llm_static_analysis.md` - `prompts/phases/llm_discovery.md` - `prompts/phases/llm_verification.md` - `prompts/phases/ticket_crossref.md` - `prompts/phases/git_analysis.md` - `prompts/phases/cross_file_analysis.md` - `prompts/phases/confidence_scoring.md` - `prompts/phases/ai_aggregation.md` - `prompts/phases/reporting.md` 查看 [GitHub 上的完整 prompt 模板](prompts/phases/) 以了解默认行为。 **在 config.toml 中内联覆盖**: ``` [llm.phases.prompt_overrides.phases] llm_static_analysis = """Analyze this %%LANGUAGE%% code for security vulnerabilities. Focus on: memory safety, injection risks, and insecure API usage. File: %%FILE_PATH%% Code: %%CODE_CONTENT%% """ llm_discovery = """Given this finding, determine if it's a true vulnerability: Title: %%FINDING_TITLE%% Location: %%FILE_PATH%%:%%LINE_NUMBER%% Description: %%VULNERABILITY_DESCRIPTION%% """ ``` **可用的模板变量:** - `%%PROJECT_PATH%%` - 目标项目路径 - `%%FILE_EXTENSIONS%%` - 检测到的文件扩展名 - `%%LANGUAGES%%` - 目标语言 - `%%CODE_CONTENT%%` - 正在分析的代码片段 - `%%LANGUAGE%%` - 文件的编程语言 - `%%FILE_PATH%%` - 文件路径 - `%%LINE_RANGE%%` - 行号 - `%%FINDING_TITLE%%` - 漏洞标题 - `%%VULNERABILITY_DESCRIPTION%%` - 描述文本 - `%%FINDINGS_COUNT%%` - 总发现数 - `%%SCAN_DATE%%` - 扫描日期 **从外部文件加载:** ``` # 在 config.toml 中 prompt_overrides = "prompts.toml" ``` 创建 `prompts.toml`: ``` [phases] llm_static_analysis = "Your custom prompt here..." llm_verification = "Your verification prompt..." ``` Prompt 在使用前会进行验证(最多 10,000 个字符,无 null 字节)。 ### 工单系统 ``` [[tickets.systems]] type = "github" url = "https://api.github.com" credentials.token = "${GITHUB_TOKEN}" ``` ## 输出格式 - **findings.json**:包含所有 16 个字段的完整漏洞数据 - **report.html**:带有严重性颜色、代码片段、AI 摘要的可视化报告 - **report.sarif**:用于 CI/CD 集成的 SARIF 格式
标签:DLL 劫持, Python安全, 云安全监控, 可视化界面, 大语言模型, 通知系统, 静态分析