arXiv:2604.02548cs.CRcs.AI2026-04

用大模型生成与安全框架匹配的漏洞代码,提升漏洞研究与检测能力

From Theory to Practice: Code Generation Using LLMs for CAPEC and CWE Frameworks

  • 基于GPT-4o等模型,按CAPEC/CWE描述生成具体漏洞代码
  • 产出615个跨语言漏洞样本,三模型生成代码相似度达0.98
  • 适合做漏洞检测、自动修复的机器学习研究者使用

软件系统复杂度上升,安全漏洞识别与缓解愈发重要。现有漏洞数据集常缺乏与具体漏洞描述明确关联的完整代码片段,限制了高级研究与深入理解。为此,我们构建了一个新数据集,提供与常见攻击模式(CAPEC)和通用弱点(CWE)描述对应的漏洞代码示例。利用生成式预训练模型(如GPT-4o、Llama、Claude),我们开发了生成方法,生成符合文档描述的具体漏洞代码。该数据集不仅深化了对代码漏洞的理解,还可用于训练自动化漏洞检测与修复的机器学习模型。初步评估显示,大模型生成的代码具有高准确率,且三模型间代码余弦相似度达0.98。最终数据集包含615个跨Java、Python、JavaScript三种语言的代码片段,是该领域最全面、多样的资源之一。

原文摘要 · Abstract (English)

The increasing complexity and volume of software systems have heightened the importance of identifying and mitigating security vulnerabilities. The existing software vulnerability datasets frequently fall short in providing comprehensive, detailed code snippets explicitly linked to specific vulnerability descriptions, reducing their utility for advanced research and hindering efforts to develop a deeper understanding of security vulnerabilities. To address this challenge, we present a novel dataset that provides examples of vulnerable code snippets corresponding to Common Attack Pattern Enumerations and Classifications (CAPEC) and Common Weakness Enumeration (CWE) descriptions. By employing the capabilities of Generative Pre-trained Transformer (GPT) models, we have developed a robust methodology for generating these examples. Our approach utilizes GPT-4o, Llama and Claude models to generate code snippets that exhibit specific vulnerabilities as described in CAPEC and CWE documentation. This dataset not only enhances the understanding of security vulnerabilities in code but also serves as a valuable resource for training machine learning models focused on automatic vulnerability detection and remediation. Preliminary evaluations suggest that the dataset generated by Large Language Models demonstrates high accuracy and can serve as a reliable reference for vulnerability identification systems. We found consistent results across the three models, with 0.98 cosine similarity among codes. The final dataset comprises 615 CAPEC code snippets in three programming languages: Java, Python, and JavaScript, making it one of the most extensive and diverse resources in this domain.

漏洞生成大模型安全检测代码生成

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。