Monday, April 28, 2008

Quirks with libnet v 1.1.2.1

Many loopholes in the libnet, like checksum calculation are mentioned on the net. But this one is not mentioned anywhere(or may be I could'nt use google search ) and it took hell lot of time to trace it out. As all the while I was under the assumption that its the problem with my code.

Its basically with ipv6 packet construction. The structure libnet_protocol_block has a variable called ip_offset which points to the IP header position in the whole packet and is used while calculating checksum of the transport protocol included in it. While constructing ipv4 packets ip_offset is being set but not while constructing ipv6 packets. Becuase of that, if the ipv6 packet has a transport layer sitting in its payload, the buffer which is being passed for checksum calculation is erroneous. As the pointer (which should be the location of Ip in the buffer) which is being sent to calculate checksum is dependent on ip_offset variable and as its not set the char* being sent points to the end of the packet buffer.

The solution is, while building the ipv6 packet a simple call to libnet_pblock_record_ip_offset will be sufficient but with a check that its not the last header i.e., the ip packet has the transport layer in its payload.

1 comment:

Anonymous said...

Good for people to know.