1#!/usr/local/bin/python2.7 2# send a ping6 packet with routing header type 0 3# the address list is empty 4# hide the routing header in a second fragment to preclude header scan 5# we expect an echo reply, as there are no more hops 6 7import os 8from addr import * 9from scapy.all import * 10 11pid=os.getpid() & 0xffff 12payload="ABCDEFGHIJKLMNOP" 13packet=IPv6(src=SRC_OUT6, dst=DST_IN6)/\ 14 IPv6ExtHdrDestOpt()/\ 15 IPv6ExtHdrRouting(addresses=[])/\ 16 ICMPv6EchoRequest(id=pid, data=payload) 17frag=[] 18frag.append(IPv6ExtHdrFragment(nh=60, id=pid, m=1)/str(packet)[40:48]) 19frag.append(IPv6ExtHdrFragment(nh=60, id=pid, offset=1)/str(packet)[48:80]) 20eth=[] 21for f in frag: 22 pkt=IPv6(src=SRC_OUT6, dst=DST_IN6)/f 23 eth.append(Ether(src=SRC_MAC, dst=DST_MAC)/pkt) 24 25if os.fork() == 0: 26 time.sleep(1) 27 sendp(eth, iface=SRC_IF) 28 os._exit(0) 29 30ans=sniff(iface=SRC_IF, timeout=3, filter= 31 "ip6 and dst "+SRC_OUT6+" and icmp6") 32for a in ans: 33 if a and a.type == ETH_P_IPV6 and \ 34 ipv6nh[a.payload.nh] == 'ICMPv6' and \ 35 icmp6types[a.payload.payload.type] == 'Echo Reply': 36 reply=a.payload.payload 37 id=reply.id 38 print "id=%#x" % (id) 39 if id != pid: 40 print "WRONG ECHO REPLY ID" 41 exit(2) 42 data=reply.data 43 print "payload=%s" % (data) 44 if data != payload: 45 print "WRONG PAYLOAD" 46 exit(2) 47 exit(0) 48print "NO ICMP6 ECHO REPLY" 49exit(1) 50