From Theory to Practice: Code Generation Using LLMs for CAPEC and CWE Frameworks
Organizations: Department of Computer Science, Northern Illinois University, DeKalb, Illinois USA
Abstract
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.
Figures & tables
| Total CAPECs | Any Language | Java | JavaScript | Python |
|---|---|---|---|---|
| 615 | ||||
| Total CWEs | Any Language | Java | JavaScript | Python |
| 963 |
| CAPEC ID | CWE IDs Related Weaknesses (from MITRE data) | CWE IDs Related Weaknesses (from SBERT) |
| 1 | 276, 285, 434, 693, 732, 1191, 1193, 1220, 1297, | - |
| 1311, 1314, 1315, 1318, 1320, 1321, 1327 | ||
| 2 | 645 | 645, 307, 521, 305, 1390 |
| … | … | … |
| 18 | 80 | 82, 79, 80, 692, 81 |
| … | … | … |
| CAPEC ID | Selected CWE IDs Related Weaknesses |
|---|---|
| 1 | 276, 285, 434, 693, 732, 1191, 1193, 1220, 1297, |
| 1311, 1314, 1315, 1318, 1320, 1321, 1327 | |
| 2 | 645, 307, 521, 305, 1390 |
| … | … |
| 18 | 80, 82, 79, 692, 81 |
| … | … |
| Language | Dataset 1 | Dataset 2 | Dataset 3 | Dataset 4 | Dataset 5 |
|---|---|---|---|---|---|
| Java | 28 | 29 | 26 | 29 | 27 |
| Python | 27 | 29 | 30 | 29 | 29 |
| JavaScript | 24 | 24 | 27 | 27 | 27 |
| Relevance to CAPEC | Code Readability(1-5) | ||||
|---|---|---|---|---|---|
| Language | Dataset 1 | Dataset 2 | Dataset 1 | Dataset 2 | |
| Evaluator 1 | Java | 30 | 30 | 4 | 4 |
| Python | 30 | 30 | 5 | 5 | |
| JavaScript | 30 | 30 | 5 | 5 | |
| Evaluator 2 | Java | 27 | 28 | 4 | 4 |
| Python | 27 | 27 | 5 | 5 | |
| Java | |||||
|---|---|---|---|---|---|
| Dataset 1 | Dataset 2 | Dataset 3 | Dataset 4 | Dataset 5 | |
| Dataset 1 | - | 0.9938 | 0.9938 | 0.9938 | 0.9939 |
| Dataset 2 | 0.9938 | - | 0.9933 | 0.9934 | 0.9935 |
| Dataset 3 | 0.9938 | 0.9933 | - | 0.9933 | 0.9934 |
| Dataset 4 | 0.9938 | 0.9934 | 0.9933 | - | 0.9935 |
| Dataset 5 | 0.9939 | 0.9935 | 0.9934 | 0.9935 | - |
| Java | ||||||
|---|---|---|---|---|---|---|
| GPT-4o Dataset 1 | GPT-4o Dataset 2 | Llama Dataset 1 | Llama Dataset 2 | Claude Dataset 1 | Claude Dataset 2 | |
| GPT-4o Dataset 1 | - | 0.9938 | 0.9916 | 0.9915 | 0.9936 | 0.9936 |
| GPT-4o Dataset 2 | 0.9938 | - | 0.9912 | 0.9911 | 0.9931 | 0.9931 |
| Llama Dataset 1 | 0.9916 | 0.9912 | - | 0.9894 | 0.9910 | 0.9911 |
| Llama Dataset 2 | 0.9915 | 0.9911 | 0.9894 | - | 0.9910 | 0.9910 |
| Claude Dataset 1 | 0.9936 | 0.9931 | 0.9910 | 0.9910 | - | 0.9944 |
Software Security
Software security studies how to find, prevent, validate, and repair vulnerabilities in code, systems, dependencies, and software supply chains.
See all 95 papers