[论文解读] An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong Detection
本论文提出 CodeBreaker,一种由 LLM 辅助的后门框架,通过将恶意载荷用 GPT-4 转换以规避静态分析和基于 LLM 的漏洞检测,从而在推理阶段更易触发。
Large Language Models (LLMs) have transformed code completion tasks, providing context-based suggestions to boost developer productivity in software engineering. As users often fine-tune these models for specific applications, poisoning and backdoor attacks can covertly alter the model outputs. To address this critical security challenge, we introduce CodeBreaker, a pioneering LLM-assisted backdoor attack framework on code completion models. Unlike recent attacks that embed malicious payloads in detectable or irrelevant sections of the code (e.g., comments), CodeBreaker leverages LLMs (e.g., GPT-4) for sophisticated payload transformation (without affecting functionalities), ensuring that both the poisoned data for fine-tuning and generated code can evade strong vulnerability detection. CodeBreaker stands out with its comprehensive coverage of vulnerabilities, making it the first to provide such an extensive set for evaluation. Our extensive experimental evaluations and user studies underline the strong attack performance of CodeBreaker across various settings, validating its superiority over existing approaches. By integrating malicious payloads directly into the source code with minimal transformation, CodeBreaker challenges current security measures, underscoring the critical need for more robust defenses for code completion.
研究动机与目标
- 动机并解决在微调的代码补全模型中发生污染和后门攻击的安全风险。
- 提出一个 LLM 辅助的后门框架(CodeBreaker),直接将恶意载荷嵌入到代码中以规避强检测。
- 在推断阶段实现对不安全代码生成的容易触发,同时保持载荷的功能性。
- 提供对静态分析工具、基于 LLM 的检测器以及不同触发设置的全面评估,以评估规避性能。
提出的方法
- 三阶段 CodeBreaker 框架:(1) LLM 辅助的恶意载荷制作;(2) 触发嵌入和将代码上传到公共语料库以进行污染;(3) 在污染数据上对目标代码补全模型进行微调。
- Payload transformation (Phase I) 使用 GPT-4 将恶意代码转换为绕过静态分析工具(Semgrep、Bandit、Snyk Code)的变异管线(算法 1),该管线通过优化一个结合 AST 距离与规避成功的适应度分数来实现。
- Payload obfuscation (Phase II) 进一步对转换后的代码进行混淆,以在保留恶意功能的同时规避基于 LLM 的漏洞检测器(如 GPT-4)。
- Greedy、迭代式过程,在静态分析通过/未通过结果与基于 AST 的距离引导下,生成具有高规避可迁移性的多种转换载荷。
- Poisoning 后处理将片段整合到相邻行、在函数起始处注入触发器,并为微调准备“良好”和“坏的”污染样本。
- 关键技术/方程包括:(i) 基于 AST 的编辑距离以量化语法偏离;(ii) 针对 Semgrep、Bandit、Snyk Code、CodeQL、SonarCloud 的黑盒规避评分;(iii) 使用 GPT-4 提示词与代码转换的角色/指令提示设计;(iv) Phase II 混淆利用 LLM 对抗 GPT-3.5-Turbo/4 及其他检测器;(v) 为最大化规避性而设计的两阶段变换/混淆循环(算法 1 与算法 2)。
实验结果
研究问题
- RQ1LLM 辅助的后门攻击是否能够在静态分析和基于 LLM 的检测器下规避漏洞嵌入?
- RQ2恶意载荷如何经过变换与混淆在保持功能性的同时绕过多种漏洞检测工具?
- RQ3载荷的隐蔽性(AST 距离)与规避性能在不同静态和基于 LLM 的检测器之间的权衡?
- RQ4CodeBreaker 与先前的污染攻击(Simple、Covert、TrojanPuzzle)在规避能力和触发易用性方面有何差异?
主要发现
- CodeBreaker 能在多种设置下超越先前攻击,规避静态分析工具和基于 LLM 的检测器。
- 当通过任何代码或字符串触发器触发时,该攻击依然有效,并且不仅依赖代码注释来嵌入载荷。
- GPT-4 驱动的载荷转换在对五个静态分析工具的通过率方面始终高于事先选定的转换。
- Phase II 的混淆进一步降低了对基于 LLM 的漏洞检测器的检测率,同时保留恶意功能。
- 一个明确的案例研究显示,直接使用的 jinja2 漏洞可以通过动态导入和 base64 混淆来隐藏,从而通过较小的 AST 修订距离实现规避。
- 在隐蔽性(AST 距离)与规避效果之间存在可调的权衡,该阈值在 Algorithm 1/2 中控制,并在附录 D 中给出。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。