本文介绍了如何在不发送的情况下计算数据包校验和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 scapy,我想创建一个数据包并计算其校验和而不发送它.有办法吗?

谢谢.

解决方案

创建包后需要删除.chksum值;然后调用 .show2()

>>>从 scapy.layers.inet 导入 IP>>>从 scapy.layers.inet 导入 ICMP>>>从 scapy.layers.inet 导入 TCP>>>目标 = "10.9.8.7">>>ttl = 64>>>编号 = 32711>>>运动 = 2927>>>端口 = 80>>>pak = IP(dst=target, src = "100.99.98.97", ttl=ttl, flags="DF", id=id, len=1200, chksum = 0)/TCP(flags="S", Sport=sport, dport=int(dport), options=[('Timestamp',(0,0))], chksum = 0)>>>del pak[IP].chksum>>>del pak[TCP].chksum>>>pak.show2()###[ IP ]###版本 = 4LIHL = 5L托 = 0x0长度 = 1200编号 = 32711标志 = DF碎片 = 0Lttl = 64原型 = tcpchksum = 0x9afd源代码 = 100.99.98.97dst = 10.9.8.7\选项 \###[ TCP ]###运动 = 2927dport = www序列 = 0确认 = 0dataofs = 8L保留 = 0L标志 = S窗口 = 8192chksum = 0x2c0eurgptr = 0options = [('Timestamp', (0, 0)), ('EOL', None)]>>>

I'm using scapy, and I want to create a packet and calculate its' checksum without sending it. Is there a way to do it?

Thanks.

解决方案

You need to delete the .chksum value from the packet after you create it; then call .show2()

>>> from scapy.layers.inet import IP
>>> from scapy.layers.inet import ICMP
>>> from scapy.layers.inet import TCP
>>> target = "10.9.8.7"
>>> ttl = 64
>>> id = 32711
>>> sport = 2927
>>> dport = 80
>>> pak = IP(dst=target, src = "100.99.98.97", ttl=ttl, flags="DF", id=id, len=1200, chksum = 0)/TCP(flags="S", sport=sport, dport=int(dport), options=[('Timestamp',(0,0))], chksum = 0)
>>> del pak[IP].chksum
>>> del pak[TCP].chksum
>>> pak.show2()
###[ IP ]###
  version   = 4L
  ihl       = 5L
  tos       = 0x0
  len       = 1200
  id        = 32711
  flags     = DF
  frag      = 0L
  ttl       = 64
  proto     = tcp
  chksum    = 0x9afd
  src       = 100.99.98.97
  dst       = 10.9.8.7
  \options   \
###[ TCP ]###
     sport     = 2927
     dport     = www
     seq       = 0
     ack       = 0
     dataofs   = 8L
     reserved  = 0L
     flags     = S
     window    = 8192
     chksum    = 0x2c0e
     urgptr    = 0
     options   = [('Timestamp', (0, 0)), ('EOL', None)]
>>>

这篇关于如何在不发送的情况下计算数据包校验和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 16:12