
# can_replay_sim.py - Simulates CAN bus replay
import time
can_messages = []
def send_can(msg_id, data):
print(f"CAN {msg_id:#x}: {data.hex()}")
can_messages.append((msg_id, data))
def receive_can():
return can_messages[-1] if can_messages else None
# Simulate car sending "door unlock" command
send_can(0x100, b'\x01\x00\x00\x00') # unlock
# Attacker replays captured frame
time.sleep(1)
captured = receive_can()
if captured:
print("Replaying captured frame...")
send_can(captured[0], captured[1])
An automotive Controller Area Network (CAN) does not implement message authentication or freshness checks. An attacker with physical access to the OBD‑II port can capture a legitimate frame (e.g., unlock door) and replay it later to perform unauthorized actions.
Run the simulation:
python can_replay_sim.py
The script prints the capture and replay of an unlock command.