sabeel111/Vibescanner

GitHub: sabeel111/Vibescanner

一款结合正则模式检测与本地 3B LLM 分类过滤的 JavaScript/TypeScript 代码库漏洞扫描器,旨在降低传统规则扫描的误报率。

Stars: 0 | Forks: 0

# VibeScanner 一款用于 JavaScript/TypeScript 代码库的本地漏洞扫描器,它将 **快速模式检测**与**基于 LLM 的分类**结合在一起。模式检测器会撒下 一张大网;本地 3B 模型(通过 Ollama 的 VibeThinker-3B)则通过对每个候选项进行推理来 过滤误报。 ## 为什么这样设计? 该模型 (VibeThinker-3B) 擅长有边界的代码推理,但从未 接受过 tool-calling 或 autonomous agents 的训练。因此,我们没有强迫它进入 agent 循环,而是让它做擅长的事情:阅读代码片段并 判断被标记的问题是否是真正的、可利用的漏洞。 **检测**由快速、确定性的 regex 模式引擎完成(没有 幻觉,在几毫秒内运行)。**分类** —— 即决定 “真正的 bug 还是误报”这一难题 —— 才是该模型发挥价值的地方。 ``` CODEBASE │ ▼ [1] Pattern Detector ──► 11 candidate findings (wide net, fast) │ (some real, some false positives) ▼ [2] Context Extractor ──► pulls ±20 lines of code around each finding │ ▼ [3] Model Triage ──────► "Is this REAL or FALSE_POSITIVE?" │ (VibeThinker-3B reasons about data flow, │ sanitization, exploitability) ▼ [4] Report ─────────────► only confirmed REAL findings, with explanation + fix ``` ## 快速开始 ``` # 1. 安装 Ollama + 拉取模型 ollama pull nitrai/vibethinker-3b # 2. 构建自定义模型(使用 Qwen2.5 chat template) ollama create vibethinker-tools -f Modelfile.vibethinker-tools # 3. 安装 Python deps pip install -r requirements.txt # 4. 扫描目标(使用 model triage) python -m src.main scan ./my-codebase # 5. 快速扫描(仅使用 detector,不使用模型 — 瞬时完成) python -m src.main scan ./my-codebase --no-model # 6. 按 vulnerability class 筛选 python -m src.main scan ./my-codebase --class xss,command_injection # 7. JSON 输出 python -m src.main scan ./my-codebase --json # 8. 在 test fixtures 上评估 precision/recall python -m src.main eval ``` ## 漏洞类别 | 类别 | 检测内容 | 检测器规则 | |-------|--------------|----------------| | `command_injection` | 带有用户输入的 exec(), eval() | CMD-EXEC, CMD-EVAL | | `xss` | innerHTML, document.write, dangerouslySetInnerHTML | XSS-INNERHTML, XSS-DOCWRITE, XSS-DANGEROUSLY | | `path_traversal` | 带有用户输入的 fs.readFile/writeFile/unlink | PATH-READ, PATH-WRITE | | `hardcoded_secrets` | 源代码中的 API key、token、密码 | SECRET-APIKEY, SECRET-PRIVATEKEY | ## 分类的工作原理 每个候选发现都会作为一个专注的 prompt 发送给模型: ``` VULNERABILITY CLASS: command_injection FLAGGED LINE 12: exec(cmd, (err, stdout, stderr) => { CODE: [±20 lines of surrounding source] Is this a REAL exploitable vulnerability? ``` 模型会以结构化的结论进行响应: ``` VERDICT: REAL CONFIDENCE: 0.95 REASONING: The code takes req.body.command and passes it directly to exec() without validation, allowing remote code execution... FIX: Replace exec() with strict command validation or a sandboxed environment. ``` 只有真正的发现才会进入最终报告。 ## 配置 请参阅 `config/model.yaml` 了解 Ollama endpoint、模型名称、temperature 和 token 预算。 ## 项目结构 ``` vibescanner/ ├── src/ │ ├── main.py # CLI entry point │ ├── scanner/ │ │ ├── patterns.py # Vulnerability detection rules (4 classes) │ │ ├── detector.py # Pattern scanner engine │ │ └── context.py # Code context extraction │ ├── model/ │ │ ├── ollama_client.py # Single-shot Ollama API call │ │ └── triage.py # Prompt builder + verdict parser │ └── report/ │ ├── formatter.py # Text + JSON report output │ └── eval.py # Precision/recall evaluation harness ├── utils/ │ └── filesystem.py # Safe file reading/searching ├── tests/ │ └── fixtures/ │ ├── vulnerable/ # Known-buggy code (should detect) │ └── safe/ # Correctly-written code (should NOT flag) └── config/ └── model.yaml # Runtime configuration ``` ## 性能 - 检测器:即时(对于典型的代码库 <0.1s) - 模型分类:在 CPU 上每个发现约 60-90 秒(3B Q8_0 模型) - 对约 10 个发现进行全面扫描大约需要 10-15 分钟 ## 状态 可用的 pipeline:检测器 → 上下文 → 分类 → 报告,并带有 eval harness。 请参阅 `eval_results.txt` 了解测得的 precision/recall。
标签:AI风险缓解, CISA项目, DLL 劫持, LLM评估, Ollama, Python, Web安全, 代码安全审计, 加密, 大语言模型, 文档结构分析, 无后门, 漏洞扫描器, 蓝队分析, 逆向工具, 错误基检测, 静态代码分析