Libreswan and TunnelCrack

From Libreswan
Jump to navigation Jump to search

Libreswan and TunnelCrack

The TunnelCrack vulnerability is a tricky core problem to any VPN Remote Access protocol.

With a Remote Access VPN configuration, the server gives you an IP address (eg to use as your source IP, and a destination network that usually compromises everything, eg This creates a VPN policy for all packets, eg <-> But of course, you need to use the non-VPN network to send all your VPN packets over. Some kernel/userland implementations depend on routing and some have their own hooks outside of routing (eg Linux XFRM IPsec) to grab packets, and as per IPsec policy, encrypt them and send them out. The essential part is to get the source IP right. If your source IP is the VPN given IP address, then it can only leave your device if it gets encrypted properly. But when connecting to a possible hostile hotspot, this can be tricky.

Example hostile network

Let's say you connect to the StarBucks wifi, and the DHCP server on that network gives you the IP address of, in a /24 ( network, and with as the default gateway. It also gives you a DNS server IP of You connect and everything works fine. Note that if you would use Google DNS on as your DNS server, your device would think that Google DNS lives in your local network. When you browse the internet, the wifi router would NAT your packets to their real public IP address and everything works. But if you want to hide all your traffic from the local coffeeshop, you bring up a VPN. Let's say you connect to to setup a VPN connection. Your device connects, gets an IP address to use on the VPN tunnel (eg and uses a remote destination range of everything (eg

What happens now is that the IPsec policies are installed for <->

Any packet that has a source address of will be encrypted and the encrypted packet send via the wifi native IP of (which gets NATed by the wifi router to its public IP). Replies from the VPN server follow the reverse path. But how does your device know to use instead of the native wifi IP of ? An application (eg a web browser using HTTPS) will open a connection and the OS will pick a source IP for it. Linux per default picks the "nearest IP" to the destination IP. In this case, the nearest (furthest out) interface is the wifi interface, so it would pick as the source. Since this is not the VPN address we were given, the packet would go out unencrypted. So almost all VPN services use a trick called "half routes", originally invented by FreeS/WAN, a predecessor of libreswan. It installs two routes, which in Linux "ip route" syntax would be:

ip route add src dev wifi
ip route add src dev wifi

These two routes cover the entire address space ( and so cover as much as the default route. but are "more specific" and so these will be selected first by the Linux kernel. Now the application will open a TCP connection, and it will use the as source address, thus match the IPsec policies and get encrypted. The routing table will also have an entry for the wifi network. It will look something like: dev wlp0s20f3 proto kernel scope link src metric 600 
default via dev wlp0s20f3 proto dhcp src metric 600 

So once the encrypted packet is put in an IPsec packet with source IP, it will be send to as the default gateway on the network. It prefers this route because it is more specific (eg a /24) than the half routes above (and the default route).

The problem that TunnelCrack uses, is that a rogue wifi hotspot can give you any kind of IP network. In the example above, we squatted on Google DNS which uses So if your device uses Google DNS, you will open a connection to, but since that is the local network, it has a more specific route than the 'half routes' and so it will bypass the IPsec policies and not get encrypted.

Possible solutions

One solution is to block all local network traffic, with the exception of some required to keep the local network connection up (eg only allow DHCP, IKE, ESP and ipv6 neighbour discovery). Libreswan is looking at adding a default on option for this when configured as a Remote Access client. This block should happen at the IPsec policy layer so we don't risk any interactions with the firewall systems installed and running which might have conflicting rules (and with nftables, there can be more than 1 firewal running and we don't want to have to understand all firewalls people use). Note that one side effect would be that any local network service such as a local printer, would get blocked.

Another solution could be to just add a single route to the VPN DNS server IP we obtained, and force it as a more specific route with the VPN address source IP. This would help avoid the LAN from stealing DNS packetss by using a small more specific local IP range, such as stealing Google DNS Of course, if the malicious network makes the default gateway, this would collapse the VPN and it would fail. But failing on a malicious network is probably better than succeeding and getting bypassed.

Other VPN protocols

All non-IPsec VPN protocols have an additional problem. They do not have IPsec policies that can block/accept packets for encryption that works independent of the routing table. So in those scenarios, anything that bypasses the route into the encryption device (eg wireguard's wg0 interface) would leak in the clear.