[Paper Review] An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong Detection
The paper introduces CodeBreaker, an LLM-assisted backdoor framework that injects disguised vulnerabilities into code completion models by transforming malicious payloads with GPT-4 to evade static and LLM-based vulnerability detection, enabling easy triggering during inference.
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.
Motivation & Objective
- Motivate and address the security risk of poisoning and backdoor attacks in fine-tuned code completion models.
- Propose an LLM-assisted backdoor framework (CodeBreaker) that embeds malicious payloads directly in code to evade strong detection.
- Enable easy triggering of insecure code generation during inference while preserving functionality of the payloads.
- Provide a comprehensive evaluation across static analysis tools, LLM-based detectors, and various trigger settings to assess evasion performance.
Proposed method
- Three-phase CodeBreaker framework: (1) LLM-assisted malicious payload crafting; (2) trigger embedding and code uploading to public corpora for poisoning; (3) fine-tuning targeted code completion models on poisoned data.
- Payload transformation (Phase I) uses GPT-4 to transform malicious code to bypass static analysis tools (Semgrep, Bandit, Snyk Code) via an evolutionary pipeline (Algorithm 1) that optimizes a fitness score combining AST distance and evasion success.
- Payload obfuscation (Phase II) further obfuscates transformed code to evade LLM-based vulnerability detectors (e.g., GPT-4) while preserving malicious functionality.
- Greedy, iterative process guided by static analysis pass/fail outcomes and AST-based distance to generate multiple transformed payloads with high evasion transferability.
- Poisoning post-processing consolidates snippets into adjacent lines, injects triggers at function starts, and prepares both “good” and “bad” poisoned samples for fine-tuning.
- Key techniques/equations include: (i) AST-based edit distance to quantify syntactic deviation; (ii) black-box evasion scoring against Semgrep, Bandit, Snyk Code, CodeQL, SonarCloud; (iii) GPT-4 prompts and role/instruction prompt design for code transformation; (iv) Phase II obfuscation leveraging LLMs to counter GPT-3.5-Turbo/4 and other detectors; (v) a two-phase transformation/obfuscation loop (Algorithm 1 and Algorithm 2) to maximize evasion.
Experimental results
Research questions
- RQ1Can an LLM-assisted backdoor attack embed vulnerabilities in code completion models that evade both static analyses and LLM-based detectors?
- RQ2How effectively can malicious payloads be transformed and obfuscated to remain functional while bypassing multiple vulnerability detection tools?
- RQ3What is the trade-off between payload stealthiness (AST distance) and evasion performance across different static and LLM-based detectors?
- RQ4How does CodeBreaker compare to prior poisoning attacks (Simple, Covert, TrojanPuzzle) in terms of evasion capability and triggering ease?
Key findings
- CodeBreaker can outperform prior attacks by evading static analysis tools and LLM-based detectors across multiple settings.
- The attack remains effective when triggered by any code or string triggers and does not rely solely on code comments for payload embedding.
- GPT-4 driven payload transformation consistently achieves higher pass rates against five static analysis tools than pre-selected transformations.
- Phase II obfuscation further reduces detection by LLM-based vulnerability detectors while preserving malicious functionality.
- An explicit case study shows direct-use of jinja2 vulnerability can be hidden via dynamic importing and base64 obfuscation, allowing evasions with small AST revision distances.
- There is a tunable trade-off between stealthiness (AST distance) and evasion effectiveness, with thresholds controlled in Algorithm 1/2 and shown in Appendix D.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.