Skip to content

Commit 2cc925c

Browse files
Check NBT packet length before full Scapy dissection
Parse the 4-byte NBT header to get the payload length before attempting full packet dissection. This fixes two issues: 1. Incomplete packets (TCP fragmentation) are handled cleanly by returning 0, without hitting the exception path at all. 2. Malformed packets now consume exactly their declared size (nbt_length + 4) instead of len(data), which could eat the start of the next valid packet in the same TCP segment.
1 parent 7748fec commit 2cc925c

File tree

1 file changed

+10
-5
lines changed
  • modules/python/dionaea/smb

1 file changed

+10
-5
lines changed

modules/python/dionaea/smb/smb.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,15 @@ def _process_doublepulsar_payload(self):
439439
os.unlink(fp.name)
440440

441441
def handle_io_in(self, data: bytes) -> int:
442+
# Need at least the NBT header (4 bytes) to determine packet length
443+
if len(data) < 4:
444+
return 0
445+
446+
# Parse NBT length from header before full dissection
447+
nbt_length = ((data[1] & 0x01) << 16) | (data[2] << 8) | data[3]
448+
if len(data) < nbt_length + 4:
449+
return 0
450+
442451
try:
443452
p = NBTSession(data, _ctx=self)
444453
except Exception as e:
@@ -448,11 +457,7 @@ def handle_io_in(self, data: bytes) -> int:
448457
len(data),
449458
data[:16].hex() if data else "empty",
450459
)
451-
return len(data)
452-
453-
if len(data) < (p.LENGTH + 4):
454-
# we probably do not have the whole packet yet -> return 0
455-
return 0
460+
return nbt_length + 4
456461

457462
if p.TYPE == 0x81:
458463
self.send(NBTSession(TYPE=0x82).build())

0 commit comments

Comments
 (0)