Share
## https://sploitus.com/exploit?id=20B0B80E-8F18-519B-9C29-A0CDC6C4AEEC
# πŸš— End-to-end security assessment of vehicle subsystems

[! [Methodology](https://img.shields.io/badge/Methodology-ISO%2FSAE_21434-blue)](https://www.iso.org/standard/70918.html)
[! [Python](https://img.shields.io/badge/Python-3.11+-green)](https://python.org)
[! [Docker](https://img.shields.io/badge/Docker-Compose-blue)](https://docs.docker.com/compose/)
[! [License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)

**Professional-grade Vehicle Cybersecurity Assessment Platform**, demonstrating the complete ISO/SAE 21434 security engineering workflow: TARA analysis β†’ vulnerability assessment β†’ vulnerability exploitation β†’ defense β†’ intrusion detection.

> 🎯 Built specifically for cybersecurity engineers entering the automotive security field. Demonstrates real-world vehicle security skills applicable to Chinese automotive OEMs and Tier-1 suppliers.

## πŸ“‹ Catalog.

- [Project Conduct Process](# - Project Conduct Process)
- [Architecture](#-Architecture)
- [Quick Start](#-Quick Start)
- [Project Structure](#-Project Structure)
- [Phases](#-Phases)
- [Vulnerability Matrix](#-Vulnerability Matrix)
- [Attack Demo](#-Attack Demo)
- [Defense Results](#-Defense Results)
- [IDS Detection](#-ids-detection)
- [Tools](#-Tools)
- [Skill Show](#-Skill Show)

## πŸ—ΊοΈ Project Conduct Process

The execution of this project strictly follows the vehicle network security engineering process specified in the ISO/SAE 21434 standard, building a complete vehicle subsystem from scratch, and then progressively completing security assessment, attack verification, defense hardening, and intrusion detection.

### Overall methodology

``##
Environment build β†’ TARA threat analysis β†’ vulnerability assessment β†’ attack exploitation β†’ defense implementation β†’ intrusion detection β†’ final report
(Step 1) (Step 2) (Step 3) (Step 4) (Step 5) (Step 6) (Step 7)
``

### Detailed execution steps

---

#### πŸ”§ Step 1: Build the simulation environment (`environment/`)

**Objective**: build a complete remote vehicle control subsystem containing the full link from the cloud to the CAN bus.

| Substeps | What to do | Output | Verification Methods |
|:---|:---|:---|:---|
| 1.1 | Write `docker-compose.yml`, define 5 services (PostgreSQL, EMQX, Cloud API, T-BOX, ECU) | `docker-compose.yml` | `docker compose up -d` All started successfully | | 1.2 | Develop
| 1.2 | Develop **Cloud API** (Flask) to implement 20+ REST endpoints for user authentication, vehicle management, remote commands, etc. | `cloud-api/` All code | `curl` Test register/login/send commands |
| 1.3 | Develop **T-BOX gateway** (Python) for MQTT ↔ CAN bi-directional bridging | `tbox-simulator/` All code | MQTT messages are correctly forwarded to CAN bus |
| 1.4 | Develop **ECU simulator** (Python) for body control + UDS diagnostic service | `ecu-simulator/` All code | CAN messages trigger correct vehicle state changes |
| 1.5 | Write `setup.sh` one-click deployment script + SQL seed data | `setup.sh`, `init-db.sql` | Execute `. /setup.sh` and end-to-end command flow works |
| 1.6 | Develop 3 security assessment tools | `tools/` all code | each tool runs independently and produces results |

**The key to this step**: 19 vulnerabilities** (V-01 through V-19) were intentionally planted in the code** that mimic common security flaws in real vehicle systems to provide targets for subsequent security assessments and attack demonstrations.

---

#### πŸ“Š Step 2: TARA Threat Analysis and Risk Assessment (`tara/`)

**Objective**: perform a systematic threat analysis and risk assessment of the system built in step 1 according to ISO/SAE 21434.

| Substeps | Output Documentation | Content |
|:---|:---|:---|
| 2.1 | `project-definition.md` | System description, architecture diagram, data flow diagram (DFD), external interfaces, communication protocols, security assumptions |
| 2.2 | `asset-inventory.md` | Identify 25 security assets (data/functional/communication/physical/software) and assign a C/I/A rating to each | 2.3 | `asset-inventory.md` | Identify and assign a C/I/A rating to each
| 2.3 | `threat-scenarios.md` | Identify 26 threat scenarios using the STRIDE methodology and build an attack tree | 2.4 | `threat-scenarios.md` | Identify 25 security assets (data/functional/communication/physical/software) and assign a C/I/A rating to each
2.4 | `attack-paths.md` | Describes each step of four high-risk attack paths in detail, labeling existing security control points | 2.5 | `threat-scenarios.md` | Identifies 26 threat scenarios using the STRIDE methodology to build an attack tree.
| 2.5 | `risk-assessment.md` | 5Γ—4 risk matrix (Impact I0-I3 Γ— Feasibility E0-E3) with R1-R4 ratings | 2.6 | `attack-paths.md` | Detailed description of each step of the 4 high-risk attack paths, with existing security control points labeled
| 2.6 | `security-requirements.md` | Derivation of 22 security requirements from R3/R4 risks, creation of traceability matrix | 2.7 | `risk-assessment.md` | 5Γ—4 risk matrix (impacts I0-I3 Γ— feasibility E0-E3)

**Expected results**: 15 R4 (severe) risks + 11 R3 (high) risks, clear baseline of security requirements.

---

#### πŸ” Step 3: Vulnerability Assessment (`assessment/`)

**Objective**: perform systematic security testing of every component of the system to discover and document all vulnerabilities.

| Sub-steps | Test Objects | Test Methods |
|:---|:---|:---|
| 3.1 | Cloud API | Authentication Bypass Testing, BOLA Testing, SQL Injection, JWT Weakness, Rate Limiting, CORS, Error Handling |
| 3.2 | MQTT Broker | TLS Configuration Check, ACL Testing, Subject Enumeration, Credential Strength, Message Injection | 3.3 | TQTT Broker | TLS Configuration Check, ACL Testing, Subject Enumeration, Credential Strength, Message Injection
| 3.3 | T-BOX Gateway | Port Scanning, Credential Extraction, CAN Interface Accessibility, Firewall Rule Analysis | 3.4 | CAN Interface Accessibility, Firewall Rule Analysis
| 3.4 | CAN Bus | Sniffing and Protocol Reversal, Message Injection, Replay Attacks, DoS Flooding, UDS Service Enumeration | 3.5 | Aggregate | T-BOX Gateway | Port Scanning, Credential Extraction, CAN Interface Accessibility, Firewall Rules Analysis
| 3.5 | Aggregation | Generate Vulnerability Matrix (19 vulnerabilities with CVSS scores, reproduction steps, remediation scenarios) + Attack Chain Mapping

---

#### βš”οΈ Step 4: Attack Exploitation (`exploitation/`)

**Objective**: develop a runnable PoC attack script to validate the actual harm of the vulnerability from the attacker's perspective.

| Attack Scenarios | Exploit Vulnerability | Attack Link | Run Command |
|:---|:---|:---|:---|:---|
| **Remote Control Chain** | V-01, V-04, V-05, V-06 | Low-privilege login β†’ BOLA overpass β†’ Unsigned command injection β†’ Take control of someone else's vehicle | `python exploit.py --base-url http://localhost:5000` |
| **CAN injection** | V-15, V-16 | Direct connection to vcan0 β†’ Reverse CAN protocol β†’ Inject forged messages β†’ Control doors/engine | `sudo python can_inject.py --channel vcan0` |
| **MQTT injection** | V-11, V-12, V-13, V-14 | Steal credentials β†’ connect to Broker β†’ issue forged commands β†’ fleet-level impact | `python mqtt_attack.py --host localhost` |
| **UDS Exploit** | V-17 | Enumerate UDS Services β†’ XOR Crack SecurityAccess β†’ Read/Write DID β†’ ECU Control | `sudo python uds_exploit.py --channel vcan0` |

---

#### πŸ›‘οΈ Step 5: Defense Implementation (`defense/`)

**Objective**: implement the security requirements derived in step 2, fix all vulnerabilities, and verify the effectiveness of the defense.

| Substeps | Hardened Content | Fixed Vulnerabilities |
|:---|:---|:---|
| 5.1 | **API Hardening**: add Ownership Authentication Middleware, Password Policies, Rate Limiting, HMAC Signatures, Parameterized Queries, CORS Limitations, OTP Authentication, RBAC | V-01 to V-10 |
| 5.2 | **MQTT Security**: enable TLS, per-vehicle independent credentials, topic-level ACLs, message signature verification | V-11 through V-14 | 5.3 | **MQTT Security**: enable TLS, per-vehicle independent credentials, topic-level ACLs, message signature verification
| 5.3 | **CAN SecOC**: Enforce secure in-vehicle communication (counters + AES-CMAC) to prevent replay and injection | V-15, V-16 | 5.4 | *MQTT Security**: Enable TLS, per-vehicle independent credentials, subject-level ACLs, message signature validation
| 5.4 | **Gateway Filtering**: CAN ID whitelisting, frequency restriction, content validation, source authentication | V-15, V-16 (enhanced) |
| 5.5 | **Validation**: retest with attack scripts from step 4 β†’ Generate pre- and post-enforcement comparison report | `validation-results.md` |

**Expected Results**: **90.5% of attacks completely blocked**, remaining 9.5% mitigated to acceptable residual risk.

---

#### πŸ“‘ Step 6: Intrusion Detection System (`ids/`)

**Objective**: build a multi-layer IDS to achieve real-time detection of attacks and cross-layer correlation analysis.

| Components | Functionality | Detection Capability |
|:---|:---|:---|
| `can_ids.py` | CAN Bus Anomaly Detection | Whitelist Filtering, Frequency Anomaly, Content Checking, Sequence Anomaly |
| `mqtt_ids.py` | MQTT Traffic Monitoring | Authentication Monitoring, Subject Access Monitoring, Message Frequency, Load Checking |
| `api_monitor.py` | API Attack Detection | Brute Force Detection, BOLA Detection, SQL Injection Detection, Endpoint Scanning Detection | `correlation_ids.py` | MQTT Traffic Monitor
| `correlation_engine.py` | Cross-layer correlation engine | 7 attack chain pattern matching, duplicate alarm suppression, confidence calculation | `dashboard.py` | API attack detection | Violent crack detection, BOLA detection, SQL injection detection, endpoint scan detection
| `dashboard.py` | Endpoint real-time dashboard | Three-layer status panel, real-time alarms, attack chain timeline |

**Expected results**: **85% detection rate**, false alarm rate below 5%, average detection delay 2.3 seconds.

---

#### πŸ“ Step 7: Final Report (`report/`)

**Objective**: to produce a two-tier report for management and technical teams.

| reports | readers | content |
|:---|:---|:---|
| `executive-summary.md` | management | One-page summary: Key Findings Top 5, Risk Overview, Prioritized Recommendations, Security Posture Score |
| `technical-report.md` | Technical Team | Full technical report: methodology, TARA summary, vulnerability details, exploitation results, defense validation, IDS performance, lessons learned |

---

### Process Overview Diagram

``
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Vehicle Subsystem End-to-End Security Assessment Process β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Step 1 β”‚ β”‚ β”‚ Step 2 β”‚ β”‚ Step 3 β”‚ β”‚ Step 4 β”‚ β”‚ Step 5 β”‚ β”‚ Step 6 β”‚ β”‚ β”‚ Step 7 β”‚
β”‚ πŸ—οΈ │───→│ πŸ“Š │───→│ πŸ” │───→│ βš”οΈ │───→│ πŸ›‘οΈ │───→│ πŸ“‘ │──→│ πŸ“ β”‚
β”‚ Environment Setup β”‚ β”‚ TARA Analysis β”‚ β”‚ Vulnerability Assessment β”‚ β”‚ Attack Exploitation β”‚ β”‚ Defense Implementation β”‚ β”‚ Intrusion Detection β”‚ β”‚ Final Report β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ 5 Services β”‚ β”‚ 25 Assets β”‚ β”‚ 19 Vulnerabilities β”‚ β”‚ 4 PoCs β”‚ β”‚ 22 Hardenings β”‚ β”‚ 5 IDSs β”‚ β”‚ 2 Reports β”‚
β”‚ 19 Vulnerabilities β”‚ β”‚ 26 Threats β”‚ β”‚ CVSS Score β”‚ β”‚ Operational β”‚ β”‚ 90.5% Blocking β”‚ β”‚ 85% Detection Rate β”‚ β”‚ Management+Technology β”‚
β”‚ Intentionally implanted β”‚ β”‚ 22 requirements β”‚ β”‚ Attack chain diagram β”‚ β”‚ Attack script β”‚ β”‚ Residual receivable β”‚ β”‚ Low false positives β”‚ β”‚ Technical level β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
environment/ tara/ assessment/ exploitation/ defense/ ids/ report/
```

### Corresponds to ISO/SAE 21434 standard.

| Steps in this project | Correspondence to ISO/SAE 21434 Clause | Description |:---|:---|:---|
|:--- |:--- |:--- | Step 1.
| Step 1 Environment Setup | Clause 9 - Conceptual Phase | Define Relevant Items, System Boundaries, Preliminary Architecture | Step 2 TARA
| Step 2 TARA Analysis | Clause 15 - Threat Analysis and Risk Assessment | Asset Identification, Threat Scenarios, Impact Ratings, Attack Feasibility, Value at Risk Determination |
| Step 3 Vulnerability Assessment | Clause 10 - Product Development (Cybersecurity Validation) | Systematic Testing, Vulnerability Discovery, CVSS Scoring |
| Step 4 Attack Exploitation | Clause 10 - Product Development (Penetration Testing) | Attack Path Verification, PoC Development, Proof of Hazard |
| Step 5 Defense Implementation | Clause 10 - Product Development (Cybersecurity Measures) | Security Requirements Implementation, Vulnerability Remediation, Verification Testing |
| Step 6 Intrusion Detection | Clause 12 - Production/Operation (Cybersecurity Monitoring) | Real-Time Detection, Incident Response, Continuous Monitoring | Step 7 Final Reporting
| Step 7 Final Reporting | Clause 15 - Risk Assessment Reporting | TARA Reporting, Vulnerability Reporting, Verification Reporting |

## πŸ— Architecture

Γ°ΕΈ "Γ°ΕΈ "Γ°ΕΈ "Γ°ΕΈ "Γ°ΕΈ
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” HTTPS/JSON β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” MQTT β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Mobile Apps β”‚ ──────────────────→│ Cloud API β”‚ ───────────────→│ MQTT Proxy β”‚
β”‚ (External) β”‚ β”‚ (Flask) β”‚ β”‚ (EMQX) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ PostgreSQL β”‚ MQTT
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Database β”‚ β”‚ T-BOX β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Gateway β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”˜ β”‚ β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ CAN (vcan0)
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Body Control β”‚
β”‚ ECU (BCM) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Five components** to simulate the complete remote vehicle control chain:
1. **Cloud API** (Flask + JWT + PostgreSQL) - user authentication, vehicle management, command distribution
2. **MQTT proxy** (EMQX) - real-time message relaying
3. **T-BOX Gateway** (Python) - telematics unit connecting the cloud to the CAN bus
4. **CAN bus** (SocketCAN vcan0) - 500kbps legacy CAN
5. **Body Control ECU** (Python + UDS) - door locks, engine, lights, HVAC simulation

## πŸš€ Quick Start

### Prerequisites

- **Linux** (Ubuntu 22.04+) with `docker`, `python3.11+`, `curl` installed.
- Windows users: using WSL2

### One-click installation

``bash``
## Clone and install
cd environment
chmod +x setup.sh
. /setup.sh

# This script will:
# 1. create the virtual CAN interface (vcan0)
# 2. start all 5 Docker services
# 3. initialize the database with seed data
# 4. verify end-to-end command flow
``

### Manual installation

``## bash
# 1. Create the CAN interface
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

# 2. Start the service
cd environment
docker compose up -d --build

# 3. Initialize the database
curl -X POST http://localhost:5000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "alice", "email": "alice@example.com", "password": "password123"}'
```

### Quick test

```bash.
### Login
TOKEN=$(curl -s -X POST http://localhost:5000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "password123"}' \
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")

# Send command
curl -X POST http://localhost:5000/api/v1/vehicles/SIMULATED12345678/commands \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"command_type": "lock", "parameters":{}}'

# Monitor CAN bus
candump vcan0
\ -d '{"command_type": "lock": "parameters":{}}'

### Service endpoints

| Service | URL | credentials |
|:---|:---|:---|
| **Cloud API** | http://localhost:5000 | - |
| **API Health Check** | http://localhost:5000/health | - |
| **EMQX Dashboard** | http://localhost:18083 | admin / admin123 |
| **MQTT proxy** | localhost:1883 | tbox_client / tbox_pass_2024 |
| **PostgreSQL** | localhost:5432 | admin / admin123 / vehicle_security |

### Test account

| username | password | role | vehicle |
|:---|:---|:---|:---|
| alice | password123 | owner | SIMULATED12345678, SIMULATED87654321 |
| bob | bob2024 | owner | SIMULATED1111111111 |

## πŸ“ Project structure

``
vehicle-security-assessment/
β”œβ”€β”€ README.md # ← current file
β”‚
β”œβ”€β”€ environment/ # Docker + application code
β”‚ β”œβ”€β”€ docker-compose.yml # 5 Service Orchestration
β”‚ β”œβ”€β”€ setup.sh # 1-click install scripts
β”‚ β”œβ”€β”€ init-db.sql # Database schema + seed data
β”‚ β”œβ”€β”€ cloud-api/ # Flask REST API (Python)
β”‚ β”‚ β”œβ”€β”€ app.py # Application factory
β”‚ β”œβ”€β”€ config.py # Configuration (V-03, V-04, V-08)
β”‚ β”‚ β”œβ”€β”€ models.py # SQLAlchemy models
β”‚ β”œβ”€β”€ auth.py # /api/v1/auth/* Endpoints
β”‚ β”œβ”€β”€ vehicles.py # /api/v1/vehicles/* (V-01, V-06)
β”‚ β”‚ β”œβ”€β”€ commands.py # /api/v1/vehicles/*/commands/* (V-05, V-09)
β”‚ β”œβ”€β”€ diagnostics.py # /api/v1/vehicles/*/diagnostics/* (V-10)
β”‚ β”‚ β”œβ”€β”€ mqtt_publisher.py # MQTT Client (V-11, V-12)
β”‚ └── crypto_utils.py # HMAC utilities (V-05)
β”‚ β”œβ”€β”€ tbox-simulator/ # T-BOX gateway (Python)
β”‚ β”‚ └── tbox_simulator/ # T-BOX Gateway (Python)
β”‚ β”‚ β”œβ”€β”€ main.py # Entry point
β”‚ β”‚ β”œβ”€β”€ config.py # Configuration (V-11, V-12, V-14,V-15,V-16)
β”‚ β”‚ β”œβ”€β”€ mqtt_client.py # MQTT connection
β”‚ β”‚ β”œβ”€β”€ can_bridge.py # CAN bus interface
β”‚ β”‚ β”œβ”€β”€ command_processor.py # Command Routing (V-14)
β”‚ β”‚ β”œβ”€β”€ firewall.py # CAN firewall (V-15, V-16)
β”‚ β”‚ β”œβ”€β”€ crypto_utils.py # HMAC/SecOC
β”‚ └── uds_handler.py # UDS forwarding
β”‚ β”œβ”€β”€ ecu-simulator/ # Body Control ECU (Python)
β”‚ β”‚ └── ecu_simulator/ # Body Control ECU (Python)
β”‚ β”‚ β”œβ”€β”€ main.py # Entry point
β”‚ β”‚ β”œβ”€β”€ state.py # Vehicle state management
β”‚ β”‚ β”œβ”€β”€ body_control.py # door/engine/light/HVAC control
β”‚ β”‚ β”œβ”€β”€ can_handler.py # CAN Message Handler
β”‚ β”‚ β”œβ”€β”€ uds_server.py # UDS Diagnostics (V-17)
β”‚ └── logger.py # Event Logging
β”‚ └── mqtt-broker/ # EMQX Configuration (V-11, V-13)
β”‚ └── emqx.conf
β”‚
β”œβ”€β”€ tara/ # Phase 1: TARA Analysis
β”‚ β”œβ”€β”€ project-definition.md # System description + DFD
β”‚ β”œβ”€β”€ asset-inventory.md # 25 assets with C/I/A ratings
β”‚ β”œβ”€β”€ threat-scenarios.md # 26 STRIDE threats + attack tree
β”‚ β”œβ”€β”€ attack-paths.md # 4 detailed attack paths
β”‚ β”œβ”€β”€ risk-assessment.md # impact Γ— feasibility matrix
β”‚ └── security-requirements.md # 22 requirements + traceability
β”‚ └─ security-requirements.md # 22 requirements + traceability
β”œβ”€β”€ assessment/ # Stage 2: Vulnerability Assessment
β”‚ β”œβ”€ api-assessment.md # 10 API vulnerabilities
β”‚ β”œβ”€β”€ mqtt-assessment.md # 4 MQTT vulnerabilities
β”‚ β”œβ”€β”€ tbox-assessment.md # T-BOX security test
β”‚ β”œβ”€β”€ can-assessment.md # CAN bus security test
β”‚ └── vulnerability-summary.md # Full Vulnerability Matrix
β”‚
β”‚ β”œβ”€β”€ exploitation/ # Phase 3: Attack Demonstration
β”‚ β”œβ”€β”€ attack-remote-control/ # API β†’ Vehicle Chain of Control
β”‚ β”‚ β”œβ”€β”€ exploit.py # Runnable PoC Scripts
β”‚ └── README.md # Step-by-step instructions
β”‚ β”œβ”€β”€ attack-can-injection/ # Direct CAN injection
β”‚ β”‚ β”œβ”€β”€ can_inject.py # Runnable PoC Scripts
β”‚ └── README.md
β”‚ β”œβ”€β”€ attack-mqtt-injection/ # MQTT proxy vulnerability exploitation
β”‚ β”‚ β”œβ”€β”€ mqtt_attack.py # Runnable PoC scripts
β”‚ β”‚ └── README.md
β”‚ └── attack-uds-abuse/ # UDS diagnostic exploit
β”‚ β”œβ”€β”€ uds_exploit.py # Runnable PoC script β”‚ └── README.md β”‚ └── attack-uds-abuse/ # UDS diagnostic exploit
β”‚ └── README.md
β”‚ └─ README.md
β”œβ”€β”€ defense/ # Phase 4: Defense Implementation
β”‚ β”œβ”€β”€ api-hardening/ # Hardened APIs (SR-01 to SR-10)
β”‚ β”œβ”€β”€ mqtt-security/ # TLS + ACL Configuration (SR-13 to SR-15)
β”‚ β”œβ”€β”€ can-secoc/ # SecOC implementation (SR-12, SR-20)
β”‚ β”œβ”€β”€ gateway-filter/ # Enhanced Firewall (SR-17 to SR-19)
β”‚ └── validation-results.md # Before and after enhancements
β”‚ └── validation-results.md
β”œβ”€β”€ ids/ # Phase 5: Intrusion Detection
β”‚ β”œβ”€ can_ids.py # CAN bus anomaly detection
β”‚ β”œβ”€β”€ mqtt_ids.py # MQTT Traffic Monitoring
β”‚ β”œβ”€β”€ api_monitor.py # API Attack Detection
β”‚ β”œβ”€β”€ correlation_engine.py # Cross-layer attack chain detection
β”‚ β”œβ”€β”€ dashboard.py # Terminal real-time dashboards
β”‚ └── detection-results.md # Detection rate analysis
β”‚
β”‚ β”œβ”€β”€ tools/ # Security assessment tools
β”‚ β”œβ”€β”€ can_analyzer.py # CAN protocol reverse engineering
β”‚ β”œβ”€β”€ mqtt_fuzzer.py # MQTT protocol fuzzer tester
β”‚ └── api_scanner.py # API security scanner
β”‚ └── api_scanner.py # API security scanner β”‚
└── report/ # Final report
β”œβ”€β”€ executive-summary.md # One-page management summary β”‚ └── technical-report.md # API security scanner
└── technical-report.md # Comprehensive technical report
``

## πŸ”¬ phases

### Phase 1: TARA Analysis
- 25 assets covering 5 categories (data, functional, communications, physical, software)
- 26 threat scenarios analyzed using the STRIDE methodology
- "Unauthorized Remote Vehicle Control" Full Attack Tree
- 5Γ—4 Risk Matrix: 15 Critical (R4), 11 High Risk (R3)
- 22 derived security requirements with full traceability

### Phase 2: Vulnerability Assessment
- Systematic testing of all 5 components
- 19 vulnerability documents with CVSS scores, reproduction steps and remediation options
- Attack chain mapping, showing combinations of vulnerabilities

### Phase 3: Exploitation
- **4 runnable Python PoC scripts** with detailed README instructions
- Demonstrates the complete remote control chain
- CAN injection with replay and DoS
- MQTT proxy intrusion affecting entire fleet
- Breaking UDS security access in 1 attempt

### Phase 4: Defense Implementation
- 22 security requirements implemented
- **90.5% of attacks completely blocked
- All R3/R4 risks eliminated
- Pre- and post-hardening validation results documented

### Phase 5: Intrusion Detection
- Multi-layer IDS (CAN + MQTT + API)
- Cross-layer correlation engine with 7 attack pattern definitions
- Endpoint-based real-time dashboard
- **85% Detection rate** with less than 5% false alarm rate

## πŸ”΄ Vulnerability Matrix

| ID | Component | Vulnerability | CVSS | Risk |
|:---:|:---|:---|:---:|:---:|:---:|
| V-01 | Cloud API | BOLA - No Ownership Authentication | 9.1 | R4 |
| V-01 | Cloud API | BOLA - No Ownership Authentication | 9.1 | R4 | V-02 | Cloud API | Weak Password Policies | 5.3 | R3 |
| V-03 | Cloud API | Hard-Coded JWT Key ("secret123") | 8.0 | R4 | V-02 | Cloud API | Weak Password Policy | 5.3 | R3
| V-04 | Cloud API | Login without Rate Limit | 7.5 | R3 | V-03 | Cloud API | Hard-Coded JWT Key ("secret123")
| V-05 | Cloud API | Command Signature Optional | 8.6 | R4 |
| V-06 | Cloud API | SQL Injection in Vehicle Search | 9.8 | R4 | V-06 | Cloud API | SQL Injection in Vehicle Search | 9.8 | R4 | V-07 | Cloud API
| V-07 | Cloud API | Detailed Error Messages Leaked | 5.3 | R3 | V-08 | Cloud API | SQL Injection in Vehicle Search | 9.8 | R4 | Cloud API
| V-08 | Cloud API | CORS Allow All Sources (*) | 6.5 | R3 | V-08 | Cloud API | CORS Allow All Sources (*) | 6.5 | R4 |
| V-09 | Cloud API | No OTP Validation for Sensitive Commands | 7.4 | R3 | V-08 | Cloud API | CORS Allow All Sources (*) | 6.5 | R3 |
| V-10 | Cloud API | Diagnostic Interface without Role Checking | 8.1 | R3 | V-11 | MQTAG | Cloud API

| V-11 | MQTT | No TLS encryption | 7.5 | R4 | V-12 | MQTT | Shared T-BOX credentials | 8.0 | R4 |
| V-12 | MQTT | Shared T-BOX Credentials | 8.0 | R4 | V-12 | MQTT | Shared T-BOX Credentials | 7.5 | R4

| V-15 | T-BOX | Firewall No Source Checking | 7.5 | R4 |
| V-16 | T-BOX | Firewall no content validation | 6.5 | R3 |
| V-17 | ECU | Weak UDS SecurityAccess (XOR) | 6.5 | R3 |
| V-18 | Infrastructure | Weak Database Passwords | 7.5 | R3 |
| V-19 | Infrastructure | Weak MQTT Dashboard Password | 6.5 | R3 |

## βš”οΈ Attack Demo

### 1. Remote control via cloud APIs
```bash
cd exploitation/attack-remote-control
python exploit.py --base-url http://localhost:5000
```
Exploitation Vulnerabilities: V-01 (BOLA), V-04 (No Rate Limit), V-05 (No Signature), V-06 (SQL Injection)

### 2. Direct CAN bus injection
```bash
sudo python exploitation/attack-can-injection/can_inject.py --channel vcan0
```
Exploitation Vulnerabilities: V-15 (no source checking), V-16 (no content validation), CAN protocol weaknesses

### 3. MQTT proxy vulnerability exploitation
```bash
python exploitation/attack-mqtt-injection/mqtt_attack.py --host localhost
```
Exploitation Vulnerabilities: v-11 (no TLS), v-12 (shared credentials), v-13 (no ACL), v-14 (no signature checking)

### 4. UDS Diagnostics Vulnerability Exploits
```bash
sudo python exploitation/attack-uds-abuse/uds_exploit.py --channel vcan0
```
Exploitation Vulnerability: V-17 (Weak XOR SecurityAccess)

## πŸ›‘οΈ Defense results

| Attack | Pre-Hardened | Post-Hardened | Status |
|:---|:---|:---|:---:---:|
| BOLA | Full Access | 403 Banned | βœ… Blocked |
| SQL Injection | Data Extraction | ORM Queries | βœ… Blocked |
| JWT Forgery | Token Forgery | Random 256-bit Keys | βœ… Blocked
| JWT Forging | Token Forgery | Random 256-bit Key βœ… Blocked | Brute Force | Unlimited | 5x/minute + Lockout βœ… Blocked
| Unsigned Commands | Executable | Signature Verification Required βœ… Blocked | CAN Injection | Executable | Random 256-bit Keys βœ… Blocked
| CAN Injection | Executable | SecOC MAC Invalid | βœ… Blocked | | CAN Replay | Executable | Signature Verification βœ… Blocked
| CAN Replay | Executable | Counter Expired | βœ… Blocked | CAN DoS | 500 | CAN DoS | 500 | Signature Verification βœ… Blocked
| CAN DoS | 500 bars/sec | 10 bars/sec limit | ⚠️ Mitigated |
| MQTT Eavesdropping | Visible in Plaintext | TLS 1.3 | βœ… Blocked |
| MQTT Injection | Executable | Signature Invalid | βœ… Blocked |
| UDS Cracking | 1 attempt | AES Challenge | ⚠️ mitigated |

**Overall: 90.5% fully blocked, 9.5% mitigated to an acceptable residual risk**

## πŸ“Š IDS Detection

| Attacks | CAN IDS | MQTT IDS | API Monitoring | Correlation Engine | Detection Results |
|:---|:---:|:---:|:---:|:---:|:---:|
| Remote Control Chain | βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ“ βœ… |
| CAN Injection | βœ“ | - | - | - | βœ… |
| MQTT Injection | - | βœ“ | - | - βœ… |
| UDS Brute Force | | βœ“ | - | - | - βœ… |
| CAN DoS | βœ“ | - | - | - βœ… |
| CAN Replay | βœ“ | - | - | - βœ… |
| API Brute Force | - | - | βœ“ | - βœ… | βœ… |
| SQL Injection | - | - | βœ“ | - | βœ… |

**Detection Rate: 85% | False Alarm Rate:
Built for automotive cybersecurity engineers entering the vehicle security space.
All simulations are containerized - no real vehicle hardware required.