Skip to main content
QUICK REVIEW

[论文解读] DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructions

Fangzhou Wu, Xiaogeng Liu|arXiv (Cornell University)|Dec 7, 2023
Software Engineering Research被引用 6
一句话总结

DeceptPrompt 提出了一种新颖的对抗性攻击框架,通过生成具有欺骗性的自然语言指令,诱导代码大模型生成功能正确但存在漏洞的代码。该方法采用基于遗传进化的优化策略,并引入一种拆分控制损失函数,通过注入语义上看似无害的前缀/后缀,在保持语义一致性的前提下,成功在多个代码大模型中触发特定漏洞,使攻击成功率(ASR)平均提升50%。

ABSTRACT

With the advancement of Large Language Models (LLMs), significant progress has been made in code generation, enabling LLMs to transform natural language into programming code. These Code LLMs have been widely accepted by massive users and organizations. However, a dangerous nature is hidden in the code, which is the existence of fatal vulnerabilities. While some LLM providers have attempted to address these issues by aligning with human guidance, these efforts fall short of making Code LLMs practical and robust. Without a deep understanding of the performance of the LLMs under the practical worst cases, it would be concerning to apply them to various real-world applications. In this paper, we answer the critical issue: Are existing Code LLMs immune to generating vulnerable code? If not, what is the possible maximum severity of this issue in practical deployment scenarios? In this paper, we introduce DeceptPrompt, a novel algorithm that can generate adversarial natural language instructions that drive the Code LLMs to generate functionality correct code with vulnerabilities. DeceptPrompt is achieved through a systematic evolution-based algorithm with a fine grain loss design. The unique advantage of DeceptPrompt enables us to find natural prefix/suffix with totally benign and non-directional semantic meaning, meanwhile, having great power in inducing the Code LLMs to generate vulnerable code. This feature can enable us to conduct the almost-worstcase red-teaming on these LLMs in a real scenario, where users are using natural language. Our extensive experiments and analyses on DeceptPrompt not only validate the effectiveness of our approach but also shed light on the huge weakness of LLMs in the code generation task. When applying the optimized prefix/suffix, the attack success rate (ASR) will improve by average 50% compared with no prefix/suffix applying.

研究动机与目标

  • 探究代码大模型是否对保留语义意义但诱导产生漏洞代码的对抗性自然语言指令具有鲁棒性。
  • 开发一种实用的红队测试方法,模拟真实用户输入,以检验代码大模型在最坏情况下的安全行为。
  • 评估主流代码大模型(如 CodeLlama、WizardCoder)在语义上看似无害但经过恶意构造的提示下,生成漏洞代码的易感性。
  • 理解提示结构(如前缀/后缀位置、长度及群体规模)对对抗性提示攻击效果的影响。
  • 证明即使功能正确的代码,也可通过细微的自然语言操控系统性地引入关键安全漏洞。

提出的方法

  • DeceptPrompt 采用基于遗传进化的优化过程,生成语义上无害但能诱导目标代码大模型产生特定漏洞的对抗性自然语言前缀和后缀。
  • 提出一种新型的拆分控制损失函数,同时确保生成代码的功能正确性,并注入目标漏洞(如 CWE-79、CWE-200)。
  • 使用参考语言模型(GPT-2)评估困惑度,确保优化后的前缀在语义上连贯且不易被识别为对抗性输入。
  • 对关键超参数(如前缀/后缀长度、位置(前缀 vs. 后缀)、种群群体规模)进行消融实验,分析其对攻击成功率的影响。
  • 在多种代码大模型(包括 CodeLlama-7B、StarChat-15B 和 WizardCoder 变体)上评估该框架,覆盖多种漏洞目标和提示配置。
  • 通过使用纯自然语言指令的现实部署场景,避免依赖代码片段或软提示,以模拟实际用户交互。

实验结果

研究问题

  • RQ1代码大模型能否通过保留语义意义但具有欺骗性的对抗性自然语言指令,被诱导生成功能正确但存在漏洞的代码?
  • RQ2与不使用对抗性前缀/后缀的基线提示相比,DeceptPrompt 在提升攻击成功率(ASR)方面的有效性如何?
  • RQ3提示结构(如长度、位置(前缀 vs. 后缀)、群体规模)对对抗性攻击性能有何影响?
  • RQ4DeceptPrompt 生成的对抗性前缀是否在语义上保持连贯,并可通过困惑度等标准指标检测为非对抗性输入?
  • RQ5像 CodeLlama 和 WizardCoder 这类主流代码大模型,在不同漏洞类型(如 CWE-79、CWE-200)下,对这类攻击的易感程度如何?

主要发现

  • 与不使用对抗性前缀或后缀的基线提示相比,DeceptPrompt 将平均攻击成功率(ASR)提升了50%。
  • 当使用10-token的种子前缀模板时,DeceptPrompt 的 ASR 达到62.5%;使用6-token模板时降至55%,使用3-token模板时进一步降至35%,表明更长的模板可提升性能。
  • 将对抗性上下文置于后缀时,ASR 从62.5%降至52.5%,错误功能率(WFR)从0%升至5%,表明靠近任务描述的位置可增强攻击效果。
  • 当种群群体规模从100减少到64时,ASR 降至45%;进一步减少到40时,ASR 为42.5%,表明更大的搜索空间可提升优化成功率。
  • 优化后前缀的困惑度保持较低水平,表明 DeceptPrompt 在保持语义连贯性的同时,避免了被标准语言质量指标检测为异常。
  • 所有评估的代码大模型——CodeLlama-7B、StarChat-15B、WizardCoder-3B 和 WizardCoder-15B——均被成功攻击,揭示了此类对抗性提示攻击的广泛漏洞。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。