Skip to content

mistaken msglen in MQTTPublish message #3572

@ZodiacLyu

Description

@ZodiacLyu

Brief description

I noticed that the StrLenField of value in MQTTPublish packets is defined as

StrLenField("value", "",
                    length_from=lambda pkt: (pkt.underlayer.len -
                                             pkt.length - 2)),

However, if the QoS of the publish message is 1 or 2, because of the field of msgid, I guess it should be pkt.underlayer.len - pkt.length - 4, as I met this problem when I was trying to parse a packet that contains two MQTT Publish messages.
image
I tried to fix it with codes as followed. Perhaps it could help.

StrLenField("value", "",
                    length_from=lambda pkt: pkt.underlayer.len -pkt.length - 2 if pkt.underlayer.QOS == 0 
                                            else pkt.underlayer.len -pkt.length - 4)

Scapy version

2.4.5

Python version

3.8

Operating system

Win11

Additional environment information

No response

How to reproduce

Sniff a packet with two MQTT Publish messages......

Actual result

No response

Expected result

No response

Related resources

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions