How to run a program in Linux raw sockets? To step back a little bit, an application using TCP or UDP must, when opening up a STREAM or DGRAM socket, declare a port to receive data on. This means that packets read from raw sockets don’t have any notion of “port”. Where are destination ports stored in raw sockets?įor instance, the destination port is stored in the TCP headers. If you are implementing a a transport-level protocol, you’ll have to write code to decode and encode the transport-level headers in your application. Raw sockets operate at the network OSI level, which means that transport-level headers such as TCP or UDP headers will not be automatically decoded. Usage example with this file named my arp-packet.dat and the python script named send_raw_packet.py: host:~$ send_raw_packet.py eth0 arp_packet.datĪnd capturing with tcpdump shows the packet was sent: host:~$ tcpdump -i eth0 -Q out -tevvv -XX arp Note that because separator between hex bytes is spaces or new lines, it is easy to separate frames in the file, here the 3 first lines are the Ether frame, then the next lines are the ARP frame and the last line is the padding to reach 60 bytes in length. Print("Sent packet of length %d bytes" % sentbytes) With socket.socket(socket.AF_PACKET, socket.SOCK_RAW) as rs: Usage is script_name.py interface packet_file #!/bin/python This Python script allows to send a raw packet written in hex in a separate file (bytes hex representation separated by space or newline). Also I am not going to use any other modules, I have to use socket. *This (the 0101) is the start of the payload even though it was supposed to be the start of the packet. S = socket(AF_INET, SOCK_RAW, IPPROTO_IP) Here is my code - only the raw function: def raw(): Do you know of any way I can take out these headers? I don't want it to make the headers automatically, that is what my raw packet class was for anyway. The problem is that when I capture the packet by using wireshark it shows up as being the payload of a ipv4 packet. I then did a sendto call to send it on the wire. After completing this I created a raw packet class, its all in hex. When I bind it to my local ip address it works fine. I have no problem with creating that, I am just stuck on sending the packets.įirst I tried to bind it to an interface 'en1' but it keeps giving me an error nodename not known. The catch is that it needs to be all raw sockets. I need to have a project done in a few days, its a basic client and server interface.
0 Comments
Leave a Reply. |