Skip to content

Add support for multiple ports and docker secrets #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ custom hidden services in the deepweb.
# Variables

- `PRIVATE_KEY` - Private key to be used by the hidden service.
- `PRIVATE_KEY_FILE` Path to private key file for use with docker secrets.
- `LISTEN_PORT` - Port that the hidden service will listen to
- `REDIRECT` - To where the Tor will redirect the traffic (your server), in the
format `host:port`.
- `SERVICES` - Define multiple services in the format public_port:host:host_port
- `PROXY_PORT` - If you want to enable Tor Proxy Socks, use this variable to set
which port you want tor listening to.

Expand Down Expand Up @@ -79,6 +81,32 @@ services:
-----END RSA PRIVATE KEY-----
```

# Example with secrets

Store the private key in `tor.key` next to this `docker-compose.yml`:

```yml
version: '3.1'

services:
tor:
image: strm/tor
depends_on:
- nginx
environment:
SERVICES: "80:nginx:80;8080:nginx:80"
PRIVATE_KEY_FILE: /run/secrets/torkey
secrets:
- torkey

nginx:
image: nginx

secrets:
torkey:
file: tor.key
```

### Disclaimer

This or previous program is for Educational purpose ONLY. Do not use it without
Expand Down
25 changes: 21 additions & 4 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ HiddenServiceDir /web/
Log notice stdout
EOF

if [[ ! -z "${PRIVATE_KEY}" && ! -z "${LISTEN_PORT}" && ! -z "${REDIRECT}" ]]
then
echo "[+] Starting the listener at port ${LISTEN_PORT}, redirecting to ${REDIRECT}"
if [[ ! -z "${PRIVATE_KEY_FILE}" ]]; then
ln -s -f "${PRIVATE_KEY_FILE}" /web/private_key
elif [[ ! -z "${PRIVATE_KEY}" ]]; then
echo "${PRIVATE_KEY}" > /web/private_key
fi

function add_service {
echo "[+] Adding listener at port $2, redirecting to $1"
cat >> /etc/tor/torrc << EOF
HiddenServicePort ${LISTEN_PORT} ${REDIRECT}
HiddenServicePort $2 $1
EOF
}

if [[ ! -z "${LISTEN_PORT}" && ! -z "${REDIRECT}" ]]; then
add_service ${REDIRECT} ${LISTEN_PORT}
fi

if [[ ! -z "${SERVICES}" ]]; then
SERVICES=(${SERVICES//;/ })
for service in "${SERVICES[@]}"; do
service_data=(${service//:/ })
add_service "${service_data[1]}:${service_data[2]}" ${service_data[0]}
done

fi

if [[ ! -z "${PROXY_PORT}" ]]
Expand Down