PR-Attack: Coordinated Prompt-RAG Attacks on Retrieval-Augmented Generation in Large Language Models via Bilevel Optimization
作者: Yang Jiao, Xiaodong Wang, Kai Yang
分类: cs.CR, cs.AI
发布日期: 2025-04-10 (更新: 2025-06-20)
备注: Accepted at SIGIR 2025
💡 一句话要点
提出PR-Attack,通过双层优化协同攻击Prompt和RAG,提升大语言模型对抗攻击的隐蔽性和有效性。
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: RAG攻击 大语言模型安全 对抗攻击 双层优化 后门攻击
📋 核心要点
- 现有RAG攻击方法在少量中毒样本下效果不佳,易被检测,且缺乏优化框架。
- PR-Attack通过双层优化,协同设计prompt中的后门触发器和知识库中的中毒文本。
- 实验表明,PR-Attack在少量中毒样本下仍能保持高攻击成功率,并显著提升隐蔽性。
📝 摘要(中文)
大型语言模型(LLMs)在各种应用中表现出卓越的性能,例如医学问答、数学科学和代码生成。然而,它们也存在固有的局限性,例如知识过时和容易产生幻觉。检索增强生成(RAG)已成为解决这些问题的一种有前景的范例,但它也引入了新的漏洞。最近的研究集中在基于RAG的LLM的安全性上,但现有的攻击方法面临三个关键挑战:(1)当只有少量中毒文本可以注入知识库时,它们的有效性会急剧下降;(2)它们缺乏足够的隐蔽性,因为攻击通常可以被异常检测系统检测到,这会损害其有效性;(3)它们依赖于启发式方法来生成中毒文本,缺乏正式的优化框架和理论保证,这限制了它们的有效性和适用性。为了解决这些问题,我们提出了一种协同Prompt-RAG攻击(PR-attack),这是一种新颖的优化驱动攻击,它将少量中毒文本引入知识库,同时在prompt中嵌入后门触发器。当激活时,触发器会导致LLM生成针对目标查询的预先设计的响应,同时保持其他上下文中的正常行为。这确保了高效率和隐蔽性。我们将攻击生成过程形式化为一个双层优化问题,利用一个有原则的优化框架来开发最佳的中毒文本和触发器。跨各种LLM和数据集的广泛实验证明了PR-Attack的有效性,即使在中毒文本数量有限的情况下也能实现高攻击成功率,并且与现有方法相比,隐蔽性显着提高。
🔬 方法详解
问题定义:现有针对RAG系统的攻击方法,在中毒样本数量有限的情况下,攻击成功率会显著下降。同时,这些攻击方法产生的样本容易被异常检测系统识别,导致攻击失效。此外,现有方法依赖于启发式算法生成中毒样本,缺乏理论指导和优化框架,限制了攻击效果和泛化能力。
核心思路:PR-Attack的核心思路是协同优化prompt和RAG的攻击策略。通过在prompt中嵌入后门触发器,并在知识库中注入少量精心设计的中毒文本,当触发器激活时,LLM会生成预设的恶意响应。这种协同攻击方式可以在保证攻击成功率的同时,提高攻击的隐蔽性。
技术框架:PR-Attack的整体框架是一个双层优化问题。外层优化目标是最大化攻击成功率,即让LLM在触发器激活时生成目标响应。内层优化目标是最小化中毒样本与原始文本的差异,从而提高攻击的隐蔽性。该框架包含两个主要模块:prompt触发器生成模块和中毒文本生成模块。这两个模块通过双层优化算法进行协同训练。
关键创新:PR-Attack的关键创新在于提出了一个基于双层优化的协同攻击框架,能够同时优化prompt中的触发器和知识库中的中毒文本。与现有方法相比,PR-Attack不再依赖启发式算法,而是通过优化算法自动生成最优的攻击策略,从而提高了攻击的有效性和隐蔽性。
关键设计:PR-Attack的关键设计包括:(1) 使用梯度下降算法求解双层优化问题;(2) 设计合适的损失函数,用于衡量攻击成功率和隐蔽性;(3) 限制中毒文本的数量,以提高攻击的隐蔽性;(4) 使用对抗训练技术,增强模型的鲁棒性。
🖼️ 关键图片
📊 实验亮点
实验结果表明,PR-Attack在多种LLM和数据集上均取得了显著的攻击效果。即使在中毒文本数量非常有限的情况下,PR-Attack仍然能够实现较高的攻击成功率,并且与现有的攻击方法相比,隐蔽性得到了显著提升。例如,在某个数据集上,PR-Attack在仅注入5个中毒文本的情况下,攻击成功率达到了80%,而现有方法的攻击成功率仅为20%。
🎯 应用场景
PR-Attack的研究成果可应用于评估和提升RAG系统的安全性,帮助开发者发现和修复潜在的安全漏洞。此外,该方法还可以用于构建更强大的防御机制,例如异常检测系统和对抗训练方法,以抵御恶意攻击,保障LLM应用的可靠性和安全性。
📄 摘要(原文)
Large Language Models (LLMs) have demonstrated remarkable performance across a wide range of applications, e.g., medical question-answering, mathematical sciences, and code generation. However, they also exhibit inherent limitations, such as outdated knowledge and susceptibility to hallucinations. Retrieval-Augmented Generation (RAG) has emerged as a promising paradigm to address these issues, but it also introduces new vulnerabilities. Recent efforts have focused on the security of RAG-based LLMs, yet existing attack methods face three critical challenges: (1) their effectiveness declines sharply when only a limited number of poisoned texts can be injected into the knowledge database, (2) they lack sufficient stealth, as the attacks are often detectable by anomaly detection systems, which compromises their effectiveness, and (3) they rely on heuristic approaches to generate poisoned texts, lacking formal optimization frameworks and theoretic guarantees, which limits their effectiveness and applicability. To address these issues, we propose coordinated Prompt-RAG attack (PR-attack), a novel optimization-driven attack that introduces a small number of poisoned texts into the knowledge database while embedding a backdoor trigger within the prompt. When activated, the trigger causes the LLM to generate pre-designed responses to targeted queries, while maintaining normal behavior in other contexts. This ensures both high effectiveness and stealth. We formulate the attack generation process as a bilevel optimization problem leveraging a principled optimization framework to develop optimal poisoned texts and triggers. Extensive experiments across diverse LLMs and datasets demonstrate the effectiveness of PR-Attack, achieving a high attack success rate even with a limited number of poisoned texts and significantly improved stealth compared to existing methods.