File size: 10,937 Bytes
f0ad107
 
 
c9368c7
f0ad107
 
f2aaa20
f0ad107
 
f2aaa20
f0ad107
 
 
 
 
 
 
f2aaa20
f0ad107
f2aaa20
 
734d08e
f2aaa20
f0ad107
 
 
 
 
 
f2aaa20
 
f0ad107
 
f2aaa20
 
 
 
 
 
f0ad107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9368c7
f0ad107
 
 
 
 
 
 
 
c9368c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0ad107
 
 
 
 
 
 
 
 
 
 
 
 
 
a5fc69d
644833d
734d08e
f2aaa20
 
f0ad107
 
 
b7a81c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b2e541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
license: apache-2.0
base_model: Qwen/Qwen3-8B
tags: [cybersecurity, agentic, red-team, blue-team, distillation, glm-5.2, kimi-k3, function-calling, tool-calling, tool-use]
---

# k3-sec-8b (v8)

An 8B cybersecurity agent (offense + defense) fine-tuned from `Qwen/Qwen3-8B` on
**2197 verified agentic + Q&A traces**, distilled from GLM-5.2 (round 4) and Kimi K3/K2.6
(rounds 1–3). Trained to operate an autonomous security harness β€” plan, run bash, read
observations, write files, finish β€” not just answer security questions.

Pipeline per iteration: failure analysis on eval traces β†’ parameterized, decontaminated
seed factory β†’ teacher best-of-3 rejection-sampled agentic transcripts (judged +
artifact-checked) β†’ full-FT SFT β†’ multi-run attack/defend eval β†’ next round.

## Version 8 highlights

- **Data**: 2197 unique rows (2103 agentic + 94 Q&A). Round 8 was a 136-trace DNS
  top-up (75 decode + 75 detector-contract, $8). Round 7 was the broad-coverage
  round: 985 traces across ALL ten eval skills (flaky six weighted 100-120, solid four
  kept warm at 60-80, 80 generalization). Round 6 added
  564 GLM-5.2 traces targeting the five v3 tasks that never passed, generated from 580
  parameterized seeds with decontamination-by-construction (every eval-graded string is
  blacklisted and asserted absent). Best-of-3 rejection with a glm-4.7-flash judge
  (kept 97%). Note: v3's advertised 157 rows contained only 135 unique after legacy
  merge duplicates; v4 is a genuine 5.2Γ— data increase.
- **Training**: full FT bf16, 2 epochs, lr 1e-5 cosine, eff. batch 32, seq 8192,
  adamw_8bit, 5.37M tokens, ~42 min on 1Γ— A100-80GB. **train_loss 0.616 Β· token-acc
  87.2%** (v7: 0.627 / 86.6%, v6: 0.838 / 83.1%, v3: 1.395 / 69.1%). Ships with Qwen3 YaRN `rope_scaling` for 131072-token
  serving.
- **Eval** (fixed 10-task synthetic attack/defend lab, agentic harness, 3 runs):
  **mean 8.0/10 with ZERO variance (8, 8, 8) -- attack side 5/5 in all three runs**
  (atk-dns fixed by the top-up). Defend side: bruteforce/webshell(2/3)/harden solid,
  def-detect-dns 1/3, def-ioc regressed to 0/3 (round-9 target).
- **MMLU spot check** (60 questions, temp 0, same harness): v8 0.533 vs v7 0.550 vs
  **base Qwen3-8B 0.550** -- general capability statistically indistinguishable from
  base. NO capability collapse from the agentic diet.

### Per-task pass rates (P across runs)

| Task | v3 (4 runs) | v4 (3 runs) |
|---|---|---|
| atk-sqli | 0/4 | 0/3 |
| atk-hash | 4/4 | 3/3 |
| atk-re | 3/4 | 2/3 |
| atk-dns | 0/4 | 1/3 |
| atk-jwt | 0/4 | **3/3** |
| def-bruteforce | 3/4 | 3/3 |
| def-webshell | 2/4 | 2/3 |
| def-harden | 4/4 | 3/3 |
| def-detect-dns | 0/4 | 1/3 |
| def-ioc | 0/4 | 2/3 |

Run-to-run variance is significant at temperature 0.7; single-run scores are not
meaningful for this suite. Known v4 gap: `atk-sqli` β€” the model prefers to start the
staged vulnerable app and fuzz it over HTTP instead of reading the offline artifacts
(trace-verified behavioral prior, targeted in round 5).

## Usage

vLLM, short-task/eval serving (disable static YaRN):

```bash
python3 -m vllm.entrypoints.openai.api_server \
  --model bebrws/k3-sec-8b --revision v7cti \
  --port 8000 --hf-overrides '{"rope_scaling":null}' --max-model-len 32768
```

