Add fine-tuned DistilBERT attack-type classifier
Browse files- README.md +59 -0
- config.json +47 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: distilbert-base-uncased
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
language: en
|
| 6 |
+
tags:
|
| 7 |
+
- cybersecurity
|
| 8 |
+
- cve
|
| 9 |
+
- vulnerability
|
| 10 |
+
- text-classification
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# DockerGuard attack-type classifier
|
| 14 |
+
|
| 15 |
+
Reads a vulnerability (CVE) description and predicts what kind of attack it allows, one of 8 types:
|
| 16 |
+
|
| 17 |
+
Code execution · Memory corruption · Injection · Web attack · Information disclosure ·
|
| 18 |
+
Access control bypass · Denial of service · File access
|
| 19 |
+
|
| 20 |
+
Part of **DockerGuard AI**, a college project that scans Docker images, ranks vulnerabilities by
|
| 21 |
+
exploit risk, and explains them.
|
| 22 |
+
|
| 23 |
+
## Training
|
| 24 |
+
|
| 25 |
+
- **Base model:** `distilbert-base-uncased`, fine-tuned for 8-class classification.
|
| 26 |
+
- **Data:** public CVE descriptions from the NIST National Vulnerability Database (2016 onwards).
|
| 27 |
+
- **Labels:** each CVE's CWE code (type of programming mistake) grouped into the 8 attack types. The model
|
| 28 |
+
only sees the description text, never the CWE code.
|
| 29 |
+
- **Setup:** balanced sample of 16,000 CVEs (2,000 per type), 1 epoch, AdamW, learning rate 5e-5 with
|
| 30 |
+
linear warmup, max 128 tokens, CPU only.
|
| 31 |
+
|
| 32 |
+
## Results
|
| 33 |
+
|
| 34 |
+
Tested on 4,000 of the newest CVEs (published after all training CVEs):
|
| 35 |
+
|
| 36 |
+
| Model | Trained on | Accuracy | Macro F1 |
|
| 37 |
+
|---|---|---|---|
|
| 38 |
+
| TF-IDF + Logistic Regression | all ~2 lakh labelled CVEs | 89.6% | 0.875 |
|
| 39 |
+
| TF-IDF + Logistic Regression | same 16,000 as this model | 85.1% | 0.827 |
|
| 40 |
+
| **This model (DistilBERT)** | 16,000 CVEs, 1 epoch | 85.5% | 0.833 |
|
| 41 |
+
|
| 42 |
+
With the same training data this model slightly beats the baseline, but the baseline trained on far more
|
| 43 |
+
data is better overall. Training on more CVEs and for more epochs (on a GPU) is the obvious next step.
|
| 44 |
+
|
| 45 |
+
## Use
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import pipeline
|
| 49 |
+
|
| 50 |
+
classify = pipeline("text-classification", model="syedubaid/dockerguard-attack-classifier")
|
| 51 |
+
classify("Apache Log4j2 JNDI features do not protect against attacker controlled LDAP endpoints, "
|
| 52 |
+
"allowing remote code execution.")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Limitations
|
| 56 |
+
|
| 57 |
+
- Labels come from CWE codes, which are sometimes vague or wrong in NVD, so some "errors" are label noise.
|
| 58 |
+
- "Information disclosure" is the weakest type (F1 0.62): it overlaps with access-control bugs.
|
| 59 |
+
- English descriptions only.
|
config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"dim": 768,
|
| 9 |
+
"dropout": 0.1,
|
| 10 |
+
"dtype": "float32",
|
| 11 |
+
"eos_token_id": null,
|
| 12 |
+
"hidden_dim": 3072,
|
| 13 |
+
"id2label": {
|
| 14 |
+
"0": "Code execution",
|
| 15 |
+
"1": "Memory corruption",
|
| 16 |
+
"2": "Injection",
|
| 17 |
+
"3": "Web attack",
|
| 18 |
+
"4": "Information disclosure",
|
| 19 |
+
"5": "Access control bypass",
|
| 20 |
+
"6": "Denial of service",
|
| 21 |
+
"7": "File access"
|
| 22 |
+
},
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"label2id": {
|
| 25 |
+
"Access control bypass": 5,
|
| 26 |
+
"Code execution": 0,
|
| 27 |
+
"Denial of service": 6,
|
| 28 |
+
"File access": 7,
|
| 29 |
+
"Information disclosure": 4,
|
| 30 |
+
"Injection": 2,
|
| 31 |
+
"Memory corruption": 1,
|
| 32 |
+
"Web attack": 3
|
| 33 |
+
},
|
| 34 |
+
"max_position_embeddings": 512,
|
| 35 |
+
"model_type": "distilbert",
|
| 36 |
+
"n_heads": 12,
|
| 37 |
+
"n_layers": 6,
|
| 38 |
+
"pad_token_id": 0,
|
| 39 |
+
"problem_type": "single_label_classification",
|
| 40 |
+
"qa_dropout": 0.1,
|
| 41 |
+
"seq_classif_dropout": 0.2,
|
| 42 |
+
"sinusoidal_pos_embds": false,
|
| 43 |
+
"tie_weights_": true,
|
| 44 |
+
"tie_word_embeddings": true,
|
| 45 |
+
"transformers_version": "5.24.1",
|
| 46 |
+
"vocab_size": 30522
|
| 47 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f051164e0c6f8caea46772c768cec380f5ae644adab845222bc2e59a0d6959de
|
| 3 |
+
size 267851024
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"local_files_only": false,
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"strip_accents": null,
|
| 12 |
+
"tokenize_chinese_chars": true,
|
| 13 |
+
"tokenizer_class": "BertTokenizer",
|
| 14 |
+
"unk_token": "[UNK]"
|
| 15 |
+
}
|