ChatInject: Abusing Chat Templates for Prompt Injection in LLM Agents

📄 arXiv: 2509.22830v2 📥 PDF

作者: Hwan Chang, Yonghyun Jun, Hwanhee Lee

分类: cs.CL

发布日期: 2025-09-26 (更新: 2026-01-30)

备注: ICLR 2026


💡 一句话要点

ChatInject:利用聊天模板在LLM Agent中进行提示注入攻击

🎯 匹配领域: 支柱一:机器人控制 (Robot Control) 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 提示注入 LLM Agent 聊天模板 多轮对话 安全漏洞

📋 核心要点

  1. 现有方法主要关注纯文本提示注入,忽略了LLM对结构化聊天模板的依赖性,这为攻击者提供了新的可乘之机。
  2. ChatInject攻击通过构造模仿原生聊天模板的恶意payload,诱导LLM Agent执行恶意指令,实现更高的攻击成功率。
  3. 实验表明,ChatInject攻击具有很强的跨模型迁移性,且能有效绕过现有的基于提示的防御机制,对Agent系统构成严重威胁。

📝 摘要(中文)

基于大型语言模型(LLM)的Agent与外部环境交互的日益普及,为对抗性操纵创造了新的攻击面。一个主要的威胁是间接提示注入,攻击者将恶意指令嵌入到外部环境的输出中,导致Agent将其解释并执行为合法的提示。先前的研究主要集中在纯文本注入攻击上,而我们发现了一个重要但未被充分探索的漏洞:LLM对结构化聊天模板的依赖以及它们通过有说服力的多轮对话进行上下文操纵的敏感性。为此,我们引入了ChatInject,一种将恶意payload格式化为模仿原生聊天模板的攻击,从而利用模型固有的指令遵循倾向。在此基础上,我们开发了一种说服驱动的多轮变体,通过对话轮次来启动Agent,使其接受并执行原本可疑的操作。通过对前沿LLM的全面实验,我们证明了三个关键发现:(1)ChatInject实现了比传统提示注入方法显著更高的平均攻击成功率,在AgentDojo上从5.18%提高到32.05%,在InjecAgent上从15.13%提高到45.90%,多轮对话在InjecAgent上表现出特别强的性能,平均成功率为52.33%。(2)基于聊天模板的payload表现出强大的跨模型迁移性,并且即使对于闭源LLM仍然有效,尽管它们的模板结构未知。(3)现有的基于提示的防御措施对这种攻击方法在很大程度上无效,特别是对多轮变体。这些发现突出了当前Agent系统中的漏洞。

🔬 方法详解

问题定义:论文旨在解决LLM Agent中存在的间接提示注入漏洞,特别是利用LLM对聊天模板的依赖性进行攻击的问题。现有方法主要关注纯文本注入,忽略了LLM在多轮对话中对上下文的敏感性,以及利用聊天模板进行攻击的可能性。

核心思路:论文的核心思路是利用LLM对聊天模板的固有信任,构造恶意payload,使其看起来像是合法的用户输入或系统指令。通过模仿聊天模板的结构,攻击者可以更容易地诱导LLM Agent执行恶意操作。此外,通过多轮对话,逐步引导Agent接受并执行恶意指令,提高攻击的成功率。

技术框架:ChatInject攻击主要包含两个阶段:Payload构造和多轮对话诱导。Payload构造阶段,攻击者根据目标LLM的聊天模板(如果已知)或通过试错,构造模仿聊天模板的恶意payload。多轮对话诱导阶段,攻击者通过多轮对话,逐步引导Agent接受并执行恶意指令,例如,先让Agent执行一些无害的任务,然后逐渐引入恶意指令,最终控制Agent。

关键创新:论文的关键创新在于发现了LLM Agent对聊天模板的依赖性,并提出了利用这种依赖性进行提示注入攻击的方法。与传统的纯文本注入攻击相比,ChatInject攻击更具隐蔽性和有效性,能够绕过现有的防御机制。此外,多轮对话诱导策略进一步提高了攻击的成功率。

关键设计:ChatInject攻击的关键设计包括:(1) 聊天模板模仿:攻击者需要尽可能准确地模仿目标LLM的聊天模板,包括角色名称、分隔符等。(2) 多轮对话策略:攻击者需要设计合理的对话流程,逐步引导Agent接受并执行恶意指令,避免引起Agent的怀疑。(3) Payload选择:攻击者需要选择合适的恶意指令,使其能够实现攻击目标,例如,读取敏感信息、执行恶意代码等。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,ChatInject攻击在AgentDojo和InjecAgent上的平均攻击成功率分别从5.18%提高到32.05%和从15.13%提高到45.90%。多轮对话变体在InjecAgent上取得了52.33%的平均成功率。此外,实验还表明,ChatInject攻击具有很强的跨模型迁移性,并且能够有效绕过现有的基于提示的防御机制。

🎯 应用场景

该研究成果可应用于评估和提升LLM Agent的安全性,帮助开发者识别和修复潜在的提示注入漏洞。此外,该研究也为开发更有效的防御机制提供了思路,例如,通过检测和过滤恶意payload,或者通过增强LLM对上下文的理解能力,提高其对提示注入攻击的抵抗力。该研究对于构建安全可靠的LLM Agent系统具有重要意义。

📄 摘要(原文)

The growing deployment of large language model (LLM) based agents that interact with external environments has created new attack surfaces for adversarial manipulation. One major threat is indirect prompt injection, where attackers embed malicious instructions in external environment output, causing agents to interpret and execute them as if they were legitimate prompts. While previous research has focused primarily on plain-text injection attacks, we find a significant yet underexplored vulnerability: LLMs' dependence on structured chat templates and their susceptibility to contextual manipulation through persuasive multi-turn dialogues. To this end, we introduce ChatInject, an attack that formats malicious payloads to mimic native chat templates, thereby exploiting the model's inherent instruction-following tendencies. Building on this foundation, we develop a persuasion-driven Multi-turn variant that primes the agent across conversational turns to accept and execute otherwise suspicious actions. Through comprehensive experiments across frontier LLMs, we demonstrate three critical findings: (1) ChatInject achieves significantly higher average attack success rates than traditional prompt injection methods, improving from 5.18% to 32.05% on AgentDojo and from 15.13% to 45.90% on InjecAgent, with multi-turn dialogues showing particularly strong performance at average 52.33% success rate on InjecAgent, (2) chat-template-based payloads demonstrate strong transferability across models and remain effective even against closed-source LLMs, despite their unknown template structures, and (3) existing prompt-based defenses are largely ineffective against this attack approach, especially against Multi-turn variants. These findings highlight vulnerabilities in current agent systems.