Created
August 23, 2026 18:53
-
-
Save v3l0c1r4pt0r/c77f5fa023bfcecdc9081d0dddf20bd2 to your computer and use it in GitHub Desktop.
Scapy script to query all ECUs in a network for VIN (via ENET cable)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| import select | |
| from scapy.all import StreamSocket | |
| from scapy.packet import Raw | |
| from scapy.utils import hexdump | |
| from scapy.compat import raw | |
| from scapy.packet import bind_layers | |
| from scapy.layers.inet import TCP | |
| from scapy.contrib.automotive.bmw.hsfz import HSFZ | |
| from scapy.contrib.automotive.uds import UDS, UDS_RDBI, UDS_DSC | |
| bind_layers(TCP, HSFZ, sport=6801) | |
| bind_layers(TCP, HSFZ, dport=6801) | |
| #bind_layers(HSFZ, UDS) | |
| sock = socket.socket() | |
| sock.connect(("169.254.106.69", 6801)) | |
| s = sock | |
| sock = StreamSocket(s, Raw) | |
| # Tester->Broadcast: ReadDataByIdentifier VIN | |
| pkt = HSFZ(source=0xf4, target=0xdf, control=0x1) / UDS() / UDS_RDBI(identifiers=0xf190) | |
| sock.send(pkt) | |
| ack = sock.recv() | |
| poll_interval = 1 | |
| while True: | |
| ready, _, _ = select.select([sock.ins], [], [], poll_interval) | |
| if ready: | |
| pkt = sock.recv() | |
| if pkt is not None: | |
| stack = HSFZ(bytes(pkt)) | |
| vin = stack[3].fields['load'].decode('utf-8') | |
| ecu = hex(stack[HSFZ].source) | |
| print(f'ECU={ecu}: VIN={vin}') | |
| #print(hexdump(raw(pkt))) | |
| else: | |
| # recv() returned None -> peer closed / EOF | |
| break | |
| else: | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment