With the setsockopt() we tell the kernel not to generate an IP header, since we are providing it ourselves. We are creating a socket s out of the Internet Protocol family AF_INET, in “raw” mode SOCK_RAW which will be sending TCP packets IPPROTO_TCP. For this example we are going to use Python’s built-in socket module: import socket s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP) s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) ip_header = b'\x45\x00\x00\x28' # Version, IHL, Type of Service | Total Length ip_header = b'\xab\xcd\x00\x00' # Identification | Flags, Fragment Offset ip_header = b'\x40\x06\xa6\xec' # TTL, Protocol | Header Checksum ip_header = b'\x0a\x0a\x0a\x02' # Source Address ip_header = b'\x0a\x0a\x0a\x01' # Destination Address tcp_header = b'\x30\x39\x00\x50' # Source Port | Destination Port tcp_header = b'\x00\x00\x00\x00' # Sequence Number tcp_header = b'\x00\x00\x00\x00' # Acknowledgement Number tcp_header = b'\x50\x02\x71\x10' # Data Offset, Reserved, Flags | Window Size tcp_header = b'\xe6\x32\x00\x00' # Checksum | Urgent Pointer packet = ip_header tcp_header s.sendto(packet, ( '10.10.10.1', 0)) As this is a packet we are sending to our webserver, we expect him to respond with a if everything works as planned. For better readability, they are arranged like this: 45Īfter we have now manually created our first TCP/IP packet, let’s put it on the wire. Now let’s put the calculated checksums in our blueprint. ![]() TTL, Protocol Header Checksum (0x0000 in calculation)Īs you could see, both checksums follow the same algorithm, just their input values are different. ![]() Version, IHL, Type of Service Total Length It consists out of all values in the IP header, again added in 16 bit words and prepended with zeros in case the value is too short: Description The IP header checksum is easy to calculate. (no actual header field, has to be counted!)ĭata Offset, Reserved, Flags, Window SizeĬhecksum (set to 0x0000 in calculation), Urgent Pointer TCP length (including the data part) in byte In case the value isn’t 16 bit long, it will be prepended with zeros. For the calculations, all necessary values are used in 16 bit words and added together as shown below. Remembering from the first part of this series we know, that the checksum consists of values of the TCP Header itself, as well as a pseudo-header. TCP Checksum
0 Comments
Leave a Reply. |