Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ########################################################################
    #
    # A single start fragment with zero length IPv6 header (jumbo).
    # Make sure we do hit the Fragment case, which is tricky as the
    # jumbogram needs to be > 64k.
    #
    # A:  Jumbo-Fragment not allowed.
    # R:  ICMPv6 param problem.
    #
    #data = "6" * (65536 - 2 - 6 - 8 - 8)
    data = "6" * 65512
    ip6f01 = sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0], plen=0) / \
     sp.IPv6ExtHdrHopByHop(options=sp.Jumbo(jumboplen=65536)) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=6) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    # We should only need to sleep 0.10 but it seems scapy
    # takes time for this one.
    sleep(75)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser("pft_icmp_check.py",
                                     description="ICMP error validation tool")
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--fromaddr',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet(s) will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        help='The interface on which to expect the ICMP error')

    args = parser.parse_args()
    sniffer = None
    if not args.recvif is None:
        sniffer = Sniffer(args, check_icmp_too_big)

    ping(args.sendif[0], args.to[0], args)

    if sniffer:
        sniffer.join()

        if sniffer.foundCorrectPacket:
            sys.exit(0)
        else:
            sys.exit(1)
Exemplo n.º 3
0
 def scan_udp_ports(self, ports):
     s = Sniffer()
     s.start()
     self._scan_ports(ports, self.scan_udp_port)
     s.stop.set()
     s.join()
     closed_ports = self.get_closed_udp_ports(s.packets)
     return [Port('UDP', p) for p in ports if p not in closed_ports]
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ########################################################################
    #
    # A single start fragment with payload.
    #
    # A:  Waiting for more data.
    # R:  Timeout / Expiry.
    #
    data = "6" * 1280
    ip6f01 = sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=3) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    # Wait for ICMPv6 error generation on timeout.
    sleep(75)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ########################################################################
    #
    # Atomic fragment.
    #
    # A:  Nothing listening on UDP port.
    # R:  ICMPv6 dst unreach, unreach port.
    #
    ip6f01 = sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0, m=0, id=3) / \
     sp.UDP(dport=3456, sport=6543)
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    sleep(0.10)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ########################################################################
    #
    # 0-byte first fragment.
    #
    # A:  0-byte fragment payload not allowed. Discarded.
    # R:  ICMPv6 param prob, paramprob header.
    #
    ip6f01 = sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=4)
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    sleep(0.10)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser("pft_ping.py",
                                     description="Ping test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet(s) will be sent')
    parser.add_argument(
        '--recvif',
        nargs=1,
        help='The interface on which to expect the ICMP echo response')
    parser.add_argument('--ip6', action='store_true', help='Use IPv6')
    parser.add_argument(
        '--to',
        nargs=1,
        required=True,
        help='The destination IP address for the ICMP echo request')

    # Packet settings
    parser.add_argument('--send-tos',
                        nargs=1,
                        help='Set the ToS value for the transmitted packet')

    # Expectations
    parser.add_argument('--expect-tos',
                        nargs=1,
                        help='The expected ToS value in the received packet')

    args = parser.parse_args()

    # We may not have a default route. Tell scapy where to start looking for routes
    sp.conf.iface6 = args.sendif[0]

    sniffer = None
    if not args.recvif is None:
        sniffer = Sniffer(args, check_ping_request)

    if args.ip6:
        ping6(args.sendif[0], args.to[0], args)
    else:
        ping(args.sendif[0], args.to[0], args)

    if sniffer:
        sniffer.join()

        if sniffer.foundCorrectPacket:
            sys.exit(0)
        else:
            sys.exit(1)
Exemplo n.º 8
0
def main():

    sniffer = Sniffer(**vars(args))
    logging.info("[*] Start sniffing...")
    sniffer.start()
    try:
        while True:
            sleep(100)
    except KeyboardInterrupt:
        logging.info("[*] Stop sniffing")
        sniffer.join(2.0)

        if sniffer.is_alive():
            sniffer.socket.close()
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser("CVE-2019-icmp.py",
                                     description="CVE-2019-icmp test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')

    args = parser.parse_args()

    # Send the allowed packet to establish state
    udp = sp.Ether() / \
        sp.IP(src=args.src[0], dst=args.to[0]) / \
        sp.UDP(dport=53, sport=1234)
    sp.sendp(udp, iface=args.sendif[0], verbose=False)

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp_error)

    # Send the bad error packet
    icmp_reachable = sp.Ether() / \
               sp.IP(src=args.src[0], dst=args.to[0]) / \
        sp.ICMP(type=3, code=3) / \
        sp.IP(src=args.src[0], dst=args.to[0]) / \
        sp.UDP(dport=53, sport=1234)
    sp.sendp(icmp_reachable, iface=args.sendif[0], verbose=False)

    sniffer.join()
    if sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
Exemplo n.º 10
0
def main():
    global got_pfsync
    global got_ping
    global sent_ping

    parser = argparse.ArgumentParser("pfsync_defer.py",
                                     description="pfsync defer mode test")
    parser.add_argument('--syncdev',
                        nargs=1,
                        required=True,
                        help='The pfsync interface')
    parser.add_argument('--outdev',
                        nargs=1,
                        required=True,
                        help='The interface we will send packets on')
    parser.add_argument('--indev',
                        nargs=1,
                        required=True,
                        help='The interface we will receive packets on')

    args = parser.parse_args()

    syncmon = Sniffer(args, check_pfsync, args.syncdev[0])
    datamon = Sniffer(args, check_reply, args.indev[0])

    # Send traffic on datadev, which should create state and produce a pfsync message
    ping(args.outdev[0])

    syncmon.join()
    datamon.join()

    if not got_pfsync:
        sys.exit(1)

    if not got_ping:
        sys.exit(1)

    if got_pfsync > got_ping:
        sys.exit(1)

    # Deferred packets are delayed up to 20ms (unless the pfsync peer, which we
    # don't have here, acks their state update earlier)
    if (sent_ping + 0.020) > got_ping:
        sys.exit(1)
Exemplo n.º 11
0
def main():
	parser = argparse.ArgumentParser("pft_ping.py",
		description="Ping test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet(s) will be sent')
	parser.add_argument('--recvif', nargs=1,
		help='The interface on which to expect the ICMP echo response')
	parser.add_argument('--ip6', action='store_true',
		help='Use IPv6')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address for the ICMP echo request')

	# Packet settings
	parser.add_argument('--send-tos', nargs=1,
		help='Set the ToS value for the transmitted packet')

	# Expectations
	parser.add_argument('--expect-tos', nargs=1,
		help='The expected ToS value in the received packet')

	args = parser.parse_args()

	# We may not have a default route. Tell scapy where to start looking for routes
	sp.conf.iface6 = args.sendif[0]

	sniffer = None
	if not args.recvif is None:
		sniffer = Sniffer(args, check_ping_request)

	if args.ip6:
		ping6(args.sendif[0], args.to[0], args)
	else:
		ping(args.sendif[0], args.to[0], args)

	if sniffer:
		sniffer.join()

		if sniffer.foundCorrectPacket:
			sys.exit(0)
		else:
			sys.exit(1)
Exemplo n.º 12
0
def main():
	parser = argparse.ArgumentParser("pcp.py",
		description="PCP test tool")
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface where to look for packets to check')
	parser.add_argument('--expect-pcp', nargs=1,
		help='The expected PCP value on VLAN packets')

	args = parser.parse_args()

	sniffer = Sniffer(args, check_pcp, recvif=args.recvif[0], timeout=20)

	sniffer.join()

	if sniffer.foundCorrectPacket:
		sys.exit(0)

	sys.exit(1)
Exemplo n.º 13
0
def main():
	parser = argparse.ArgumentParser("CVE-2019-icmp.py",
		description="CVE-2019-icmp test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet will be sent')
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface on which to check for the packet')
	parser.add_argument('--src', nargs=1,
		required=True,
		help='The source IP address')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address')

	args = parser.parse_args()

        # Send the allowed packet to establish state
        udp = sp.Ether() / \
            sp.IP(src=args.src[0], dst=args.to[0]) / \
            sp.UDP(dport=53, sport=1234)
        sp.sendp(udp, iface=args.sendif[0], verbose=False)

	# Start sniffing on recvif
	sniffer = Sniffer(args, check_icmp_error)

	# Send the bad error packet
	icmp_reachable = sp.Ether() / \
            sp.IP(src=args.src[0], dst=args.to[0]) / \
	    sp.ICMP(type=3, code=3) / \
	    sp.IP(src=args.src[0], dst=args.to[0]) / \
	    sp.UDP(dport=53, sport=1234)
	sp.sendp(icmp_reachable, iface=args.sendif[0], verbose=False)

	sniffer.join()
	if sniffer.foundCorrectPacket:
		sys.exit(1)

	sys.exit(0)
Exemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser("stp.py", description="STP test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet(s) will be sent')
    parser.add_argument(
        '--recvif',
        nargs=1,
        help='The interface on which to expect the ICMP echo request')

    args = parser.parse_args()

    sniffer = Sniffer(args, check_stp)

    invalid_stp(args.sendif[0])

    sniffer.join()

    # The 'correct' packet is a corrupt STP packet, so it shouldn't turn up.
    if sniffer.foundCorrectPacket:
        sys.exit(1)
Exemplo n.º 15
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)
    sniffer2 = Sniffer(args, check_icmp6_error_2)

    ########################################################################
    #
    # A fragment with payload and offset set to add up to >64k when
    # another frag with offset=0 arrives and has an unfrag part.
    # This is us checking for all fragments queued already when the
    # one with off=0 arrives.  Note:  unless the off=0 has its own problem
    # it will be queued and off!=0 ones might be expunged with param prob.
    #
    # A:  Reassembly failure, timeout after
    # R:  ICMPv6 param prob, param header (1st frag)
    # R:  ICMPv6 time exceeded (2nd frag, as off=0)
    #
    data = "6" * 15
    ip6f01 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0x1ffc, m=0, id=8) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    data = "6" * 8
    ip6f02 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrDestOpt(options = \
         sp.PadN(optdata="\x00\x00\x00\x00\x00\x00")) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=8) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
        ip6f02.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
    sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

    sleep(1.00)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)
    sleep(75)
    sniffer2.setEnd()
    sniffer2.join()
    if not sniffer2.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ########################################################################
    #
    # A single fragmented packet with upper layer data in multiple segments
    # to pass fragmentation.
    # We need to do a bit of a dance to get the UDP checksum right.
    #
    # A:  1 reassembled packet
    # R:  Statistics and ICMPv6 error (non-fragmentation) as no port open.
    #
    data = "6" * 1280
    dataall = data * 30
    ip6f01 = \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.UDP(dport=3456, sport=6543) / \
     dataall
    ip6fd = sp.IPv6(sp.raw(ip6f01))

    ip6f01 = sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=16) / \
     sp.UDP(dport=3456, sport=6543, len=ip6fd.len, chksum=ip6fd.chksum) / \
     data
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    foffset = (int)(1288 / 8)
    mbit = 1
    for i in range(1, 30):
        if i is 29:
            mbit = 0
        ip6f0n = sp.Ether() / \
         sp.IPv6(src=args.src[0], dst=args.to[0]) / \
         sp.IPv6ExtHdrFragment(offset=foffset, m=mbit, id=16, nh=socket.IPPROTO_UDP) / \
         data
        if args.debug:
            ip6f0n.display()
        sp.sendp(ip6f0n, iface=args.sendif[0], verbose=False)
        foffset += (int)(1280 / 8)

    sleep(0.10)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
