1*527238f8Sbluhm#!/usr/local/bin/python3
2233b170eSbluhm
3*527238f8Sbluhmprint("ping6 fragment that overlaps the first fragment with its head")
4741f9993Sbluhm
57cd47444Sbluhm# |---------|
67cd47444Sbluhm#      |XXXX-----|
7741f9993Sbluhm
8741f9993Sbluhmimport os
9741f9993Sbluhmfrom addr import *
10741f9993Sbluhmfrom scapy.all import *
11741f9993Sbluhm
129ae5678bSbluhmpid=os.getpid()
139ae5678bSbluhmeid=pid & 0xffff
14*527238f8Sbluhmpayload=b"ABCDEFGHIJKLMNOP"
157b3475a7Sbluhmpacket=IPv6(src=LOCAL_ADDR6, dst=REMOTE_ADDR6)/ \
167b3475a7Sbluhm    ICMPv6EchoRequest(id=eid, data=payload)
17741f9993Sbluhmfrag=[]
189ae5678bSbluhmfid=pid & 0xffffffff
19*527238f8Sbluhmfrag.append(IPv6ExtHdrFragment(nh=58, id=fid, m=1)/bytes(packet)[40:56])
20*527238f8Sbluhmfrag.append(IPv6ExtHdrFragment(nh=58, id=fid, offset=1)/bytes(packet)[48:64])
21741f9993Sbluhmeth=[]
22741f9993Sbluhmfor f in frag:
237b3475a7Sbluhm	pkt=IPv6(src=LOCAL_ADDR6, dst=REMOTE_ADDR6)/f
247b3475a7Sbluhm	eth.append(Ether(src=LOCAL_MAC, dst=REMOTE_MAC)/pkt)
25741f9993Sbluhm
26741f9993Sbluhmif os.fork() == 0:
27741f9993Sbluhm	time.sleep(1)
287b3475a7Sbluhm	sendp(eth, iface=LOCAL_IF)
29741f9993Sbluhm	os._exit(0)
30741f9993Sbluhm
317b3475a7Sbluhmans=sniff(iface=LOCAL_IF, timeout=3, filter=
327b3475a7Sbluhm    "ip6 and src "+REMOTE_ADDR6+" and dst "+LOCAL_ADDR6+" and icmp6")
33741f9993Sbluhmfor a in ans:
349c70e3bfSbluhm	if a and a.type == ETH_P_IPV6 and \
35741f9993Sbluhm	    ipv6nh[a.payload.nh] == 'ICMPv6' and \
36741f9993Sbluhm	    icmp6types[a.payload.payload.type] == 'Echo Reply':
37741f9993Sbluhm		id=a.payload.payload.id
38*527238f8Sbluhm		print("id=%#x" % (id))
399ae5678bSbluhm		if id != eid:
40*527238f8Sbluhm			print("WRONG ECHO REPLY ID")
41741f9993Sbluhm			exit(2)
42741f9993Sbluhm		data=a.payload.payload.data
43*527238f8Sbluhm		print("payload=%s" % (data))
44741f9993Sbluhm		if data == payload:
45*527238f8Sbluhm			print("ECHO REPLY")
46741f9993Sbluhm			exit(1)
47*527238f8Sbluhm		print("PAYLOAD!=%s" % (payload))
48741f9993Sbluhm		exit(2)
49*527238f8Sbluhmprint("no echo reply")
50499024ccSbluhmexit(0)
51