Views
No views yet
Research Model | Final Year Project Generates structured MITRE ATT&CK-aligned attack chains from network log features.
1!pip install -q hf_xet
2
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5from peft import PeftModel
6
7BASE_MODEL = "mistralai/Mistral-7B-Instruct-v0.2"
8ADAPTER = "sohomn/attack-chain-simulator-mistral7b-lora"
9
10torch.cuda.empty_cache()
11
12tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
13tokenizer.pad_token = tokenizer.eos_token
14
15# No quantization — same as training environment
16base_model = AutoModelForCausalLM.from_pretrained(
17 BASE_MODEL,
18 torch_dtype=torch.float16,
19 device_map="auto",
20 low_cpu_mem_usage=True,
21)
22
23model = PeftModel.from_pretrained(base_model, ADAPTER)
24model.eval()
25print("Model ready.")
26print(f"VRAM: {torch.cuda.memory_allocated()/1e9:.1f} GB")
27
28def generate_attack_chain(log_text):
29 messages = [{"role": "user", "content": (
30 "You are a cybersecurity expert.\n\n"
31 "Simulate a realistic enterprise attack chain for the following network activity.\n\n"
32 f"LOG:\n{log_text}\n\n"
33 "Generate the ATT&CK-aligned attack chain with these exact fields:\n"
34 "Initial Access:\nExecution:\nPersistence:\n"
35 "Privilege Escalation:\nLateral Movement:\n"
36 "Command & Control:\nData Exfiltration:"
37 )}]
38 prompt = tokenizer.apply_chat_template(
39 messages, tokenize=False, add_generation_prompt=True
40 )
41 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
42 input_len = inputs["input_ids"].shape[-1]
43
44 with torch.no_grad():
45 out = model.generate(
46 **inputs,
47 max_new_tokens=300,
48 do_sample=True,
49 temperature=0.7,
50 top_p=0.9,
51 top_k=50,
52 repetition_penalty=1.3,
53 pad_token_id=tokenizer.eos_token_id
54 )
55 return tokenizer.decode(out[0][input_len:], skip_special_tokens=True).strip()
56
57# Tests
58tests = [
59 "53 | 196 | 2 | 2 | 84 | 116 | 42 | 42 | 42.0 | 0.0",
60 "Suspicious PowerShell from WINHOST-04, outbound HTTPS to 185.234.x.x:443",
61 "Spear phishing email opened, macro executed, LSASS dump, PsExec lateral move",
62]
63
64for i, t in enumerate(tests, 1):
65 print(f"\n{'='*60}")
66 print(f"TEST {i}")
67 print(f"{'='*60}")
68 print(generate_attack_chain(t))| Dataset | Samples | Purpose |
|---|---|---|
| CICIDS2017 | ~4,200 | Network traffic attack labels |
| DAPT2020 | ~1,500 | APT behavioral patterns |
| MITRE ATT&CK | ~3,000 | Enterprise/ICS/Mobile techniques |
| Total | ~8,700 |
| Property | Value |
|---|---|
| Base Model | mistralai/Mistral-7B-Instruct-v0.2 |
| Method | QLoRA 4-bit NF4 |
| LoRA Rank | r=16, alpha=32 |
| Target Modules | q_proj, k_proj, v_proj, o_proj |
| Hardware | Kaggle T4 GPU |