Skip to main content

Transparent Tor Proxy โ€” route all system traffic through Tor

Project description


๐Ÿ›ก๏ธ TTP โ€” Transparent Tor Proxy

A Linux CLI tool that transparently routes all system traffic through the Tor network using nftables.

Linux Python CI Status License

Features โ€ข Contribute โ€ข Requirements โ€ข Installation โ€ข Usage โ€ข How It Works


TTP Demo


No per-application setup needed โ€” just sudo ttp start and every connection goes through Tor.

[!CAUTION] TTP is a tool designed to aid privacy by routing traffic through Tor. However, no tool can guarantee 100% anonymity. Your safety also depends on your behavior (e.g., using a regular browser vs. Tor Browser, signing into accounts, etc.). Always use TTP as part of a multi-layered security strategy.

[!WARNING] If you are a whistleblower or are engaging in high-risk activities, DO NOT use TTP. Instead, use officially audited and reliable tools like TailsOS or the Tor Browser directly. The authors and contributors of TTP assume no responsibility for your safety or the consequences of using this software.

๐Ÿค Call for Contributors

We are actively looking for developers to join the TTP project! Whether you are a student looking to learn or a seasoned professional, your help is welcome.

We are particularly seeking Senior Developers with expertise in:

  • ๐Ÿ›ก๏ธ Linux Networking (nftables, routing tables, network namespaces).
  • ๐Ÿง… Tor Internals (daemon configuration, Stem library, circuit management).
  • ๐Ÿ System-level Python (asynchronous I/O, process management, security best practices).

If you want to contribute to making transparent proxying safer and more robust, please check out our Contributing Guidelines or dive right into the Issues.

โœจ Features

  • ๐ŸŒ System-wide transparent proxy โ€” all TCP traffic is redirected to Tor's TransPort, all DNS queries go through Tor's DNSPort.
  • ๐Ÿ›ก๏ธ DNS leak prevention โ€” dual-mode DNS management (resolvectl / resolv.conf fallback) with symlink-aware detection.
  • ๐Ÿšซ IPv6 leak prevention โ€” all outgoing IPv6 is blocked to avoid ISP-level leaks.
  • ๐Ÿ”„ Crash-safe โ€” a lock file tracks session state; even after kill -9 or a power outage, the next run detects the orphaned session and restores the network.
  • โšก Atomic firewall rules โ€” nftables rules are loaded with nft -f (all-or-nothing), avoiding dangerous intermediate states.
  • ๐ŸŽญ IP rotation โ€” ttp refresh requests a new Tor circuit for a fresh exit IP.
  • ๐Ÿ›ก๏ธ SELinux optimization โ€” Compiles a custom SELinux policy from source (.te) on Fedora/RHEL to allow Tor to bind to necessary ports. No opaque binaries shipped.
  • ๐Ÿง Multi-distro โ€” auto-detects apt-get, pacman, dnf, and zypper for Tor installation. Handles Debian multi-instance services (tor@default), Fedora (toranon user), and more.
  • ๐Ÿ› ๏ธ Auto-configuration โ€” validates and sanitizes torrc before starting, removing invalid settings and appending missing options.

โš™๏ธ Requirements

  • Linux with systemd (tested on Debian 12+, Ubuntu 22.04+, Fedora 40+, Arch Linux)
  • Python 3.10+
  • nftables (pre-installed on most modern distros)
  • Root privileges (required for firewall and DNS modifications)

๐Ÿš€ Installation

Choose the method that best fits your needs. Native packages are strongly recommended for system stability, security, and clean uninstallation.

1. Native Packages (Recommended)

Installing via native packages ensures that all system dependencies (tor, nftables) and kernel-level optimizations (SELinux) are managed by your OS package manager.

  • Debian / Ubuntu: sudo apt install ./packaging/ttp_0.1.1_all.deb
  • Fedora / RHEL: sudo dnf install ./packaging/ttp-0.1.1-1.fc43.noarch.rpm
  • Arch Linux: cd packaging && makepkg -si

