Scapy and checksum calculation
Sometimes you have to (re)calculate a checksum when you modify packets or when you try to solve friends networking challenge like the following:
I’m 45000064000f0000fe013726c0a80108c0a8030b - a 20 bytes IP header.
What will be my checksum after the next hop? :-)
It’s easy with scapy … first, import the hex, modify the TTL, delete the checksum then apply show2() function. This one automatically recalculate the new checksum for you.
»> pownage=IP(import_hexcap())
0000 4500 0064 000f 0000 fe01 3726 c0a8 0108
0010 c0a8 030b
»> pownage.ttl = pownage.ttl - 1
»> del pownage.chksum
»> pownage.show2()
###[ IP ]###
version= 4L
ihl= 5L
tos= 0x0
len= 100
id= 15
flags=
frag= 0L
ttl= 253
proto= icmp
chksum= 0x3826
src= 192.168.1.8
dst= 192.168.3.11
options= ”