This repository provides a production-oriented proxy chain with policy enforcement, authentication, and privacy-focused egress routing.
Core flow:
Client -> Mitmproxy (auth + policy + rate limit) -> Privoxy -> Tor -> Exit Node -> Target
mitmproxy: authenticated ingress proxy with user policy enforcement and request/response controls.privoxy: HTTP forward proxy that forwards to Tor SOCKS.tor: privacy egress layer with strict node selection, stream isolation, and connection padding.unbound: local DNS resolver with DNSSEC and optional DNS-over-TLS (DoT).
project-root/
├── app/
│ ├── gatekeeper.py
│ ├── policy.yaml
│ ├── users.yaml.example
│ └── __init__.py
├── unbound/
│ ├── unbound.conf
│ └── blacklist.conf
├── privoxy/
│ └── config
├── tor/
│ └── torrc
├── services/
│ ├── unbound/Dockerfile
│ ├── privoxy/Dockerfile
│ └── tor/Dockerfile
├── init/
│ ├── bootstrap.sh
│ ├── setup-vps.sh
│ ├── setup-domain.sh
│ ├── generate-certs.sh
│ └── vps-proxy-stack.service
├── cron/
│ └── update_blacklist.sh
├── ssl-certificates/ # generated at runtime
├── logs/
├── Dockerfile
├── docker-compose.yml
├── Makefile
├── requirements.txt
├── requirements-dev.txt
├── .env.example
└── README.md
-
Prepare environment:
cp .env.example .envcp app/users.yaml.example app/users.yaml
-
Generate password hash:
python3 -c "import hashlib; print(hashlib.sha256(b'STRONG_PASSWORD').hexdigest())"
-
Set credentials and token in
app/users.yaml. -
Build and validate:
make buildmake verify
-
Start stack:
make up
-
Update DNS blocklist:
make update-blacklist
Run a full host bootstrap (system update, Docker install, optional CloudPanel setup, firewall, kernel tuning, Fail2Ban, TLS generation, stack start):
sudo make setup-vps
The script init/setup-vps.sh performs all required host-level steps and then calls init/bootstrap.sh.
To switch from IP-only access to domain-based access:
make setup-domain
The wizard:
- Prompts for domain and email.
- Shows recommended DNS records.
- Checks DNS propagation.
- Lets you choose TLS mode:
cloudpanelletsencryptselfsigned
- Generates/links certificates and restarts the stack.
Certificate logic is managed by init/generate-certs.sh.
selfsigned: generatesserver.keyandserver.crtinssl-certificates/.letsencrypt: obtains certs with certbot standalone, then copies tossl-certificates/.cloudpanel: copies certs from/etc/nginx/ssl-certificates/<domain>.{key,crt}.
Run manually:
make generate-certs
Ports are intentionally separated between exposed and internal services.
MITMPROXY_BIND_PORT(default8080/tcp): authenticated ingress proxy.UNBOUND_DNS_PORT(default5353/tcp+udp): local DNS resolver.UNBOUND_DOT_PORT(default853/tcp): DNS-over-TLS.PRIVOXY_BIND_PORT(default8118/tcp): intermediate forward proxy (recommended loopback-only).TOR_SOCKS_PORT(default9050/tcp): internal SOCKS endpoint for Privoxy.
Recommended firewall posture:
- Expose only required ports (
8080, and optionally53/udp+tcp,853/tcp). - Keep
8118and9050internal.
tor/torrc is configured for privacy-focused operation:
- fixed entry-guard behavior (
UseEntryGuards,NumEntryGuards), - strict geo-constrained exit policy (
ExitNodes,ExcludeNodes,StrictNodes), - anti-profiling circuit timing,
- traffic-analysis resistance (
ConnectionPadding), - stream isolation (
IsolateDestAddr,IsolateDestPort,IsolateSOCKSAuth), - persistent operational logging (
/var/log/tor/notices.log,/var/log/tor/info.log).
Tor logs can be tailed with:
make logs-tor
Auth and policy are implemented in app/gatekeeper.py.
- auth mode:
basicortokenviaAUTH_MODE, - users file:
USERS_FILE(default/app/app/users.yaml), - policy file:
POLICY_FILE(default/app/app/policy.yaml), - rate limit:
RATE_LIMIT_RPMandRATE_LIMIT_WINDOW_SEC.
If authentication fails, the proxy returns 407 Proxy Authentication Required.
If limits are exceeded, the proxy returns 429.
- Auth log:
logs/auth.log - Traffic log:
logs/traffic.log - Tor logs:
/var/log/tor/notices.logand/var/log/tor/info.log(insidetorcontainer)
make init: runbootstrap.sh(compose up + generated config + optional systemd/cron)make setup-vps: full Debian host bootstrapmake setup-domain: guided domain and HTTPS setupmake generate-certs: generate/sync TLS certificates
make build: build all imagesmake up: start stackmake down: stop stackmake logs: stream logs for all core servicesmake logs-auth: stream auth logmake logs-traffic: stream traffic logmake logs-tor: stream Tor notice logmake update-blacklist: regenerateunbound/blacklist.conf
make lint: run Ruff checksmake test: run testsmake smoke: verify mitmdump runtimemake verify: lint + smoke +docker compose config -q
- Run on hardened hosts with deny-by-default ingress policy.
- Keep user secrets (
app/users.yaml,.env) out of source control. - Rotate tokens and credentials regularly.
- Review legal/compliance requirements before TLS interception in your jurisdiction.