Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +352 -324
- inference.py +3 -5
README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
---
|
| 3 |
title: Network Forensics Environment
|
| 4 |
emoji: "π°οΈ"
|
|
@@ -8,331 +7,360 @@ sdk: docker
|
|
| 8 |
sdk_version: "1.0.0"
|
| 9 |
pinned: false
|
| 10 |
app_port: 8000
|
| 11 |
-
base_path: /
|
| 12 |
tags:
|
| 13 |
- openenv
|
|
|
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
# Network Forensics Environment
|
| 17 |
-
|
| 18 |
-
`network_forensics` is an OpenEnv benchmark for packet triage and intrusion investigation. It simulates a real analyst workflow: inspect traffic, flag
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
##
|
| 23 |
-
|
| 24 |
-
Security analysts
|
| 25 |
-
|
| 26 |
-
- Which packets are suspicious?
|
| 27 |
-
- Which packets belong to the same
|
| 28 |
-
- What kind of attack is
|
| 29 |
-
-
|
| 30 |
-
|
| 31 |
-
This environment turns that
|
| 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 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
```
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
```
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Network Forensics Environment
|
| 3 |
emoji: "π°οΈ"
|
|
|
|
| 7 |
sdk_version: "1.0.0"
|
| 8 |
pinned: false
|
| 9 |
app_port: 8000
|
| 10 |
+
base_path: /
|
| 11 |
tags:
|
| 12 |
- openenv
|
| 13 |
+
- rl-environment
|
| 14 |
+
- network-security
|
| 15 |
---
|
| 16 |
|
| 17 |
# Network Forensics Environment
|
| 18 |
+
|
| 19 |
+
`network_forensics` is an OpenEnv benchmark for packet triage and intrusion investigation. It simulates a real analyst workflow: inspect traffic, flag suspicious packets, group related activity into sessions, classify attack patterns, identify the likely entry point, and submit a final report.
|
| 20 |
+
|
| 21 |
+
The environment is backed by generated PCAP traces and deterministic JSON answer keys, so agents can be evaluated consistently while still solving a real-world security analysis task.
|
| 22 |
+
|
| 23 |
+
## Motivation
|
| 24 |
+
|
| 25 |
+
Security analysts routinely ask:
|
| 26 |
+
|
| 27 |
+
- Which packets are suspicious?
|
| 28 |
+
- Which packets belong to the same malicious session?
|
| 29 |
+
- What kind of attack is this?
|
| 30 |
+
- Which packet looks like the initial compromise or entry point?
|
| 31 |
+
|
| 32 |
+
This environment turns that workflow into a reproducible benchmark for LLM and RL-style agents.
|
| 33 |
+
|
| 34 |
+
## Tasks
|
| 35 |
+
|
| 36 |
+
The benchmark includes three deterministic tasks with increasing difficulty.
|
| 37 |
+
|
| 38 |
+
### Easy
|
| 39 |
+
|
| 40 |
+
- Files: `pcaps/easy_task.pcap`, `pcaps/easy_task.json`
|
| 41 |
+
- Theme: DDoS-heavy traffic mixed with benign flows
|
| 42 |
+
- Goal: recover the main malicious traffic and dominant attack sessions
|
| 43 |
+
|
| 44 |
+
### Medium
|
| 45 |
+
|
| 46 |
+
- Files: `pcaps/medium_task.pcap`, `pcaps/medium_task.json`
|
| 47 |
+
- Theme: mixed web attacks
|
| 48 |
+
- Attack families: `web_bruteforce`, `web_xss`, `web_sql_injection`
|
| 49 |
+
- Goal: separate multiple web attack sessions and tag them correctly
|
| 50 |
+
|
| 51 |
+
### Hard
|
| 52 |
+
|
| 53 |
+
- Files: `pcaps/hard_task.pcap`, `pcaps/hard_task.json`
|
| 54 |
+
- Theme: noisy denial-of-service and exploitation traffic
|
| 55 |
+
- Attack families: `dos_hulk`, `dos_goldeneye`, `dos_slowloris`, `dos_slowhttptest`, `heartbleed`
|
| 56 |
+
- Goal: recover multiple malicious sessions, avoid false positives, and identify the root cause accurately
|
| 57 |
+
|
| 58 |
+
## Action Space
|
| 59 |
+
|
| 60 |
+
The environment uses the `NetworkForensicsAction` Pydantic model:
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
class NetworkForensicsAction(Action):
|
| 64 |
+
action_type: str
|
| 65 |
+
packet_id: Optional[str] = None
|
| 66 |
+
packet_ids: Optional[List[str]] = None
|
| 67 |
+
session_name: Optional[str] = None
|
| 68 |
+
pattern_type: Optional[str] = None
|
| 69 |
+
claimed_entry_point: Optional[str] = None
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
Supported actions:
|
| 73 |
+
|
| 74 |
+
- `inspect_packet`: reveal the payload of `packet_id`
|
| 75 |
+
- `flag_as_suspicious`: mark `packet_id` as suspicious
|
| 76 |
+
- `group_into_session`: group `packet_ids` under `session_name`
|
| 77 |
+
- `tag_pattern`: assign an attack label to a session
|
| 78 |
+
- `identify_entry_point`: claim the likely first malicious packet
|
| 79 |
+
- `submit_report`: end the episode and trigger deterministic final grading
|
| 80 |
+
|
| 81 |
+
## Observation Space
|
| 82 |
+
|
| 83 |
+
The environment returns `NetworkForensicsObservation`:
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
class NetworkForensicsObservation(Observation):
|
| 87 |
+
step_number: int
|
| 88 |
+
steps_remaining: int
|
| 89 |
+
total_packets: int
|
| 90 |
+
visible_packets: List[PacketRecord]
|
| 91 |
+
flagged_packet_ids: List[str]
|
| 92 |
+
grouped_sessions: Dict[str, List[str]]
|
| 93 |
+
tagged_patterns: Dict[str, str]
|
| 94 |
+
claimed_entry_point: Optional[str]
|
| 95 |
+
connection_graph_summary: Dict[str, Any]
|
| 96 |
+
current_score_estimate: float
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Each `PacketRecord` includes fields such as:
|
| 100 |
+
|
| 101 |
+
- `packet_id`
|
| 102 |
+
- `src_ip`
|
| 103 |
+
- `dst_ip`
|
| 104 |
+
- `src_port`
|
| 105 |
+
- `dst_port`
|
| 106 |
+
- `protocol`
|
| 107 |
+
- `ttl`
|
| 108 |
+
- `payload_size`
|
| 109 |
+
- `payload_preview`
|
| 110 |
+
- `full_payload` once revealed
|
| 111 |
+
|
| 112 |
+
## Reward and Grading
|
| 113 |
+
|
| 114 |
+
The environment uses two complementary signals.
|
| 115 |
+
|
| 116 |
+
### Shaped Step Reward
|
| 117 |
+
|
| 118 |
+
Dense reward is provided across the trajectory instead of only at the end.
|
| 119 |
+
|
| 120 |
+
Higher reward is given for:
|
| 121 |
+
|
| 122 |
+
- first-time malicious packet inspection
|
| 123 |
+
- correct suspicious flags
|
| 124 |
+
- high-overlap session grouping
|
| 125 |
+
- correct pattern tagging
|
| 126 |
+
- correct entry-point identification
|
| 127 |
+
|
| 128 |
+
Lower reward is given for undesirable behavior such as:
|
| 129 |
+
|
| 130 |
+
- repeated inspection
|
| 131 |
+
- duplicate flags
|
| 132 |
+
- poor grouping recall
|
| 133 |
+
- low-quality or incorrect actions
|
| 134 |
+
|
| 135 |
+
Both step reward and running score are normalized into `[0.0, 1.0]`.
|
| 136 |
+
|
| 137 |
+
### Deterministic Final Grader
|
| 138 |
+
|
| 139 |
+
The final `submit_report` action runs a deterministic audit against the task JSON answer key.
|
| 140 |
+
|
| 141 |
+
The final score is:
|
| 142 |
+
|
| 143 |
+
```text
|
| 144 |
+
0.3 * precision + 0.4 * recall + 0.3 * logic
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
Where:
|
| 148 |
+
|
| 149 |
+
- `precision`: how cleanly the agent flagged malicious packets
|
| 150 |
+
- `recall`: how much malicious traffic the agent actually recovered
|
| 151 |
+
- `logic`: whether the agent linked sessions, tags, and entry point correctly for the task difficulty
|
| 152 |
+
|
| 153 |
+
Difficulty-specific success rules are enforced:
|
| 154 |
+
|
| 155 |
+
- `easy`: strong malicious-packet recall
|
| 156 |
+
- `medium`: strong recall plus meaningful session overlap and acceptable precision
|
| 157 |
+
- `hard`: all of the above plus correct root-cause identification
|
| 158 |
+
|
| 159 |
+
Ground truth comes from the JSON files in `pcaps/`, including:
|
| 160 |
+
|
| 161 |
+
- `malicious_packets`
|
| 162 |
+
- `packet_roles`
|
| 163 |
+
- `sessions`
|
| 164 |
+
- `session_roles`
|
| 165 |
+
- `entry_point`
|
| 166 |
+
|
| 167 |
+
Core implementation lives in:
|
| 168 |
+
|
| 169 |
+
- `src/reward.py`
|
| 170 |
+
- `src/pcap_generator.py`
|
| 171 |
+
- `server/network_forensics_environment.py`
|
| 172 |
+
|
| 173 |
+
## Baseline Inference
|
| 174 |
+
|
| 175 |
+
The baseline runner is `inference.py`.
|
| 176 |
+
|
| 177 |
+
It:
|
| 178 |
+
|
| 179 |
+
- uses the OpenAI-compatible client for model calls
|
| 180 |
+
- supports `server` and `docker` execution modes
|
| 181 |
+
- prints `[START]`, `[STEP]`, and `[END]` logs
|
| 182 |
+
- runs `easy`, `medium`, and `hard` sequentially
|
| 183 |
+
|
| 184 |
+
Important environment variables:
|
| 185 |
+
|
| 186 |
+
- `API_BASE_URL`
|
| 187 |
+
- `MODEL_NAME`
|
| 188 |
+
- `OPENAI_API_KEY`, `API_KEY`, or `HF_TOKEN`
|
| 189 |
+
- `NETWORK_FORENSICS_ENV_MODE`
|
| 190 |
+
- `ENV_BASE_URL`
|
| 191 |
+
- `LOCAL_IMAGE_NAME`
|
| 192 |
+
|
| 193 |
+
### Example Baseline Results
|
| 194 |
+
|
| 195 |
+
Observed recent runs:
|
| 196 |
+
|
| 197 |
+
- `openai/gpt-oss-120b`
|
| 198 |
+
- `easy`: success `true`, score `0.64`
|
| 199 |
+
- `medium`: success `false`, score `0.55`
|
| 200 |
+
- `hard`: success `true`, score `0.63`
|
| 201 |
+
- `mistralai/mistral-small-4-119b-2603`
|
| 202 |
+
- `easy`: success `false`, score `0.46`
|
| 203 |
+
- `medium`: success `false`, score `0.57`
|
| 204 |
+
- `hard`: success `true`, score `0.60`
|
| 205 |
+
|
| 206 |
+
These examples show that the environment and final grader are sensitive to model behavior rather than returning a constant score.
|
| 207 |
+
|
| 208 |
+
## Setup and Local Usage
|
| 209 |
+
|
| 210 |
+
Install dependencies:
|
| 211 |
+
|
| 212 |
+
```bash
|
| 213 |
+
uv sync
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
Start the server:
|
| 217 |
+
|
| 218 |
+
```bash
|
| 219 |
+
uv run server
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
Or with uvicorn directly:
|
| 223 |
+
|
| 224 |
+
```bash
|
| 225 |
+
uvicorn server.app:app --host 0.0.0.0 --port 8000
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
Useful endpoints:
|
| 229 |
+
|
| 230 |
+
- `/` for the custom Gradio analyst UI
|
| 231 |
+
- `/web` redirects to `/`
|
| 232 |
+
- `/health`
|
| 233 |
+
- `/docs`
|
| 234 |
+
- `/reset`
|
| 235 |
+
- `/step`
|
| 236 |
+
- `/state`
|
| 237 |
+
- `/schema`
|
| 238 |
+
- `/ws`
|
| 239 |
+
|
| 240 |
+
Run the baseline against the local server:
|
| 241 |
+
|
| 242 |
+
```bash
|
| 243 |
+
NETWORK_FORENSICS_ENV_MODE=server ENV_BASE_URL=http://localhost:8000 python inference.py
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
On Windows PowerShell:
|
| 247 |
+
|
| 248 |
+
```powershell
|
| 249 |
+
$env:NETWORK_FORENSICS_ENV_MODE="server"
|
| 250 |
+
$env:ENV_BASE_URL="http://localhost:8000"
|
| 251 |
+
py .\inference.py
|
| 252 |
+
```
|
| 253 |
+
|
| 254 |
+
## Docker
|
| 255 |
+
|
| 256 |
+
The deployment Dockerfile is:
|
| 257 |
+
|
| 258 |
+
- `server/Dockerfile`
|
| 259 |
+
|
| 260 |
+
From the cloned `network_forensics` repository root:
|
| 261 |
+
|
| 262 |
+
```bash
|
| 263 |
+
docker build -t network-forensics-env -f server/Dockerfile .
|
| 264 |
+
docker run -p 8000:8000 network-forensics-env
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
This is the canonical OpenEnv and Hugging Face Space deployment path.
|
| 268 |
+
|
| 269 |
+
## Hugging Face Space Deployment
|
| 270 |
+
|
| 271 |
+
This project is configured as a Docker-based OpenEnv Space through `openenv.yaml`.
|
| 272 |
+
|
| 273 |
+
Validate locally:
|
| 274 |
+
|
| 275 |
+
```bash
|
| 276 |
+
openenv validate
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
Push to Hugging Face using the custom UI rather than the default OpenEnv web interface:
|
| 280 |
+
|
| 281 |
+
```bash
|
| 282 |
+
openenv push --no-interface
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
On the deployed Space:
|
| 286 |
+
|
| 287 |
+
- `/` serves the custom Gradio analyst console
|
| 288 |
+
- `/web` redirects to `/`
|
| 289 |
+
- the OpenEnv API remains available for agent evaluation
|
| 290 |
+
|
| 291 |
+
## Connecting From Python
|
| 292 |
+
|
| 293 |
+
Connect to a running local or remote server:
|
| 294 |
+
|
| 295 |
+
```python
|
| 296 |
+
from network_forensics import NetworkForensicsAction, NetworkForensicsEnv
|
| 297 |
+
|
| 298 |
+
with NetworkForensicsEnv(base_url="http://localhost:8000") as env:
|
| 299 |
+
result = env.reset(task_id="easy")
|
| 300 |
+
result = env.step(
|
| 301 |
+
NetworkForensicsAction(
|
| 302 |
+
action_type="inspect_packet",
|
| 303 |
+
packet_id="pkt_0008",
|
| 304 |
+
)
|
| 305 |
+
)
|
| 306 |
+
```
|
| 307 |
+
|
| 308 |
+
Connect to a deployed Hugging Face Space:
|
| 309 |
+
|
| 310 |
+
```python
|
| 311 |
+
from network_forensics import NetworkForensicsAction, NetworkForensicsEnv
|
| 312 |
+
|
| 313 |
+
with NetworkForensicsEnv.from_env("<hf-username>/<hf-repo-name>") as env:
|
| 314 |
+
result = env.reset(task_id="medium")
|
| 315 |
+
result = env.step(
|
| 316 |
+
NetworkForensicsAction(
|
| 317 |
+
action_type="flag_as_suspicious",
|
| 318 |
+
packet_id="pkt_0008",
|
| 319 |
+
)
|
| 320 |
+
)
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
## Dataset Build Pipeline
|
| 324 |
+
|
| 325 |
+
Task PCAPs and answer keys are generated from labeled flow data using:
|
| 326 |
+
|
| 327 |
+
- `scripts/build_task_pcaps.py`
|
| 328 |
+
|
| 329 |
+
That script writes:
|
| 330 |
+
|
| 331 |
+
- `pcaps/easy_task.pcap`
|
| 332 |
+
- `pcaps/easy_task.json`
|
| 333 |
+
- `pcaps/medium_task.pcap`
|
| 334 |
+
- `pcaps/medium_task.json`
|
| 335 |
+
- `pcaps/hard_task.pcap`
|
| 336 |
+
- `pcaps/hard_task.json`
|
| 337 |
+
|
| 338 |
+
## Repository Structure
|
| 339 |
+
|
| 340 |
+
```text
|
| 341 |
+
network_forensics/
|
| 342 |
+
βββ .dockerignore
|
| 343 |
+
βββ .gitignore
|
| 344 |
+
βββ __init__.py
|
| 345 |
+
βββ client.py
|
| 346 |
+
βββ inference.py
|
| 347 |
+
βββ models.py
|
| 348 |
+
βββ openenv.yaml
|
| 349 |
+
βββ pcaps/
|
| 350 |
+
βββ pyproject.toml
|
| 351 |
+
βββ README.md
|
| 352 |
+
βββ scripts/
|
| 353 |
+
β βββ build_task_pcaps.py
|
| 354 |
+
βββ server/
|
| 355 |
+
β βββ app.py
|
| 356 |
+
β βββ Dockerfile
|
| 357 |
+
β βββ gradio_ui.py
|
| 358 |
+
β βββ network_forensics_environment.py
|
| 359 |
+
βββ src/
|
| 360 |
+
βββ pcap_generator.py
|
| 361 |
+
βββ reward.py
|
| 362 |
+
βββ tasks/
|
| 363 |
+
βββ easy.py
|
| 364 |
+
βββ medium.py
|
| 365 |
+
βββ hard.py
|
| 366 |
+
```
|
inference.py
CHANGED
|
@@ -19,8 +19,8 @@ from models import NetworkForensicsAction
|
|
| 19 |
load_dotenv(Path(__file__).parent / ".env")
|
| 20 |
|
| 21 |
API_BASE_URL = os.getenv("API_BASE_URL")
|
| 22 |
-
MODEL_NAME = os.getenv("MODEL_NAME")
|
| 23 |
-
API_KEY = os.getenv("API_KEY") or os.getenv("HF_TOKEN")
|
| 24 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME", "network-forensics-env:latest")
|
| 25 |
ENV_MODE = (os.getenv("NETWORK_FORENSICS_ENV_MODE") or os.getenv("ENV_MODE") or "docker").lower()
|
| 26 |
ENV_BASE_URL = os.getenv("ENV_BASE_URL", "http://localhost:8000")
|
|
@@ -50,10 +50,8 @@ def validate_config() -> None:
|
|
| 50 |
missing = []
|
| 51 |
if not API_BASE_URL:
|
| 52 |
missing.append("API_BASE_URL")
|
| 53 |
-
if not MODEL_NAME:
|
| 54 |
-
missing.append("MODEL_NAME")
|
| 55 |
if not API_KEY:
|
| 56 |
-
missing.append("API_KEY")
|
| 57 |
if missing:
|
| 58 |
raise RuntimeError(f"Missing required environment variables: {', '.join(missing)}")
|
| 59 |
if ENV_MODE not in {"server", "docker"}:
|
|
|
|
| 19 |
load_dotenv(Path(__file__).parent / ".env")
|
| 20 |
|
| 21 |
API_BASE_URL = os.getenv("API_BASE_URL")
|
| 22 |
+
MODEL_NAME = os.getenv("MODEL_NAME", "openai/gpt-oss-120b")
|
| 23 |
+
API_KEY = os.getenv("OPENAI_API_KEY") or os.getenv("API_KEY") or os.getenv("HF_TOKEN")
|
| 24 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME", "network-forensics-env:latest")
|
| 25 |
ENV_MODE = (os.getenv("NETWORK_FORENSICS_ENV_MODE") or os.getenv("ENV_MODE") or "docker").lower()
|
| 26 |
ENV_BASE_URL = os.getenv("ENV_BASE_URL", "http://localhost:8000")
|
|
|
|
| 50 |
missing = []
|
| 51 |
if not API_BASE_URL:
|
| 52 |
missing.append("API_BASE_URL")
|
|
|
|
|
|
|
| 53 |
if not API_KEY:
|
| 54 |
+
missing.append("OPENAI_API_KEY/API_KEY/HF_TOKEN")
|
| 55 |
if missing:
|
| 56 |
raise RuntimeError(f"Missing required environment variables: {', '.join(missing)}")
|
| 57 |
if ENV_MODE not in {"server", "docker"}:
|