| English | Persian |
|---|
MHR-Hybrid runs a local proxy backend and can optionally expose a local web dashboard endpoint plus a separate PyQt desktop dashboard.
Browser / App Client
|
v
Local MHR-Hybrid Proxy Backend (main.py)
|
+--> Relay backend(s):
- Google Apps Script relay (`mode: apps_script`)
- Google fronting relay (`mode: google_fronting`)
- Domain-fronted worker relay (`mode: domain_fronting`)
- Direct custom-domain worker relay (`mode: custom_domain`)
Separate process:
PyQt Desktop Dashboard (desktop_ui/main.py)
-> reads backend API: GET http://<host>:<port>/__mhr/api/dashboard
- The legacy
ui/web dashboard is now optional/deprecated for day-to-day use. - The recommended local operator interface is the PyQt desktop dashboard (
python -m desktop_ui.main). - The embedded web route (
/__mhr/ui/) remains available for compatibility, but it is no longer the primary UX.
- Install Python 3.10+ and ensure it is available on your PATH as
python(Windows) orpython3(Linux/macOS). - Install dependencies:
- Windows:
pip install -r requirements.txt- Linux/macOS:
pip install -r requirements.txt
- Create config:
- Windows:
Copy-Item config.example.json config.json- Linux/macOS:
cp config.example.json config.json
- Run launcher:
- Windows:
run.bat - Linux/macOS:
./run.sh
- Windows:
The launchers also try to auto-install missing dependencies on first run.
If you prefer isolated Python packages, use a virtual environment:
Windows (PowerShell):
py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtLinux/macOS (bash/zsh):
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtIf your network cannot reach PyPI directly:
pip install -r requirements.txt -i https://mirror-pypi.runflare.com/simple/ --trusted-host mirror-pypi.runflare.comCreate your local config file first:
Windows (PowerShell):
Copy-Item config.example.json config.jsonLinux/macOS:
cp config.example.json config.json{
"mode": "apps_script",
"google_ip": "216.239.38.120",
"front_domain": "www.google.com",
"script_id": "YOUR_APPS_SCRIPT_DEPLOYMENT_ID",
"auth_key": "CHANGE_ME_TO_A_STRONG_SECRET",
"listen_host": "127.0.0.1",
"listen_port": 8085,
"log_level": "INFO",
"verify_ssl": true
}-
mode- Purpose: Select relay strategy.
- Type/allowed: string; one of
apps_script,google_fronting,domain_fronting,custom_domain. - Default behavior: If omitted, runtime treats mode like
domain_fronting. - Example:
"mode": "apps_script"
-
auth_key- Purpose: Shared auth secret for relay contract.
- Type/allowed: non-empty string.
- Default behavior: required; startup fails if missing.
- Example:
"auth_key": "my-strong-secret"
-
listen_host- Purpose: Bind address for local proxy/API.
- Type/allowed: string IP/host.
- Default behavior:
127.0.0.1. - Example:
"listen_host": "127.0.0.1"
-
listen_port- Purpose: TCP listen port for local proxy/API.
- Type/allowed: integer.
- Default behavior: backend defaults to
8080if not set. - Example:
"listen_port": 8085
-
log_level- Purpose: Logging verbosity.
- Type/allowed:
DEBUG,INFO,WARNING,ERROR. - Default behavior:
INFO. - Example:
"log_level": "DEBUG"
-
verify_ssl- Purpose: Upstream TLS verification behavior.
- Type/allowed: boolean.
- Default behavior:
trueif omitted in example flow. - Example:
"verify_ssl": true
-
apps_scriptmode keysscript_id(string) orscript_ids(array of strings)- Purpose: Apps Script deployment ID(s), optional round-robin when list provided.
- Default behavior: required in this mode; startup fails without valid value.
- Example:
"script_id": "AKfycbx..."
-
google_frontingmode keysworker_host(string)- Purpose: Upstream worker/Cloud Run host used behind Google front.
- Default behavior: required in this mode.
- Example:
"worker_host": "my-service.a.run.app"
google_ip/front_domain- Purpose: Google-facing front target details.
- Default behavior: if omitted, runtime logs default front domain as
www.google.comand common Google IP usage. - Example:
"front_domain": "www.google.com"
-
domain_frontingmode keysfront_domain(string),worker_host(string)- Purpose: SNI/front host and effective upstream host.
- Default behavior: both required in this mode.
- Example:
{ "front_domain": "www.google.com", "worker_host": "myworker.workers.dev" }
-
custom_domainmode keycustom_domain(string)- Purpose: Use your own domain endpoint routing.
- Default behavior: required in this mode.
- Example:
"custom_domain": "relay.example.com"
socks5_enabled(bool, defaulttrue),socks5_host(string),socks5_port(int, default1080)hosts(object map of host/suffix overrides to IPs)router(object)enabled(bool, defaulttrue)prefer_worker_first(bool, defaulttrue)worker_payload_limit(int bytes, default2097152)worker_retry_threshold(int, default2)worker_error_threshold(int, default3)worker_timeout_floor_ms(int, default1200)
Certificate trust is most relevant when using interception flows (notably
apps_script).
Run installer mode:
python main.py --install-certThis installs the generated CA certificate into supported trust stores, then exits.
Certificate file path used by the project:
ca/ca.crt
Manual install targets:
- Windows: Trusted Root Certification Authorities (Current User or Local Machine)
- macOS: login keychain or system keychain
- Linux: distro trust store (
update-ca-certificates,update-ca-trust, ortrust extract-compat) - Firefox/NSS stores when present
Start backend without skipping checks:
python main.py --config config.jsonExpected success signal in logs:
MITM CA is already trusted.
Remove the installed MHR-Hybrid root CA from your OS/browser trust store using platform certificate manager tools.
After rollback, restart the browser and backend; HTTPS interception paths should no longer be trusted.
python main.py [--config PATH] [--host HOST] [--port PORT] [--log-level LEVEL] [--install-cert] [--no-cert-check]- Use explicit config file:
python main.py --config config.json
- Bind custom interface/port:
python main.py --host 127.0.0.1 --port 8085
- Verbose debug logs:
python main.py --log-level DEBUG
- Certificate bootstrap only:
python main.py --install-cert
- Skip startup trust verification (advanced/debug only):
python main.py --no-cert-check
Successful startup usually includes:
- Mode banner (for example
MHR-Hybrid starting (mode: apps_script)). - Mode-specific routing info (script IDs or host mappings).
- Proxy bind line (
Proxy address : <host>:<port>).
Success criteria:
- Process remains running.
- Config validation passes (no missing mode-required keys).
- Local endpoint is reachable at configured host/port.
- Target host/port:
python -m desktop_ui.main --host 127.0.0.1 --port 8085
- Or pass full API base URL:
python -m desktop_ui.main --api-base-url http://127.0.0.1:8085
- Optional periodic refresh:
python -m desktop_ui.main --host 127.0.0.1 --port 8085 --poll-seconds 5
- Manual refresh: Refresh button.
- Automatic refresh: enabled only if
--poll-seconds > 0.
If backend API is unreachable, dashboard modules move into error state and show actionable guidance (start/check backend, verify host/port/API URL).
Manual browser proxy values:
- HTTP proxy host:
127.0.0.1 - HTTP proxy port: your
listen_port(for example8085)
Optional extension workflow:
- Install FoxyProxy (Chrome or Firefox).
- Add a profile pointing to
127.0.0.1:<listen_port>. - Enable profile before browsing test targets.
- Start backend and ensure no startup config/cert errors.
- Enable browser proxy profile.
- Open a validation site (for example
https://ipleak.net). - Confirm traffic egress matches expected relay/provider behavior.
- Check backend logs for relay activity and status summaries.
- Backend status / health: confirms API connectivity/runtime health.
- Routing policy preview: shows worker/apps-script routing decisions.
- Relay diagnostics / log summaries: surfaces upstream response patterns.
- Config validation: highlights missing or invalid settings.
Use this checklist for a clean initial deployment:
- Install dependencies
- Create and activate
.venv. - Install packages with
pip install -r requirements.txt.
- Create and activate
- Configure runtime
- Copy
config.example.jsontoconfig.json. - Set required keys for your selected mode (
mode,auth_key, plus mode-specific fields).
- Copy
- Install/trust certificate (when interception mode is used)
- Run
python main.py --install-cert. - Confirm
ca/ca.crtis trusted in your OS/browser trust store.
- Run
- First backend run
- Start backend with
python main.py --config config.json. - Verify startup logs show bind address and no config/certificate errors.
- Start backend with
- UI verification
- Launch desktop UI:
python -m desktop_ui.main --host 127.0.0.1 --port <listen_port>. - Confirm dashboard modules load without backend/API error states.
- Launch desktop UI:
- Start
python main.py --config config.json
- Stop
- Use
Ctrl+Cin the terminal running backend. - Wait for process exit before restarting on the same port.
- Use
- Safe restart sequence
- Stop backend cleanly (
Ctrl+C). - Confirm port is free (for example with
ss -ltnpon Linux/macOS ornetstat -anoon Windows). - Start backend again with explicit config.
- Stop backend cleanly (
- Start
python -m desktop_ui.main --host 127.0.0.1 --port <listen_port>
- Stop
- Close the desktop window, or terminate process from terminal (
Ctrl+Cif launched interactively).
- Close the desktop window, or terminate process from terminal (
- Enable browser proxy to
127.0.0.1:<listen_port>. - Open a test endpoint such as
https://ipleak.net. - Confirm expected egress behavior.
- In dashboard, verify backend health is green/reachable and no API error banners appear.
- Pull latest changes:
git pull --rebase
- Reactivate
.venvand update dependencies:pip install -r requirements.txt --upgrade
- Compare
config.example.jsonto yourconfig.jsonand merge any new required keys. - Restart backend and desktop UI after updates.
- Generate a new strong random secret.
- Update
auth_keyinconfig.json. - Update the corresponding secret in your relay backend(s).
- Restart backend and validate requests succeed (no auth mismatch errors).
- Re-run installer workflow:
python main.py --install-cert
- Restart browser and backend.
- Re-verify trust via startup logs (
MITM CA is already trusted.).
- Backend logs print to the terminal/session where
python main.py ...is running. - Desktop UI diagnostics appear in the terminal/session used to start
python -m desktop_ui.main ....
- Normal operation:
INFO - Investigation/debug sessions:
DEBUG - You can set level via
config.json(log_level) or CLI--log-level.
- Start backend with debug logging:
python main.py --config config.json --log-level DEBUG
- Reproduce issue with timestamps noted.
- Capture:
- Backend terminal logs.
- Desktop UI terminal logs (if UI-related).
- Sanitized
config.json(redactauth_keyand sensitive hosts if needed).
- Include OS, Python version, selected
mode, and exact command lines used.
- Stop backend/UI.
- Backup current config:
cp config.json config.json.bak
- Restore baseline:
cp config.example.json config.json
- Re-apply required environment-specific values (
auth_key, relay identifiers/domains, ports). - Start backend and validate health from dashboard/API.
- Identify conflicting process on target port (
listen_port/socks5_port). - Stop conflicting process or change MHR-Hybrid ports in
config.json. - Restart backend and confirm bind succeeds.
- Remove
MHR-HybridCA from OS/browser trust store. - Restart browser to clear trust cache.
- Reinstall certificate:
python main.py --install-cert
- Restart backend and verify trust success log.
- From repository root, delete virtual environment folder:
- Linux/macOS:
rm -rf .venv - Windows (PowerShell):
Remove-Item -Recurse -Force .venv
- Linux/macOS:
- Remove project-generated certificate artifacts (if present), such as files under
ca/created by local setup. - Remove temporary local logs/artifacts you created during debugging.
- Optionally remove cloned repository directory once no longer needed.
| Symptom | Probable cause | Fix |
|---|---|---|
| Browser cert warning / HTTPS fails | Local MITM CA not trusted | Run python main.py --install-cert, restart browser, verify trust logs. |
Address already in use |
Port conflict on listen_port or socks5_port |
Change port(s) in config.json or CLI --port; ensure socks and proxy ports differ on same host. |
| Startup says missing config key | Invalid/incomplete config.json for chosen mode |
Recheck required keys (auth_key, plus mode-specific fields). |
| Relay returns auth or quota-like errors | auth_key mismatch or relay-side throttling |
Sync secret on both ends; rotate key; inspect relay logs/status. |
| Desktop UI shows API error state | Backend not running or wrong host/port | Start backend first; verify --host/--port or --api-base-url in desktop launch command. |
- This project is for educational/testing/research use.
- Running local MITM interception changes TLS trust on your system.
- Misconfiguration can expose sensitive traffic or break normal browsing.
- You are responsible for legal/policy compliance in your jurisdiction and service-provider terms.
- Use isolated test environments (VM, non-primary browser profile, dedicated accounts) before production-like usage.
main.py→ CLI entrypoint.src/app.py→ argument parsing, config validation, startup orchestration.src/proxy/server.py→ local proxy runtime.src/domain_fronter.py/src/backend_adapters.py/src/backend_router.py→ relay transport, adapters, and backend selection policy.src/cert_installer.py→ cross-platform trust install/check.desktop_ui/main.py+desktop_ui/*→ PyQt dashboard app.ui/*→ legacy web UI assets (compatibility path).config.example.json→ baseline config template.
- Define config contract and validation in
src/app.py. - Add relay transport/adapter behavior (
src/backend_adapters.pyand/orsrc/domain_fronter.py). - Update backend selection policy if needed (
src/backend_router.py). - Expose telemetry fields expected by dashboard API.
- Document new mode keys in this README and
config.example.json.
- Add module definition in
desktop_ui/view_model.py. - Map new API payload segment to panel state.
- Ensure backend endpoint (
/__mhr/api/dashboard) includes required fields. - Add rendering details in PyQt view if custom display logic is needed.
MHR-Hybrid is provided without warranty for educational, testing, and research purposes. You are solely responsible for deployment, configuration, legal compliance, and operational safety.