Path: blob/main/tests/sys/netpfil/pf/CVE-2019-5598.py
39507 views
#!/usr/bin/env python31#2# SPDX-License-Identifier: BSD-2-Clause3#4# Copyright (c) 2019 Kristof Provost <[email protected]>5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions8# are met:9# 1. Redistributions of source code must retain the above copyright10# notice, this list of conditions and the following disclaimer.11# 2. Redistributions in binary form must reproduce the above copyright12# notice, this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25# SUCH DAMAGE.2627import argparse28import logging29logging.getLogger("scapy").setLevel(logging.CRITICAL)30import scapy.all as sp31import sys32from sniffer import Sniffer3334def check_icmp_error(args, packet):35ip = packet.getlayer(sp.IP)36if not ip:37return False38if ip.dst != args.to[0]:39return False4041icmp = packet.getlayer(sp.ICMP)42if not icmp:43return False44if icmp.type != 3 or icmp.code != 3:45return False4647return True4849def main():50parser = argparse.ArgumentParser("CVE-2019-icmp.py",51description="CVE-2019-icmp test tool")52parser.add_argument('--sendif', nargs=1,53required=True,54help='The interface through which the packet will be sent')55parser.add_argument('--recvif', nargs=1,56required=True,57help='The interface on which to check for the packet')58parser.add_argument('--src', nargs=1,59required=True,60help='The source IP address')61parser.add_argument('--to', nargs=1,62required=True,63help='The destination IP address')6465args = parser.parse_args()6667# Send the allowed packet to establish state68udp = sp.Ether() / \69sp.IP(src=args.src[0], dst=args.to[0]) / \70sp.UDP(dport=53, sport=1234)71sp.sendp(udp, iface=args.sendif[0], verbose=False)7273# Start sniffing on recvif74sniffer = Sniffer(args, check_icmp_error, args.recvif[0])7576# Send the bad error packet77icmp_reachable = sp.Ether() / \78sp.IP(src=args.src[0], dst=args.to[0]) / \79sp.ICMP(type=3, code=3) / \80sp.IP(src="4.3.2.1", dst="1.2.3.4") / \81sp.UDP(dport=53, sport=1234)82sp.sendp(icmp_reachable, iface=args.sendif[0], verbose=False)8384sniffer.join()85if sniffer.correctPackets:86sys.exit(1)8788sys.exit(0)8990if __name__ == '__main__':91main()929394