Comparing TCP checksums with Scapy?

你离开我真会死。 提交于 2019-12-10 10:29:27

问题


I am trying to identify packets with incorrect checksums while using Scapy as a sniffer. I am able to get the original checksum by accessing

packet[TCP].chksum  

I then remove this using

del packet[TCP].chksum 

I would like to do something like

if(originalChecksum == recomputedChecksum):
     # Checksum is valid

I understand that using show2() recomputes the checksum, but is there anyway to access this attribute for comparing back to the original? Calling show2() simply displays what the checksum would be, and does not set any of the values in the packet.

Thanks for any clarification


回答1:


to make Scapy recompute all fields, assemble the packet by dumping it to a string, then parse the string.

originalChecksum=packet['TCP'].chksum
del packet['TCP'].chksum
packet=IP(str(packet))
recomputedChecksum=packet['TCP'].chksum


来源:https://stackoverflow.com/questions/6665844/comparing-tcp-checksums-with-scapy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!