ipfw bypass via overlapping-fragment attack reddit / BSD ---------------------------------------------------------------------- TheGrandSchlonging · 2019-05-22 07:33 [Feel free to send this to the FreeBSD lists, the FreeBSD bug tracker, or whatever to get it fixed.] The ipfw manual page says the following: >Another type of packet is unconditionally dropped, a TCP packet with a fragment offset of one. This is a valid packet, but it only has one use, to try to circumvent firewalls. When logging is enabled, these packets are reported as being dropped by rule -1. The original ipfw did this, but the current ipfw (aka ipfw2), which has been around since 2002, has never done this. Therefore, ipfw is vulnerable to bypasses via the overlapping-fragment attack described in RFC1858. (The tiny-fragment attack described in the same RFC isn't an issue, for `ipfw_chk()` still performs header pull-ups when the IP offset is zero.) There are some conditions for a successful attack: **(1)** A vulnerable ipfw configuration will typically be a stateless configuration patterned along the lines of some of the configurations in `/etc/rc.firewall`: # Allow TCP through if setup succeeded ${fwcmd} add pass tcp from any to any established # Allow IP fragments to pass through ${fwcmd} add pass all from any to any frag [...] # Disallow setup of all other TCP connections ${fwcmd} add deny tcp from any to any setup The order of the rules is irrelevant. Note that there's no 'reass' action in effect. **(2)** The network stack of the device targeted behind the firewall must perform IP reassembly in a manner that allows the attack to succeed. Linux doesn't allow the attack to succeed, for the Linux reassembly algorithm rejects overlapping fragments altogether (`inet_frag_queue_insert()` in `net/ipv4/inet_fragment.c`). BSD doesn't allow the attack to succeed, for the BSD reassembly algorithm allows overlapping fragments but prioritizes the data from lower- numbered IP offsets regardless of the order of delivery (`ip_reass()` in `netinet/ip_reass.c` or `netinet/ip_input.c` on the common BSDs). On the other hand, the quasi-official reassembly algorithms given in RFC791 and RFC815 are vulnerable, and many vendors of embedded/IoT devices are known to use exotic network stacks or even roll their own. (Note: The BSD vendors who've yet to get around to fixing the offset- modifying numeric overflow in `ip_reass()` discovered by NetBSD developers in 2018 also won't be affected by the overlapping-fragment attack -- or, for that matter, bypasses in which an attacker tries to rewrite IP offsets by using the numeric overflow.) ---------------------------------------------------------------------- emaste · 2019-08-13 20:12 This was fixed in [FreeBSD r349366](https://reviews.freebsd.org/rS349366).