master-thesis/bin/checksum_delta_diff_test.py

52 lines
1.1 KiB
Python
Raw Normal View History

2019-06-29 13:23:00 +00:00
#!/usr/bin/python3
from scapy.all import *
if __name__ == '__main__':
p = []
e0 = Ether(src="00:00:00:00:00:00",
dst="00:00:00:00:00:00")
e = Ether(src="02:53:55:42:45:01",
dst='ff:ff:ff:ff:ff:ff')
i0 = IP(src = "0.0.0.0",
dst = "0.0.0.0")
i4 = IP(src = "192.168.1.1",
dst = "192.168.4.2")
i6 = IPv6(src = "2001:db8:42::1",
dst = "2001:db8::2")
t0 = TCP(dport=0, sport=0)
#t = TCP(dport=80, sport=random.randint(49152,65535))
# print("chk_t = {}".format(t))
t = TCP(dport=80, sport=1337)
#print("chk_t = {}".format(t))
d0 = ""
d = "A"
p.append(e / i4 / t / d)
p.append(e / i6 / t / d)
for packet in p:
print("p = {}".format(packet.__repr__()))
packet_rebuild = packet.__class__(str(packet))
chk_old = packet[TCP].chksum
chk_new = packet_rebuild[TCP].chksum
print("chk1 = {} chk2={}".format(chk_old, chk_new))
# Checksums:
# - tcp
# - udp
# - icmp6
# - icmp
# - ipv4 (no payload)
#
# t.chksum = None