🧅 𝙏𝙤𝙧𝙍𝙪𝙣𝙣𝙚𝙧
TorRunner is a Python package designed to facilitate the deployment of Tor hidden services. It simplifies the process by allowing you to set up and run a hidden service that listens on a specified port. This package automates the installation and configuration of the Tor software, removing the need for manual setup and making it easier to get started.
Special thanks
This project uses the Vanguards implementation of mikeperry-tor at mikeperry-tor/vanguards under MIT license found here, the socks implementation of Anorov at Anorov/PySocks under BSD License found here and the win_inet_pton implementation of hickeroar at hickeroar/win_inet_pton under Public Domain License found here.
📌 Planned for the future
- Vanguards
- Auto Bridge Updates
- Multi Threads
- Tor version check & auto update
- Proxy mode [only for urllib implemented]
❌ (not feasible) Tor preinstalled
🚀 Installation
Make sure you have the latest version of Python and Pip installed.
- Create an virtual env with
python3 -m venv .venvandsource .venv/bin/activate - Install TorRunner with pip
pip install tor-runneror manually viagit clone https://github.com/tn3w/TorRunneror download the zip here. - If you installed it manually, run
pip install .in the downloaded and extracted folder. - [Optional] Install stem with
pip install stemif you want to use Vanguards.
Quick command (Linux / macOS):
python -m venv .venv; source .venv/bin/activate; pip install tor-runner
Quick command (Windows):
python -m venv .venv; .venv/Scripts/activate.bat; pip install tor-runner
Examples
TorProxy
TorRunner has the ability to route your urllib requests through Tor.
Example:
import time
import urllib.request
import urllib.error
from tor_runner import TorProxy
proxy = TorProxy()
proxy.start()
print("SocksPort running on 127.0.0.1:" + str(proxy.socks_port))
with proxy.urllib():
start_time = time.time()
url = "https://check.torproject.org/?lang=en_US"
try:
response = urllib.request.urlopen(url)
content = response.read().decode('utf-8')
if "Congratulations" in content:
print("Connected to Tor!")
elif "Sorry" in content:
print("Not connected to Tor")
except urllib.error.URLError as e:
print(f"Error connecting to {url}: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
first_byte_time = time.time() - start_time
print(f"Time to first byte: {first_byte_time:.4f} seconds")
On the command line
tor_runner --help
Output:
usage: tor_runner [-h] [-p PORT] [-l [LISTENER ...]] [-t THREADS] [-d [HIDDEN_SERVICE_DIRS ...]] [-b [BRIDGES ...]] [-s SOCKS_PORT] [-v [VANGUARDS]] [--bridge-quantity BRIDGE_QUANTITY]
[--default-bridge-type DEFAULT_BRIDGE_TYPE] [--direct] [--delete] [--quiet]
Run as a Tor hidden service, allowing configuration of listeners, hidden service directories, and bridges.
options:
-h, --help show this help message and exit
-p PORT, --port PORT HTTP port for the hidden service to listen on.
-l [LISTENER ...], --listener [LISTENER ...]
List of listeners in the format 'tor_port,listen_port'.
-t THREADS, --threads THREADS
How many times Tor should start. (default: 1)
-d [HIDDEN_SERVICE_DIRS ...], --hidden-service-dirs [HIDDEN_SERVICE_DIRS ...]
Directories for storing hidden service keys and hostname files.
-b [BRIDGES ...], --bridges [BRIDGES ...]
List of bridges to use for connecting to the Tor network.
-s SOCKS_PORT, --socks-port SOCKS_PORT
SOCKS port for Tor connections.
-v [VANGUARDS], --vanguards [VANGUARDS]
Enables Vanguards with an optional thread count to protect against guard discovery and related traffic analysis attacks.
--bridge-quantity BRIDGE_QUANTITY
Number of bridges to use for connecting to the Tor network.
--default-bridge-type DEFAULT_BRIDGE_TYPE
Default bridge type to use when connecting to Tor.
--direct Executes your command directly via Tor.
--delete Delete all data associated with tor_runner.
--quiet Run the script in quiet mode with no output.
Without an App
from tor_runner import TorRunner
# Uses 11 default obfs4 bridges to connect
runner = TorRunner(
hs_dirs = ["/path/to/hs"], bridges = [],
default_bridge_type = "obfs4", bridge_quantity = 11
)
if __name__ == '__main__':
# Forwards 5000 -> 80 and 22 -> 22
runner.run([(5000, 80), (22, 22)], socks_port = 9050, quite = False, wait = True)
For Flask
from flask import Flask
from tor_runner import TorRunner
app = Flask(__name__)
# Uses 11 default obfs4 bridges to connect
runner = TorRunner(default_bridge_type = "obfs4", bridge_quantity = 11)
@app.route('/')
def index():
"""
Route accessible via the Tor network
"""
return 'Hello, Anonymous!🖐️'
if __name__ == '__main__':
runner.flask_run(app, host = '127.0.0.1', port = 9000)
For Sanic
from sanic import Sanic, HTTPResponse
from sanic.response import text
from tor_runner import TorRunner
app = Sanic(__name__)
# Uses 11 default obfs4 bridges to connect
runner = TorRunner(default_bridge_type = "obfs4", bridge_quantity = 11)
@app.route('/')
async def index(request) -> HTTPResponse:
"""
Route accessible via the Tor network
"""
return text('Hello, Anonymous!🖐️')
if __name__ == '__main__':
runner.sanic_run(app, host = '127.0.0.1', port = 8000, workers = 16)
Metadata
Release files for tor-runner 1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tor_runner-1.5.tar.gz | 58.3 kB | Without provenance | Details for tor_runner-1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tor_runner-1.5-py3-none-any.whl | Python 3 | none | any | Details for tor_runner-1.5-py3-none-any.whl |
Total release size: 121.4 kB
Release files / tor_runner-1.5.tar.gz
| Download URL | tor_runner-1.5.tar.gz |
|---|---|
| Size | 58.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a82d985979d7dda8bfbe898ae0dc0030c0092c65c90e69d55ae0aa6a89ea61d3
|
|
BLAKE2b-256 checksum How to use checksums |
9da721cae9c93137931f971c803b595ce54435de632211eb716b6a0fffc557bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / tor_runner-1.5-py3-none-any.whl
| Download URL | tor_runner-1.5-py3-none-any.whl |
|---|---|
| Size | 63.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b465b98a597f104b4bf6907b828bdc7d381bfb64ee4a8d32297154ebe69fb624
|
|
BLAKE2b-256 checksum How to use checksums |
d5ac8b197b08650c17e63804e8ce7c029bac80df6d74dddbbe3a247118f3a050
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for tor-runner 1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.