Skip to content

Herorif/TrafficLightExploit

Repository files navigation

Traffic Light & Cyber Range Simulator

Modernized traffic-light cyber range with live 2D/3D visuals, MQTT-driven control loop, attack orchestration, and an embedded red-light camera simulator. Everything runs locally (simulation only); no physical devices are touched.

Overview

  • Frontend: React + Vite + Electron shell, with Spline 3D landing/dashboard backgrounds and switchable 2D/3D intersection renders.
  • Backend: Flask API + MQTT client; optional DB state logging with tunable queue sizes; simulation-only guardrails.
  • Attacks: DoS/replay/MITM/timing perturbations, camera tampering presets, and live SSE/mqtt streams for dashboards.
  • Profiles: Ideal/legacy envelopes that change timings, mitigations, and fallback behaviors.

Initialize & Run

Prerequisites

  • Python 3.10+ (with pip)
  • Node 18+ (npm)
  • Mosquitto (local broker) or set MQTT_BROKER_HOST/PORT

One-time setup

# Backend
cd backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

# Frontend
cd ../frontend
npm install

Dev workflow (recommended)

From the repo root, start the stack:

# MQTT broker (local install or your own)
# Mosquitto default ports: 1885 (tcp), 9001 (ws)

# Backend
cd backend
venv\Scripts\activate
python src/main.py

# Frontend (separate shell)
cd frontend
npm run dev

# Electron shell (separate shell, after frontend dev server is up)
cd electron
npx electron ..

Packaged/static workflow

cd frontend
npm run build    # builds UI + syncs static assets to backend/src/static

cd ../backend
venv\Scripts\activate
python src/main.py   # serves the built UI at http://127.0.0.1:5000

# Optional: Electron against built UI
cd ../electron
npx electron ..

Quick launcher (Windows)

run.bat will start Mosquitto (if installed), backend, frontend dev server, auto-initialize the simulator, and launch Electron.

Getting Started

  1. Start the Flask backend (python backend/src/main.py) and the frontend client.
  2. Use /api/traffic/* and /api/attack/* endpoints or the dashboard panels to provision profiles, launch attacks, and watch events stream live.
  3. Optional tooling:
    • Export the last 200 synthetic incidents via GET /api/sim/events/export.
    • Run unit tests (after installing pytest) with python -m pytest tests/sim_camera/test_state.py.

Camera Profiles

Profile Detection OCR Health Ticket Delay (min) Baseline Deterrence
ideal 0.94 0.92 0.95 3 0.45
mid 0.82 0.78 0.75 7 0.70
legacy 0.58 0.55 0.50 18 1.05

Switch profiles via POST /api/sim/camera/profile with body {"profile": "mid"}. Each profile defines detection probabilities, OCR confidence ranges, baseline enforcement delays, and the deterrence multiplier that feeds the red-light runner model.

Attack Presets

Presets live in backend/src/sim_camera/presets.json and are loaded at runtime. Each entry exposes the base effect payload that is scaled by intensity (low, medium, high).

ID Default Duration (s) Key Effects
natural_state -- Baseline operation; no simulated impact
cam_occlusion 600 Detection -45%, OCR -40%, health -50%
lens_glare 420 Detection -25%, OCR -50%
network_outage 900 Backend offline, enforcement paused, packet loss 65%
sim_ddos 480 Detection -35%, OCR -20%, latency +350 ms
time_drift 780 Clock offset +14 s, detection/OCR -5%
replay 540 Replay flag active, detection -20%
signage_tamper 720 Deterrence x1.5, detection/OCR -10%
insider_override 600 Enforcement paused, latency +150 ms

Deploy an attack via POST /api/sim/attack/deploy:

{
  "preset_id": "network_outage",
  "duration_sec": 300,
  "intensity": "high",
  "target_intersection": "main"
}

SSE events (/api/sim/events/stream) broadcast attack_deployed, attack_ended, and event frames so the UI can show countdowns and recent incidents.

Event Schema

Every stored incident follows this shape:

{
  "event_id": "string",
  "intersection_id": "main",
  "lane_id": "north",
  "vehicle_type": "car",
  "license_plate": "ABC1234",
  "plate_confidence": 0.91,
  "timestamp_frame": "2025-11-02T12:34:56+00:00",
  "timestamp_violation": "2025-11-02T12:34:55+00:00",
  "phase": "NS_GREEN",
  "time_into_red": 1.6,
  "speed_estimated": 58.2,
  "image_front_url": null,
  "detected_by_camera": true,
  "detected_by_backend": true,
  "detection_accuracy": 0.92,
  "ticket_generated": true,
  "ticket_id": "TKT-XXX",
  "enforcement_delay_minutes": 3.5,
  "camera_health": 0.88,
  "attack_flags": ["network_outage"],
  "notes": "",
  "false_positive": false,
  "needs_review": false,
  "operator_actions": []
}

Tickets are generated only when:

  • backend link is healthy,
  • central detection succeeded,
  • plate_confidence >= ticket_threshold (profile-specific).

Results & Exports

  • Traffic Throughput vs. Attack and Violation Rate vs. Profile charts show mitigation effects.
  • Export incidents for analysis via /api/sim/events/export?format=csv|json.

Experiments & Metrics

  • Baseline 1,000 violations per profile; compare detection/OCR rates.
  • Apply cam_occlusion or network_outage and watch detection drop vs false positives.
  • Combine time_drift + replay to inspect timestamp divergence.
  • Metrics block shows rolling detection, OCR, violations, tickets, mean delay, false-positive ratio.

Performance / Tuning

  • Light mode (default): SIM_LIGHT_MODE=1 skips DB state logging. Enable logging with SIM_STATE_LOGGING=1 and optional SIM_DB_QUEUE_SIZE (default 5000, min 500).
  • MQTT pacing: MQTT_MIN_INTERVAL_MS (default 40ms for non-attack topics), MQTT_QUEUE_LIMIT (default 400). Attack topics bypass pacing.
  • Broker host/port: MQTT_BROKER_HOST, MQTT_BROKER_PORT (default 1885).
  • Frontend: 3D renderer trimmed (shadows off, moderate assets) for smoother attack runs.

About

This project is created for my Final Year Project and built for my passion in improving the Cybersecurity in general.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors