Explicit Vulnerability Generation with LLMs: An Investigation Beyond Adversarial Attacks
Not on the map. Why?
Abstract (arXiv)
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 differences. Gemma achieves the highest correctness for memory vulnerabilities under Dynamic Prompting (e.g., 98.6% for buffer overflows), while Qwen2 demonstrates the most balanced performance across all tasks. We find that professional personas (e.g., "DevOps Engineer") consistently elicit higher success rates than student personas, and that the effectiveness of direct versus indirect phrasing is inverted depending on the prompting strategy. Vulnerability reproduction accuracy follows a non-linear pattern with code complexity, peaking in a moderate range. Our findings expose how LLMs' reliance on pattern recall over semantic reasoning creates significant blind spots in their safety alignments, particularly for requests framed as plausible professional tasks.
Key facts. Cited by 2 papers in the map (data through 14 Oct 2026). First posted on arXiv 14 Jul 2025.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2026: 2.
2 papers.
Similar, not cited
Close in wording, no citation either way
- 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security
- 2025A Mixture of Linear Corrections Generates Secure Code
- 2026Enhancing Reliability in LLM-Based Secure Code Generation
- 2026Minimal Prompt Perturbations Lead to Code Vulnerabilities: Prompt Fragility and Hidden-State Signals in Coding LLMs
- 2025Smoke and Mirrors: Jailbreaking LLM-based Code Generation via Implicit Malicious Prompts
- 2026PromptAudit: Auditing Prompt Sensitivity in LLM-Based Vulnerability Detection