I am trying to send a udp packet to a local ip address. This is my example code:
from scapy.all import *
if __name__ == "__main__":
send(IP(dst="127.0.0.1")/UDP(sport=19600,dport=39600)/"abc")
I’ve started netcat to catch what I am going to send:
nc -ul 39600
Then I am executing the code:
python3 example_scapy_send.py
Nothing is received by the listening netcat.
At the same time I have started wireshark and I can see the packet is sent.
If I send a packet using netcat it is ariving on the listening netcat.
usr@dev:/home/usr# nc -u 127.0.0.1 39600
test
The only difference I can see is that at layer 2 – destination address is multicast/broadcast when sent with scapy and unicast when sent with netcat. But this is not something I can control.
If I sent the same packet with scapy to another ip on the network (another host) the packet is received (by netcat). So the issue applies only if I am sending to a local address. Tested with any local ip. Not only 127.0.0.1. I’ve also tested with sendp and sr scapy functions but the result is the same.
Something more: if I’ve started another scapy script to listen to UDP/39600 (instead of netcat) I can see/I am receiving the packet I’ve sent.
Any ideas what is wrong?
tests done under ubuntu/scapy 2.5/python 3.8
2
Answers
I couldn't find a way to make it work with send/sendp scapy functions, but instead I tried using standart python socket and it did the job:
someSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) someSocket.sendto(bytes('abc', "utf-8"), (127.0.0.1, 39600))
Acording to Scapy troubleshooting:
So you may need to add line before sending packet:
In your script. That way everything should supposed to work. At least in my environment worked out fine.