2. Manual Source Install (Developer/Universal)

If you are a developer or want to install from the repository:

git clone https://github.com/onyks-os/TransparentTorProxy.git
cd TransparentTorProxy
sudo ./scripts/install.sh

[!TIP] Why use ./install.sh?
Unlike standard Python installers, this script is "intelligent". On Red Hat-based systems, it detects if SELinux is in Enforcing mode and dynamically compiles a custom policy module (from ttp_tor_policy.te) to allow Tor to bind to the non-standard ports required by TTP (9040, 9053). This kernel-level optimization cannot be performed by pip.


3. Fallback: pipx / pip (PEP 668)

[!WARNING] Note on Linux Distributions (PEP 668)
Recent versions of Ubuntu/Debian prevent global pip install to protect system stability. Using these methods will bypass TTP's kernel-level optimizations (SELinux) and won't handle system dependencies automatically.

Option A: pipx (Recommended Fallback)

pipx installs TTP in an isolated environment but makes the command available globally.

pipx install transparent-tor-proxy

Option B: Standard pip with venv

If you prefer standard pip, use a virtual environment to avoid the externally-managed-environment error.

# 1. Create the environment
python3 -m venv ~/.local/share/ttp-venv

# 2. Install the package
~/.local/share/ttp-venv/bin/pip install transparent-tor-proxy

# 3. Create a symbolic link to use 'ttp' everywhere
sudo ln -s ~/.local/share/ttp-venv/bin/ttp /usr/local/bin/ttp

[!CAUTION] Uninstallation Warning: Running pipx uninstall or deleting the venv only removes the Python code. If TTP is active, your firewall and DNS will remain hijacked. Always use ttp stop before uninstalling via pip, or use ./scripts/uninstall.sh if you installed via the source script. [!NOTE]
After installation, the ttp command is available system-wide.

๐Ÿ’ป Usage

[!IMPORTANT] All commands require sudo. Except ttp status and ttp --help.

Start the proxy

sudo ttp start
[TTP] Detecting Tor... found (v0.4.9.6), service active (user: debian-tor).
[TTP] Stateless nftables rules applied (Table: inet ttp).
[TTP] DNS set via resolvectl on interface ens3.
[TTP] Waiting for Tor to bootstrap...
[TTP] Tor is 100% bootstrapped.
[TTP] Verifying Tor routing...
[TTP] โœ… Session active. Exit IP: 109.70.100.11
[TTP] Use 'ttp stop' to terminate. 'ttp refresh' to change IP.

Stop the proxy

sudo ttp stop
[TTP] Removing nftables rules...
[TTP] Restoring DNS...
[TTP] ๐Ÿ”ด Session terminated. Traffic in cleartext.

Change exit IP

sudo ttp refresh

Sends NEWNYM to Tor via the control interface โ€” all active circuits are rotated and you get a new exit IP.

Check status

sudo ttp status
[TTP] Status: ACTIVE
[TTP] Exit IP: 185.181.61.201
[TTP] Session started: 2026-04-19T01:07:33.384801+00:00
[TTP] Process PID: 3392

๐Ÿ” Manual Leak Verification

To confirm that the tunnel is working correctly and no leaks are present:

  1. Verify Tor Exit IP:

    curl -s https://check.torproject.org/api/ip
    
  2. Verify DNS Routing:

    # Should return a valid IP via Tor's DNSPort
    dig +short A check.torproject.org
    
  3. DNS Leak Test (Terminal):

    # This TXT query SHOULD return an EMPTY output
    dig +short TXT whoami.ipv4.akahelp.net
    

    Note: An empty output is the expected behavior under Tor. Tor's transparent resolver does not support TXT records; if this command returns your real ISP's IP, you have a DNS leak.

  4. Web-based Verification: Always perform additional tests on dnsleaktest.com and ipleak.net.

Full Uninstallation

