UDP Packet Creation With Scapy

Multi tool use
UDP Packet Creation With Scapy
I am having trouble sending custom UDP packets with Scapy on Python3 with a MacBook.
want to send a UDP packet with a custom Source IP of 192.168.1.11
to my current machine with the IP of, 192.168.1.17
that is hosting a UDP
Server on port 6789
. I want to send a message saying "Hi" using Scapy so I wrote the following code,
192.168.1.11
192.168.1.17
UDP
6789
from scapy.all import *
from random import randrange
sendp(IP(src="192.168.11",dst="192.168.1.17")/UDP(sport=randrange(80,65535),dport=6789)/"Hi",iface="en0",count=10)
Then I have a server waiting to respond once data is received and print the message received to the screen. But when executing this code with elevated privileges, scapy says the packets were sent but the server didn't receive the response.
the packets were sent but the server didn't receive the response.
So I went to en0
the wireless interface on my Mac to debug. This is what I found:
en0
Wireshark says
the source is Applicon_11:f8:61, the destination is 45:00:00:1e:00:01, the protocol is 0xc0a8(Unknown) and the data is 16 bytes of Hex: 0000 45 00 00 1e 00 01 00 00 40 11 f8 61 c0 a8 00 0b ASCII Dump: E.......@.øaÀ¨..
0010 c0 a8 01 11 67 18 1a 85 00 0a b3 66 48 69 À¨..g.....³fHi
I have no idea what any of that means or what I am doing wrong here can anyone help to point me in the right direction?
1 Answer
1
sendp
is for sending at layer 2send
is for sending at layer 3
sendp
send
In your case, you should either use
at layer 2: sendp(Ether()/IP(..)....)
. (Replace Ether
by Loopback
if needed)
sendp(Ether()/IP(..)....)
Ether
Loopback
at layer 3: send(IP(...))
send(IP(...))
send(IP(src='192.168.1.11',dst='192.168.1.17')/UDP(dport=6789),iface='en0',loop=1)
send(IP(src='192.168.1.11',dst='192.168.1.17')/UDP(dport=6789)/"Hi",iface='en0',loop=1)
Update, the later sometimes works but it isn't predictable and when I try to send larger message it fails entirely.
– DatagramDigger
Jul 3 at 20:09
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I used the send method like you said and the packets seem to go through when I use the command
send(IP(src='192.168.1.11',dst='192.168.1.17')/UDP(dport=6789),iface='en0',loop=1)
but not without an error .WARNING: Mac address to reach destination not found. Using broadcast. When I add the payload to say "Hi",send(IP(src='192.168.1.11',dst='192.168.1.17')/UDP(dport=6789)/"Hi",iface='en0',loop=1)
Wireshark says the packet is malformed, it doesn't go through and says the protocol is DNS and no longer UDP.– DatagramDigger
Jul 3 at 19:08