[包编辑]修复包的checksum
[包编辑]修复包的checksum
如果我们修改了pcap的内容,之后会导致在TCP层里的checksum不对,这时我们就需要重新生成新的cksum并将Checksum字段修改正确,可使用如下脚本:
from scapy.all import *
import sys
import logging
logging.getLogger("scapy").setLevel(1)
if len(sys.argv) != 2:
print("Usage:./ChecksumFixer <input_pcap_file> <output_pcap_file>")
print("Example: ./ChecksumFixer input.pcap output.pcap")
sys.exit(1)
# ------------------------Command Line Argument---------------------------------------
input_file = sys.argv[1]
output_file = sys.argv[2]
# ------------------------Get The layer and Fix Checksum-------------------------------
def getLayer(p):
for paktype in (IP, TCP, UDP, ICMP):
try:
p.getlayer(paktype).chksum = None
except AttributeError:
pass
return p
# -----------------------FixPcap in input file and write to output fi`enter code here`le----------------
def fixpcap():
paks = rdpcap(input_file)
fc = map(getLayer, paks)
wrpcap(output_file, fc)
if __name__ == '__main__':
fixpcap()