Closed rkinder2023 closed 3 weeks ago
Hi all, I'd like to submit a PR for this, but seems I can't create branches from master. Do I need to be added into the project somehow? Please let me know.
The behavior you're describing is by design.
You can set len
to None
to have Scapy recompute it.
The behavior you're describing is by design. You can set
len
toNone
to have Scapy recompute it.
OK, makes sense, but how do I get Scapy to recompute the len
field after setting to None? Is there any special command to do this? I have tried 'build()' on the full packet and the IE layer itself but it doesn't seem to update the len field.
Second question is if setting len to None, how do I create a fuzzed IE field where the info is not empty but I want to force zero length to test the robustness of IE parsing on a device?
@gpotter2, any comments here? I've looked further into this and I can confirm the build of the packet will insert the length field into the byte stream correctly, but will not set the length field within the given IE correctly (ie, still shows as None when dumping the IE). This seems counter-intuitive to me, as the 'byte' consistency is different than the printout. In the earlier case it's fine - explicit length set to make a 'bad' IE, and both the 'byte' and printout values are consistent. Does it make sense?
Example of this behaviour below:
>>> from scapy.all import *
WARNING: No IPv4 address found on anpi1 !
WARNING: No IPv4 address found on anpi0 !
WARNING: more No IPv4 address found on en3 !
>>> a=b"\x00\x07NewSSID"
>>> ssid=Dot11Elt(a)
>>> ssid
<Dot11Elt ID=SSID len=7 info=b'NewSSID' |>
>>> ssid.info="New SSID longer"
>>> bytes(ssid)
b'\x00\x07New SSID longer' # Expected - len field unaltered
>>> ssid.len=None
>>> bytes(ssid)
b'\x00\x0fNew SSID longer' # Expected - new length field calculated correctly.
>>> ssid
<Dot11Elt ID=SSID len=None info=b'New SSID longer' |> # Unexpected - len field should be updated
>>>
Brief description
The Dot11Elem class is used to encapsulate information elements as per the 802.11 standard. These consist of a one byte type, one byte length, then variable data. If one modifies the 'info' field (data) of an IE, the length field may need to be recalculated if the size of the info field changes. If this is not done, the resulting packet created will be invalid due to IE length mismatch.
The fix for this issue is to modify the Dot11Elem.setattr call to update the 'len' field if the size of the info field changes.
The following diff achieves this.
Scapy version
b4bf3d62d5aa6f160a0768ca3ad598fb415f0994
Python version
3.12.2
Operating system
MacOS Sonoma 14.4
Additional environment information
No response
How to reproduce
Simple script to show the problem. The solution is presented earlier in the report.