CoolFace
Modelpublic

jacobmahon/zero-day-exploit-scanner-fixer

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
1likes
Model Card

๐Ÿ”’ Zero-Day Exploit Scanner & Fixer

A fine-tuned code security model that detects vulnerabilities and generates fixes across multiple programming languages.

Built on Qwen2.5-Coder-7B-Instruct with QLoRA fine-tuning on 90K+ real-world vulnerability-fix pairs from CVE/CWE databases.

๐ŸŽฏ What It Does

Given any code snippet, this model will:

  1. 1.SCAN โ€” Determine if the code contains a security vulnerability (VULNERABLE / SAFE)
  2. 2.IDENTIFY โ€” Classify the vulnerability type (CWE ID) and link to known CVEs
  3. 3.EXPLAIN โ€” Describe the attack vector, impact, and exploitation mechanism
  4. 4.FIX โ€” Generate corrected code that patches the vulnerability
  5. 5.DOCUMENT โ€” Explain what was changed and why

๐Ÿ—๏ธ Architecture

ComponentDetails
Base ModelQwen/Qwen2.5-Coder-7B-Instruct
MethodQLoRA (4-bit NF4 quantization)
LoRA Configr=16, ฮฑ=32, dropout=0.05
Target Modulesq, k, v, o, gate, up, down projections
TrainingSFT with assistant-only loss
Max Length2048 tokens

๐Ÿ“Š Training Data

Combined from 3 curated vulnerability datasets totaling ~90K samples:

DatasetSamplesLanguagesSource
MegaVul~17KC/C++992 repos, 169 CWE types, 2006-2023
TitanVul~38KC, C++, Java, Python, JSAggregated from 7 sources, deduplicated
CleanVul~26KMulti-languageLLM-filtered, vulnerability_score โ‰ฅ 1
Safe samples~12KMulti-languageFixed code from TitanVul (negative examples)

Data Quality Controls

  • โ€”CleanVul filtered by vulnerability_score >= 1 (removes ~27% noise)
  • โ€”TitanVul aggregates and deduplicates BigVul + DiverseVul + CVEFixes + PrimeVul + more
  • โ€”Safe code examples from patched functions reduce false positive rate
  • โ€”Each sample includes CVE ID, CWE type, vulnerability description, and commit message

๐Ÿš€ Quick Start

Installation

bash
pip install transformers peft torch bitsandbytes accelerate

Python API

python
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch

# Load model
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-Coder-7B-Instruct",
    quantization_config=bnb_config,
    device_map="auto",
)
model = PeftModel.from_pretrained(base_model, "jacobmahon/zero-day-exploit-scanner-fixer")
tokenizer = AutoTokenizer.from_pretrained("jacobmahon/zero-day-exploit-scanner-fixer")

# Scan code
messages = [
    {"role": "system", "content": "You are a security expert. Analyze code for vulnerabilities and provide fixes."},
    {"role": "user", "content": "Analyze this C code for vulnerabilities:\n```c\nvoid process(char *input) {\n    char buf[64];\n    strcpy(buf, input);\n}\n```"},
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=1024, temperature=0.3, top_p=0.9)

print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

CLI Usage

bash
# Scan a code string
python inference.py --code "char buf[10]; gets(buf);"

# Scan a file
python inference.py --file vulnerable.c

# Interactive mode
python inference.py --interactive

๐Ÿ“‹ Supported Vulnerability Types

The model has been trained on 169+ CWE types including:

CategoryCWE Examples
Memory SafetyCWE-119 (Buffer Overflow), CWE-120 (Buffer Copy), CWE-416 (Use After Free), CWE-476 (NULL Pointer Deref)
InjectionCWE-79 (XSS), CWE-89 (SQL Injection), CWE-78 (OS Command Injection)
AuthenticationCWE-287 (Improper Auth), CWE-306 (Missing Auth), CWE-798 (Hardcoded Credentials)
CryptographyCWE-327 (Broken Crypto), CWE-330 (Insufficient Randomness)
Race ConditionsCWE-362 (Race Condition), CWE-367 (TOCTOU)
Input ValidationCWE-20 (Improper Input Validation), CWE-190 (Integer Overflow)
Access ControlCWE-862 (Missing Authorization), CWE-863 (Incorrect Authorization)
Information DisclosureCWE-200 (Info Exposure), CWE-209 (Error Message Info Leak)

๐Ÿ”ฌ Training Recipe

Based on research from:

  • โ€”R2Vul (arXiv:2504.04699) โ€” Structured reasoning for vulnerability detection (81.47% F1)
  • โ€”MSIVD (arXiv:2406.05892) โ€” Multi-task instruction tuning (0.92 F1 on BigVul)
  • โ€”SecRepair (arXiv:2401.03374) โ€” Combined detection + repair with RL
  • โ€”SecureCode โ€” QLoRA recipe: r=16, ฮฑ=32, lr=2e-4, 3 epochs
  • โ€”TitanVul (arXiv:2507.21817) โ€” 0.881 OOD accuracy on BenchVul benchmark

Hyperparameters

python
learning_rate = 2e-4        # LoRA-optimized (10x base)
num_train_epochs = 3
per_device_train_batch_size = 2
gradient_accumulation_steps = 8  # Effective batch = 16
max_length = 2048
lr_scheduler = "cosine"
warmup_steps = 100
optimizer = "adamw_torch"
quantization = "4-bit NF4 (double quant)"
lora_rank = 16
lora_alpha = 32
lora_dropout = 0.05

โš ๏ธ Limitations & Ethical Use

  • โ€”Not a replacement for professional security audits โ€” Use as a screening tool alongside manual review
  • โ€”May produce false positives/negatives โ€” Always verify findings with static analysis tools (CodeQL, Semgrep)
  • โ€”Training data bias โ€” Primarily C/C++ and Java; coverage for newer languages (Rust, Go, Kotlin) is limited
  • โ€”Zero-day detection โ€” The model generalizes from known vulnerability patterns; truly novel attack vectors may not be detected
  • โ€”Do not use for malicious purposes โ€” This tool is designed for defensive security only

๐Ÿ“š Evaluation

Recommended evaluation benchmarks:

  • โ€”BenchVul โ€” MITRE Top 25 CWEs, balanced real-world + synthetic
  • โ€”SVEN โ€” Curated CWE-typed pairs with character-level diffs

๐Ÿƒ Training

To reproduce or fine-tune further:

bash
# Install dependencies
pip install transformers trl torch datasets trackio accelerate peft bitsandbytes

# Run training (requires 24GB+ GPU)
python train.py

See train.py in this repository for the full training script.

๐Ÿ“„ License

Apache 2.0

๐Ÿ™ Acknowledgments

  • โ€”Qwen Team for Qwen2.5-Coder-7B-Instruct
  • โ€”MegaVul, TitanVul, CleanVul dataset authors
  • โ€”Research teams behind R2Vul, MSIVD, SecRepair, and SecureCode