Installer un relais Tor sur un Synology - Astuces-webmaster.ch
Accueil > synology > tor-relay-synology

{ Installer un relais tor sur un synology }

Introduction

Si vous apprécié avoir un peu d'anonymat et de respect de votre vie privée dans la vraie vie il en va surement de même lorsque vous naviguez sur le net. Vous n'êtes pas sans avoir que de nos jours l'ensemble du traffic internet est surveillé, épié, espionné, guetté, observé, pisté. Bref, ça devient difficle d'être anonyme sur le net. Bien sur il existe les proxys, mais ceux-ci ne répondent par forcément à hauteur de l'anonymat attendu, c'est là qu'entre en jeu le projet Tor =)) Pour ceux qui ne connaissent pas je vous laisse jeter un oeil sur la page wikipédia du projet Tor

Naturellement, comme tout projet libre dans le monde, celui-ci n'existerait pas sans qu'on y contribue ! Je vais donc vous expliquer dans ce tutoriel comment contribuer au réseau Tor et ainsi permettre à des pékins d'accéder au net de manière anonyme sans qu'ils ne soient fusillés sur la place publique ;-). L'installation d'un relai (ou noeud) sur votre NAS permettra de conduire une partie du traffic dans le réseau Tor avant de le relayer plus loin vers un autre noeud et ainsi de suite jusqu'à ce que les pistes soient suffisamment brouillées.

  

Prérequis

Avant d'avoir un relai Tor fonctionnel, qu'il soit exit relai ou non-exit les conditions suivantes doivent être remplies

Posséder un NAS Synology connecté directement à Internet

Disposer d'IPKG (Bootstrap) sur son NAS

Savoir utiliser un éditeur de texte en ligne de commande


Mise en place

Première étape pour la mise en place de notre noeud Tor : installation du paquet Tor

ipkg install tor

Et voici ce que vous devriez obtenir

