From e1d90110f7101f8bd246d272445f94833cffe998 Mon Sep 17 00:00:00 2001 From: JR Date: Sat, 24 Oct 2026 20:15:42 +0200 Subject: [PATCH] enipTCP: fix list reply item counts and lengths ListServices, ListIdentity and ListInterfaces encoded itemCount (and the ListInterfaces itemLength) big-endian, so a device reply with one item dissected as itemCount=256. The counts and lengths also defaulted to 0, so a built reply wrote 0 for itemCount, itemLength and productNameLength, and peers (and scapy itself) read an empty product name. Items after the first were dissected as Raw. Encode them little-endian, compute them when left unset, and split the items of a list. AI-Assisted: yes (Claude Opus 5.5, GPT-6.1 Sol) --- scapy/contrib/enipTCP.py | 34 +++++++++++++----- test/contrib/enipTCP.uts | 76 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 14 deletions(-) diff --git a/scapy/contrib/enipTCP.py b/scapy/contrib/enipTCP.py index e35d2e27f67..c79bf044d7f 100644 --- a/scapy/contrib/enipTCP.py +++ b/scapy/contrib/enipTCP.py @@ -139,12 +139,24 @@ class ENIPUnknownCommand(Packet): # List services (0x0004) -class ENIPListServicesItem(Packet): +class _ENIPListItem(Packet): + """Item whose itemLength counts every byte after the length field""" + + def post_build(self, pkt, pay): + if self.itemLength is None: + pkt = pkt[:2] + struct.pack("