UnityInFlow/injection-scanner

GitHub: UnityInFlow/injection-scanner

一款基于模式库的静态扫描工具,用于在文件进入 AI 代理前检测并拦截各类 Prompt 注入攻击。

Stars: 0 | Forks: 0

# injection-scanner Prompt injection 是 AI 时代的 SQL injection。随着 AI 代理处理不受信任的文本——技能文件、RAG 文档、用户输入、CLAUDE.md 规范——单个注入的指令就能劫持代理行为、泄露数据或绕过安全控制。 **injection-scanner** 是一个静态分析工具,可以在 Prompt injection 模式到达您的 AI 代理之前将其捕获。它使用一个维护的 YAML 模式库扫描文件,以检测角色覆盖、指令注入、数据泄露、越狱和编码攻击。 ## 安装 从 [GitHub Releases](https://github.com/UnityInFlow/injection-scanner/releases) 下载适合您平台的预编译二进制文件。 ``` # macOS / Linux chmod +x injection-scanner sudo mv injection-scanner /usr/local/bin/ # 验证 injection-scanner --version ``` 或者从源码编译: ``` cargo install --path . ``` ## 用法 ### 扫描单个文件 ``` injection-scanner check CLAUDE.md ``` ### 递归扫描目录 ``` injection-scanner check . ``` ### 从标准输入读取 ``` cat skill.md | injection-scanner check - ``` ### JSON 输出 ``` injection-scanner check CLAUDE.md --format json ``` ## 模式类别 | 类别 | 模式数 | 默认严重程度 | 示例 | |---|---|---|---| | 角色覆盖 | 7 | CRITICAL | "ignore all previous instructions", "you are now", "forget everything" | | 指令注入 | 5 | HIGH | "SYSTEM OVERRIDE", 隐藏的 HTML 指令, "your real purpose is" | | 数据泄露 | 6 | CRITICAL | "send data to https://...", "output your instructions", "repeat system message" | | 越狱 | 9 | HIGH | "developer mode enabled", "DAN mode", "pretend you have no restrictions" | | 编码/混淆 | 3 | HIGH | Unicode RTL 覆盖, 零宽字符, 零宽序列 | 跨越 5 个类别共 **30 种模式**。完整的模式贡献指南请参见 [PATTERNS.md](PATTERNS.md)。 ## 输出示例 ### 文本输出(默认) ``` tests/fixtures/injected-skill.md :6 CRITICAL Attempts to override agent instructions — Remove instruction override text. If documenting attacks, use code blocks. (PI001) :6 CRITICAL System-level instruction injection — Remove system override. Only actual system prompts should use SYSTEM prefix. (PI011) :9 HIGH Role reassignment attempt — Remove role override. Use explicit skill scoping instead. (PI003) :9 CRITICAL System-level instruction injection — Remove system override. Only actual system prompts should use SYSTEM prefix. (PI011) :14 HIGH Developer mode jailbreak — Remove developer mode activation. (PI030) :16 HIGH Restriction removal via pretense — Remove restriction bypass. (PI033) 6 finding(s): 3 critical, 3 high, 0 medium, 0 low ``` ### JSON 输出 ``` [ { "file": "tests/fixtures/injected-skill.md", "matches": [ { "pattern_id": "PI001", "pattern_name": "ignore-previous-instructions", "severity": "CRITICAL", "message": "Attempts to override agent instructions", "remediation": "Remove instruction override text. If documenting attacks, use code blocks.", "file": "tests/fixtures/injected-skill.md", "line": 6, "matched_text": "ignore all previous instructions" } ], "critical_count": 3, "high_count": 3, "medium_count": 0, "low_count": 0 } ] ``` ## 内联抑制 通过在上方一行添加注释来抑制特定行的模式: ``` ignore all previous instructions ``` 可以同时抑制多个模式: ``` ``` ## 退出代码 | 代码 | 含义 | |---|---| | 0 | 未发现问题 | | 1 | 检测到一个或多个问题 | ## UnityInFlow 的一部分 injection-scanner 是 [UnityInFlow](https://github.com/UnityInFlow) AI 代理工具生态系统中的 03 号工具——包含 20 个开源工具,涵盖规范验证、token 成本控制、运行时、合规性等方面。 ## 许可证 MIT
标签:AI安全, Chat Copilot, DNS 反向解析, Jailbreak, LNA, Naabu, RAG安全, Red Canary, Rust, YAML模式库, 云安全监控, 内容安全, 可视化界面, 大模型安全, 安全防护, 数据窃取, 编码混淆, 网络安全, 网络流量审计, 角色覆盖, 通知系统, 隐私保护, 零宽字符, 静态代码扫描, 静态分析