Red-Teaming Coding Agents from a Tool-Invocation Perspective: An Empirical Security Assessment

📄 arXiv: 2509.05755v5 📥 PDF

作者: Yuchong Xie, Mingyu Luo, Zesen Liu, Zhixiang Zhang, Kaikai Zhang, Yu Liu, Zongjie Li, Ping Chen, Shuai Wang, Dongdong She

分类: cs.CR, cs.AI

发布日期: 2025-09-06 (更新: 2026-01-04)


💡 一句话要点

针对代码生成Agent工具调用环节的安全风险,提出ToolLeak漏洞和双通道注入攻击。

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码生成Agent 工具调用 安全漏洞 提示注入 远程代码执行 红队评估 ToolLeak LLM安全

📋 核心要点

  1. 现有代码生成Agent通过工具调用执行复杂任务,但工具调用环节存在严重安全风险,缺乏针对性的安全评估。
  2. 提出ToolLeak漏洞和双通道提示注入攻击,前者泄露系统提示,后者劫持工具调用,最终实现远程代码执行。
  3. 实验证明,该方法在多种Agent和LLM组合上成功实现提示泄露和远程代码执行,优于现有基线方法。

📝 摘要(中文)

本文对六种流行的代码生成Agent(Cursor, Claude Code, Copilot, Windsurf, Cline, Trae)进行了首次系统的红队评估,重点关注工具调用环节的安全风险。研究分两个阶段进行:第一阶段,通过提示泄露侦察恢复系统提示,发现了一种通用漏洞ToolLeak,该漏洞允许通过工具调用期间的良性参数检索恶意泄露提示。第二阶段,利用一种新颖的双通道提示注入(在工具描述和返回值中)劫持Agent的工具调用行为,实现远程代码执行(RCE)。通过在五个后端进行模拟,该方法在Claude-Sonnet-4、Claude-Sonnet-4.5、Grok-4和GPT-5上优于基线。在真实Agent上,该方法在25个Agent-LLM对中的19个上成功,并且在使用Claude和Grok后端的每个Agent上都实现了泄露。对于工具调用劫持,在每个测试的Agent-LLM对上都获得了RCE,并且双通道方法提供了最高的成功率。最后,提供了Cursor和Claude Code的案例研究,分析了外部和内置工具的安全防护措施,并提出了实际的防御建议。

🔬 方法详解

问题定义:论文旨在解决代码生成Agent中工具调用环节存在的安全漏洞问题。现有方法缺乏对该环节的系统性安全评估,使得攻击者可以利用工具调用机制进行恶意操作,例如泄露敏感信息或执行恶意代码。

核心思路:论文的核心思路是模拟攻击者的行为,通过红队评估的方式,发现并利用代码生成Agent在工具调用环节存在的漏洞。具体来说,通过提示泄露侦察获取系统提示,然后利用这些信息构造恶意payload,劫持Agent的工具调用行为。

技术框架:该研究分为两个阶段: 1. 提示泄露侦察(Phase 1):利用ToolLeak漏洞,通过构造特定的工具调用参数,诱导Agent泄露其系统提示。 2. 工具调用劫持(Phase 2):利用双通道提示注入,在工具描述和返回值中注入恶意payload,劫持Agent的工具调用行为,最终实现远程代码执行。

关键创新:论文的关键创新在于提出了ToolLeak漏洞和双通道提示注入攻击。ToolLeak漏洞是一种通用的提示泄露方法,可以应用于多种代码生成Agent。双通道提示注入攻击则是一种新颖的劫持工具调用行为的方法,可以绕过现有的安全防护措施。

关键设计: * ToolLeak漏洞:通过构造包含特定指令的工具调用参数,例如要求Agent返回其系统提示,从而实现提示泄露。 * 双通道提示注入:在工具描述和返回值中同时注入恶意payload,利用Agent对工具描述和返回值的信任,诱导其执行恶意代码。 * 自适应Payload构造:利用Phase 1中泄露的安全信息,自适应地构造Payload,提高攻击成功率。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,提出的ToolLeak漏洞和双通道提示注入攻击在多种代码生成Agent和LLM组合上均取得了成功。在真实Agent上,ToolLeak漏洞在使用Claude和Grok后端的每个Agent上都实现了泄露。对于工具调用劫持,在每个测试的Agent-LLM对上都获得了RCE,并且双通道方法提供了最高的成功率,显著优于基线方法。

🎯 应用场景

该研究成果可应用于提升代码生成Agent的安全性,例如用于安全审计、漏洞挖掘和安全防护。通过识别和修复工具调用环节的安全漏洞,可以有效防止恶意攻击,保护用户的代码和数据安全。此外,该研究还可以促进代码生成Agent安全标准的制定,推动行业健康发展。

📄 摘要(原文)

Coding agents powered by large language models are becoming central modules of modern IDEs, helping users perform complex tasks by invoking tools. While powerful, tool invocation opens a substantial attack surface. Prior work has demonstrated attacks against general-purpose and domain-specific agents, but none have focused on the security risks of tool invocation in coding agents. To fill this gap, we conduct the first systematic red-teaming of six popular real-world coding agents: Cursor, Claude Code, Copilot, Windsurf, Cline, and Trae. Our red-teaming proceeds in two phases. In Phase 1, we perform prompt leakage reconnaissance to recover system prompts. We discover a general vulnerability, ToolLeak, which allows malicious prompt exfiltration through benign argument retrieval during tool invocation. In Phase 2, we hijack the agent's tool-invocation behavior using a novel two-channel prompt injection in the tool description and return values, achieving remote code execution (RCE). We adaptively construct payloads using security information leaked in Phase 1. In emulation across five backends, our method outperforms baselines on Claude-Sonnet-4, Claude-Sonnet-4.5, Grok-4, and GPT-5. On real agents, our approach succeeds on 19 of 25 agent-LLM pairs, achieving leakage on every agent using Claude and Grok backends. For tool-invocation hijacking, we obtain RCE on every tested agent-LLM pair, with our two-channel method delivering the highest success rate. We provide case studies on Cursor and Claude Code, analyze security guardrails of external and built-in tools, and conclude with practical defense recommendations.