From b26c721e6042cb48409f2fddb51f583a84af9700 Mon Sep 17 00:00:00 2001 From: Fabian Peter Hammerle Date: Sun, 5 Sep 2021 16:22:00 +0200 Subject: [PATCH] added ability to select exit nodes explicitly via EXIT_NODES env var --- CHANGELOG.md | 2 ++ Dockerfile | 4 +++- README.md | 6 ++++++ docker-compose.yml | 1 + entrypoint.sh | 5 +++++ torrc.template | 2 ++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f127a..f7aa49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- added ability to select exit nodes explicitly via `EXIT_NODES` environment variable ## [4.4.0] - 2021-07-07 ### Added diff --git a/Dockerfile b/Dockerfile index b3e6b09..018e7e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,9 @@ EXPOSE 9050/tcp EXPOSE 9053/udp COPY torrc.template entrypoint.sh / RUN chmod -c a+rX /torrc.template /entrypoint.sh -ENV SOCKS_TIMEOUT_SECONDS= +ENV SOCKS_TIMEOUT_SECONDS= \ + EXIT_NODES= \ + EXCLUDE_EXIT_NODES= ENTRYPOINT ["/entrypoint.sh"] # entrypoint.sh drops privileges after configuring nftables for transparent proxy diff --git a/README.md b/README.md index 9de8897..078592b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ sudo iptables -A OUTPUT ! -o lo -j REJECT --reject-with icmp-admin-prohibited $ sudo docker run -e SOCKS_TIMEOUT_SECONDS=60 … ``` +### Select Exit Nodes + +```sh +$ sudo docker run -e EXIT_NODES=1.2.3.4,1.2.3.5,{at} … +``` + ### Exclude Exit Nodes ```sh diff --git a/docker-compose.yml b/docker-compose.yml index d90b0c5..3c92c7b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: image: fphammerle/tor-proxy environment: SOCKS_TIMEOUT_SECONDS: 30 + #EXIT_NODES: '1.2.3.4,1.2.3.5,{at}' #EXCLUDE_EXIT_NODES: '{xx},{yy},1.2.3.4,128.0.0.0/1' volumes: - type: volume diff --git a/entrypoint.sh b/entrypoint.sh index a8ed8c7..2bcab83 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,6 +20,11 @@ else sed -e "s/{socks_timeout_seconds}/$SOCKS_TIMEOUT_SECONDS/" /torrc.template > /tmp/torrc fi +if [ -z "$EXIT_NODES" ]; then + sed --in-place -e '/{exit_nodes}/d' /tmp/torrc +else + sed --in-place -e "s#{exit_nodes}#$EXIT_NODES#" /tmp/torrc +fi if [ -z "$EXCLUDE_EXIT_NODES" ]; then sed --in-place -e '/{exclude_exit_nodes}/d' /tmp/torrc else diff --git a/torrc.template b/torrc.template index 5a80590..cff7c59 100644 --- a/torrc.template +++ b/torrc.template @@ -26,6 +26,8 @@ SocksTimeout {socks_timeout_seconds} # https://github.com/mitmproxy/mitmproxy/blob/v6.0.2/mitmproxy/platform/linux.py#L27 TransPort 0.0.0.0:9040 IsolateClientAddr IsolateClientProtocol +# > list of identity fingerprints, country codes, and address patterns +ExitNodes {exit_nodes} ExcludeExitNodes {exclude_exit_nodes} # try to