arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.02509cs.CRcs.LGcs.PLcs.SE
收藏

针对基于大语言模型的代码补全的黑盒对抗攻击

Black-Box Adversarial Attacks on LLM-Based Code Completion

Department of Computer Science, ETH Zurich, Switzerland(计算机科学系,苏黎世联邦理工学院)

Slobodan Jenko, Niels Mündler, Jingxuan He, Mark Vero, Martin Vechev

AI总结:

本研究提出名为INSEC的黑盒对抗攻击方法,通过注入优化生成的注释字符串提升LLM代码补全的不安全代码生成率,在多模型和商业服务上验证了有效性与实用性。

摘要:

现代代码补全引擎由大语言模型(LLM)驱动,凭借其生成功能正确代码的强大能力为数百万开发者提供协助。鉴于其普及性,研究依赖基于LLM的代码补全的安全影响至关重要。在本研究中,我们证明了当前最先进的黑盒基于LLM的代码补全引擎可被攻击者隐秘地施加偏向,从而大幅提升其生成不安全代码的概率。我们提出了首个实现该目标的攻击方法,名为INSEC。INSEC的工作原理是将攻击字符串作为短注释注入到补全输入中。该攻击字符串通过基于查询的优化过程生成,优化过程从一组精心设计的初始化方案启动。我们通过在多种当前最先进的开源模型及黑盒商业服务(例如OpenAI API和GitHub Copilot)上进行评估,证明了INSEC的广泛适用性和有效性。在一组多样化的安全关键测试用例中(涵盖5种编程语言的16个CWE),INSEC将生成不安全代码的概率提升了50%以上,同时保持了生成代码的功能正确性。我们认为INSEC具备实用性——它所需资源少,在商用硬件上开发的成本不到10美元。此外,我们通过开发一款能将INSEC隐秘注入GitHub Copilot扩展的IDE插件,展示了该攻击在真实场景中的可部署性。

英文摘要:

Modern code completion engines, powered by large language models (LLMs), assist millions of developers with their strong capabilities to generate functionally correct code. Due to this popularity, it is crucial to investigate the security implications of relying on LLM-based code completion. In this work, we demonstrate that state-of-the-art black-box LLM-based code completion engines can be stealthily biased by adversaries to significantly increase their rate of insecure code generation. We present the first attack, named INSEC, that achieves this goal. INSEC works by injecting an attack string as a short comment in the completion input. The attack string is crafted through a query-based optimization procedure starting from a set of carefully designed initialization schemes. We demonstrate INSEC's broad applicability and effectiveness by evaluating it on various state-of-the-art open-source models and black-box commercial services (e.g., OpenAI API and GitHub Copilot). On a diverse set of security-critical test cases, covering 16 CWEs across 5 programming languages, INSEC increases the rate of generated insecure code by more than 50%, while maintaining the functional correctness of generated code. We consider INSEC practical -- it requires low resources and costs less than 10 US dollars to develop on commodity hardware. Moreover, we showcase the attack's real-world deployability, by developing an IDE plug-in that stealthily injects INSEC into the GitHub Copilot extension.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