GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400 Victims

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

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.

本地大语言模型通常以 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 日对 Hugging Face 上所有 3,273,389 个公共模型仓库进行的扫描发现,截至 11 月 27 日,共有 5 个恶意 GGUF 模型,下载量为 2,428 次。Hugging Face 统计的是下载次数而非人数,因此受影响的用户数量应小于或等于该数值。规模最大的 Mir2k 活动上传了两个未经审查的 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 节中进行了说明。

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 文件。仅查看文件最后几千字节的杀毒引擎和检查程序无法发现压缩后的有效载荷。

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 节中进行了介绍。

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 命令,用户可能会复制并运行该命令。

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 节中的回复前缀是将这两部分连接起来的关键:打印出的那行代码会从磁盘上的模型文件中读取隐藏的字节并启动它们。

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 将其与附加在最后一个张量之后的可执行文件相结合,并在数天后激活模板的手段,此前未见相关公开报道。

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 上的所有公共模型仓库,包括 226,310 个总计 2.56 PB 权重的 GGUF 仓库,并静态解析了 572,184 个聊天模板,且未执行其中任何一个。GGUF 头部和文件末尾是通过 HTTP Range 请求读取的,因此没有完整下载任何模型。人工审核剔除了安全测试仓库、无害的角色提示词和已发表的研究样本。最终剩下 5 个仓库,截至 11 月 27 日均仍在线。下表列出了每个仓库所属的活动、其模板使用的方法、可检查的有效载荷量及其下载量:

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 日扫描时,这些仓库的下载量为 1,502 次。仅一天时间,下载量就增长了一半以上,几乎全部集中在两个 Mir2k 模型上。

Mir2k is a new Hugging

Mir2k 是一个新的 Hugging