Agent Against Agent: An Agentic System for Automatic Prompt Injection Red Teaming
不靠强化学习重新训练,靠写攻击笔记来持续变强的AI代理红队系统
PIMiner是一个自动寻找“提示注入”攻击的系统,这类攻击会把恶意指令偷偷藏进LLM代理读取的内容里。它不像强化学习方法那样为每个新目标重新训练攻击模型,而是把攻击经验积累成可复用的Markdown策略文件,无需重新训练就能迁移到未见过的目标模型上。在IPIArena和AgentDojo基准上,它达到了与最先进的强化学习方法相当的攻击成功率。
METAL MEDIA 解读图
PIMiner的四阶段攻击与学习流程
证据状态已报告实测结果
- 策略路由器针对每个新样本,只从不断增长的策略库中挑选最相关的前K个策略文件交给攻击者,而非加载全部内容,以此降低成本
- 迭代攻击模块结合长期策略、同一数据集内此前样本的经验、当前样本此前尝试的记录三种记忆,对注入提示进行最多10次迭代优化
- 经验整理器每轮结束后按攻击机制分析成功与失败的攻击案例,据此完善已有策略或新建策略文件,更新策略库
- 策略库记录目标模型适用范围、可用任务范围、注入模板、成功示例和已知失败条件的一组Markdown文件,无需重新训练即可迁移到未见过的模型
- 结果在IPIArena、AgentDojo和InjecAgent上,无需重新训练攻击者就达到了与最先进强化学习方法相当的攻击成功率
他们做了什么
- 提示注入攻击是把恶意指令藏在网页、搜索结果或工具返回结果等AI代理会读取的不可信文本中,诱使代理执行用户本意之外的操作。红队测试,即主动尝试攻击以发现漏洞,是构建防御手段的关键前提。
- 现有方法分两派:基于强化学习的攻击者效果好,但训练需要数万次查询,而且很难迁移到新的目标模型;基于搜索的攻击者(如PAIR、TAP)每个样本都从零开始尝试,无法复用以往经验,因此效果较差。
- PIMiner整合了策略路由器、迭代攻击模块和经验整理器三个部分。成功的攻击模式会被保存进一个策略库(一组Markdown文件),供后续攻击复用。记忆分三层:跨数据集和模型的长期策略库、同一数据集内的中期经验、当前样本此前尝试记录的短期记忆。
- 为避免每次都把不断增长的整个策略库塞进攻击模型的上下文,路由器只挑选最相关的前K个策略文件传给攻击者,从而降低成本。实验中路由器将攻击者的输入长度缩短了43%到61%,同时攻击成功率基本保持不变甚至略有提升。
- 在IPIArena和AgentDojo上针对GPT、Claude、Gemini、DeepSeek系列共9个前沿大模型进行测试,PIMiner对Gemini-2.5-Pro在IPIArena上达到76.2%的攻击成功率,在AgentDojo上达到86.7%;在InjecAgent基准上,它与最先进的强化学习方法(RL-Hammer、PISmith)打成平手,成功率均为1.0。

