Skip to content

mqtt: support TCP stream reassembly (#4595) - #5311

Open
Vigneshwarans32241 wants to merge 2 commits into
secdev:masterfrom
Vigneshwarans32241:fix/mqtt-tcp-reassemble
Open

Vigneshwarans32241 wants to merge 2 commits into
secdev:masterfrom
Vigneshwarans32241:fix/mqtt-tcp-reassemble

Conversation

@Vigneshwarans32241

Copy link
Copy Markdown

Description

MQTT in scapy/contrib/mqtt.py does not implement tcp_reassemble, causing multi-segment MQTT packets (such as MQTTConnect with a large Will payload) to be dissected segment-by-segment under TCPSession, and VariableFieldLenField.getfield implicitly returns None when the variable-byte length field is truncated.

In addition, TCPSession.process treats Ethernet trailer Padding on payload-less TCP segments (e.g. a 60-byte padded handshake ACK) as TCP stream payload, prepending zero bytes to the reassembly buffer.

This PR implements MQTT.tcp_reassemble, raises Scapy_Exception on truncated variable-length headers, and ignores conf.padding_layer payloads on empty TCP segments in TCPSession.process.

fixes #4595

This message was written with the help of AI (Arena.ai).

Vigneshwarans32241 and others added 2 commits November 23, 2026 22:01
Implement MQTT.tcp_reassemble() using the variable-length header so
multi-segment and coalesced MQTT packets are reassembled by TCPSession,
and raise Scapy_Exception in VariableFieldLenField.getfield() when the
length varint is truncated.

Also ignore Ethernet trailer Padding on payload-less TCP segments in
TCPSession.process() so padded handshake ACKs are not appended to the
TCP stream buffer.

AI-Assisted: yes (Arena.ai)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scapy Fails to Reassemble Large MQTT CONNECT Packets with WILL message Across Multiple TCP Segments

1 participant