Skip to content

Commit

Permalink
the same packet works as ethernet but not as ip?!
Browse files Browse the repository at this point in the history
So the dpkt lib clearly correctly understands this very payload
I must be doing something wrong here
  • Loading branch information
ChillerDragon committed Feb 19, 2024
1 parent d8e628f commit 436f5ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def extract_udp_payload(data: bytes) -> Tuple[bytes, List[str]]:
try:
ip = dpkt.ethernet.Ethernet(data).data
if not isinstance(ip.data, dpkt.udp.UDP):
print("not ethernet")
raise ValueError("not udp")
udp_payload = ip.data.data
messages.append("extracting udp payload from ethernet packet ...")
Expand All @@ -28,13 +29,14 @@ def extract_udp_payload(data: bytes) -> Tuple[bytes, List[str]]:
raise ValueError("not udp")
udp_payload = ip.data.data
messages.append("extracting udp payload from ip packet ...")
except ValueError: # TODO: catch all again when done with debugging
except:
pass

data = udp_payload
return (data, messages)



# data = \
# b'\x60\x0a\xa5\x6d\x00\x1d\x11\x40\x00\x00\x00\x00\x00\x00\x00\x00' \
# b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00' \
Expand Down
14 changes: 14 additions & 0 deletions tests/extract_udp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ def test_extract_udp():
# b'\x0f\x9e\xa0\x05\x02'
#
# print(extract_udp_payload(data))

def test_extract_ethernet_input_timing_and_snap_empty():
# real packet from tcpdump -xx
# verified expected value with wireshark
data = \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x86\xdd\x60\x0a' \
b'\xa5\x6d\x00\x1d\x11\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x01\x20\x6f\xd9\xc8\x00\x1d\x00\x30\x00\x19' \
b'\x02\x23\xec\x92\x03\x00\x05\x15\x9e\xa0\x05\x0c\x00\x05\x0f\x9e' \
b'\xa0\x05\x02'

assert extract_udp_payload(data) == (b'\x00\x19\x02#\xec\x92\x03\x00\x05\x15\x9e\xa0\x05\x0c\x00\x05\x0f\x9e\xa0\x05\x02', ['extracting udp payload from ethernet packet ...'])

0 comments on commit 436f5ad

Please sign in to comment.