Hugging Face扫描发现恶意GGUF模型致2400人中招
GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400 Victims
本地部署大模型的安全隐患不容忽视,这篇报告详细拆解了GGUF文件的恶意载荷隐藏机制与模板注入手法,建议所有使用本地LLM的同学立即用gguf-radar等工具自查模型文件。
Contents
目录
1. SummaryCopy Anchor Link
1. 摘要复制锚点链接
Local LLMs are usually shared as GGUF files, and every GGUF file carries a chat template that the runtime applies to each prompt. Chat template poisoning abuses that template. The model answers normally, while the template quietly adds instructions the user never sees: make an agent run a PowerShell command, or open every reply with a command for the user to run. In its strongest form, the malicious program travels inside the model file itself, appended after the last tensor where loaders never read, and the template is switched on later.
本地大语言模型(LLM)通常以 GGUF 文件格式共享,每个 GGUF 文件都包含一个聊天模板,运行时会将该模板应用于每个提示词。聊天模板注入利用的就是这个模板。模型回答看起来正常,但模板会悄悄添加用户看不到的指令:让智能体运行 PowerShell 命令,或在每条回复的开头插入一条供用户运行的命令。在最严重的形式中,恶意程序隐藏在模型文件本身内部,附加在最后一个张量之后,加载器不会读取该部分,且模板会在稍后被激活。
A scan of all 3273389 public Hugging Face model repositories on 26 November 2026 found 5 malicious GGUF models with 2428 downloads as of 27 November. Hugging Face counts downloads, not people, so the number of affected users is lower or equal. The largest campaign, Mir2k, uploaded two uncensored GGUF models with a Windows remote access trojan named ollie hidden at the end of each file, and on 26 November rewrote both templates so the model asks the user to run the line that unpacks it.
2026 年 11 月 26 日对所有 3,273,389 个公共 Hugging Face 模型仓库的扫描发现,截至 11 月 27 日,共有 5 个恶意 GGUF 模型,累计下载量为 2428 次。Hugging Face 统计的是下载次数而非独立用户数,因此受影响的用户数量低于或等于该数字。最大的攻击活动 Mir2k 上传了两个未加限制(uncensored)的 GGUF 模型,每个文件末尾隐藏了一个名为 ollie 的 Windows 远程访问特洛伊木马,并于 11 月 26 日重写了这两个模型的模板,使模型要求用户运行解压该文件的命令行。
The open-source tool gguf-radar detects these templates and hidden bytes without running anything, and rebuilds a clean GGUF file with the model weights unchanged. Indicators, YARA rules and a MITRE mapping close the post.
开源工具 gguf-radar 无需运行任何代码即可检测这些模板和隐藏字节,并重建一个权重不变的干净 GGUF 文件。指标、YARA 规则和 MITRE 映射详见文章末尾。
The key figures of the scan are summarized below; each one is explained in Section 3.
本次扫描的关键数据总结如下;每项数据均在第 3 节中详细解释。
The scan in numbers
扫描数据统计
public model repositories scanned
已扫描的公共模型仓库数量
3.27 million
327 万
malicious models still online
仍在线的恶意模型数量
5 repos
5 个仓库
downloads of those models
这些模型的下载次数
2428
actors behind them
幕后行为者数量
2
If one of these models was downloaded
如果您下载了上述任一模型
Check endpoints against the indicators in Section 7.2 and scan local .gguf files with gguf-radar. Antivirus engines and checks that only look at the last few kilobytes of a file do not see the compressed payload.
请根据第 7.2 节中的指标检查端点,并使用 gguf-radar 扫描本地的 .gguf 文件。杀毒引擎以及仅检查文件最后几千字节的检测手段无法发现压缩载荷。
2. Attack MechanicsCopy Anchor Link
2. 攻击机制复制锚点链接
A GGUF file has a simple layout. A header and a metadata table come first, the tensor table follows, then padding up to an alignment boundary, and finally the model weights. Runtimes such as llama.cpp and LM Studio read exactly the byte ranges the header points to and ignore everything else. The figure below draws a GGUF file from its first byte to its end and marks the four places where data can hide. The top row shows the file as an attacker publishes it, the bottom row the same file after gguf-radar rebuilds it. Two of the places are used by real malware and are explained in this section; the other two were reproduced in the lab and are covered in Section 4.
GGUF 文件具有简单的布局结构。首先是头部和数据元表,接着是张量表,然后是填充至对齐边界的空间,最后是模型权重。llama.cpp 和 LM Studio 等运行时仅读取头部指定的字节范围,忽略其他所有内容。下图展示了从第一个字节到文件末尾的 GGUF 文件结构,并标记了四个可隐藏数据的位置。顶行显示攻击者发布时的文件状态,底行显示使用 gguf-radar 重建后的文件状态。其中两个位置被真实恶意软件使用,将在本节中解释;另外两个位置是在实验室环境中复现的,将在第 4 节中介绍。
Where data can hide inside a GGUF file. Two places are used by real malware; gguf-radar cleans all four without changing the weights.
数据可以隐藏在 GGUF 文件中的位置。真正的恶意软件使用了两个地方;gguf-radar 在不改变权重的情况下清理了所有四个位置。
2.1 The Chat TemplateCopy Anchor Link
2.1 聊天模板复制锚点链接
The chat template is a small Jinja2 program stored under the metadata key tokenizer.chat_template. Before every reply, the runtime passes the conversation through it to build the exact text the model reads. C++ runtimes render it in a restricted engine with no Python behind it, so the classic template injection payloads that reach the operating system do not work there. Chat templates are not unique to GGUF: models in the Safetensors and PyTorch formats carry the same kind of template in a separate file, usually tokenizer_config.json or chat_template.jinja, so this half of the method applies to them too.
聊天模板是存储在元数据键 tokenizer.chat_template 下的一个小型 Jinja2 程序。在每次回复之前,运行时都会将对话通过该模板进行处理,以构建模型读取的确切文本。C++ 运行时在一个受限的引擎中渲染它,背后没有 Python,因此那些能够触及操作系统的经典模板注入载荷在那里不起作用。聊天模板并非 GGUF 独有:Safetensors 和 PyTorch 格式的模型也在单独的文件(通常是 tokenizer_config.json 或 chat_template.jinja)中携带相同类型的模板,因此该方法的一半也适用于它们。
The attacks found in this study do not need to escape that engine. They use ordinary template logic to add text to the conversation, and that text never appears in the chat window. In the timdedid models, a trigger phrase in the user's message makes the template insert a fake [SYSTEM DIRECTIVE] that orders an agent with shell access to download and run a script. In the Mir2k models, the template adds a system message telling the model to begin every answer with one PowerShell line, which a user may copy and run.
本研究中发现的攻击不需要逃逸出那个引擎。它们使用普通的模板逻辑向对话中添加文本,而这些文本永远不会出现在聊天窗口中。在 timdedid 模型中,用户消息中的触发短语会使模板插入一个伪造的 [SYSTEM DIRECTIVE],指示具有 shell 访问权限的代理下载并运行脚本。在 Mir2k 模型中,模板添加了一条系统消息,指示模型在每个回答的开头加上一行 PowerShell 代码,用户可能会复制并运行该行代码。
2.2 Bytes After the Last TensorCopy Anchor Link
2.2 最后一个张量之后的字节复制锚点链接
This half of the method is specific to GGUF. The header and tensor table define exactly where the model data ends: the start of the data section plus the end of the farthest tensor. Anything after that point is never read, so it does not change how the model loads or behaves, and no runtime warns about it. An attacker can append a whole executable there. Safetensors files do not allow this, because the safetensors loader refuses a file whose declared tensors do not fill it exactly.
该方法的一半是 GGUF 特有的。头部和张量表精确地定义了模型数据的结束位置:数据部分的起始位置加上最远张量的结束位置。在此点之后的任何内容都不会被读取,因此不会改变模型的加载方式或行为,也没有运行时会对此发出警告。攻击者可以在那里附加一个完整的可执行文件。Safetensors 文件不允许这样做,因为 safetensors 加载器会拒绝声明的张量未完全填充文件的请求。
Mir2k used two forms. Its first model carries a plain Windows program followed by about half a megabyte of filler, so a scanner that reads only the last few kilobytes sees nothing. Its second model carries the same program compressed with raw Deflate, which removes every recognizable file signature, while PowerShell can still decompress it in memory with IO.Compression.DeflateStream. The reply prefix from Section 2.1 is what connects the two halves: the printed line reads the hidden bytes back out of the model file on disk and starts them.
Mir2k 使用了两种形式。其第一个模型携带一个普通的 Windows 程序,后面跟着大约半兆字节的填充数据,因此只读取最后几千字节的扫描器什么也看不到。其第二个模型携带使用原始 Deflate 压缩的相同程序,这会移除所有可识别的文件签名,而 PowerShell 仍然可以使用 IO.Compression.DeflateStream 在内存中对其进行解压缩。第 2.1 节中的回复前缀是将这两部分连接起来的关键:打印的行从磁盘上的模型文件中读取隐藏的字节并将其启动。
2.3 Prior WorkCopy Anchor Link
2.3 先前工作复制锚点链接
Neither half of the method is new on its own. Pillar Security showed hidden instructions in GGUF chat templates in July 2025, and Fogel et al. (2026) measured the attack on 18 models and four inference engines, including trigger phrases that stay dormant until they appear and the hijacking of an agent's tool calls, the same pattern the timdedid template follows. Hiding malware inside a model file goes back to EvilModel (2021), which wrote it into the low bits of the weights. Those studies used test models in the lab. What this post adds is the method seen in real attacks on Hugging Face, and its combination by Mir2k with an executable appended after the last tensor and a template switched on days later, for which no earlier public report was found.
该方法的两部分单独来看都不新。Pillar Security 于 2025 年 7 月在 GGUF 聊天模板中展示了隐藏指令,Fogel 等人(2026)对 18 个模型和四个推理引擎进行了攻击测量,包括在出现前处于休眠状态的触发短语以及劫持智能体工具调用,这与 timdedid 模板遵循的模式相同。将恶意软件隐藏在模型文件中可追溯至 EvilModel(2021),它将恶意代码写入权重的低位。这些研究使用的是实验室中的测试模型。本文的贡献在于揭示了在 Hugging Face 真实攻击中看到的方法,以及 Mir2k 将其与附加在最后张量之后的可执行文件相结合,并在数天后激活模板的做法,此前未发现任何公开报告。
3. Scan Results Across 3.27 Million RepositoriesCopy Anchor Link
3. 跨 327 万个存储库的扫描结果复制锚点链接
The scan covered every public model repository on Hugging Face, including 226310 GGUF repositories holding 2.56 PB of weights, and parsed 572184 chat templates statically, without executing any of them. GGUF headers and file ends were read through HTTP Range requests, so no model was downloaded in full. Manual review removed security test repositories, harmless persona prompts and published research samples. Five repositories remained, all still online on 27 November. The table lists each one with its campaign, the method its template uses, how much of the payload could be examined, and its downloads:
扫描覆盖了 Hugging Face 上所有公共模型存储库,包括持有 2.56 PB 权重的 226310 个 GGUF 存储库,并静态解析了 572184 个聊天模板,未执行其中任何一个。通过 HTTP Range 请求读取 GGUF 头部和文件末尾,因此未完整下载任何模型。人工审查移除了安全测试存储库、无害的人设提示词和已发表的研究样本。剩余五个存储库截至 11 月 27 日仍在线。下表列出了每个存储库及其所属活动、模板使用的方法、可检查的有效载荷比例及其下载次数:
| Repository | Campaign | Method | Payload status | Downloads |
|---|---|---|---|---|
| Mir2k/Huihui-Qwen3.5-9B-abliterated-GGUF | Mir2k | Reply prefix with hidden executable | Recovered and analyzed | 1488 |
| Mir2k/Inkling-2-Mini-Uncensored-GGUF | Mir2k | Reply prefix with hidden compressed executable | Recovered and analyzed | 458 |
| timdedid/qwen3.8-cyber-uncensored | timdedid | Tool hijacking | Second stage not recovered | 271 |
| timdedid/qwen3-cyber-UNCENSORED-2 | timdedid | Tool hijacking | Second stage not recovered | 136 |
| timdedid/qwen3-cyber-UNCENSORED | timdedid | Tool hijacking | Second stage not recovered | 75 |
| Total | 2 actors | 2428 |
| 存储库 | 活动 | 方法 | 有效载荷状态 | 下载次数 |
|---|---|---|---|---|
| Mir2k/Huihui-Qwen3.5-9B-abliterated-GGUF | Mir2k | 带有隐藏可执行文件的回复前缀 | 已恢复并分析 | 1488 |
| Mir2k/Inkling-2-Mini-Uncensored-GGUF | Mir2k | 带有隐藏压缩可执行文件的回复前缀 | 已恢复并分析 | 458 |
| timdedid/qwen3.8-cyber-uncensored | timdedid | 工具劫持 | 第二阶段未恢复 | 271 |
| timdedid/qwen3-cyber-UNCENSORED-2 | timdedid | 工具劫持 | 第二阶段未恢复 | 136 |
| timdedid/qwen3-cyber-UNCENSORED | timdedid | 工具劫持 | 第二阶段未恢复 | 75 |
| 总计 | 2 名参与者 | 2428 |
At the time of the scan on 26 November the same repositories had 1502 downloads. The count grew by more than half in one day, almost entirely on the two Mir2k models.
在 11 月 26 日扫描时,这些存储库共有 1502 次下载。下载次数在一天内增长了超过一半,几乎全部来自两个 Mir2k 模型。
3.1 Campaign 1: Mir2k, Plant First and Arm LaterCopy Anchor Link
3.1 活动 1:Mir2k,先植入后武装复制锚点链接
Mir2k is a new Hugging Face account with French traces throughout: the model card of the first upload, the system prompt inside the template, the commit messages and the strings in the malware. On 22 November it created 14 repositories. Twelve of them are empty placeholders named after expected releases such as Qwen4-27B, DeepSeek-V4, Llama-4-Scout and gemma-4-27b, created in two automated bursts and ready to be filled when those models appear.
Mir2k 是一个带有法语痕迹的新 Hugging Face 账号:首次上传的模型卡片、模板内的系统提示词、提交信息以及恶意软件中的字符串均体现了这一点。11 月 22 日,该账号创建了 14 个仓库。其中 12 个是空占位符,以预期发布的模型命名,如 Qwen4-27B、DeepSeek-V4、Llama-4-Scout 和 gemma-4-27b,它们分两批自动化创建,待这些模型出现后即可填充内容。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力