I’ve changed my approach and am now using a simple docker setup to achieve the same result
Somehow I have to use VPN services throughout the day:
- when pen-testing from abroads I really need to login to my company’s network first. Otherwise my provider is kinda grumpy when I’m doing fast non-cloaked scans against large companies.
- also when pen-testing I like to use some cloaking VPNs to test the client’s detection capabilities
- if I would ever use bit-torrent I’d really like to make sure that the torrent program can only communicate through a private proxy (as pia).
The easy solution would be to connect the openvpn tunnels on startup and just route all the traffic through the tunnels. Alas this is way to slow for daily use – and somehow error prone: if a tunnel dies and some pen-test is currently under progress traffic might escape into ‘unsecured’ public networks. The same would be true for torrents.
Just to state the obvious: all links to Private Internet Access contain my referral ID – if you want to sign up theere and use this link I’m getting some money (hopefully).
How to route/bind programs to the VPN interface
So let’s change my openvpn client’s configuration to not accept a new default route from the VPN service’s DHCP server (once again, I’m using my privateinteraccess.com account):
|
|
The route_up.sh is mostly empty: it just outputs environment variable (set by openvpn) that show my which IP address and routing addresses were forwarded to the route_up.sh script:
|
|
After firing up the VPN tunnel (via openvpn openvpn.vpn
) the script outputs the following:
|
|
and my routing table looks like I would expect it to be (my ip is 10.188.1.10, the gateway’s IP is 10.188.1.9):
|
|
Now we need to create a new routing table, which I will call ‘custom_table’.
|
|
Now is the perfect time to test what my external IP would be. To do this I use wget, which I bind to use the local VPN IP. wget connects to http://ipecho.net which will return my external IP address:
|
|
Which is a IP address belonging to the VPN service. Mission accomplished.
How does it behave when VPN tunnel dies?
Lets test this too: I’ll just retry the wget command after closing the VPN tunnel:
|
|
I really like this: when the VPN tunnel dies no communication will be routed through the default gateway (or leave the host at all).
WIP: start application through the openvpn config file
We can use the environment variables to set everything up through route_up.sh:
|
|
My problem now is, that the wget command is not finishing (but the tunnel itself works if I comment out this final bit, I can use the same wget command on the command line).
This is kinda disappointing. I would really like to automatically start the pen-testing tools (or bittorrent clients) through the openvpn script – with this setup I wouldn’t have to do anything manually.
Any suggestions? If so, please add comments.. I will update this post as soon as better solutions are found. Another thing I’m looking into is retrieving the PID of the started command and automatically adding futher iptable rules that block any traffic of the program in question that wouldn’t use the configured routing table.