To remove TTP completely from the system:

sudo ./scripts/uninstall.sh

๐Ÿง  How It Works

  1. Detection โ€” checks if Tor is installed, which systemd service runs the daemon, and dynamically detects the Tor user.
  2. Installation โ€” if Tor is missing, detects the system's package manager and installs it automatically.
  3. Configuration โ€” sanitizes torrc, validates with tor --verify-config, restarts the correct service.
  4. Firewall โ€” generates nftables rules in a dedicated inet ttp table:
    • Stateless approach โ€” no system backups needed; cleanup is an atomic nft destroy table.
    • Multi-Chain Protection:
      • prerouting: Intercepts traffic if TTP is used as a gateway.
      • output (NAT): Redirects local TCP/DNS to Tor's ports.
      • filter_out (Filter): Acts as a Kill-Switch.
    • Execution Sequence:
      1. Exclude Tor user (prevents routing loops).
      2. Exclude root processes (system stability).
      3. Intercept DNS (UDP :53) and redirect to Tor's DNSPort.
      4. Accept loopback and local traffic (required for redirected packets).
      5. Redirect all TCP to Tor's TransPort (:9040).
      6. Drop all IPv6 output to prevent leaks.
      7. Kill-Switch (Reject): Terminate any cleartext traffic that bypassed redirection (e.g., pre-existing connections).
  5. DNS โ€” redirects DNS resolution to 127.0.0.1 via resolvectl or /etc/resolv.conf.
  6. Bootstrap โ€” waits for Tor to reach 100% bootstrap via the control interface.
  7. Verification โ€” confirms traffic is routed through Tor via multiple endpoints (check.torproject.org, ipify, ifconfig.me) for resilience.
  8. State โ€” writes a JSON lock file at /var/lib/ttp/ttp.lock for crash recovery.

๐Ÿš‘ Crash Recovery

TTP is designed to always restore your network, even in edge cases:

Scenario What happens
ttp stop Normal cleanup: firewall restored, DNS restored, lock deleted
Ctrl+C / kill Signal handler catches SIGINT/SIGTERM and runs cleanup before exit
kill -9 / Power Outage Next ttp start detects the orphaned lock file and auto-restores the network
Manual emergency Run sudo ./scripts/restore-network.sh to flush all nftables rules, reset DNS, and delete the lock file

โš ๏ธ Known Behavior

[!WARNING]

  • Tor Browser: Applications using an explicit SOCKS5 proxy will create a double Tor hop. Use a regular browser instead while TTP is active.
  • Chromium-based Browsers (DoH Leak): Chrome, Brave, and Edge might use DNS-over-HTTPS (DoH), which bypasses system DNS settings. To prevent leaks:
    1. Disable "Secure DNS" in browser settings.
    2. Ideally, avoid Chromium-based browsers entirely while using TTP; use Firefox instead (ensuring its own "DNS over HTTPS" setting is also disabled). This still DOES NOT ensure the absence of leaks.
  • IPv6: All IPv6 traffic is blocked to prevent leaks. Future versions may support IPv6 through Tor.
  • Exit IP variation: Different connections may show different exit IPs due to Tor stream isolation. After ttp refresh, all connections get new circuits.

๐Ÿงช Development & Testing

TTP uses a Makefile to automate and standardize the testing pipeline. This ensures that every change is verified against unit and integration tests before being committed.

The "Pre-Push" Rule

[!IMPORTANT] Always run make verify before pushing code. If this command fails, the code is NOT ready for production.

Essential Commands

Command Goal
make test Runs fast Unit Tests locally (no root needed, fully mocked).
make integration-debian Runs full system tests inside a privileged Docker container (Debian).
make integration-all Runs integration tests for all supported distros (Debian, Fedora, Arch).
make verify The Gold Standard: Runs Unit Tests + All Integration Tests.

Advanced: Real-World VM Testing

While Docker integration tests are fast and atomic, they don't capture 100% of the kernel/systemd nuances. For critical changes, it is highly recommended to test in a real QEMU VM:

