frag_dropold.py revision 1.4
1#!/usr/local/bin/python2.7 2# new fragment completely overlaps old one 3 4# |----| 5# |XXXX| 6# |------------| 7 8# If an existing fragment is completely overlapped by the current 9# one, drop the older fragment. 10# TAILQ_REMOVE(&frag->fr_queue, after, fr_next); 11# Smaller older fragments might not have been nearer, and might be 12# trying to overwrite a very small part of the full packet. 13 14import os 15from addr import * 16from scapy.all import * 17 18dstaddr=sys.argv[1] 19pid=os.getpid() & 0xffff 20payload="ABCDEFGHIJKLOMNOQRSTUVWX" 21dummy="01234567" 22packet=IP(src=SRC_OUT, dst=dstaddr)/ICMP(id=pid)/payload 23frag0=str(packet)[20:28] 24frag1=dummy 25frag2=str(packet)[28:52] 26pkt0=IP(src=SRC_OUT, dst=dstaddr, proto=1, id=pid, frag=0, flags='MF')/frag0 27pkt1=IP(src=SRC_OUT, dst=dstaddr, proto=1, id=pid, frag=2, flags='MF')/frag1 28pkt2=IP(src=SRC_OUT, dst=dstaddr, proto=1, id=pid, frag=1)/frag2 29eth=[] 30eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0) 31eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1) 32eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt2) 33 34if os.fork() == 0: 35 time.sleep(1) 36 sendp(eth, iface=SRC_IF) 37 os._exit(0) 38 39ans=sniff(iface=SRC_IF, timeout=3, filter= 40 "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp") 41a=ans[0] 42if a and a.type == ETH_P_IP and \ 43 a.payload.proto == 1 and \ 44 a.payload.frag == 0 and a.payload.flags == 0 and \ 45 icmptypes[a.payload.payload.type] == 'echo-reply': 46 id=a.payload.payload.id 47 print "id=%#x" % (id) 48 if id != pid: 49 print "WRONG ECHO REPLY ID" 50 exit(2) 51 load=a.payload.payload.payload.load 52 print "payload=%s" % (load) 53 if load == payload: 54 exit(0) 55 print "PAYLOAD!=%s" % (payload) 56 exit(1) 57print "NO ECHO REPLY" 58exit(2) 59