Working showing version of checksums
This commit is contained in:
parent
92e1407729
commit
e1dd4d44d4
1 changed files with 77 additions and 22 deletions
|
@ -16,11 +16,16 @@ def checksum_scapy(pkt):
|
||||||
s = ~s
|
s = ~s
|
||||||
return (((s>>8)&0xff)|s<<8) & 0xffff
|
return (((s>>8)&0xff)|s<<8) & 0xffff
|
||||||
|
|
||||||
|
# a) Compare for TCP, UDP -> IPv6 does not have checksum!
|
||||||
# 1. convert to array of "bytes"
|
# 1. convert to array of "bytes"
|
||||||
# 2. import into an array
|
# 2. import into an array
|
||||||
# 3. sum everything up
|
# 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):
|
def sum_for_udp(packet):
|
||||||
sums = ""
|
sums = ""
|
||||||
|
@ -52,7 +57,7 @@ def sum_for_v6(packet):
|
||||||
sums += struct.pack("H", packet[IPv6].plen)
|
sums += struct.pack("H", packet[IPv6].plen)
|
||||||
sums += struct.pack("B", packet[IPv6].nh)
|
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
|
return sums
|
||||||
|
|
||||||
|
@ -99,31 +104,81 @@ if __name__ == '__main__':
|
||||||
d0 = ""
|
d0 = ""
|
||||||
d = "A"
|
d = "A"
|
||||||
|
|
||||||
p.append(e / i4 / u / d)
|
p6_udp = e / i6 / u / d
|
||||||
p.append(e / i6 / u / d)
|
p6_udp2 = e / i62 / u / d
|
||||||
p.append(e / i62 / u / d)
|
p4_udp = e / i4 / u / d
|
||||||
|
|
||||||
for packet in p:
|
p4_p6_1 = {
|
||||||
print("p = {}".format(packet.__repr__()))
|
"ipv6": p6_udp,
|
||||||
packet_rebuild = packet.__class__(str(packet))
|
"ipv4": p4_udp
|
||||||
print("rebuild = {}".format(packet_rebuild.__repr__()))
|
}
|
||||||
chk_old = packet[UDP].chksum
|
p.append(p4_p6_1)
|
||||||
chk_new = packet_rebuild[UDP].chksum
|
|
||||||
print("chk1 = {} chk2={}".format(chk_old, chk_new))
|
|
||||||
|
|
||||||
sums = ""
|
p4_p6_2 = {
|
||||||
|
"ipv6": p6_udp2,
|
||||||
|
"ipv4": p4_udp
|
||||||
|
}
|
||||||
|
p.append(p4_p6_2)
|
||||||
|
|
||||||
if IP in packet:
|
#p.append(e / i62 / u / d)
|
||||||
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)
|
|
||||||
|
|
||||||
print("Checksum-parts {} for {}".format(checksum_scapy(sums), packet_rebuild.__repr__()))
|
|
||||||
|
|
||||||
|
|
||||||
# Checksums:
|
|
||||||
|
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"]))
|
||||||
|
|
||||||
|
print("Header v6: {} v4: {} diff: {}".format(header_checksums["ipv6"],
|
||||||
|
header_checksums["ipv4"],
|
||||||
|
header_checksums["ipv6"] - header_checksums["ipv4"]))
|
||||||
|
|
||||||
|
p
|
||||||
|
|
||||||
|
# if UDP in packet:
|
||||||
|
# sums += sum_for_udp(packet_rebuild)
|
||||||
|
# if TCP in packet:
|
||||||
|
# sums += sum_for_udp(packet_rebuild)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# diff_total += packet_rebuild[IP].chksum
|
||||||
|
# diff_total -= packet_rebuild[IPv6].chksum# Checksums:
|
||||||
# - tcp
|
# - tcp
|
||||||
# - udp
|
# - udp
|
||||||
# - icmp6
|
# - icmp6
|
||||||
|
|
Loading…
Reference in a new issue