guychuk's picture
Update README.md
0594557 verified
|
Raw History Blame Contribute Delete
6.32 kB
metadata
license: mit
task_categories:
  - text-generation
language:
  - en
tags:
  - code
  - security
  - cyber
  - nuclei
pretty_name: CVE to Nuclei Template

Ernest Nuclei Templates Dataset v3

A comprehensive dataset for training models to generate Nuclei security scanning templates from vulnerability descriptions.

Dataset Description

This dataset contains 11,590 training examples for generating Nuclei YAML templates in JSON IR (Intermediate Representation) format from structured vulnerability specifications.

Format

Each training example consists of:

  1. id: Unique identifier (CVE ID, CWE ID, or template name)
  2. prompt: Structured input with 4 sections (see below)
  3. completion: JSON IR output matching nuclei_ir.schema.json

Prompt Structure

The prompt contains exactly 4 sections in this order:

[CANONICAL_RECORD]

Structured vulnerability representation as JSON:

{
  "cve_id": "cve-2024-1234",
  "summary": "Description of vulnerability",
  "affected_products": [{"vendor": "...", "product": "...", "version_range": "..."}],
  "paths": ["/admin/upload.php"],
  "indicators": ["error", "exception"],
  "severity_hint": "high"
}

[RETRIEVED_TEMPLATES]

JSON array of 2-3 similar templates (flattened, structural):

[
  {
    "id": "cve-2024-5678",
    "severity": "high",
    "tags": ["cve", "sqli", "apache"],
    "requests": [
      {
        "method": "GET",
        "paths": ["{{BaseURL}}/admin.php?id=1"],
        "matcher_types": ["word", "status"]
      }
    ]
  }
]

[POC_SNIPPETS]

JSON array of PoC snippets (or empty array):

[
  {
    "source": "nvd",
    "url": "https://...",
    "snippet": "curl -X POST ..."
  }
]

[INSTRUCTION]

Fixed instruction text:

Generate a valid Nuclei template as JSON IR. Output ONLY the JSON object matching nuclei_ir.schema.json. No markdown, no explanations, no code fences.

Completion Format

Pure JSON IR matching nuclei_ir.schema.json:

{
  "id": "cve-2024-1234",
  "info": {
    "name": "XSS Vulnerability in Product X",
    "author": "ernest-generator",
    "severity": "high",
    "description": "...",
    "tags": ["cve", "xss"],
    "reference": ["https://..."]
  },
  "requests": [
    {
      "method": "GET",
      "path": ["{{BaseURL}}/vulnerable.php"],
      "matchers": [...]
    }
  ],
  "safety_flags": {...},
  "limits": {...},
  "metadata": {...}
}

No markdown, no code fences, no extra text - ONLY the JSON object.

Dataset Statistics

  • Total examples: 11,590
  • Train split: 8,112 (70%)
  • Test split: 1,736 (15%)
  • Validation split: 1,742 (15%)

By Category

  • CVE-based: 3,666 (31.6%) - Enriched with NVD CVE data
  • CWE-based: 2,499 (21.6%) - Enriched with MITRE CWE data
  • Generic: 5,425 (46.8%) - Self-contained templates

File Sizes

  • full.jsonl: 60 MB
  • train.jsonl: 42 MB
  • test.jsonl: 9 MB
  • validation.jsonl: 9 MB

Usage

Loading the Dataset

from datasets import load_dataset

# Load from local files
dataset = load_dataset('json', data_files={
    'train': 'train.jsonl',
    'test': 'test.jsonl',
    'validation': 'validation.jsonl'
})

# Or from Hugging Face Hub
# dataset = load_dataset('OzLabs/ernest-nuclei-templates-v3')

# Access a training example
example = dataset['train'][0]
print(f"ID: {example['id']}")
print(f"\nPrompt:\n{example['prompt'][:500]}...")
print(f"\nCompletion:\n{example['completion'][:500]}...")

Fine-tuning Example

from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def format_example(example):
    """Format example for instruction tuning."""
    return {
        "input": example["prompt"],
        "output": example["completion"]
    }

# Prepare dataset
formatted_dataset = dataset.map(format_example)

# Fine-tune with your preferred framework (TRL, Axolotl, etc.)

Data Source

Templates extracted from ProjectDiscovery/nuclei-templates repository and enriched with:

  • CVE Data: National Vulnerability Database (NVD) API 2.0
  • CWE Data: MITRE Common Weakness Enumeration
  • Template Similarity: Pre-computed similar templates for few-shot learning

Schema Validation

~70% of examples pass strict JSON schema validation. Validation failures are mostly due to:

  • Empty path arrays (legitimate for SSL/TLS templates)
  • Templates with minimal matchers

The prompt structure (4 sections) is valid for 100% of examples.

Intended Use

This dataset is designed for:

  1. Fine-tuning code generation models (Qwen, CodeLlama, DeepSeek Coder, etc.)
  2. Few-shot learning for security template generation
  3. Research on structured code generation from specifications

Model Recommendations

Best suited for instruction-tuned models:

  • Qwen2.5-Coder (1.5B - 32B)
  • CodeLlama-Instruct (7B - 34B)
  • DeepSeek-Coder-Instruct (6.7B - 33B)
  • StarCoder2-Instruct (3B - 15B)

Citation

If you use this dataset, please cite:

@dataset{ernest_nuclei_v3_2025,
  title={Ernest Nuclei Templates Dataset v3},
  author={OzLabs},
  year={2025},
  publisher={Hugging Face},
  howpublished={\url{https://huggingface.co/datasets/OzLabs/ernest-nuclei-templates-v3}}
}

License

This dataset is derived from Nuclei templates which are licensed under MIT. The dataset itself is released under MIT License.

Changelog

v3 (2025-01-13)

  • Complete restructuring to match specification
  • Added CANONICAL_RECORD with structured vulnerability data
  • Added RETRIEVED_TEMPLATES for few-shot learning
  • Added POC_SNIPPETS from CVE references
  • JSON IR completions (no YAML, no markdown)
  • Optimized similarity matching (O(n) vs O(n²))
  • 11,590 training pairs (99.8% success rate)

Contact


Note: This dataset is for security research and defensive purposes only. Generated templates should be validated before use in production environments.