Libreswan Documentation

Logo

Libreswan's Online Documentation

View the Project on GitHub libreswan/libreswan.github.io

Support
FAQ Common Error Messages
History
Implemented Standards
Kernel Support
HOWTO Additional ipsec.conf documentation
AWS Mesh
brendans Road Warrior Setup at Home
Configuration examples
Confuse !?@: github wiki
Enterprise cloud encryption
Entropy matters
EoIP shared ethernet LAN using IPsec
High Availability Fallover VPN in AWS
Host to host VPN
Host to host VPN with PSK
Libreswan as client to a Cisco ASA or VPN3000 server
Microsoft Azure configuration
Migrate from IKEv1 DPD to IKEv2 LIVENESS
Opportunistic IPsec
Opportunistic IPsec using LetsEncrypt
Pluto and DNSSEC
Read status output
Route based VPN
SElinux and Labeled IPsec VPN
Subnet extrusion
Subnet to subnet using NAT
Subnet to subnet VPN
Subnet to subnet VPN with PSK
Unauthenticated Opportunistic IPsec
Using Apache to serve PKCS
Using NSS Hardware Tokens
Using NSS with libreswan
VPN server for remote clients using IKEv2
VPN server for remote clients using IKEv2 split VPN
GSoC 2027 Code Project Ideas DRAFT
Contributor Guidance DRAFT
Completed Projects 2026 RFC 9593 Announcing Supported Authentication Methods in IKEv2
2026 Improve the ACQUIRE to IKE policy lookup
2026 Add HOST TO HOST Support on BSD
2021 RFC 8420 Add EdDSA Signature Authentication Support to IKEv2
2020 Session Resumption
2020 IKEv2 Interop testing with OpenBSD
2020 IKE Intermediate Exchange
2019 Libreswan Opportunistic IPsec using LetsEncrypt
2018 RSA PSS Support in compliance with RFC 7427 and RFC 8247
2018 RFC 7427 Add ECDSA Signature Authentication Support to IKEv2
2018 RFC 5685 Redirect Mechanism
2018 Managing Interface
2017 TCP encapsulation of IKE and IPsec
2017 RFC 7427 Add Signature Authentication Support to IKEv2
2017 Postquantum Preshared Keys
Presentations
IRC
Hacking Documentation
Git, GitHub, and Pull Requests
Merging GitHub Pull Requests
Programming Conventions
Testing Docker
KVM 1. Setup The Host
2. Configure Testing
3. Compile Libreswan
4. Test Libreswan
5. Accessing The Console
6. Maintenance and Internals
Bisecting
Debugging Pluto
Logging In Using SSH
Performance
Running A Custom Kernel
Running A Single Test
Running In The Background
Setup a Web Server
Testing Old Branches
Updating Test Results
Namespace Magic
Namespaces
Topology
Internals 3.14 X509
Benchmarking and Performance testing
Cipher suites and algorithm support
Cloud OE ideas
Compiling with AddressSanitizer
Compliance of RFC 7427 Signature Authentication in IKEv2
Coverity
Cryptographic Acceleration
Developer links strongswan android
Discouraged or forbidden C functions
IKEv2 Child SA
IKEv2 CP and EAP support
Introduction
Libreswan xfrm kernel support
Logging cleanup
New OE
Pluto
Pluto packet processing
Proposed ipsec ca command
Retransmit timings
Road Map
SAref code
Setting up system for debug logging
stf status
Testing 2017 Next Generation
Unbound
Uncrustify
Use Cases and Requirements document for ECC ECDSA support
Use Cases and Requirements document
XFRM Interface Development Notes
XFRM pCPU
XFRM pCPU RSS
Security Crypto boundary and certification
Libreswan and Heartbleed
Libreswan and TunnelCrack
Reporting a Vulnerability
Vulnerabilities
Meetups 2013 Helsinki
2014 San Francisco
2014 Toronto
2018 Toronto
Obsolete HOWTOs IKEv1 XAUTH with FreeOTP and FreeIPA
IKEv1 XAUTH with Google Authenticator One Time Passwords
Route based VPN using VTI
Testing Namespace
VPN server for remote clients using IKEv1 with L2TP
VPN server for remote clients using IKEv1 XAUTH with Certificates
VPN server for remote clients using IKEv1 XAUTH with PSK

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 10.0.1.1) to use as your source IP, and a destination network that usually compromises everything, eg 0.0.0.0/0. This creates a VPN policy for all packets, eg 10.0.1.1/32 <-> 0.0.0.0/0. 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 8.8.8.1, in a /24 (255.255.255.0) network, and with 8.8.8.8 as the default gateway. It also gives you a DNS server IP of 8.8.8.8. You connect and everything works fine. Note that if you would use Google DNS on 8.8.8.8 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 vpn.nohats.ca. to setup a VPN connection. Your device connects, gets an IP address to use on the VPN tunnel (eg 172.16.0.2) and uses a remote destination range of everything (eg 0.0.0.0/0).

What happens now is that the IPsec policies are installed for 172.16.0.2/32 <-> 0.0.0.0/0

Any packet that has a source address of 172.16.0.2 will be encrypted and the encrypted packet send via the wifi native IP of 8.8.8.1 (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 172.16.0.2 instead of the native wifi IP of 8.8.8.1 ? 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 8.8.8.1 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 0.0.0.0/1 src 172.16.0.2 dev wifi ip route add 128.0.0.0/1 src 172.16.0.2 dev wifi

These two routes cover the entire address space (0.0.0.0/0) 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 172.16.0.2 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:

8.8.8.0/24 dev wlp0s20f3 proto kernel scope link src 8.8.8.1 metric 600  default via 8.8.8.8 dev wlp0s20f3 proto dhcp src 8.8.8.1 metric 600 

So once the encrypted packet is put in an IPsec packet with source IP 8.8.8.1, it will be send to 8.8.8.8 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 8.8.8.8. So if your device uses Google DNS, you will open a connection to 8.8.8.8, 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 8.8.8.0/24. Of course, if the malicious network makes 8.8.8.8 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.