google / google/gopacket

Certain tests fail when support for parsing information elements is added

Open
#544 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Gopacket doesn't support parsing information elements out of some 802.11 frames, such as probe requests. This means that when iterating through layers using the `nextLayer()` and `LayerPayload()` functions, you can't retrieve any information located within information elements for these frames. When I added support to parse these information elements, two different tests broke. I think it's because the information elements wouldn't be parsed properly in the first place, but due to the fact that normally the tests never check the info elements, nobody realized that this part of the test wouldn't work.

I went in and did some extensive data digging. Even without my changes, the payload for the ProbeReq layer for the second test here should have been 102 bytes (I was evaluating this value within the function `checkLayers` in `base_test.go`). Instead, it was only 98 bytes, with a capacity of 102 bytes. The bytes were, to be precise, `{0x00 0x00 0x01 0x04 0x02 0x04 0x0b 0x16 0x32 0x08 0x0c 0x12 0x18 0x24 0x30 0x48 0x60 0x6c 0x03 0x01 0x01 0x2d 0x1a 0x2d 0x11 0x17 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7f 0x08 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x40 0xdd 0x09 0x00 0x10 0x18 0x02 0x00 0x00 0x10 0x00 0x00 0xdd 0x1e 0x00 0x90 0x4c 0x33 0x2d 0x11 0x17 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}`. This is missing 4 bytes at the end, `{0x00 0x00 0x00 0x00}`, compared to the packet that's constructed in the test file. This correspondingly leads to the error that I'm showing below, where gopacket complains that the last information element is 4 bytes short.

#542 The corresponding pull request

This is the error output from the failed test:

```--- FAIL: TestPacketDot11MgmtAction (0.00s)
dot11_test.go:234: Failed to decode packet: Dot11InformationElement length 1 too short, 2 required
base_test.go:26: Checking packet layers, want [RadioTap Dot11 Dot11MgmtAction]
base_test.go:28: Got layer RadioTap, 18 bytes, payload of 35 bytes
base_test.go:28: Got layer Dot11, 24 bytes, payload of 7 bytes
base_test.go:28: Got layer Dot11MgmtAction, 7 bytes, payload of 7 bytes
base_test.go:28: Got layer Dot11InformationElement, 6 bytes, payload of 1 bytes
base_test.go:28: Got layer DecodeFailure, 1 bytes, payload of 0 bytes
base_test.go:31: PACKET: 53 bytes, truncated
- Layer 1 (18 bytes) = RadioTap {Contents=[..18..] Payload=[..35..] Version=0 Length=18 Present=18478 TSFT=0 Flags=FCS Rate=1 Mb/s ChannelFrequency=2412 MHz ChannelFlags=CCK,Ghz2 FHSS=0 DBMAntennaSignal=-67 DBMAntennaNoise=0 LockQuality=0 TxAttenuation=0 DBTxAttenuation=0 DBMTxPower=0 Antenna=5 DBAntennaSignal=0 DBAntennaNoise=0 RxFlags= TxFlags= RtsRetries=0 DataRetries=0 MCS= AMPDUStatus=ref#0 VHT=}
- Layer 2 (24 bytes) = Dot11 {Contents=[..24..] Payload=[..7..] Type=MgmtAction Proto=0 Flags= DurationID=0 Address1=ff:ff:ff:ff:ff:ff Address2=8e:3a:e3:44:ac:c6 Address3=8e:3a:e3:44:ac:c6 Address4= SequenceNumber=432 FragmentNumber=0 Checksum=871381333 QOS=nil HTControl=nil DataLayer=nil}
- Layer 3 (07 bytes) = Dot11MgmtAction {Contents=[..7..] Payload=[..7..]}
- Layer 4 (06 bytes) = Dot11InformationElement 802.11 Information Element (ID: SSID parameter set, Length: 4, SSID: %)
- Layer 5 (01 bytes) = DecodeFailure Packet decoding error: Dot11InformationElement length 1 too short, 2 required

--- FAIL: TestPacketPrism (0.00s)
prism_test.go:63: Failed to decode packet: Dot11InformationElement length 28 too short, 32 required
base_test.go:26: Checking packet layers, want [Prism monitor mode header Dot11 Dot11MgmtProbeReq]
base_test.go:28: Got layer Prism monitor mode header, 144 bytes, payload of 126 bytes
base_test.go:28: Got layer Dot11, 24 bytes, payload of 98 bytes
base_test.go:28: Got layer Dot11MgmtProbeReq, 98 bytes, payload of 98 bytes
base_test.go:28: Got layer Dot11InformationElement, 2 bytes, payload of 96 bytes
base_test.go:28: Got layer Dot11InformationElement, 6 bytes, payload of 90 bytes
base_test.go:28: Got layer Dot11InformationElement, 10 bytes, payload of 80 bytes
base_test.go:28: Got layer Dot11InformationElement, 3 bytes, payload of 77 bytes
base_test.go:28: Got layer Dot11InformationElement, 28 bytes, payload of 49 bytes
base_test.go:28: Got layer Dot11InformationElement, 10 bytes, payload of 39 bytes
base_test.go:28: Got layer Dot11InformationElement, 11 bytes, payload of 28 bytes
base_test.go:28: Got layer DecodeFailure, 28 bytes, payload of 0 bytes
base_test.go:31: PACKET: 270 bytes, truncated
- Layer 1 (144 bytes) = Prism monitor mode header {Contents=[..144..] Payload=[..126..] Code=68 Length=144 DeviceName=ra0 Values=[..10..]}
- Layer 2 (24 bytes) = Dot11 {Contents=[..24..] Payload=[..98..] Type=MgmtProbeReq Proto=0 Flags= DurationID=0 Address1=ff:ff:ff:ff:ff:ff Address2=cc:fa:00:ad:79:e8 Address3=ff:ff:ff:ff:ff:ff Address4= SequenceNumber=1050 FragmentNumber=0 Checksum=0 QOS=nil HTControl=nil DataLayer=nil}
- Layer 3 (98 bytes) = Dot11MgmtProbeReq {Contents=[..98..] Payload=[..98..]}
- Layer 4 (02 bytes) = Dot11InformationElement 802.11 Information Element (ID: SSID parameter set, Length: 0, SSID: )
- Layer 5 (06 bytes) = Dot11InformationElement 802.11 Information Element (ID: Supported Rates, Length: 4, Rates: 1.0 2.0 5.5 11.0 Mbit)
- Layer 6 (10 bytes) = Dot11InformationElement 802.11 Information Element (ID: Extended Supported Rates, Length: 8, Info: 0C1218243048606C)
- Layer 7 (03 bytes) = Dot11InformationElement 802.11 Information Element (ID: DS Parameter set, Length: 1, Info: 01)
- Layer 8 (28 bytes) = Dot11InformationElement 802.11 Information Element (ID: HT Capabilities (802.11n D1.10), Length: 26, Info: 2D1117FF00000000000000000000000000000000000000000000)
- Layer 9 (10 bytes) = Dot11InformationElement 802.11 Information Element (ID: Extended Capabilities, Length: 8, Info: 0000000000000040)
- Layer 10 (11 bytes) = Dot11InformationElement 802.11 Information Element (ID: Vendor, Length: 9, OUI: 00101802, Info: 0000100000)
- Layer 11 (28 bytes) = DecodeFailure Packet decoding error: Dot11InformationElement length 28 too short, 32 required

FAIL
exit status 1
FAIL github.com/Galadros/gopacket/layers 0.344s
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.