# 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])
汽车控制器局域网(CAN)不实现消息认证或新鲜度检查。能够物理访问OBD‑II端口的攻击者可以捕获合法帧(例如,解锁车门),并在之后重放该帧以执行未授权操作。
运行模拟:
python can_replay_sim.py
该脚本会打印解锁命令的捕获与重放过程。