Long-context serving: omit `--hf-overrides` and set `--max-model-len 131072`.
Recommended sampling for agentic loops (non-thinking): `temperature=0.7 top_p=0.8
top_k=20 min_p=0`, `chat_template_kwargs.enable_thinking=false`, per-step completion
cap ~4096 tokens.

## Tool / function calling

Supported. The chat template accepts a `tools` argument (OpenAI-style JSON function
schemas) and renders them into the system turn inside `<tools></tools>`. The model emits
calls as:

```
<tool_call>
{"name": "<function-name>", "arguments": {<args-json-object>}}
</tool_call>
```

Multiple calls may be emitted in a single assistant turn. Return each result as a message
with `role: "tool"`; the template renders it as `<tool_response>…</tool_response>`, and
consecutive tool messages are merged into one user turn.

```python
messages = [{"role": "user", "content": "Scan 10.0.0.5 for open ports"}]
tools = [{
    "type": "function",
    "function": {
        "name": "exec_shell_command",
        "description": "Run a shell command and return its output",
        "parameters": {
            "type": "object",
            "properties": {"command": {"type": "string"}},
            "required": ["command"],
        },
    },
}]

text = tokenizer.apply_chat_template(
    messages, tools=tools, add_generation_prompt=True, tokenize=False
)
```

vLLM serving with native tool-call parsing:

```bash
python3 -m vllm.entrypoints.openai.api_server \
  --model bebrws/k3-sec-8b \
  --enable-auto-tool-choice --tool-call-parser hermes
```

`llama.cpp` requires `--jinja` for the embedded template (and therefore tool calls) to be
used.

## Intended use & limitations

Defensive/offensive **security research artifact**, evaluated on a small synthetic lab.
Not for: real intrusion activity, exploit weaponization, unsupervised security
decisions, or non-security tasks. Outputs require qualified human review. Attack-side
competence is deliberately scoped to CTF/lab-grade tasks.

## Version history (8B lineage)

| Version | Data | Eval mean | Notes |
|---|---|---|---|
| v1 | 135 traces | 4/10 single | first 8B run |
| v2 | 149 traces | 6/10 single | failure-targeted r2 |
| v3 | 157 (135 unique) | 4.0/10 (4 runs) | parser-fixed harness baseline |
| v4 | 699 | 6.67/10 (3 runs) | GLM-5.2 scale-up, jwt fixed |
| v5 | 891 | 6.67/10 (3 runs: 4,8,8) | sqli breakthrough, ioc fixed; harden regressed (newline stripping) |
| v6 | 1076 | 7.0/10 (3 runs: 7,8,6) | harden fixed, webshell solid |
| v7 | 2061 | 8.33/10 (3 runs: 8,7,10) | gate passed; sqli 3/3 |
| **v8** | **2197** | **8.0/10 (3 runs: 8,8,8)** | attack 5/5 x3; MMLU == base; ioc regressed |

Weights are Apache-2.0 per the Qwen3 base; training traces were generated by GLM-5.2
and Kimi teachers and filtered by automated judging.


## My main question

# Did k3-sec-8b iterations beat their base model?

**Answer: Yes β€” by v6, clearly. But early iterations were worse than base.**

The k3-sec-8b line starts training from **`Qwen/Qwen3-8B`** (per `docs/training-history.md`).
All numbers below are on the project's fixed 10-task agentic lab (5 attack + 5 defend,
identical sampling conditions).

| Iteration | Attack | Defend | Combined | vs base |
|---|---:|---:|---:|---|
| **Qwen3-8B base** (3 runs, 2026-07-31) | 12/15 | 12/15 | **24/30** (9, 8, 7 per run) | β€” |
| k3-sec-8b-v1 | 2/5 | 2/5 | 4/10 | below base |
| k3-sec-8b-v2 | 3/5 | 3/5 | 6/10 | below base |
| k3-sec-8b-v3 (4-run baseline) | β€” | β€” | mean 4.0/10 | below base |
| **k3-sec-8b-v6** (3 runs, 2026-07-31) | **15/15** | 12/15 | **27/30** (9, 9, 9 per run) | **+3 overall** |

## Details

- **v6 vs base (head-to-head, 3 runs each):** v6 wins 27/30 vs 24/30.
  - Attack: v6 is a **perfect 15/15** (all 5 attack tasks, all 3 runs); base is 12/15
    (atk-dns failed all 3 runs).
  - Defense: tied 12/15 both (def-detect-dns fails for both; base also drops def-webshell/def-ioc once each).
  - Consistency: v6 scores 9/10 on *every* run; the base declines 9 β†’ 8 β†’ 7 across runs.
