Skip to content

Commit 0405f88

Browse files
committed
Add SOCKS5 auth, --manage TUI, --status, --add-tunnel, --remove-tunnel
- Optional SOCKS5 authentication for DNS tunnel proxies (microsocks -u/-P) - --manage: unified post-setup TUI menu with SIGINT-safe subshell isolation - --status: display all tunnels, share URLs, SOCKS auth, DNS resolvers - --add-tunnel: interactive wizard for adding individual tunnels - --remove-tunnel [tag]: remove tunnels with interactive picker or direct tag - Exact tag matching (awk field-exact + grep -qxF) prevents substring collisions - Safe awk ENVIRON approach for systemd ExecStart credential injection - EOF-safe menu loops, hash cache clearing after uninstall - Smart router restart (skip if zero tunnels remain) - README updated in English and Farsi with all new features
1 parent afb10e6 commit 0405f88

2 files changed

Lines changed: 938 additions & 20 deletions

File tree

README.md

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Deploys [dnstm](https://github.com/net2share/dnstm) DNS tunnel servers with **Sl
2020
- [📱 Client Apps](#-client-apps)
2121
- [🛠️ Management Commands](#️-management-commands)
2222
- [👤 SSH Tunnel User Management](#-ssh-tunnel-user-management)
23+
- [🔐 SOCKS Proxy Authentication](#-socks-proxy-authentication)
2324
- [🗑️ Uninstall](#️-uninstall)
2425
- [📖 Manual Setup Guide](#-manual-setup-guide)
2526
- [🔧 Troubleshooting](#-troubleshooting)
@@ -114,7 +115,7 @@ When someone queries `t2.yourdomain.com`, the global DNS system follows this cha
114115
| 🔑 **slip-ssh** | `s2.domain` | Slipstream (QUIC) | SSH | When you need per-user authentication |
115116
| 🔑 **dnstt-ssh** | `ds2.domain` | DNSTT (Noise) | SSH | SSH fallback if Slipstream is blocked |
116117

117-
> 🧦 **SOCKS backend:** Anyone who knows the domain can connect. Simpler, faster, no login required.
118+
> 🧦 **SOCKS backend:** Optionally secured with SOCKS5 username/password authentication. Without auth, anyone who knows the domain can connect.
118119
>
119120
> 🔑 **SSH backend:** Requires username + password. Provides per-user access control. The SSH user is restricted — even if credentials leak, no one can access your server.
120121
@@ -247,8 +248,13 @@ The wizard has **12 steps**. Here's what each one does:
247248
<details>
248249
<summary><b>Step 9 — 🧦 Verify SOCKS Proxy</b></summary>
249250

251+
- **Asks if you want SOCKS5 authentication** — recommended for security
252+
- If yes: prompts for username (default: `proxy`) and password
253+
- Modifies the microsocks systemd service to require credentials
254+
- If no: proxy runs open (anyone who knows the domain can connect)
250255
- Checks if microsocks is running (process or systemd service)
251256
- Starts it if not running
257+
- Applies SOCKS5 auth to microsocks if enabled (adds `-u`/`-P` flags to service)
252258
- Tests the SOCKS proxy by detecting the microsocks port and making a request through it
253259
</details>
254260

@@ -283,7 +289,8 @@ Displays everything you need:
283289
- All 4 tunnel endpoints
284290
- DNSTT public key
285291
- `dnst://` share URLs for dnstc CLI client
286-
- `slipnet://` deep-link URLs for SlipNet Android app (tap to import)
292+
- `slipnet://` deep-link URLs for SlipNet Android app (tap to import) — includes SOCKS credentials when auth is enabled
293+
- SOCKS proxy credentials (if authentication was enabled) or warning if open
287294
- SSH tunnel credentials (if configured) or warning if not set up
288295
- List of DNS resolvers for SlipNet
289296
- Client app download link
@@ -332,19 +339,33 @@ Create these records in your **Cloudflare** dashboard:
332339
## ⌨️ Usage
333340

334341
```bash
335-
# 🚀 Run the interactive setup wizard
342+
# 🚀 Run the interactive setup wizard (first time)
336343
sudo bash dnstm-setup.sh
337344

345+
# 🎛️ Post-setup management menu (all actions in one place)
346+
sudo bash dnstm-setup.sh --manage
347+
338348
# 🔧 Set custom DNSTT MTU (default: 1232, range: 512-1400)
339349
sudo bash dnstm-setup.sh --mtu 1200
340350

341351
# 🌐 Add a backup domain with custom MTU
342352
sudo bash dnstm-setup.sh --add-domain --mtu 1200
343353

354+
# 🚇 Add a single tunnel (interactive)
355+
sudo bash dnstm-setup.sh --add-tunnel
356+
357+
# ❌ Remove a specific tunnel (interactive picker)
358+
sudo bash dnstm-setup.sh --remove-tunnel
359+
# Or specify the tag directly
360+
sudo bash dnstm-setup.sh --remove-tunnel slip1
361+
344362
# 👤 Manage SSH tunnel users (add, list, update, delete)
345363
sudo bash dnstm-setup.sh --users
346364

347-
# 🗑️ Remove all installed components
365+
# 📊 Show all tunnels, credentials, and share URLs
366+
sudo bash dnstm-setup.sh --status
367+
368+
# 🗑️ Remove ALL installed components (nuclear option)
348369
sudo bash dnstm-setup.sh --uninstall
349370

350371
# ❓ Show help (no root needed)
@@ -454,6 +475,19 @@ The setup generates two types of share URLs for easy client configuration:
454475
After setup, manage your tunnels with these commands:
455476

456477
```bash
478+
# 🎛️ Interactive management menu (all actions below in one menu)
479+
sudo bash dnstm-setup.sh --manage
480+
481+
# 📊 Show everything: tunnels, credentials, share URLs (all in one)
482+
sudo bash dnstm-setup.sh --status
483+
484+
# 🚇 Add a single tunnel (interactive — pick transport, backend, domain, tag)
485+
sudo bash dnstm-setup.sh --add-tunnel
486+
487+
# ❌ Remove a specific tunnel (interactive picker or pass tag directly)
488+
sudo bash dnstm-setup.sh --remove-tunnel
489+
sudo bash dnstm-setup.sh --remove-tunnel slip1
490+
457491
# 📋 View all tunnels and their status
458492
dnstm tunnel list
459493

@@ -484,7 +518,10 @@ dnstm router stop
484518
dnstm router start
485519

486520
# 🧪 Test the SOCKS proxy locally (check port with: ss -tlnp | grep microsocks)
521+
# Without authentication:
487522
curl --socks5 127.0.0.1:<MICROSOCKS_PORT> https://api.ipify.org
523+
# With SOCKS5 authentication:
524+
curl --socks5-basic --proxy socks5://127.0.0.1:<MICROSOCKS_PORT> --proxy-user user:pass https://api.ipify.org
488525
```
489526

490527
---
@@ -513,6 +550,54 @@ If `sshtun-user` is not installed, the script will automatically download and co
513550

514551
---
515552

553+
## 🔐 SOCKS Proxy Authentication
554+
555+
During setup (Step 9), the wizard asks whether to enable SOCKS5 authentication on the microsocks proxy. This controls access to the **SOCKS tunnels** (`t2` and `d2` subdomains).
556+
557+
### With Authentication (Recommended)
558+
559+
When enabled, microsocks requires a **username and password** for every SOCKS5 connection. This means:
560+
- Only clients with the correct credentials can use the tunnel
561+
- The `slipnet://` share URLs automatically include the credentials (clients auto-configure)
562+
- The `authMode` field in SlipNet is set to `1` (username/password)
563+
564+
The credentials are applied by adding `-u user -P pass` flags to the microsocks systemd service.
565+
566+
### Without Authentication
567+
568+
When disabled, the proxy is **open** — anyone who can resolve the DNS tunnel domain can connect. Security relies solely on the domain being secret.
569+
570+
### Changing Auth After Setup
571+
572+
To **add** authentication to an existing open proxy:
573+
574+
```bash
575+
# 1. Edit the microsocks service
576+
sudo systemctl edit --full microsocks.service
577+
578+
# 2. Find the ExecStart line and append: -u youruser -P yourpass
579+
# Example: ExecStart=/usr/local/bin/microsocks -p 19801 -u proxy -P s3cret
580+
581+
# 3. Reload and restart
582+
sudo systemctl daemon-reload
583+
sudo systemctl restart microsocks
584+
```
585+
586+
To **remove** authentication:
587+
588+
```bash
589+
# 1. Edit the service and remove the -u and -P flags from ExecStart
590+
sudo systemctl edit --full microsocks.service
591+
592+
# 2. Reload and restart
593+
sudo systemctl daemon-reload
594+
sudo systemctl restart microsocks
595+
```
596+
597+
> **Note:** When adding a backup domain with `--add-domain`, the script auto-detects existing SOCKS authentication from the microsocks service and includes the credentials in the generated share URLs.
598+
599+
---
600+
516601
## 🗑️ Uninstall
517602

518603
To remove everything installed by this script:
@@ -827,10 +912,10 @@ sudo bash dnstm-setup.sh --users
827912
6. 🔍 **بررسی پورت 53** — تأیید اینکه DNS Router روی پورت 53 گوش می‌دهد
828913
7. 🚇 **ایجاد تانل‌ها** — تنظیم MTU و ساخت ۴ تانل (Slipstream+SOCKS، DNSTT+SOCKS، Slipstream+SSH، DNSTT+SSH)
829914
8. ▶️ **شروع سرویس‌ها** — راه‌اندازی روتر و تمام تانل‌ها
830-
9. 🧦 **بررسی پروکسی SOCKS** — تست microsocks (تشخیص خودکار پورت)
915+
9. 🧦 **بررسی پروکسی SOCKS**انتخاب فعال‌سازی احراز هویت SOCKS5 (نام کاربری/رمز عبور)، تست microsocks (تشخیص خودکار پورت)
831916
10. 👤 **کاربر SSH** — ایجاد کاربر محدود برای تانل SSH (بدون آن تانل‌های SSH کار نمی‌کنند)
832917
11. 🧪 **تست‌های نهایی** — ۶ تست خودکار برای تأیید عملکرد
833-
12. 📊 **خلاصه** — نمایش تمام اطلاعات اتصال، لینک‌های dnst:// (برای dnstc) و slipnet:// (برای اپ SlipNet)
918+
12. 📊 **خلاصه** — نمایش تمام اطلاعات اتصال، اطلاعات احراز هویت SOCKS، لینک‌های dnst:// (برای dnstc) و slipnet:// (برای اپ SlipNet)
834919

835920
---
836921

@@ -843,7 +928,7 @@ sudo bash dnstm-setup.sh --users
843928
| 🔑 **Slipstream + SSH** | `s2` | QUIC + TLS + SSH | ~60 KB/s | نیاز به نام کاربری و رمز عبور |
844929
| 🔑 **DNSTT + SSH** | `ds2` | Noise + Curve25519 + SSH | ~40 KB/s | جایگزین SSH اگر Slipstream مسدود شود |
845930

846-
> 🧦 **بک‌اند SOCKS:** هر کسی که دامنه را بداند می‌تواند وصل شود. ساده‌تر و سریع‌تر.
931+
> 🧦 **بک‌اند SOCKS:** امکان فعال‌سازی احراز هویت SOCKS5 با نام کاربری و رمز عبور. بدون احراز هویت، هر کسی که دامنه را بداند می‌تواند وصل شود.
847932
>
848933
> 🔑 **بک‌اند SSH:** نیاز به نام کاربری و رمز عبور. حتی اگر رمز لو برود، کاربر فقط می‌تواند تانل بزند و دسترسی shell ندارد.
849934
@@ -923,6 +1008,19 @@ sudo bash dnstm-setup.sh --users
9231008
</div>
9241009

9251010
```bash
1011+
# 🎛️ منوی مدیریت تعاملی (تمام عملیات در یک منو)
1012+
sudo bash dnstm-setup.sh --manage
1013+
1014+
# 📊 نمایش همه چیز: تانل‌ها، اطلاعات احراز هویت، لینک‌های اشتراک‌گذاری
1015+
sudo bash dnstm-setup.sh --status
1016+
1017+
# 🚇 افزودن یک تانل (تعاملی — انتخاب پروتکل، بک‌اند، دامنه)
1018+
sudo bash dnstm-setup.sh --add-tunnel
1019+
1020+
# ❌ حذف یک تانل خاص (تعاملی یا مستقیم)
1021+
sudo bash dnstm-setup.sh --remove-tunnel
1022+
sudo bash dnstm-setup.sh --remove-tunnel slip1
1023+
9261024
# 📋 نمایش تمام تانل‌ها و وضعیت آنها
9271025
dnstm tunnel list
9281026

@@ -952,7 +1050,10 @@ dnstm router stop
9521050
dnstm router start
9531051

9541052
# 🧪 تست پروکسی SOCKS (بررسی پورت: ss -tlnp | grep microsocks)
1053+
# بدون احراز هویت:
9551054
curl --socks5 127.0.0.1:<MICROSOCKS_PORT> https://api.ipify.org
1055+
# با احراز هویت SOCKS5:
1056+
curl --socks5-basic --proxy socks5://127.0.0.1:<MICROSOCKS_PORT> --proxy-user user:pass https://api.ipify.org
9561057
```
9571058

9581059
<div dir="rtl">

0 commit comments

Comments
 (0)