← Latest papers
🤖 AI

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

This paper introduces a novel dataset of 615 vulnerable code snippets across Java, Python, and JavaScript, generated using GPT-4o, Llama, and Claude models to map Common Attack Pattern Enumerations (CAPEC) and Common Weakness Enumerations (CWE) descriptions, thereby addressing the lack of detailed, labeled vulnerability data for advancing security research and machine learning-based detection systems.

Original authors: Murtuza Shahzad, Joseph Wilson, Ibrahim Al Azher, Hamed Alhoori, Mona Rahimi

Published 2026-04-06
📖 4 min read☕ Coffee break read

Original authors: Murtuza Shahzad, Joseph Wilson, Ibrahim Al Azher, Hamed Alhoori, Mona Rahimi

Original paper dedicated to the public domain under CC0 1.0 (http://creativecommons.org/publicdomain/zero/1.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to learn how to fix a leaky faucet, but the only instruction manual you have is a dry, technical list of parts and pressure ratings. It tells you what is broken, but it doesn't show you how the water actually sprays out or what the broken part looks like in real life. You're left guessing.

This is exactly the problem the researchers at Northern Illinois University faced with software security.

The Problem: A Manual Without Pictures

In the world of cybersecurity, there are two massive "encyclopedias" maintained by a group called MITRE:

  1. CAPEC: A list of all the different ways hackers can attack software (like "SQL Injection" or "Cross-Site Scripting").
  2. CWE: A list of the specific weak spots in code that allow those attacks to happen.

The problem? These encyclopedias are full of definitions, but they are missing the "how-to" videos. They describe the attack in theory, but they rarely provide actual lines of code showing what a vulnerable program looks like. It's like having a dictionary of words but no sentences to show how they are used.

Because of this, developers, students, and security experts struggle to truly understand how these attacks work in the real world.

The Solution: Hiring a Super-Intelligent Robot Chef

To fix this, the researchers decided to use Large Language Models (LLMs)—the same kind of AI that powers tools like ChatGPT. Think of these AIs as super-intelligent robot chefs who have read every cookbook (code repository) in the world.

Here is how they used the robots:

  1. The Recipe (The Prompt): The researchers didn't just ask the AI, "Write bad code." That would be like asking a chef to "make a mess." Instead, they gave the AI a very specific recipe. They fed it the description of the attack (from CAPEC) and the list of weak spots (from CWE).
  2. The Ingredients (Context): Sometimes, the attack description wasn't detailed enough. So, the researchers used a smart tool (SBERT) to find the 5 most closely related "weaknesses" to add to the recipe. This ensured the AI had enough context to cook up a perfect example.
  3. The Cooking (Generation): The AI (specifically GPT-4o, along with Llama and Claude) then generated actual code snippets in Java, Python, and JavaScript.
    • It wrote code that looked normal but contained a hidden trap (a vulnerability).
    • It added comments explaining exactly where the trap was and why it was dangerous.
    • It wrote a summary explaining the "story" of the attack.

The Result: A New "Cookbook" for Security

The team created a massive new dataset containing 615 different examples of vulnerable code.

To make sure the robots did a good job, the researchers acted as food critics:

  • Did it compile? (Could the code actually run, or was it gibberish?) Yes, about 90% of the time.
  • Was it relevant? (Did the code actually show the attack described?) Yes, experts agreed on this almost 100% of the time.
  • Was it readable? (Was it easy to understand?) Yes, the code was rated very highly for clarity.

They even checked if the robots were consistent. If they asked the same robot to cook the same dish five times, did they get the same result? Yes. The code was 98-99% identical every time, proving the AI wasn't just guessing randomly.

Why This Matters

This new dataset is like opening a security training gym.

  • For Students: Instead of just reading about a "lockpick," they can see a lockpick in action and learn how to spot it.
  • For Developers: They can see exactly what a "bad habit" looks like in their own code so they can avoid making the same mistake.
  • For AI Researchers: They can use this dataset to train other AI tools to automatically find and fix these security holes in the future.

The Catch (Limitations)

The researchers admit the robot chefs aren't perfect yet.

  • Sometimes they tried to write code for attacks that don't involve software at all (like "bypassing a physical lock"), which is a bit silly for a coding robot.
  • They only used three programming languages, though the world uses many more.

The Bottom Line

This paper is about bridging the gap between theory and practice. By using AI to generate real-world examples of security flaws, the researchers have created a powerful new tool. It turns dry, boring definitions into living, breathing examples that help us build safer software for everyone.

In short: They taught the AI to show us the "bugs" in the system so we can learn how to squash them before the hackers do.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →