Andreas Happe: Building a secure torrent download station by combining Private Internet Access (PIA), OpenVPN and transmission through docker

August 5, 2019 in tech

Sometimes I want to work on client assignments (penetration-tests) from home, if I do that I am using my company VPN so that all traffic is routed thorugh their public IP address (which is white-listed by the client). I do not want for traffic to ever leave that VPN as that would look like as if I’d be performing cyber attacks from my private home IP address. The same requirements arise for different use-cases, e.g., when downloading bittorrent files or forcing traffic through the tor network if whistle-blowing.

To achieve a secure setup I want to combine the following:

  • a Private Internet Access VPN tunnel – this hides (or should hide) my identity. You can replace that with your company or tor proxy for the other use cases.
  • the software that should run through/behind the VPN. To improve reusability I will use docker images for those.

This setup should be fail-secure: if the VPN tunnel gets disconnected, the bittorrent download container will loose network connectivity. This is good. What you wouldn’t want is the container to automatically use my “normal” network connection — this would use my public IP address and throught that might leak my identity.

I did some searching around and found dperson’s docker images which nicely provide all needed functionality. Sadly the inital setup did not work as smooth as I assumed, so I wrote my setup procedure up.

Setup OpenVPN image

The openvpn-client docker image does support using an user-supplied configuration file, so I went with that. For testing purposes I’ve created /tmp/vpn and adapted an PIA openvpn config file to use file-based authentication (change auth-user-pass to auth-user-pass login.conf in the PIA configuration file). this file must be named vpn.conf and be placed within the /tmp/vpn directory (on the host):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
client
dev tun
proto udp
remote de-frankfurt.privateinternetaccess.com 1197
resolv-retry infinite
nobind
persist-key
persist-tun
cipher aes-256-cbc
auth sha256
tls-client
remote-cert-tls server

auth-user-pass login.conf
compress
verb 1
reneg-sec 0
<crl-verify>
-----BEGIN X509 CRL-----
MIIDWDCCAUAwDQYJKoZIhvcNAQENBQAwgegxCzAJBgNVBAYTAlVTMQswCQYDVQQI
EwJDQ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Z0YqfbkWx3NHTZ7OE9ZRhdMP/RqHQE1p4N4Sa1nZKhTKasV6KhHDqSCt/dv
Em89xWm2MVA7nyzQxVlHa9AkcBaemcXEiyT19XdpiXOP4Vhs+J1R5m8zQOxZlV1G
tF9vsXmJqWZpOVPmZ8f35BCsYPvv4yMewnrtAC8PFEK/bOPeYcKN50bol22QYaZu
LfpkHfNiFTnfMh8sl/ablPyNY7DUNiP5DRcMdIwmfGQxR5WEQoHL3yPJ42LkB5zs
6jIm26DGNXfwura/mi105+ENH1CaROtRYwkiHb08U6qLXXJz80mWJkT90nr8Asj3
5xN2cUppg74nG3YVav/38P48T56hG1NHbYF5uOCske19F6wi9maUoto/3vEr0rnX
JUp2KODmKdvBI7co245lHBABWikk8VfejQSlCtDBXn644ZMtAdoxKNfR2WTFVEwJ
iyd1Fzx0yujuiXDROLhISLQDRjVVAvawrAtLZWYK31bY7KlezPlQnl/D9Asxe85l
8jO5+0LdJ6VyOs/Hd4w52alDW/MFySDZSfQHMTIc30hLBJ8OnCEIvluVQQ2UQvoW
+no177N9L2Y+M9TcTA62ZyMXShHQGeh20rb4kK8f+iFX8NxtdHVSkxMEFSfDDyQ=
-----END CERTIFICATE-----
</ca>

disable-occ

The username and password are stored in /tmp/vpn/login.conf. The file has a very simplistic format: the first line contains the username, the second line contains the corresponding password:

1
2
username
password

There is another important hint: on Fedora SELinux is in use and prevents using the host files as docker volumes. To fix this, we need to apply the right label to the VPN directory:

1
sudo chcon -Rt svirt_sandbox_file_t /tmp/vpn

Now we can start up the OpenVPN-client container:

1
2
$ sudo docker run -it --cap-add=NET_ADMIN --device /dev/net/tun --name vpn \
            --dns 8.8.8.8 -v /tmp/vpn:/vpn -d dperson/openvpn-client -f ""

We pass in the vpn-diretory and use a containter option (-f "") to configure it’s firewall to block all traffic if the VPN is not opened (to prevent stray communications from happening).

Test the VPN tunnel through a minimal image

You should never trust your configuration without testing it.. so let’s fire up an alpine linux container, connect it to the internet through the VPN and retrieve our external IP-Adress (which should be different to our Host computer’s external IP address):

1
2
3
4
5
$ sudo docker run -it --name shell --net=container:vpn --rm alpine /bin/ash
/ # wget http://whatismyip.akamai.com/
Connecting to whatismyip.akamai.com (2.20.189.18:80)
/ # cat index.html 
185.220.70.151/ # 

Use transmission-web images (and an nginx to allow for web access to the container)

Now we can start-up additional images for transmission and a web-server for controlling it. We will use the vpn-network configured through the openvpn-client image:

1
2
3
$ sudo docker run -it --name bit --net=container:vpn -d dperson/transmission
$ sudo docker run -it --name web -p 80:80 -p 443:443 --link vpn:bit \                        
            -d dperson/nginx -w "http://bit:9091/transmission;/transmission"

Now you should be able to access the transmission web interface through http://localhost/transmission or https://localhost/transmission. There is an HTTP BASIC AUTH based authentication, use admin as username and admin as password.

And that’s it.. steps for the future include moving this setup onto my Raspberry Pi and/or migrating it to Docker-Compose.

comments powered by Disqus