# Start a specific VM (e.g., arch)
./scripts/vm/start.sh arch

# Sync current code to the VM
./scripts/vm/send.sh

# Snapshot management for easy rollbacks
./scripts/vm/snapshot.sh arch save before-risky-test

Diagnostics

If something goes wrong, run the diagnostic command:

sudo ttp diagnose

๐Ÿ—‚๏ธ Project Structure

โ”œโ”€โ”€ pyproject.toml          # Package metadata and dependencies
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ CONTRIBUTING.md         # Contribution guidelines
โ”œโ”€โ”€ SECURITY.md             # Security policy
โ”œโ”€โ”€ scripts/                # Installation and VM management scripts
โ”‚   โ”œโ”€โ”€ install.sh          # System-wide installer
โ”‚   โ”œโ”€โ”€ uninstall.sh        # System-wide uninstaller
โ”‚   โ”œโ”€โ”€ restore-network.sh  # Emergency network recovery script
โ”‚   โ””โ”€โ”€ vm/                 # QEMU VM management scripts
โ”œโ”€โ”€ assets/                 # Branding and demo assets
โ”‚   โ””โ”€โ”€ gif/                # Demo animations
โ”œโ”€โ”€ packaging/              # Build scripts for .deb, .rpm, and Arch packages
โ”‚   โ”œโ”€โ”€ build_deb.sh
โ”‚   โ”œโ”€โ”€ build_rpm.sh
โ”‚   โ”œโ”€โ”€ ttp.spec
โ”‚   โ”œโ”€โ”€ PKGBUILD
โ”‚   โ””โ”€โ”€ ttp.service
โ”œโ”€โ”€ ttp/                    # Source code
โ”‚   โ”œโ”€โ”€ resources/          # Internal package resources (SELinux policies, etc.)
โ”‚   โ”œโ”€โ”€ cli.py              # Typer entry point
โ”‚   โ”œโ”€โ”€ exceptions.py       # Custom exception hierarchy
โ”‚   โ”œโ”€โ”€ tor_detect.py       # Tor detection logic
โ”‚   โ”œโ”€โ”€ tor_install.py      # Auto-install & configuration
โ”‚   โ”œโ”€โ”€ firewall.py         # Atomic nftables management
โ”‚   โ”œโ”€โ”€ dns.py              # DNS leak prevention
โ”‚   โ”œโ”€โ”€ state.py            # Lock file and crash recovery
โ”‚   โ”œโ”€โ”€ tor_control.py      # Tor daemon interaction and API
โ”‚   โ””โ”€โ”€ system_info.py      # System diagnostic gathering
โ”œโ”€โ”€ tests/                  # Unit tests (mocked)
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ architecture.md     # Technical Architecture & Design

๐Ÿค Contributing & Security

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

๐Ÿ“„ License

MIT. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transparent_tor_proxy-0.1.1.tar.gz (928.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transparent_tor_proxy-0.1.1-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file transparent_tor_proxy-0.1.1.tar.gz.

File metadata

  • Download URL: transparent_tor_proxy-0.1.1.tar.gz
  • Upload date:
  • Size: 928.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for transparent_tor_proxy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 17b48427967317e9f1ea446c43c31e1c5d83291b363fdca94a2e516d11dbcba0
MD5 5fb8d87bbfa22f4e20976901ab3cc9a8
BLAKE2b-256 16649cd5bc19c0c738dc657f3d7aa018d1cdbf4e8f5d6521acb0103fceca153c

See more details on using hashes here.

File details

Details for the file transparent_tor_proxy-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for transparent_tor_proxy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62bb4d013af281d8a5c7331def8ac959d51ca657699175ac2a0b6f749cf665c2
MD5 7fb5101635452d3322b174be01236f0c
BLAKE2b-256 81cdc81e568ab7312ff2e681e46616378156bb685b74de652f421ee4244abcb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page