nas> ipkg install tor
Installing tor (0.2.2.36-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/tor_0.2.2.36-1_i686.ipk
Installing libevent (2.0.20-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/libevent_2.0.20-1_i686.ipk
Configuring libevent
Configuring tor
Successfully terminated.

Contrôler juste que l'install se fait correctement, si le terminal renvoie une erreur dans le genre "-ash: ipkg: not found" c'est que vous n'avez probablement pas encore installé le gestionnaire de paquets IPKG, j'ai fais un tutoriel sur le sujet que je vous invite à suivre d'abord > Installer le bootstrap IPKG sur son Synology

Etape suivante la configuration de Tor :

cat /opt/etc/tor/torrc.sample > /opt/etc/tor/torrc

Voici à quoi ressemble le fichier de configuration de Tor

## Configuration file for a typical Tor user
## Last updated 16 July 2009 for Tor 0.2.2.1-alpha.
## (May or may not work for much older or much newer versions of Tor.)
##
## Lines that begin with "## " try to explain what's going on. Lines
## that begin with just "#" are disabled commands: you can enable them
## by removing the "#" symbol.
##
## See 'man tor', or https://www.torproject.org/tor-manual.html,
## for more options you can use in this file.
##
## Tor will look for this file in various places based on your platform:
## https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#torrc


## Replace this with "SocksPort 0" if you plan to run Tor only as a
## relay, and not make any local application connections yourself.
SocksPort 0 # what port to open for local application connections
#SocksListenAddress 127.0.0.1 # accept connections only from localhost
#SocksListenAddress 192.168.0.2:9030 # listen on this IP:port also

## Entry policies to allow/deny SOCKS requests based on IP address.
## First entry that matches wins. If no SocksPolicy is set, we accept
## all (and only) requests from SocksListenAddress.
#SocksPolicy accept 192.168.0.0/16
#SocksPolicy reject *

## Logs go to stdout at level "notice" unless redirected by something
## else, like one of the below lines. You can have as many Log lines as
## you want.
##
## We advise using "notice" in most cases, since anything more verbose
## may provide sensitive information to an attacker who obtains the logs.
##
## Send all messages of level 'notice' or higher to /opt/var/log/tor/notices.log

# Ici je décide d'envoyer tous les logs vers /var/log/
# Sera utile après pour contrôler que tout fonctionne bien
Log notice file /var/log/tor-notice.log
## Send every possible message to /opt/var/log/tor/debug.log
#Log debug file /opt/var/log/tor/debug.log
## Use the system log instead of Tor's logfiles

# Possibilité aussi d'envoyer vers un serveur Syslog
# Log notice syslog
## To send all messages to stderr:
#Log debug stderr

## Uncomment this to start the process in the background... or use
## --runasdaemon 1 on the command line. This is ignored on Windows;
## see the FAQ entry if you want Tor to run as an NT service.

# Permet de lancer tor en tâche de fond (recommandé)
RunAsDaemon 1

## The directory for keeping all the keys/etc. By default, we store
## things in $HOME/.tor on Unix, and in Application Datator on Windows.
#DataDirectory /opt/var/lib/tor

## The port on which Tor will listen for local connections from Tor
## controller applications, as documented in control-spec.txt.
#ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C
#CookieAuthentication 1

############### This section is just for location-hidden services ###

## Once you have configured a hidden service, you can look at the
## contents of the file ".../hidden_service/hostname" for the address
## to tell people.
##
## HiddenServicePort x y:z says to redirect requests on port x to the
## address y:z.

#HiddenServiceDir /opt/var/lib/tor/hidden_service/
#HiddenServicePort 80 127.0.0.1:80

#HiddenServiceDir /opt/var/lib/tor/other_hidden_service/
#HiddenServicePort 80 127.0.0.1:80
#HiddenServicePort 22 127.0.0.1:22

################ This section is just for relays #####################
#
## See https://www.torproject.org/docs/tor-doc-relay for details.

## Required: what port to advertise for incoming Tor connections.

# Là on définit le port par lequel va passer le traffic
# Pensez bien à autoriser le port choisi dans le pare feu du Synology + si nécessaire ajouter le forward sur votre routeur (si NAT, pas besoin)
ORPort 9030
## If you want to listen on a port other than the one advertised
## in ORPort (e.g. to advertise 443 but bind to 9090), uncomment the
## line below too. You'll need to do ipchains or other port forwarding
## yourself to make this work.
#ORListenAddress 0.0.0.0:9090

## A handle for your relay, so people don't have to refer to it by key.
Nickname lapin

## The IP address or full DNS name for your relay. Leave commented out
## and Tor will guess.

# Adresse DynDNS de votre NAS
Address mon-nas.dyndns.org

## Define these to limit how much relayed traffic you will allow. Your
## own traffic is still unthrottled. Note that RelayBandwidthRate must
## be at least 20 KB.

# Si vous voulez limiter la bande passante c'est ici (conseillé)
RelayBandwidthRate 100 KB  # Throttle traffic to 100KB/s (800Kbps)
RelayBandwidthBurst 200 KB # But allow bursts up to 200KB/s (1600Kbps)

## Use these to restrict the maximum traffic per day, week, or month.
## Note that this threshold applies to sent _and_ to received bytes,
## not to their sum: Setting "4 GB" may allow up to 8 GB
## total before hibernating.
##
## Set a maximum of 4 gigabytes each way per period.
#AccountingMax 4 GB
## Each period starts daily at midnight (AccountingMax is per day)
#AccountingStart day 00:00
## Each period starts on the 3rd of the month at 15:00 (AccountingMax
## is per month)
#AccountingStart month 3 15:00

## Contact info to be published in the directory, so we can contact you
## if your relay is misconfigured or something else goes wrong. Google
## indexes this, so spammers might also collect it.
#ContactInfo Random Person 
#
## You might also include your PGP or GPG fingerprint if you have one:
ContactInfo Marian 


## Uncomment this to mirror directory information for others. Please do
## if you have enough bandwidth.
#DirPort 9030 # what port to advertise for directory connections
## If you want to listen on a port other than the one advertised
## in DirPort (e.g. to advertise 80 but bind to 9091), uncomment the line
## below too. You'll need to do ipchains or other port forwarding yourself
## to make this work.
#DirListenAddress 0.0.0.0:9091
## Uncomment to return an arbitrary blob of html on your DirPort. Now you
## can explain what Tor is if anybody wonders why your IP address is
## contacting them. See contrib/tor-exit-notice.html in Tor's source
## distribution for a sample.
#DirPortFrontPage /opt/etc/tor/tor-exit-notice.html

## Uncomment this if you run more than one Tor relay, and add the identity
## key fingerprint of each Tor relay you control, even if they're on
## different networks. You declare it here so Tor clients can avoid
## using more than one of your relays in a single circuit. See
## https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#MultipleServers
#MyFamily $keyid,$keyid,...

## A comma-separated list of exit policies. They're considered first
## to last, and the first match wins. If you want to _replace_
## the default exit policy, end this with either a reject *:* or an
## accept *:*. Otherwise, you're _augmenting_ (prepending to) the
## default exit policy. Leave commented to just use the default, which is
## described in the man page or at
## https://www.torproject.org/documentation.html
##
## Look at https://www.torproject.org/faq-abuse.html#TypicalAbuses
## for issues you might encounter if you use the default exit policy.
##
## If certain IPs and ports are blocked externally, e.g. by your firewall,
## you should update your exit policy to reflect this -- otherwise Tor
## users will be told that those destinations are down.
##
#ExitPolicy accept *:6660-6667,reject *:* # allow irc ports but no more
#ExitPolicy accept *:119 # accept nntp as well as default exit policy
#ExitPolicy reject *:* # no exits allowed
#
## Bridge relays (or "bridges") are Tor relays that aren't listed in the
## main directory. Since there is no complete public list of them, even if an
## ISP is filtering connections to all the known Tor relays, they probably
## won't be able to block all the bridges. Also, websites won't treat you
## differently because they won't know you're running Tor. If you can
## be a real relay, please do; but if not, be a bridge!
#BridgeRelay 1
#ExitPolicy reject *:*

Tranquille tranquille, il y a plus de commentaire et d'indication qu'autres choses, si vous prenez le temps de lire un peu vous verrez que ya pas mal de choses qui peuvent être configurés et on peut ainsi arrivé à une configuration assez précise, pour ma part je vais pas m'attarder sur tous les aspects de la conf mais dans les grandes lignes voici ce qu'il est important de décider pour votre relai

Simple relai ou relai de sortie ?

Politique de traffic

Port utilisé par le relai

Bande passante allouée


Attention ! Si vous décidez de configurer votre NAS en tant que noeud de sortie il est très TRES important que vous lisiez ceci https://blog.torproject.org/blog/tips-running-exit-node-minimal-harassment en effet il faut bien comprendre qu'en mode exit node votre NAS devient porte de sortie du réseau Tor, ainsi si une personne mal intentioné fait de la merde en passant par le réseau Tor et que sa merde sort par votre NAS c'est votre adresse IP qu'on verra comme "origine" de l'attaque, vous vous exposez donc à d'éventuelles blâmes pour rester poli. C'est pour cette raison qu'il est primordial de définir une "politique de sortie".

Démarrage du service

Juste avant de passer à la suite on va crééer le fichier de log afin d'éviter qu'il maille lorsqu'on lancera le service. Procédez comme suit :

mkdir /var/log/tor
touch /var/log/tor/tor-notices.log

Maintenant que tout est prêt il ne reste plus qu'à démarrer notre relai grâce à la commande suivante :

Le paramètre -f permet de préciser où se trouve notre fichier de configuration tandis que --runasdaemon se charge de lancer tor en arrière plan

/opt/bin/tor -f /opt/etc/tor/torrc --runasdaemon 1

Voici ce qu'on obtient lorsqu'on lance le service

nas>
/opt/bin/tor -f /opt/etc/tor/torrc --runasdaemon 1
Jul 16 21:51:19.525 [notice] Tor v0.2.2.36 (git-c1414cf70cbfcbb7). This is experimental software. Do not rely on it for strong anonymity. (Running on Linux x86_64)
Jul 16 21:51:19.527 [notice] Your ContactInfo config option is not set. Please consider setting it, so we can contact you if your server is misconfigured or something else goes wrong.
Jul 16 21:51:19.528 [notice] We were compiled with headers from version 2.0.19-stable of Libevent, but we're using a Libevent library that says it's version 2.0.20-stable.
Jul 16 21:51:19.529 [notice] Initialized libevent version 2.0.20-stable using method epoll. Good.
Jul 16 21:51:19.529 [notice] Opening OR listener on 0.0.0.0:9001
Jul 16 21:51:19.529 [notice] Opening Socks listener on 127.0.0.1:9050

Check

OK super on y est ! Maintenant on va jeter un oeil dans les logs pour voir si tout est en ordre

cat /var/log/tor-notice.log
Tor commence par construire le circuit
Jul 16 21:51:27.033 [notice] Bootstrapped 45%: Asking for relay descriptors.
Jul 16 21:51:27.033 [notice] I learned some more directory information, but not enough to build a circuit: We have only 0/4088 usable descriptors.
Jul 16 21:51:34.900 [notice] Bootstrapped 50%: Loading relay descriptors.
Jul 16 21:51:35.387 [notice] Bootstrapped 52%: Loading relay descriptors.
Jul 16 21:51:35.389 [notice] I learned some more directory information, but not enough to build a circuit: We have only 96/4088 usable descriptors.
Jul 16 21:51:35.653 [notice] Bootstrapped 55%: Loading relay descriptors.
Jul 16 21:51:35.654 [notice] I learned some more directory information, but not enough to build a circuit: We have only 192/4088 usable descriptors.
Jul 16 21:51:35.795 [notice] Bootstrapped 58%: Loading relay descriptors.
Jul 16 21:51:35.796 [notice] I learned some more directory information, but not enough to build a circuit: We have only 288/4088 usable descriptors.
Jul 16 21:51:35.994 [notice] Bootstrapped 60%: Loading relay descriptors.
Jul 16 21:51:35.995 [notice] I learned some more directory information, but not enough to build a circuit: We have only 384/4088 usable descriptors.
Jul 16 21:51:36.171 [notice] Bootstrapped 63%: Loading relay descriptors.
Jul 16 21:51:36.172 [notice] I learned some more directory information, but not enough to build a circuit: We have only 480/4088 usable descriptors.
Jul 16 21:51:36.313 [notice] Bootstrapped 66%: Loading relay descriptors.
Jul 16 21:51:36.314 [notice] I learned some more directory information, but not enough to build a circuit: We have only 576/4088 usable descriptors.
Jul 16 21:51:36.595 [notice] Bootstrapped 69%: Loading relay descriptors.
Jul 16 21:51:36.597 [notice] I learned some more directory information, but not enough to build a circuit: We have only 672/4088 usable descriptors.
Jul 16 21:51:36.742 [notice] Bootstrapped 71%: Loading relay descriptors.
Jul 16 21:51:36.743 [notice] I learned some more directory information, but not enough to build a circuit: We have only 768/4088 usable descriptors.
Jul 16 21:51:36.913 [notice] Bootstrapped 74%: Loading relay descriptors.
Jul 16 21:51:36.914 [notice] I learned some more directory information, but not enough to build a circuit: We have only 864/4088 usable descriptors.
Jul 16 21:51:37.046 [notice] Bootstrapped 77%: Loading relay descriptors.
Jul 16 21:51:37.047 [notice] I learned some more directory information, but not enough to build a circuit: We have only 960/4088 usable descriptors.
Jul 16 21:51:37.259 [notice] I learned some more directory information, but not enough to build a circuit: We have only 229/909 usable exit node descriptors.
Jul 16 21:51:37.388 [notice] I learned some more directory information, but not enough to build a circuit: We have only 246/909 usable exit node descriptors.
Jul 16 21:51:37.517 [notice] I learned some more directory information, but not enough to build a circuit: We have only 263/909 usable exit node descriptors.
Jul 16 21:51:37.645 [notice] I learned some more directory information, but not enough to build a circuit: We have only 280/909 usable exit node descriptors.

On dirait que Tor a assez d'info pour construire le circuit
Jul 16 21:51:37.775 [notice] We now have enough directory information to build circuits.
Jul 16 21:51:37.775 [notice] Bootstrapped 80%: Connecting to the Tor network.
Jul 16 21:52:38.760 [notice] Bootstrapped 85%: Finishing handshake with first hop.
Jul 16 21:52:39.551 [notice] Bootstrapped 90%: Establishing a Tor circuit.

La ligne suivante nous confirme que la partie client fonctionne
Jul 16 21:52:40.467 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Jul 16 21:52:40.467 [notice] Bootstrapped 100%: Done.
Jul 16 21:52:40.467 [notice] Now checking whether ORPort 85.1.121.233:9001 is reachable... (this may take up to 20 minutes -- look for log messages indicating success)

Self-test qui nous confirme que votre relai est bien accessible depuis l'extérieur =))
Jul 16 21:52:41.911 [notice] Self-testing indicates your ORPort is reachable from the outside. Excellent. Publishing server descriptor.
Jul 16 21:53:30.398 [notice] Performing bandwidth self-test...done.

Si vous avez passé toutes les étapes du tuto avec succès alors la dernière étape consiste à aller checker dans la base de données des relais Tor si vous y trouvez le votre, pour cela rendez-vous ici et faites une recherche d'après le "nickname" que vous avez défini dans la conf /opt/etc/tor/torrc. Vous inquiétez pas si vous ne trouvez pas votre relai tout de suite ça peut prendre un peu de temps avant qu'il soit propagé dans tout le réseau Tor

Dans mon cas ça donne ça :

Conclusion

Voilà c'est fini ! Bravo pour votre contribution à ce merveilleux projet, hésitez pas si vous avez des questions.a