0

I am new to networking. And have found using scapy a great way to learn different protocols.

I am trying to send a DHCPDISCOVER packet, however in wireshark it comes out as a malformed packet.

Here is the code I use to construct the packet (my MAC address has been excluded and replaced with "[my MAC address]":

ethernet = Ether(dst='ff:ff:ff:ff:ff:ff',src="[my MAC address]",type=0x800)
ip = IP(src ='0.0.0.0',dst='255.255.255.255')
udp = UDP (sport=68,dport=67)
fam,hw = get_if_raw_hwaddr("Wi-Fi")
bootp = BOOTP(chaddr = hw, ciaddr = '0.0.0.0',xid =  0x01020304,flags= 1)
dhcp = DHCP(options=[("message-type","discover"),"end"])
packet = ethernet / ip / udp / bootp / dhcp
scap.send(packet, iface="Wi-Fi")

This is the wireshark result of the packet:

14 2.065968 ASUSTekC_a5:fa:7a Broadcast IPX 300 [Malformed Packet]

Thanks!

1 Answers1

0

If you're going to specify layer 2, you need to use the *p variants of the send/receive functions instead:

scap.sendp(packet, iface="Wi-Fi")

I have to admit, I haven't gotten around to looking into exactly why this otherwise results in a malformed packet, but I've assumed it attempts to add a layer 2 protocol to the packet for you, resulting in two such layers in the final packet.

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
  • Thank you, that's solved the issue. I've read RFC 2131 (DHCP) about three times now and couldn't figure out what was wrong. I'd give you an upvote but have less than 15 rep. – Zen Marais Jan 04 '21 at 19:36