SamsonCyber/stegoff

GitHub: SamsonCyber/stegoff

专为企业AI系统设计的隐写术检测与无害化工具,全面覆盖文本、图像、音频、二进制文件中100+种隐写技术,并具备prompt injection防护能力。

Stars: 0 | Forks: 0

StegOFF


### 🛡 [ST3GG](https://github.com/elder-plinius/st3gg) 的克星 🛡
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://python.org) [![st3gg tested](https://img.shields.io/badge/st3gg-109%2F109%20detected-red.svg)](https://github.com/elder-plinius/st3gg) [![False Positives](https://img.shields.io/badge/False%20Positives-0%25%20(0%2F88)-brightgreen.svg)](#numbers) [![Red Team](https://img.shields.io/badge/Red%20Team-34%2F39%20blocked-orange.svg)](REDTEAM_LOG.md)

我们构建了能捕获这一切的工具。

**所有的文本技巧:** - 零宽不可见字符 - Unicode 标签隐形墨水 - 同形字替换(西里尔文、希腊文、切罗基文) - 变体选择器和组合标记 - 易混淆的空白字符和 bidi 重写 - Emoji 二进制编码和肤色编码 - 盲文、数学粗体、韩文填充符 **所有的二进制技术:** - 跨越所有 120 种通道/位组合的 LSB - DCT 系数操作 (F5) - PVD、色度、调色板、位平面 - PNG 块、尾部数据、元数据 - PDF JS、表单字段、增量更新 - PCAP 隐蔽通道、GZip/TAR 头 - MIDI SysEx、RTF 隐藏文本、SQLite、xattr
### 109 种技术。109 种被检测。0 漏报。0 误报。
``` ╔══════════════════════════════════════════════════════════╗ ║ Text (14 methods) · Image (11 methods) ║ ║ Audio (3 formats) · Binary (7+ parsers) ║ ║ LLM Semantic Layer · Paraphrase Sanitizer ║ ║ ║ ║ 35+ detectors · 30+ formats · 3 layers ║ ║ Find it. Flag it. Destroy it. Before it reaches your AI ║ ╚══════════════════════════════════════════════════════════╝ ```
## 为什么选择 StegOFF? st3gg 以 109 种方式隐藏数据。StegOFF 捕获全部 109 种。如果 st3gg 能隐藏它,StegOFF 就能找到它。 其他检测工具仅覆盖 1-3 种方法。StegOFF 覆盖所有方法,通过 prompt injection 扫描链式解码 payload,并对内容进行无害化处理,以销毁无法检测的内容。 | | StegOFF | PromptSonar | Promptfoo | image_security_scanner | |---|:---:|:---:|:---:|:---:| | 文本隐写方法 | **14** | 3 | 1-3 | 0 | | 图像隐写方法 | **11** | 0 | 0 | 3 | | 音频隐写 | **3 种格式** | 0 | 0 | 0 | | 二进制/PDF | **7+** | 0 | 0 | 0 | | LLM 语义层 | **Yes** | No | No | No | | 无害化处理 | **Yes** | No | No | No | | 解码至注入扫描 | **Yes** | No | No | No | | 零依赖核心 | **Yes** | Tree-sitter | N/A | Tesseract | ## 安装 ``` pip install stegoff # text detection, zero deps pip install stegoff[image] # + image analysis (numpy, Pillow) pip install stegoff[full] # + audio statistical analysis (scipy) pip install stegoff[llm] # + LLM semantic layer (anthropic SDK) pip install stegoff[server] # + FastAPI server and middleware ``` ## 快速开始 ``` from stegoff import scan_text, scan_file, steg_guard report = scan_text("user input here") # free, 11ms report = scan_text("input", use_llm=True) # + LLM layer report = scan_file("upload.png") # auto-detects format @steg_guard # decorator def process(text: str) -> str: return llm.generate(text) from stegoff.server.middleware import StegOffMiddleware app.add_middleware(StegOffMiddleware) # FastAPI ``` ``` stegoff scan suspicious.png stegoff scan-text "some text" stegoff scan-dir ./uploads --json cat input.txt | stegoff guard --block ``` ## 架构 ``` Input (text, file, or bytes) │ ▼ ┌──────────────────────────────────────────────────────────┐ │ LAYER 1: Character-Level Detection │ │ 35 detectors · FREE · 11ms median │ │ 14 text + 11 image + 3 audio + 7 binary │ │ 107/109 st3gg techniques │ ├──────────────────────────────────────────────────────────┤ │ LAYER 2: LLM Semantic Detection │ │ Claude Haiku · ~$0.0001/scan · ~1s │ │ Synonym patterns · structure encoding · register shifts │ │ F1 = 1.00 · catches the remaining 2 techniques │ │ 15/15 prompt injection attacks against the scanner blocked│ ├──────────────────────────────────────────────────────────┤ │ LAYER 3: Paraphrase Canonicalization │ │ Rewrites text with LLM default word choices │ │ Destroys payload when detection is uncertain │ │ Same principle as image re-encoding, applied to language │ └──────────────────────────────────────────────────────────┘ ``` 每一层捕获前一层遗漏的内容。大多数内容在免费的 Layer 1 被拦截。同义词编码和句子长度技巧到达 Layer 2。Layer 3 通过替换载体来销毁 payload。 ## 每种攻击的原理及 StegOFF 如何阻止它 ### 文本隐写术
零宽字符 — 可见字母之间的不可见 Unicode **攻击:** U+200C (ZWNJ) = 0, U+200D (ZWJ) = 1。插入字母之间。500 个不可见字符可编码完整的 prompt injection。 ``` What you see: Hello World What's there: H[ZWNJ][ZWJ][ZWNJ][ZWNJ][ZWJ]ello World Hidden payload: ignore all previous instructions ``` **防御:** 扫描 10 个已知的零宽码点。解码二进制模式。将解码后的文本通过 17 种 prompt injection 模式运行。
Unicode 标签字符 — 在所有渲染器中不可见 **攻击:** U+E0000 范围将每个 ASCII 字符映射到一个不可见的孪生字符。U+E0068 = 不可见的 'h'。完整的字母表都有一个幽灵版本。 **防御:** 标记 U+E0000-E007F 中的任何字符。解码为 ASCII。严重程度 CRITICAL。这曾驱动了针对 ChatGPT 的“不可见 prompt injection”攻击。
同形字替换 — 西里尔字母 'а' 和拉丁字母 'a' 看起来一样 **攻击:** 将拉丁字母替换为来自其他文字的视觉上相同的字符。每次替换 = 1 位。跨西里尔文、希腊文、亚美尼亚文、切罗基文、罗马数字、修饰字母有 150+ 个易混淆对。 **防御:** 150+ 字符映射。文字主导检查避免对真实西里尔文文本的误报。从替换位置提取位模式。
另外 11 种文本方法 变体选择器 (VS1-VS256)、组合标记 (Zalgo 堆叠)、易混淆的空白字符 (en/em/NBSP)、bidi 重写 (RTL 劫持)、韩文填充符、数学字母数字 (U+1D400 粗体/斜体)、盲文 (每字符一字节)、emoji 替换 (二进制和多类型)、emoji 肤色 (每个 2.3 位)、尾部空白 (每行空格/制表符)、不可见分隔符 (兜底)。 每个解码后的 payload 都会经过 17 个 prompt injection 模式类别的检查。
### 图像隐写术
LSB (最低有效位) — 每像素 1 位,对人眼不可见 **攻击:** RGB(142, 87, 201) 变为 RGB(143, 87, 200)。一张 1000x1000 的图像可容纳 375KB 的隐藏数据。 **防御:** 三种独立的统计测试: - **Chi-square** (卡方):LSB 嵌入强制值对频率趋于相等 - **RS analysis** (RS 分析):测量规则组与奇异组比率失真 - **Bit-plane correlation** (位平面相关性):自然 LSB 平面具有空间结构 (>0.55)。嵌入数据降至 ~0.50 覆盖 PNG, BMP, TIFF, WebP, GIF, ICO, PGM/PPM。任何通道配置。位深 1-8。
结构:块、尾部数据、元数据、DCT - **PNG chunks**:非标准块类型,tEXt/zTXt 中的可疑关键词 - **Trailing data**:IEND/FFD9/3B 之后的字节。严重程度 CRITICAL - **Metadata**:EXIF、ICC 配置文件、任何元数据字段中的 base64/hex - **DCT/F5**:块效应校准可捕获 JPEG 系数操作 - **Content-type mismatch**:通过魔数扫描,而非文件扩展名
### 音频、二进制、代码
音频 LSB 解析 WAV (小端)、AIFF (大端)、AU (大端)。LSB 相关性、卡方、段熵。
PDF、压缩包、PCAP、SQLite、MIDI、RTF、xattr - **PDF**:JavaScript、增量更新、表单字段、post-EOF、流异常值 - **Archives**:多语言文件、GZip FEXTRA/FCOMMENT、TAR PAX 头 - **PCAP**:数据包 payload 扫描、DNS 隧道 (base32)、隐蔽通道检测 - **SQLite**:隐藏表检测、嵌入文本扫描 - **MIDI**:SysEx 消息、文本事件 - **RTF**:隐藏文本组 (`\v` 切换) - **Filesystem**:Linux/macOS 上的扩展属性 (xattr)
代码文件 (15 种格式) 跨 `#` `//` `;` `--` `%` `/* */` `` 扫描注释以查找 base64、hex、ROT13。JSON 数值数组解码 (`[72,101,108]` = "Hel")。HTML data-attribute 和 CSS custom property 扫描。文件名分析。Base32、Morse、Punycode 检测。
### LLM 层
同义词编码 — "big" vs "large" 编码一位 没有字符级别的痕迹。每个字符都是有效的。每个单词都是真实的。信号在于选择的模式中。Layer 2 将文本发送给 Claude Haiku,使用包含针对来自被分析文本的 prompt injection 防御的强化 prompt。在测试中,针对扫描器本身的 15/15 次注入攻击都被拦截。
改写规范化 与图像重新编码原理相同。LLM 使用其默认选词重写文本。`large` 变为 `big`。`quick` 变为 `fast`。`glad` 变为 `happy`。攻击者的载位词被替换。正常文本变化约 5%。隐写文本变化约 20%。无论哪种情况,输出都是干净的。
## 数据 ``` st3gg Detection: 109/109 techniques (100%) False Positives: 0/88 clean inputs (0.0%) Red Team: 34/39 attacks blocked LLM Injection: 15/15 scanner attacks blocked Test Suite: 192 core tests passing ``` | Layer | Detection | Cost | Latency | |-------|-----------|------|---------| | 1: Character-level | 107/109 st3gg | Free | 11ms median | | 2: LLM semantic | 109/109 st3gg | ~$0.0001/scan | ~1s | | 3: Paraphrase | Destroys payload | ~$0.0003/scan | ~2s | ## 红队 通过阅读 StegOFF 源代码设计的 39 次自定义绕过尝试。完整日志:[REDTEAM_LOG.md](REDTEAM_LOG.md) **Blocked (34):** LSB matching、ICC injection、未映射的同形字、JSON 字节数组、UTF-16 bypass、ROT13 混淆、content-type mismatch、LLM prompt injection、HTML/CSS attribute encoding、filename steg、timestamp encoding、indentation depth 等。 **Theoretical limits (5):** UUID hex digits、SHA256 hash bytes、list permutation、absence encoding、domain-specific synonyms。隐藏在由定义上随机的字段中的数据。通过 [canonicalization sanitizers](stegoff/sanitizers/structured.py) 缓解。 ## 理论极限:为什么 5 种攻击无法被检测 红队的五种攻击仍然无法被任何通用扫描器检测到。这是一个数学边界,而非实现差距。 **Cachin (1998, 2004)** 证明了当编码分布与载体分布匹配时,隐写术是不可检测的: **Hopper, Langford, von Ahn (2002)** 在计算上对此进行了形式化: | Attack | Why undetectable | Cachin's framework | |--------|-----------------|-------------------| | UUID encoding | UUID 是随机的。隐写 UUID 也是随机的。 | Encoding = cover distribution. Epsilon = 0. | | SHA256 hash channel | 哈希输出是均匀的。修改后的哈希也是均匀的。 | 与载体无法区分。 | | List permutation | 任何顺序都是有效的。 | 所有排列的可能性相等。 | | Absence encoding | 可选字段是可选的。 | 存在/不存在遵循相同的分布。 | | Domain synonyms | 医学文本自然地混合了行话和通俗语言。 | 同义词选择匹配自然变化。 | 这五种情况的检测是不可能的。无害化处理仍然有效。StegOFF 重新生成 UUID、排序列表并改写文本,以在不检测的情况下销毁信号: ``` from stegoff.sanitizers.structured import sanitize_json, canonicalize_uuids clean_json, _ = sanitize_json(data) # regenerate UUIDs, sort lists clean_text, _ = canonicalize_uuids(text) # replace all UUIDs with fresh ones ``` **Atallah et al. (2001)** 和 **Bennett (2004)** 表明语言隐写检测需要特定作者的基线。StegOFF 的改写规范化通过替换载体避开了这一点: ## 无害化处理 ``` from stegoff import sanitize_text, sanitize_image, sanitize_wav from stegoff.sanitizers.structured import sanitize_json from stegoff.sanitizers.semantic import sanitize_semantic clean, _ = sanitize_text(text) # strip invisible chars, normalize homoglyphs clean = sanitize_image(img_bytes) # re-encode pixels, strip metadata clean = sanitize_wav(wav_bytes) # re-encode audio samples clean, _ = sanitize_json(json_text) # regen UUIDs, sort lists, normalize clean, _ = sanitize_semantic(text) # paraphrase to destroy synonym encoding ``` ## 许可证 MIT
*由 [SamsonCyber](https://github.com/SamsonCyber) 构建。针对 [st3gg](https://github.com/elder-plinius/st3gg) 进行了测试。*
标签:AI安全, Chat Copilot, DNS 反向解析, DNS枚举, IP 地址批量处理, LSB隐写, Naabu, Prompt注入, Python安全工具, Unicode安全, 内容安全, 图片隐写, 大模型安全网关, 提示词注入防御, 数字水印检测, 数据清洗, 数据脱敏, 文本隐写, 流量清洗, 深度学习防御, 红队对抗, 网络安全工具, 逆向工具, 隐写分析, 隐写术检测, 零宽字符检测