6 ms·
FreeBSD pf bypass when using IPv6
- mmsc 3y agoThe final rule: pass in quick on $ATTACKER_IF inet6 label "Allow the rest of IPv6" should probably be pass in quick on $VICTIM_IF inet6 label "Allow the rest of IPv6" right?
- enrico204 3y agoAuthor here. The ruleset in the blog post is correct. The rationale of the example ruleset is the following: we want to block TCP, UDP and ICMPv6 traffic from the attacker, while allowing other protocols. Note that IPv6 packets are matched against all rules, while IPv6 fragments are matched against rules that contain network-level information only (as fragments don't have upper layer headers, except for the first fragment). If the scrubbing is enabled, then `pf` is supposed to reassemble all fragments, so that there is no more fragmented traffic (= all rules are applied to all IPv6 packets). Normally, it works. In this case, we tricked the firewall by sending an "atomic fragment" that is composed by multiple fragmented headers (this is forbidden by various RFCs). These headers trigger the reassembly mechanism of `pf`, but the packet is "re-assembled" only once: when it enters the rule matcher (after the reassembly), it is still considered a fragment, and all rules with transport-level (and higher) protocol information are skipped. So, the "block-pass" pair at the end is used to exploit this behavior (in other words, we can decide which rule we match by playing with IPv6 fragment header). PS: an "atomic fragment" is a IPv6 packet that is fragmented using only one fragment. Surprisingly, it is supported by RFCs.
- mmsc 3y agoThank you for the response! I read "allow the rest" to mean "the rest of everything", rather than "the rest of the protocols". Based on your explanation, does that mean if the restriction was block in quick on $ATTACKER_IF inet6 label "Block all connections from the attacker" it would not succumb to this vulnerability? Great job with this, btw.
- tux2bsd 3y ago[dead]
- guilhas 3y agoAnd that's why I disable IPv6 in my home network. Don't need it's benefits, and don't need the surprises it might bring
- nvy 3y agoI haven't been able to determine if OpenBSD's `pf` is also affected. Anyone know?
- enrico204 3y agoAuthor here. No, OpenBSD's `pf` is not affected.
- rollcat 3y agoIIRC FreeBSD has a quite outdated version of pf, that hasn't been synced with OpenBSD upstream in quite a while. I like FreeBSD for the breadth of features, but in some cases it feels like they've pushed it to an extreme, a bit of a kitchen sink. I don't think you need three different firewalls, a single good one would do a better job.
- toast0 3y agoI don't know that it's necessarily outdated, more than it's a fork that evolved differently, and I don't think they'll reconverge. I actively use ipfw and pf (at the same time!) because neither one can do all the things I need. I've never used the third one though.
- anthk 3y agoThat's why I prefer OpenBSD vs NetBSD and FreeBSD. Correctness at the core technologies before pushing any new cool feature. >I don't think you need three different firewalls, a single good one would do a better job. This.
- asveikau 3y agoI'm subscribed to their announcement list (where they publish errata) and I haven't seen anything yet.
- drewg123 3y agoIPv6 Extension headers are a nightmare. There are likely lots of bugs lurking in lots of places due to extension headers stacked in unusual ways. A lot of hardware and drivers simply give up on packets with more than a single extension header for this reason.
- xorcist 3y agoFragmentation is a nightmare. There's been lots of unexpected interactions and security bypasses with that over the years.
- enrico204 3y agoFragmentation is a nightmare in a nightmare: we also discovered that IPv6 fragments reassembly (as implemented by major operating systems) is still plagued by the problem of overlapping fragments. Potentially, you can still bypass IDS/IPS using the same techniques from IPv4... Shameless plug: we will present these results at ESORICS 2023 :-)
- warbeforepeace 3y agoIPv4 fragmentation was even worse since any device in the middle could fragment packets. IPv6 atleast limits it to the client/host. I still think they should have designed IPv6 to include L4 info in each fragment to avoid having to reassemble to get that data.
- formerly_proven 3y agov6 on the whole just doesn't seem like a well-designed protocol, especially not for the 21st century. It's kind of a shame that the negligible uptake in the 2000s wasn't used to do a go-around and create a more apt successor to v4.
- ianlevesque 3y agoCurious why you think that? IPv4 + ARP + DHCP + NAT has a lot more baggage. IPv6 and a stateful firewall gets the job done quite well, without the address exhaustion.
- justsomehnguy 3y agoThe most important thing: > Additionally, the scrubbing process has fixed the packet, so now any operating system behind the firewall accepts the packet. Ie if you are running a router based on pf (including pfSene and OPNSense, I suppose) you are probably fine, because you have only ssh and webgui on this host. If you have a full OS running some services (eg MySQL and like) for which you rely on the firewall to block the external connections (instead of binding to localhost or LAn interface) then you are at risk. Attacker should know what you are running that service or probe the known running hosts, so the opportunity is low. ADD: it's not clear for me, but looks like this works for the forwarded (aka routed) packets as well. If yes, the 'known hosts' still apply but exposure is a bit bigger. If you are running pf firewalls with a full IPV6 connectivity - update ASAP.
- enrico204 3y agoAuthor here. I confirm that OPNSense was vulnerable. It has been fixed in v23.7.1 (August 8, 2023): https://forum.opnsense.org/index.php?topic=35298.0 https://forum.opnsense.org/index.php?topic=35298.0 We haven't tested pfSense, but I suppose that they are vulnerable too as they use `pf` and they are FreeBSD-based.
- justsomehnguy 3y agoThanks! Can you clarify, does that works on the forwarded packets? I assume it should, given the vuln in the scrubbing function, but it would help if that would be stated clearly.
- enrico204 3y agoYes, it works on forwarded packets. In the example ruleset in the blog post, `em1` and `em2` are two network interfaces (victim and attacker, think them as LAN and WAN respectively), and the FreeBSD machine is configured as router/firewall.
- gslin 3y ago> We reported the vulnerability at 2023-07-12 20:15:43 UTC and received the ACK at 2023-07-12 01:34:54 UTC. I am not sure the timeline...