通过结构化模板注入,自动劫持大模型代理,提升攻击成功率与跨模型适用性。
Automating Agent Hijacking via Structural Template Injection
- 利用结构化模板注入,诱导代理误判恶意指令为合法输入。
- 在多个模型上实现超90%攻击成功率,查询效率显著优于基线。
- 适用于安全研究者与模型开发者,揭示真实商业系统漏洞。
代理劫持被OWASP列为大语言模型生态系统的重大威胁,攻击者可通过向检索内容中注入恶意指令来操控执行流程。现有攻击多依赖人工设计的语义驱动提示操纵,成功率低且难以迁移至闭源商业模型。本文提出Phantom框架,基于结构化模板注入,针对大模型代理的基础架构机制进行自动化攻击。核心思路是:代理依赖特定聊天模板标记区分系统、用户、助手和工具指令。通过在检索上下文中注入优化后的结构化模板,引发角色混淆,使代理将恶意内容误认为合法用户指令或先前工具输出。为增强对黑盒代理的攻击迁移能力,Phantom引入新型模板搜索框架:先进行多层级模板增强以增加结构多样性,再训练模板自编码器(TAE)将离散模板映射至连续可搜索的潜在空间,最后使用贝叶斯优化高效定位解码为高攻击效力模板的对抗向量。在Qwen、GPT和Gemini上的大量实验表明,该框架在攻击成功率(ASR)和查询效率方面均显著优于现有基线。此外,我们识别出超过70个真实商业产品中的漏洞,已获厂商确认,凸显结构化模板劫持的实际危害,并为下一代智能体系统的安全防护提供实证基础。
原文摘要 · Abstract (English)
Agent hijacking, highlighted by OWASP as a critical threat to the Large Language Model (LLM) ecosystem, enables adversaries to manipulate execution by injecting malicious instructions into retrieved content. Most existing attacks rely on manually crafted, semantics-driven prompt manipulation, which often yields low attack success rates and limited transferability to closed-source commercial models. In this paper, we propose Phantom, an automated agent hijacking framework built upon Structured Template Injection that targets the fundamental architectural mechanisms of LLM agents. Our key insight is that agents rely on specific chat template tokens to separate system, user, assistant, and tool instructions. By injecting optimized structured templates into the retrieved context, we induce role confusion and cause the agent to misinterpret the injected content as legitimate user instructions or prior tool outputs. To enhance attack transferability against black-box agents, Phantom introduces a novel attack template search framework. We first perform multi-level template augmentation to increase structural diversity and then train a Template Autoencoder (TAE) to embed discrete templates into a continuous, searchable latent space. Subsequently, we apply Bayesian optimization to efficiently identify optimal adversarial vectors that are decoded into high-potency structured templates. Extensive experiments on Qwen, GPT, and Gemini demonstrate that our framework significantly outperforms existing baselines in both Attack Success Rate (ASR) and query efficiency. Moreover, we identified over 70 vulnerabilities in real-world commercial products that have been confirmed by vendors, underscoring the practical severity of structured template-based hijacking and providing an empirical foundation for securing next-generation agentic systems.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。