Browse Source

Working showing version of checksums

master
Nico Schottelius 3 years ago
parent
commit
e1dd4d44d4
  1. 97
      bin/checksum_delta_diff_test.py

97
bin/checksum_delta_diff_test.py

@ -16,11 +16,16 @@ def checksum_scapy(pkt):
s = ~s
return (((s>>8)&0xff)|s<<8) & 0xffff
# a) Compare for TCP, UDP -> IPv6 does not have checksum!
# 1. convert to array of "bytes"
# 2. import into an array
# 3. sum everything up
# b) Generate checksum from v4 offset and IPv6 for IPv4
# a)
# UDP/TCP CONTENT stays the same
# Only the diff between v4 and v6 "counts"
#
def sum_for_udp(packet):
sums = ""
@ -52,7 +57,7 @@ def sum_for_v6(packet):
sums += struct.pack("H", packet[IPv6].plen)
sums += struct.pack("B", packet[IPv6].nh)
print("{} - {} - {}".format(len(sums), sums, checksum_scapy(sums)))
# print("{} - {} - {}".format(len(sums), sums, checksum_scapy(sums)))
return sums
@ -99,31 +104,81 @@ if __name__ == '__main__':
d0 = ""
d = "A"
p.append(e / i4 / u / d)
p.append(e / i6 / u / d)
p.append(e / i62 / u / d)
p6_udp = e / i6 / u / d
p6_udp2 = e / i62 / u / d
p4_udp = e / i4 / u / d
p4_p6_1 = {
"ipv6": p6_udp,
"ipv4": p4_udp
}
p.append(p4_p6_1)
p4_p6_2 = {
"ipv6": p6_udp2,
"ipv4": p4_udp
}
p.append(p4_p6_2)
#p.append(e / i62 / u / d)
for p_pair in p:
v6 = p_pair["ipv6"]
v4 = p_pair["ipv4"]
checksums = {}
header_checksums = {}
diff_ip_headers = 0
for packet in [v6, v4]:
#print("p = {}".format(packet.__repr__()))
packet_rebuild = packet.__class__(str(packet))
print("rebuild = {}".format(packet_rebuild.__repr__()))
chk_old = packet[UDP].chksum
chk_new = packet_rebuild[UDP].chksum
# print("chk1 = {} chk2={}".format(chk_old, chk_new))
sums = ""
if IPv6 in packet:
headertype = "ipv6"
sums += sum_for_v6(packet_rebuild)
if UDP in packet:
checksums["ipv6"] = packet_rebuild[UDP].chksum
if IP in packet:
headertype = "ipv4"
sums += sum_for_v4(packet_rebuild)
if UDP in packet:
checksums["ipv4"] = packet_rebuild[UDP].chksum
header_checksums[headertype] = checksum_scapy(sums)
print("Checksum-parts {} for {}".format(checksum_scapy(sums), packet_rebuild.__repr__()))
print("UDP v6: {} v4: {} diff: {}".format(checksums["ipv6"],
checksums["ipv4"],
checksums["ipv6"] - checksums["ipv4"]))
for packet in p:
print("p = {}".format(packet.__repr__()))
packet_rebuild = packet.__class__(str(packet))
print("rebuild = {}".format(packet_rebuild.__repr__()))
chk_old = packet[UDP].chksum
chk_new = packet_rebuild[UDP].chksum
print("chk1 = {} chk2={}".format(chk_old, chk_new))
print("Header v6: {} v4: {} diff: {}".format(header_checksums["ipv6"],
header_checksums["ipv4"],
header_checksums["ipv6"] - header_checksums["ipv4"]))
sums = ""
p
if IP in packet:
sums += sum_for_v4(packet_rebuild)
if IPv6 in packet:
sums += sum_for_v6(packet_rebuild)
# if UDP in packet:
# sums += sum_for_udp(packet_rebuild)
# if UDP in packet:
# sums += sum_for_udp(packet_rebuild)
# if TCP in packet:
# sums += sum_for_udp(packet_rebuild)
print("Checksum-parts {} for {}".format(checksum_scapy(sums), packet_rebuild.__repr__()))
# Checksums:
# diff_total += packet_rebuild[IP].chksum
# diff_total -= packet_rebuild[IPv6].chksum# Checksums:
# - tcp
# - udp
# - icmp6

Loading…
Cancel
Save