| Static | Search-Based | RL-Based | Agent-Based | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Model | Direct | Enhanced | TAP | PAIR | Strategy | GRPO | RL-Ham. | PISmith | PIMiner |
| GPT-4o-mini | 0.02 | 0.03 | 0.40 | 0.24 | 0.38 | 0.60 | 1.0 | 1.0 | 1.0 |
| GPT-4.1-nano | 0.01 | 0.02 | 0.54 | 0.32 | 0.65 | 0.75 | 1.0 | 1.0 | 1.0 |
| GPT-5-nano | 0.00 | 0.00 | 0.08 | 0.01 | 0.18 | 0.24 | 0.96 | 1.0 | 1.0 |
| Model | Direct | Ignore Prev. | Sys. Msg | Injecagent | Tool Know. | Imp. Instr. | PISmith | PIMiner |
|---|---|---|---|---|---|---|---|---|
| GPT-4o-mini | 0.03 | 0.06 | 0.03 | 0.04 | 0.12 | 0.23 | 0.78 | 0.73 |
| GPT-4.1-nano | 0.04 | 0.13 | 0.04 | 0.05 | 0.20 | 0.20 | 0.81 | 0.63 |
| GPT-5-nano | 0.02 | 0.00 | 0.01 | 0.00 | 0.01 | 0.01 | 0.38 | 0.53 |
| Benchmark | Domain | # Train | # Test |
|---|---|---|---|
| AgentDojo | Banking | 1 | 4 |
| Slack | 3 | 3 | |
| Travel | 6 | 6 | |
| Workspace | 10 | 17 | |
| Total | 20 | 30 | |
| IPIArena | Tool | 7 | 11 |
| Browser | 3 | 5 | |
| Coding | 10 | 5 | |
| Total | 20 | 21 |
| Section | Description | Consumer |
|---|---|---|
| Title & intro | One-line file description plus a 2–4 sentence summary of the attack mechanism, the target task domains it lands on, and how it differs from sibling strategies. | A/D |
| Target-LLM scope | Per-target verdicts: confirmed-effective, likely-effective, and not-shown-to-transfer (with run-dir citations), plus a one-line “use when” predicate. | R/A/D |
| Task scope | Which suites, injection-goal verbs (send_*, schedule_*, …), placeholder surface, and prerequisite conditions the strategy is known to apply to. | R/A/D |
| Mechanism distinction | 2–5 sentences contrasting the core structural move against each named sibling strategy, so the router can disambiguate superficially similar options. | A/D |
| Strategy template | The abstract recipe: numbered, named structural moves (not surface text) that every in-context example instantiates. | A/D |
| In-context examples | One block per confirmed hit: verbatim user task, injection goal, full polluted placeholder context, winning injection text, resulting tool call, and why it worked. | R/A/D |
| Fingerprint table | A compact, one-row-per-example view of the in-context examples | A/D |
| Failure conditions | Documented structural failure conditions (not “model refused”), and where possible cite a run-dir / sample that demonstrated the failure, used to steer miss-pattern analysis. | A/D |
| Iterative-attack init notes | Seed guidance for the inner attacker: iter-0 framing, iter-to-iter escalation, and failure-mode pivots. | A/D |
| Strategy | Description |
|---|---|
| Fabricated Procedure Gate | Impersonates an authoritative website or system protocol that presents the malicious tool call as a mandatory prerequisite before the agent can proceed. |
| Forged Chat Turn | Injects role-delimiter tokens to terminate the tool-output turn and fabricate a new user turn, causing the target to interpret the attacker’s directive as a legitimate user instruction. |
| Entity Data Poisoning | Embeds the attacker’s payload within a field explicitly requested by the user, making the malicious string load-bearing and encouraging provenance-aware models to reproduce it as part of an otherwise correct response. |
| Authenticated-Principal Voice Forge | Fabricates a continuation message from an already authenticated principal (or from the user), allowing the malicious directive to inherit an authority chain the target already trusts. |
| Appended Output Directive | Appends a forged “required answer format” instruction that coerces the model into emitting an attacker-chosen sentence in its final response. |
| Authority-Shed Docstring | Disguises the malicious payload as a structural element of the code (e.g., a docstring or helper definition) rather than an instruction, encouraging the model to treat it as inert program content instead of executable guidance. |
| False-History Forge | Fabricates an entire interaction history (user → assistant tool call → tool failure → user retry), framing the malicious tool invocation as a continuation of a previously authorized workflow rather than a new authorization request. |
| Component | Model | In (M) | Out (M) | Est. Cost ($) | Use Claude Code |
|---|---|---|---|---|---|
| Attacker | Opus 4.7 | ∼78.0 | ∼1.60 | ∼115 | Yes |
| Router | Opus 4.7 | ∼0.8 | ∼0.08 | ∼7 | Yes |
| Digester | Opus 4.7 | ∼0.48 | ∼0.12 | ∼5 | Yes |
| Target LLM | mixed | ∼7.9 | ∼0.65 | ∼20 | No |
研究结果
- 在IPIArena上,PIMiner对Gemini-2.5-Pro达到76.2%的ASR@10,对GPT-5.1达到61.9%,对Claude-Sonnet-4.5达到42.9%。
- 在AgentDojo上,对Gemini-2.5-Pro达到86.7%,对GPT-5.1达到53.3%,对Claude-Sonnet-4.5达到40.0%;而Claude-Opus-4.5的抗攻击能力远超其他模型,ASR仅为4.8%(IPIArena)和3.3%(AgentDojo)。
- 在InjecAgent基准上,PIMiner对GPT-4o-mini、GPT-4.1-nano、GPT-5-nano三个模型均达到ASR为1.0,与最好的强化学习方法(RL-Hammer、PISmith)持平,而基于搜索的PAIR和TAP在GPT-5-nano上分别只有1%和8%。
- 在AgentDojo上,PIMiner在GPT-5-nano上优于PISmith(53% vs 38%),在GPT-4o-mini上相当(73% vs 78%),在GPT-4.1-nano上略逊(63% vs 81%)——但PISmith需要为每个目标模型单独训练攻击者,而PIMiner是直接应用于训练阶段未见过的模型。
- 去掉路由器后,攻击者的输入长度在Claude-Haiku-4.5上增加了43%,在Claude-Sonnet-4.6上增加了61%,但攻击成功率并未因此明显提升(加入路由器后ASR仅下降1.2%或反而上升7.5%)。同时使用长期策略库和数据集内记忆,相比普通迭代攻击者,平均ASR提升了17.8到19.8个百分点。
可应用场景
- 在部署AI代理之前,以较低成本排查提示注入方面的安全漏洞
- 生成高质量的攻击数据,用于训练防护模型或改进主干大模型的对齐
- 持续性的红队测试工作流,面对新发布的目标模型时直接复用已有策略库,无需重新训练攻击者
- 每个样本只能进行有限次查询(例如10次)的黑盒评估场景
局限与待验证事项
- 面对防御能力特别强的模型(如Claude-Opus-4.5)时成功率仍然很低(4.8%和3.3%),说明该方法并非对所有目标都同样有效
- 训练阶段假设可以观察目标代理的中间输出(灰盒访问),这一假设主要适用于开源或公开中间过程的代理,而非完全封闭的系统
- 策略库中部分策略(如Authority Shed Docstring、False History Forge)仅有一个示例支撑,其在更多模型上的泛化能力尚不清楚
- 评测仅限于IPIArena、AgentDojo、InjecAgent这几个基准以及训练中使用的八组数据集-模型组合,在完全不同类型的代理或任务领域上的表现尚未验证
- 论文中约20美元的训练成本估算基于拥有Claude Code订阅套餐的前提,若纯按API调用计费,成本结构可能明显不同
为什么重要
各公司在部署AI代理之前都需要排查提示注入漏洞,并收集数据来训练更强的防御模型,但现有方法成本高昂且难以迁移到新模型。像PIMiner这样把经验沉淀为可复用知识而非每次重新训练的方法,能让这类安全测试变得更便宜、更容易规模化开展。
本文术语
- 提示注入 · 把恶意指令藏进AI代理会读取的文本(网页、工具返回结果等)中,以此操纵代理行为的攻击方式
- 红队测试 · 主动扮演攻击者去测试系统,以便在真正的攻击者之前发现漏洞
- 基于强化学习的攻击 · 通过奖励反馈反复训练攻击模型,使其生成越来越有效的攻击
- 攻击成功率(ASR) · 尝试的攻击中实际成功的比例;ASR@N表示在N次尝试内只要有一次成功就算成功
- 策略库 · 记录成功攻击模式、适用范围和示例的一组Markdown文件,供后续攻击复用
论文原文摘要(英文)
Prompt injection poses significant security risks to LLM agents. Efficient and effective red-teaming is therefore critical, both for evaluating these risks and for collecting training data to improve defenses. Existing state-of-the-art prompt injection red-teaming methods primarily rely on reinforcement learning (RL), producing attacker models that often generalize poorly to new target LLMs. In this work, we develop PIMiner, an agentic system for prompt injection red-teaming. During training, PI
在 arXiv 阅读最新论文
- SWE-bench Science: Can Coding Agents Resolve Engineering Tasks in Science?让AI编程助手去修复真实科学软件,连最强的那个也有一半以上任务没做对
- FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving把稀疏注意力从论文原型变成能真正上线服务的加速方案
- PolicyGuide: From Guarding One Action to Guiding the Whole Workflow for Policy-Compliant LLM Agents让客服AI坐席不只是拦住一个危险动作,而是把整个流程走对
- EXIMO: VLM Guided Exploration of VLA Policies不用人工遥控演示,让会说话的AI来教机械臂做新家务
- EnvHarness: Awakening Static Worlds for Agent Learning不重新搭建训练环境,而是给现有环境套一层可插拔组件,针对每个智能体的具体弱点重新塑形
- Bounded Sovereignty and the Control Tax: Pricing AI Oversight When the Deployer Does Not Own the Model租用AI而非拥有AI的机构,安全监管能力只剩一半
- Beyond Imitation: Filtering On-Policy Distillation by Reasoning ProgressAI模仿老师模型学习时,会误伤本来推理正确的步骤,新方法专门过滤掉这种误伤
- PersonalBench: Measuring the Authorship Gap in LLM Personalization让AI模仿某人的文风,结果发现它始终摆脱不了自己的腔调
METAL MEDIA 最新报道
图片来源: Yanting Wang et al., arXiv:2608.05108, CC BY 4.0