- **The training took several iterations to pay off.** v1 (4/10), v2 (6/10), and v3
  (mean 4.0/10 across 4 runs) all scored *below* the base β€” early SFT rounds initially
  hurt the strong base model before later rounds (agentic file-writing data,
  failure-targeted rounds, GLM-5.2 bulk traces) pushed v6 above it.
- **Context:** the Qwen3-8B base is itself unusually strong on this lab (24/30) β€”
  stronger than Foundation-Sec-8B-Instruct (8/30) and RedSage-Qwen3-8B-taught (16/30)
  measured on the same benchmark. Beating it at all is a meaningful bar.

## Sources

- `data/eval_cmp_base_r{1,2,3}.json` β€” Qwen3-8B base runs
- `data/eval_cmp_student_r{1,2,3}.json` β€” k3-sec-8b v6 runs
- `docs/training-history.md` β€” v1–v3 iteration evals (`data/eval_8b*.json`)

## Aside

Also interesting: base Qwen3-8B is itself very strong on this lab (24/30 = 80%) β€” stronger than FSec-Instruct (8/30) and stronger than RedSage-taught (16/30)! That's a notable context point for the report: the k3-sec-8b v6 is the strongest model evaluated on this lab so far.


## External comparison: k3-sec-8b v7cti vs Foundation-Sec-1.1-8B-Instruct (Q8_0 GGUF)

> **Comparison note:** Foundation-Sec-1.1-8B-Instruct (Cisco Foundation AI, Aug 2025)
> appears to be the closest cutting-edge cybersecurity-specialized instruct model to
> compare against β€” same 8B class, instruction-tuned, security-domain. Both models
> were evaluated in their **Q8_0 GGUF** format (the most similar quantized format
> available for each), served via vLLM on identical RTX 4090 hardware with identical
> sampling. Full report: [RunPod evaluation, 2026-08-02](https://huggingface.co/bebrws/k3-sec-8b).

### Results (3 runs Γ— 10 tasks = 30 trials per model)

| Benchmark | k3-sec-8b v7cti Q8_0 GGUF | Foundation-Sec-1.1-8B-Instruct Q8_0 GGUF |
|---|---:|---:|
| **Agentic lab β€” ATTACK** | **9/15 (60%)** | 5/15 (33%) |
| **Agentic lab β€” DEFEND** | **6/15 (40%)** | 3/15 (20%) |
| **Agentic lab β€” TOTAL** | **15/30 (50%)** | 8/30 (27%) |
| Knowledge battery (45 MCQ) | 43/45 (96%) | **45/45 (100%)** |
| Per-run consistency | 5/10 Β· 5/10 Β· 5/10 | 3/10 Β· 4/10 Β· 1/10 |

### Per-task pass rates (passes / 3 runs)

| Task | k3-sec-8b Q8_0 | FSec-1.1 Q8_0 | Winner |
|---|---:|---:|---|
| atk-sqli | **3/3** | 2/3 | k3-sec-8b |
| atk-hash | 2/3 | 2/3 | tie |
| atk-re | **2/3** | 1/3 | k3-sec-8b |
| atk-dns | 0/3 | 0/3 | neither |
| atk-jwt | **2/3** | 0/3 | k3-sec-8b |
| def-bruteforce | **2/3** | 0/3 | k3-sec-8b |
| def-webshell | **3/3** | 0/3 | k3-sec-8b |
| def-harden | 0/3 | **3/3** | FSec-1.1 |
| def-detect-dns | **1/3** | 0/3 | k3-sec-8b |
| def-ioc | 0/3 | 0/3 | neither |

k3-sec-8b wins or ties 8 of 10 tasks. Its standout is **def-webshell (3/3 vs 0/3)** β€”
log analysis and firewall-rule writing requiring multi-step shell-tool operation. FSec-1.1's
only decisive win is **def-harden (3/3 vs 0/3)** β€” single-shot SSH config editing where
instruction-following suffices.

### Key takeaways

- **k3-sec-8b is the more capable agentic model** (nearly 2Γ— the operational score),
  consistent with its training on agentic tool-use traces. It scores a stable 5/10 every
  run; FSec-1.1 is volatile (1–4/10).
- **FSec-1.1 has slightly stronger factual knowledge** (perfect 45/45 vs 43/45 on the MCQ
  battery), consistent with its 5.1B-token cybersecurity CPT. But that knowledge doesn't
  translate to agentic capability on this harness.
- **Neither model solves atk-dns or def-ioc** β€” the hardest tasks on this lab.
- The Q8_0 GGUF format costs k3-sec-8b ~1 knowledge-quiz point vs bf16 (43 vs 44) but does
  not materially degrade agentic performance.