Exemplo n.º 17
0
def main():
	parser = argparse.ArgumentParser("frag6.py",
		description="IPv6 fragementation test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet will be sent')
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface on which to check for the packet')
	parser.add_argument('--src', nargs=1,
		required=True,
		help='The source IP address')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address')
	parser.add_argument('--debug',
		required=False, action='store_true',
		help='Enable test debugging')

	args = parser.parse_args()


	# Start sniffing on recvif
	sniffer = Sniffer(args, check_icmp6_error)
	sniffer2 = Sniffer(args, check_icmp6_error_2)


	########################################################################
	#
	# Two fragments with payload and offset set to add up to >64k.
	#
	# Make a first fragment arrive and a second to explode everything.
	#
	# A:  Reassembly failure.
	# R:  ICMPv6 param prob, param header.
	# R:  ICMPv6 timeout (1st frag, off=0)
	#
	data = "6" * 1280
	ip6f01 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0, m=1, id=7) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	ip6f02 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0x1fff, m=1, id=7) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	if args.debug :
		ip6f01.display()
		ip6f02.display()
	sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
	sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

	sleep(1.00)
	sniffer.setEnd()
	sniffer.join()
	if not sniffer.foundCorrectPacket:
		sys.exit(1)


	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
	#
	# A fragment with payload and offset set to add up to >64k.
	#
	# Try again with the first packet to make things explode.
	#
	# A:  Reassembly failure.
	# R:  ICMPv6 param prob, param header.
	#

	# Start sniffing on recvif
	sniffer = Sniffer(args, check_icmp6_error)

	ip6f01 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0x1fff, m=1, id=0x7001) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	if args.debug :
		ip6f01.display()
	sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

	sleep(0.10)
	sniffer.setEnd()
	sniffer.join()
	if not sniffer.foundCorrectPacket:
		sys.exit(1)

	# Wait for expiry from first test run.
	sleep(75)
	sniffer2.setEnd()
	sniffer2.join()
	if not sniffer2.foundCorrectPacket:
		sys.exit(1)

	sys.exit(0)
