arXiv:2507.22063cs.SEcs.AI2025-07ACL被引 9

用多轮对话自动诱骗代码大模型生成漏洞代码,提升安全测试效率。

RedCoder: Automated Multi-Turn Red Teaming for Code LLMs

  • 构建多智能体博弈流程生成攻击策略和对话模板。
  • 在多个代码大模型上诱导出更多漏洞,效果优于单轮和旧多轮方法。
  • 适合安全研究人员评估代码生成模型的防御能力。

用于代码生成的大语言模型(代码大模型)在辅助软件开发与测试中表现优异,但研究显示其在对抗性场景下可能生成存在漏洞甚至恶意的代码。现有红队测试方法高度依赖人工,难以扩展,且忽视真实编程中常见的多轮交互特性。为此,我们提出 RedCoder,一种可与目标模型进行多轮对话的红队代理,旨在诱发漏洞代码生成。该系统通过多智能体博弈过程模拟对抗交互,生成原型对话与可复用攻击策略;随后在这些数据上微调大模型作为核心引擎。部署后,RedCoder能自主与代码大模型展开多轮对话,并动态调用策略库中的方法引导对话朝漏洞输出方向发展。在多个代码大模型上的实验表明,该方法在诱发漏洞方面优于以往单轮及多轮红队方法,提供了一种可扩展、高效的代码生成系统安全评估工具。

原文摘要 · Abstract (English)

Large Language Models (LLMs) for code generation (i.e., Code LLMs) have demonstrated impressive capabilities in AI-assisted software development and testing. However, recent studies have shown that these models are prone to generating vulnerable or even malicious code under adversarial settings. Existing red-teaming approaches rely on extensive human effort, limiting their scalability and practicality, and generally overlook the interactive nature of real-world AI-assisted programming, which often unfolds over multiple turns. To bridge these gaps, we present RedCoder, a red-teaming agent that engages victim models in multi-turn conversation to elicit vulnerable code. The pipeline to construct RedCoder begins with a multi-agent gaming process that simulates adversarial interactions, yielding a set of prototype conversations and an arsenal of reusable attack strategies. We then fine-tune an LLM on these prototype conversations to serve as the backbone of RedCoder. Once deployed, RedCoder autonomously engages Code LLMs in multi-turn conversations, dynamically retrieving relevant strategies from the arsenal to steer the dialogue toward vulnerability-inducing outputs. Experiments across multiple Code LLMs show that our approach outperforms prior single-turn and multi-turn red-team methods in inducing vulnerabilities in code generation, offering a scalable and effective tool for evaluating the security boundaries of modern code-generation systems.

代码安全红队测试多轮对话大模型评估

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。