扫描LLM输出和AI生成内容中的数据传输信号,在到达用户、日志或下游系统之前进行检测。
现代LLM应用通常处理敏感提示、内部文档、API响应和用户数据。 这创建了一个新的安全边界:输出层。
EchoLeak系列攻击(包括CVE-2025-32711)展示了隐藏或混淆的有效载荷如何被 嵌入在生成的文本中,并通过工具、链接或解析链来窃取数据。
传统扫描器关注文件、依赖项和运行时流量。 它们不会以专门构建的方式检查生成的模型输出。
exfil-scan提供了一个“LLM响应的病毒扫描器”:
| 类别 | 严重性 | 检测内容 |
|---|---|---|
| 隐藏文本 | 高 | 用于隐藏有效载荷的零宽度和不可见Unicode序列 |
| 编码数据 | 高 | 可能携带编码内容的Base64/hex/octal/unicode转义序列 |
| URL中的数据 | 中 | 异常长的查询字符串和编码的URL参数有效载荷 |
| 元数据泄露 | 高 | 结构化/非结构化输出中的类凭证密钥和令牌格式 |
| Unicode隐写术 | 中 | 双向控制字符以及混合脚本的同形词式单词 |
| 结构异常 | 低 | 过多的换行/制表符序列和替换字符编码异常 |
low(低), medium(中), high(高)stdin、单个文件或目录输入text(文本), json, markdown, htmlgit clone https://github.com/your-org/exfil-scan.git
cd exfil-scan
pip install -e .
pip install exfil-scan
pip install -e ".[dev]"
pytest
echo 'api_key: sk-ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' | exfil-scan
exfil-scan --input output.txt
exfil-scan --directory ./model-logs --recursive
注意:
--input或--directory之一,不能同时使用。stdin读取。1。exfil-scan --input suspicious.txt --format text
预期风格:
exfil-scan report
=================
Scanned targets: 1
Total findings: 2
1. [HIGH] metadata_leaks/known_token_format:openai_key
Location: suspicious.txt:1:10
Description: Matched known credential/token format (openai_key).
exfil-scan --input suspicious.txt --format json
预期结构:
{
"finding_count": 2,
"scanned_targets": ["suspicious.txt"],
"findings": [
{
"category": "metadata_leaks",
"rule": "known_token_format:openai_key",
"severity": "HIGH",
"description": "Matched known credential/token format (openai_key).",
"location": "suspicious.txt:1:10",
"snippet": "..."
}
]
}
exfil-scan --directory ./outputs --recursive --format html --output report.html
预期行为:
exfil-scan --input suspicious.txt --format markdown --output report.md
预期风格:
# exfil-scan Report
- Scanned targets: 1
- Total findings: 2
仓库自带default-config.yaml。
你可以使用--config传递自己的文件。
灵敏度调整:
low(低):更少的误报,更大的阈值medium(中):平衡的默认值high(高):捕获更多细微模式CLI灵敏度覆盖:
exfil-scan --input out.txt --sensitivity high
你可以添加自己的令牌格式和元数据键:
sensitivity: medium
rules:
metadata_keys:
- api_key
- db_password
- internal_token
token_patterns:
custom_jwt: "\\beyJ[A-Za-z0-9_\\-]{10,}\\.[A-Za-z0-9_\\-]{10,}\\.[A-Za-z0-9_\\-]{10,}\\b"
corp_secret: "\\bcorp_[A-Za-z0-9]{24,}\\b"
然后运行:
exfil-scan --input response.log --config ./my-config.yaml
模块职责:
exfil_scan/cli.py:参数解析、输入选择、输出渲染、退出处理exfil_scan/config.py:默认值、YAML加载、递归合并、配置标准化exfil_scan/scanner.py:六个检测引擎、发现数据类、报告格式化tests/test_scan.py:检测与输出格式回归测试执行流程:
| 代码 | 含义 |
|---|---|
0 | 无发现(干净) |
1 | 检测到发现项 |
2 | 运行时或参数错误 |
这使得CI集成变得简单:
exfil-scan --directory ./artifacts --recursive --format json --output exfil-report.json
如果发现任何检测,你的任务可以根据退出码1快速失败。
运行测试:
pytest
覆盖范围包括:
exfil-scan是一个启发式扫描器。
它的设计目的是降低风险并发现可疑输出,而非证明内容安全。
推荐部署模式:
本项目使用MIT许可证。
详见LICENSE文件以获取完整条款。
欢迎贡献。 在提交PR时,请包括:
| 选项 | 类型 | 默认值 | 描述 |
|---|
-i, --input | 路径 | 无 | 扫描一个输入文件 |
-d, --directory | 路径 | 无 | 扫描目录中所有支持的文件 |
-r, --recursive | 标志 | false | 配合--directory递归嵌套目录 |
-c, --config | 路径 | 无 | YAML配置文件路径 |
-s, --sensitivity | low|medium|high | config/default | 覆盖灵敏度配置 |
-f, --format | text|json|html|markdown | text | 渲染报告格式 |
-o, --output | 路径 | stdout | 将渲染后的报告写入文件 |
--version | 标志 | 无 | 打印CLI版本 |
-h, --help | 标志 | 无 | 显示用法和参数 |