Exemplo n.º 18
0
def main():
    parser = argparse.ArgumentParser("pft_ping.py",
                                     description="Ping test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet(s) will be sent')
    parser.add_argument(
        '--recvif',
        nargs=1,
        help='The interface on which to expect the ICMP echo request')
    parser.add_argument(
        '--replyif',
        nargs=1,
        help='The interface on which to expect the ICMP echo response')
    parser.add_argument(
        '--checkdup',
        nargs=1,
        help='The interface on which to expect the duplicated ICMP packets')
    parser.add_argument('--ip6', action='store_true', help='Use IPv6')
    parser.add_argument(
        '--to',
        nargs=1,
        required=True,
        help='The destination IP address for the ICMP echo request')
    parser.add_argument('--fromaddr',
                        nargs=1,
                        help='The source IP address for the ICMP echo request')

    # TCP options
    parser.add_argument('--tcpsyn',
                        action='store_true',
                        help='Send a TCP SYN packet')
    parser.add_argument('--tcpopt_unaligned',
                        action='store_true',
                        help='Include unaligned TCP options')

    # Packet settings
    parser.add_argument('--send-tos',
                        nargs=1,
                        help='Set the ToS value for the transmitted packet')

    # Expectations
    parser.add_argument('--expect-tos',
                        nargs=1,
                        help='The expected ToS value in the received packet')

    args = parser.parse_args()

    # We may not have a default route. Tell scapy where to start looking for routes
    sp.conf.iface6 = args.sendif[0]

    sniffer = None
    if not args.recvif is None:
        checkfn = check_ping_request
        if args.tcpsyn:
            checkfn = check_tcpsyn

        sniffer = Sniffer(args, checkfn)

    replysniffer = None
    if not args.replyif is None:
        checkfn = check_ping_reply
        replysniffer = Sniffer(args, checkfn, recvif=args.replyif[0])

    dupsniffer = None
    if args.checkdup is not None:
        dupsniffer = Sniffer(args, check_dup, recvif=args.checkdup[0])

    if args.tcpsyn:
        tcpsyn(args.sendif[0], args.to[0], args)
    else:
        if args.ip6:
            ping6(args.sendif[0], args.to[0], args)
        else:
            ping(args.sendif[0], args.to[0], args)

    if dupsniffer:
        dupsniffer.join()
        if dup_found != 1:
            sys.exit(1)

    if sniffer:
        sniffer.join()

        if sniffer.foundCorrectPacket:
            sys.exit(0)
        else:
            sys.exit(1)

    if replysniffer:
        replysniffer.join()

        if replysniffer.foundCorrectPacket:
            sys.exit(0)
        else:
            sys.exit(1)
Exemplo n.º 19
0
def main():
	parser = argparse.ArgumentParser("frag6.py",
		description="IPv6 fragementation test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet will be sent')
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface on which to check for the packet')
	parser.add_argument('--src', nargs=1,
		required=True,
		help='The source IP address')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address')
	parser.add_argument('--debug',
		required=False, action='store_true',
		help='Enable test debugging')

	args = parser.parse_args()


	# Start sniffing on recvif
	sniffer = Sniffer(args, check_icmp6_error)


	########################################################################
	#
	# Send a proper first fragment (off=0) and a second fragment which
	# just fits the 64k.  The re-send the first fragment with an extra
	# unfragmentable part making the 64k to exceed the limit.
	# This is to make sure we don't allow to update meta-data for a
	# 1st fragmented packet should a second arrive but given the
	# fragmentable part is an exact duplicate only that fragment
	# will be silently discarded.
	#
	# A:  Reassembly failure, timeout after
	# R:  ICMPv6 time exceeded / statistics for the duplicate
	#
	data = "6" * 8
	ip6f00 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0, m=1, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	data = "6" * 15
	ip6f01 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0x1ffc, m=0, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	data = "6" * 8
	ip6f02 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrDestOpt(options = \
		    sp.PadN(optdata="\x00\x00\x00\x00\x00\x00")) / \
		sp.IPv6ExtHdrFragment(offset=0, m=1, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	if args.debug :
		ip6f00.display()
		ip6f01.display()
		ip6f02.display()
	sp.sendp(ip6f00, iface=args.sendif[0], verbose=False)
	sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
	sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

	sleep(75)
	sniffer.setEnd()
	sniffer.join()
	if not sniffer.foundCorrectPacket:
		sys.exit(1)

	sys.exit(0)