1 Title: SecurityKiss + Dante == bye bye censorship
2 Tags: en, securitykiss, dante, danted, dante-server, foxyproxy, gema, censorship, socks, proxy, germany
4 I live in Germany, and unfortunately there is something in Germany called
5 GEMA_, which basically censor any content that "might have copyrighted
8 Among the sites being censored are Grooveshark_ (completely banned) and
9 YouTube_ (only banned if the video **might** have copyrighted music according
10 to some algorithm made by Google_). Basically this is because GEMA_ want these
11 company to pay royalties for each time some copyrighted song get streamed).
12 AFAIK Grooveshark_ don't want to pay at all, and Google want to pay a fixed fee
13 (which is what it does in every other country), because it makes no sense to do
14 otherwise, since anyone can just endlessly get a song streamed over and over
15 again just to be paid.
17 Even when the model is debatable, there is a key aspect and why I call this
18 censorship: **not all the banned content is copyrighted or protected by GEMA**.
20 * In Grooveshark_ there are plenty of bands that release their music using more
21 friendly license, like CC__.
22 * There are **official videos** posted in YouTube_ by the bands themselves and
23 embedded in the band **official website** that is banned by GEMA_.
24 * There are videos in YouTube_ that doesn't have copyrighted music at all, but
25 they have to cover their asses and ban everything suspicious just in case.
26 * The personal videos that do have copyrighted music get banned completely, not
29 __ https://creativecommons.org/
31 These are just the examples that pop on my mind now.
33 There are plenty of ways to bypass this censorship and they are the only way to
34 access legal content in Germany that gets unfairly banned, not only harming the
35 consumers, but also the artists, because most of the time having their music
36 exposed in YouTube_ only spreads the word and do more good than harm.
38 HideMyAss__ is a popular choice for a web proxy. But I like SecurityKiss_,
39 a free VPN (up to 300MB per day), because it gives a more comprehensive
42 __ https://hidemyass.com/proxy/
44 But here comes the **technical chalenge**! :) I don't want to route all my
45 traffic through the VPN, or to have to turn the VPN on and off again each time
46 I want to see the censored content. What I want is to see some websites through
47 the VPN. A challenge that proved to be harder than I initially thought and why
50 So the final setup I got working is:
52 * OpenVPN_ to use SecurityKiss_ free VPN service.
53 * Dante_ Socks Server to route any application capable of using a socks server
55 * FoxyProxy_ Firefox_ extension to selectively route YouTube_ and Grooveshark_
56 through the Socks proxy.
58 And here is how I did it (in Ubuntu_ 12.10):
66 sudo apt-get install openvpn
68 Get the configuration bundle generated for you account in the control panel and
69 then create a ``/etc/openvpn/sk.conf`` file with this content::
75 # VPN server IP : PORT
76 # (pick the server you want from the README file in the bundle)
77 remote 178.238.142.243 123
80 ca /etc/ssl/private/openvpn-sk/ca.crt
81 cert /etc/ssl/private/openvpn-sk/client.crt
82 key /etc/ssl/private/openvpn-sk/client.key
95 route-up "/etc/openvpn/sk.setup.sh up"
97 down "/usr/bin/sudo /etc/openvpn/sk.setup.sh down"
99 Install the certificate and key files from the bundle in
100 ``/etc/ssl/private/openvpn-sk/`` with the names specified in the ``sk.conf``
103 Create the tun device::
105 mknod /dev/net/tunsk c 10 200
107 Start the VPN at system start (optional)::
109 echo 'AUTOSTART="sk"' >> /etc/default/openvpn
111 Add the openvpn system user::
113 adduser --system --home /etc/openvpn openvpn
115 Now we need to route some specific traffic only through the VPN. I choose to
116 discriminate traffic by the uid/gid of the application that generated it. So
117 with the ``route-up`` and ``down`` script we will do all the special routing.
118 I also want my default route table to be untouched, that's why I used
119 ``route-noexec``. Here is how the ``/etc/openvpn/sk.setup.sh`` script looks for
124 # http://serverfault.com/questions/345111/iptables-target-to-route-packet-to-specific-interface
127 #exec 2>> /tmp/log.err
137 env_file="/var/run/openvpn.sk.env"
138 umark_rule="OUTPUT -t mangle -m owner --uid-owner $uid -j MARK --set-mark $mark"
139 gmark_rule="OUTPUT -t mangle -m owner --gid-owner $gid -j MARK --set-mark $mark"
140 masq_rule="POSTROUTING -t nat -o $dev -j SNAT --to-source $ifconfig_local"
147 # Route all traffic marked with $mark through route table $table
148 ip rule add fwmark $mark table $table
150 # Make all traffic go through the VPN gateway in route table $table
151 ip route add table $table default via $route_vpn_gateway dev $dev
153 # Except for the internal traffic
154 ip route | grep "dev $priv_dev" | \
155 xargs -n1 -d'\n' echo ip route add table $table | sh
157 # Flush route tables cache
160 # Mark packets originated by processes with owner $uid/$gid with $mark
161 iptables -A $umark_rule
162 iptables -A $gmark_rule
164 # Prevent the packets sent over $dev getting the LAN addr as source IP
165 iptables -A $masq_rule
167 # Relax the reverse path source validation
168 sysctl -w "net.ipv4.conf.$dev.rp_filter=2"
173 # Restore and remove environment
177 # Since the device is already removed, there is no need to clean
178 # anything that was referencing the device because it was already
179 # removed by the kernel.
181 # Delete iptable rules
182 iptables -D $umark_rule
183 iptables -D $gmark_rule
185 # Delete route table and rules for lookup
186 ip rule del fwmark $mark table $table
188 # Flush route tables cache
195 elif test "$1" = "down"
199 echo "Usage: $0 (up|down)" >&2
203 I hope this is clear enough. Finally we need to add the skvpn user/group (for
204 which all the traffic will be routed via the VPN) and let the openvpn user run
207 sudo adduser --system --home /etc/openvpn --group skvpn
210 In the editor, add this line::
212 openvpn ALL=(ALL:ALL) NOPASSWD: /etc/openvpn/sk.setup.sh
216 sudo service openvpn start
218 You should get a working VPN that is only used for processes that runs using the
219 user/group skvpn. You can try it with::
221 sudo -u skvpn wget -qO- http://www.securitykiss.com | grep YOUR.IP
223 Besides some HTML, you should see the VPN IP there instead of your own (you can
224 check your own by running the same without ``sudo -u skvpn``).
230 This should be pretty easy to configure, if it weren't for Ubuntu_ coming with
231 an ancient (1.x when there is a 1.4 beta already) BROKEN__ package. So to make
232 it work you have to compile it yourself. The easiest way is to get a `sightly
233 more updated package`__ from Debian *experimental*. Here is the quick recipe to
234 build the package, if you want to learn more about the details behind this,
235 there is always Google_::
238 for suffix in .orig.tar.gz -3.dsc -3.debian.tar.bz2
240 wget http://ftp.de.debian.org/debian/pool/main/d/dante/dante_1.2.2+dfsg$suffix
242 sudo apt-get build-dep dante-server
243 dpkg-source -x dante_1.2.2+dfsg-3.dsc
245 dpkg-buildpackage -rfakeroot
247 dpkg -i /tmp/dante-server_1.2.2+dfsg-3_amd64.deb
249 __ https://bugs.launchpad.net/ubuntu/+source/dante/+bug/816153
250 __ http://packages.debian.org/experimental/dante-server
252 Now you can configure Dante_, this is my configuration file as an example, it
253 just allow unauthenticated access to all clients in the private network::
257 internal: 10.1.1.1 port = 1080
263 user.privileged: skvpn
264 user.unprivileged: skvpn
268 from: 10.1.1.0/24 port 1-65535 to: 0.0.0.0/0
269 log: error # connect disconnect
272 from: 10.1.1.0/24 port 1-65535 to: 0.0.0.0/0
275 #generic pass statement - bind/outgoing traffic
277 from: 0.0.0.0/0 to: 0.0.0.0/0
278 command: bind connect udpassociate
279 log: error # connect disconnect iooperation
281 #generic pass statement for incoming connections/packets
283 from: 0.0.0.0/0 to: 0.0.0.0/0
284 command: bindreply udpreply
285 log: error # connect disconnect iooperation
288 I hope you get the idea...
290 Now just start dante::
292 sudo service danted start
294 And now you have a socks proxy that output all his traffic through the VPN while
295 any other network traffic goes through the normal channels!
301 Setting up FoxyProxy_ should be trivial at this point (just create a new proxy
302 server pointing to dante and set it as SOCKS v5), but just as a pointer, here
303 are some example rules (set them as *Whitelist* and *Regular Expression*)::
305 ^https?://(.*\.)?youtube\.com/.*$
306 ^https?://(.*\.)?grooveshark\.com/.*$
309 .. _Dante: http://www.inet.no/dante/
310 .. _Firefox: https://www.mozilla.org/firefox
311 .. _FoxyProxy: http://getfoxyproxy.org/
312 .. _GEMA: https://en.wikipedia.org/wiki/Gesellschaft_f%C3%BCr_musikalische_Auff%C3%BChrungs-_und_mechanische_Vervielf%C3%A4ltigungsrechte
313 .. _Grooveshark: http://grooveshark.com/
314 .. _OpenVPN: http://openvpn.net/
315 .. _SecurityKiss: http://www.securitykiss.com/
316 .. _Ubuntu: http://www.ubuntu.com/
317 .. _YouTube: https://www.youtube.com/
318 .. _Google: https://www.google.com/
321 .. vim: set et sw=3 sts=3 tw=80 fo+=lt1n: