Skip to content

onyks-os/TransparentTorProxy

Repository files navigation


πŸ›‘οΈ 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 β€’ 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.

✨ 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 distribution. Native packages are recommended for system stability and better integration.

πŸ“¦ Native Packages (Recommended)

Debian / Ubuntu / Kali / Mint

Install the pre-built .deb package. This automatically handles dependencies like tor and nftables.

sudo apt update
sudo apt install ./packaging/ttp_0.1.0_all.deb

Fedora / RHEL / AlmaLinux

Install the native .rpm. This package also pre-configures SELinux policies for you.

sudo dnf install ./packaging/ttp-0.1.0-1.fc43.noarch.rpm

Arch Linux

Use the provided PKGBUILD to build and install the package via makepkg.

cd packaging && makepkg -si

πŸ› οΈ Source Installation (Universal)

If you prefer to install from source or are on a different distribution:

git clone https://github.com/onyks-os/TransparentTorProxy.git
cd TransparentTorProxy

# For system-wide deployment (creates venv in /opt/ttp)
sudo ./install.sh

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 ./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 ./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

Running tests

pip install -e .
pytest tests/ -v

(unit tests run without root on any system, fully mocked).

VM testing

Real integration tests should be run in a QEMU VM with snapshots:

# Start a specific VM (default is debian)
./vm-helpers/start.sh arch

# Save a snapshot before testing (vm_type command name)
./vm-helpers/snapshot.sh arch save pre-test

# Sync code to VM (auto-detects the active one)
./vm-helpers/send.sh

# SSH into the VM and test (port 2223 for Arch)
ssh -p 2223 arch@localhost
cd ~/ttp && pip install -e . && sudo ttp start

# Restore if network breaks
./vm-helpers/snapshot.sh arch load pre-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
β”œβ”€β”€ install.sh              # System-wide installer
β”œβ”€β”€ uninstall.sh            # System-wide uninstaller
β”œβ”€β”€ restore-network.sh      # Emergency network recovery script
β”œβ”€β”€ assets/                 # Branding and system policies
β”‚   β”œβ”€β”€ gif/                # Demo animations
β”‚   └── selinux/            # SELinux policy source (.te only)
β”œβ”€β”€ packaging/              # Build scripts for .deb, .rpm, and Arch packages
β”‚   β”œβ”€β”€ build_deb.sh
β”‚   β”œβ”€β”€ build_rpm.sh
β”‚   β”œβ”€β”€ ttp.spec
β”‚   β”œβ”€β”€ PKGBUILD
β”‚   └── ttp.service
β”œβ”€β”€ vm-helpers/             # QEMU VM management scripts
β”œβ”€β”€ ttp/                    # Source code
β”‚   β”œβ”€β”€ 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/
    └── TDD.md              # Technical Design Document

🀝 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.

About

A Linux CLI utility that transparently routes all system traffic through the Tor network using nftables. It enables rapid IP rotation and easy toggling of global proxy settings for anticensura and privacy tasks.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Contributors