Explicit Vulnerability Generation with LLMs: An Investigation Beyond Adversarial Attacks
Emir Bosnak, Sahand Moslemi, Mayasah Lami, Anil Koyuncu

TL;DR
This study investigates how open-source Large Language Models can be prompted to generate insecure code, revealing their tendencies, strengths, and weaknesses in vulnerability reproduction through systematic experiments.
Contribution
It introduces dual prompting methods and evaluates multiple models, providing new insights into LLMs' vulnerability generation capabilities and influencing safety mitigation strategies.
Findings
Models frequently generate requested vulnerabilities.
Gemma achieves 98.6% correctness for buffer overflows.
Professional personas increase success rates.
Abstract
Large Language Models (LLMs) are increasingly used as code assistants, yet their behavior when explicitly asked to generate insecure code remains poorly understood. While prior research has focused on unintended vulnerabilities, this study examines a more direct threat: open-source LLMs generating vulnerable code when prompted. We propose a dual experimental design: (1) Dynamic Prompting, which systematically varies vulnerability type, user persona, and prompt phrasing across structured templates; and (2) Reverse Prompting, which derives natural-language prompts from real vulnerable code samples. We evaluate three open-source 7B-parameter models (Qwen2, Mistral, Gemma) using static analysis to assess both the presence and correctness of generated vulnerabilities. Our results show that all models frequently generate the requested vulnerabilities, though with significant performance…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAdversarial Robustness in Machine Learning
