diff --git a/AGENTS.md b/AGENTS.md index 0b74e04..4b49bf4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,20 +15,21 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) with **Adre - `net_tls.h`: shared C++20 TCP + OpenSSL TLS + STARTTLS socket class (`NetStream`), HTTP/HTTPS `GET` client (`httpGet`), MD5/CSPRNG helpers, and RFC 2047 / Base64 / Quoted-Printable MIME decoders. - `pjsip_media.h`: PJSIP (`pjproject` / `pjmedia-codec/g722` & `pjmedia/alaw_ulaw`) ITU-T G.722 wideband 16 kHz SB-ADPCM and G.711 PCMU/PCMA codec implementation for `sip.so`. - `monotone.h` + `bananarchy_melody.cpp` (`/usr/bin/bananarchy-melody`): Nokia RTTTL (`.nrt`, `.rtttl`, `.rtx`), Ericsson eMelody (`.emy`), and IrDA iMelody (`.imy`) monophonic ringtone parser and 48 kHz WAV synthesizer. - - `locker_plugin.cpp` (`locker.so` / `xlocker`) + `verify_passcode.c` (`/usr/bin/bananarchy-verify-passcode`), `passcode_plugin.cpp` (`passcode.so` / `xpasscode`), `dialer_plugin.cpp` (`dialer.so` / `xdialer`), `calllog_plugin.cpp` (`calllog.so` / `xcalllog`), `callscreen_plugin.cpp` (`callscreen.so` / `xcallscreen`), `contacts_plugin.cpp` (`contacts.so` / `xcontacts`), `sms_plugin.cpp` (`sms.so` / `xsms`), `files_plugin.cpp` (`files.so` / `xfiles`), `camera_plugin.cpp` (`camera.so` / `xcamera`), `themes_plugin.cpp` (`themes.so` / `xthemes`), `modem_plugin.cpp` (`modem.so` / `xmodem`), `networks_plugin.cpp` (`networks.so` / `xnetworks` / `xbluetooth`), `ringtones_plugin.cpp` (`ringtones.so` / `xringtones`), `wallpapers_plugin.cpp` (`wallpapers.so` / `xwallpapers` / `xbackground`), `music_plugin.cpp` (`music.so` / `xmusic` / `xplayer`), `sip_plugin.cpp` (`sip.so` / `xsip`), `email_plugin.cpp` (`email.so` / `xemail` / `xmail`), `irc_plugin.cpp` (`irc.so` / `xirc`), `tox_plugin.cpp` (`tox.so` / `xtox`), `smallweb_plugin.cpp` (`smallweb.so` / `xkopher` / `kopher` / `xsmallweb`), `webarchy_plugin.cpp` (`webarchy.so` / `webarchy` / `xwebarchy`), `gps_plugin.cpp` (`gps.so` / `xgps` / `xmaps` / `xnav`). - - `dwm_plugin_runner.c`: lightweight `/usr/bin/dwm-plugin` launcher symlinked by `xlocker`, `xpasscode`, `xdrawer`, `xdialer`, `xcalllog`, `xcallscreen`, `xcontacts`, `xsms`, `xfiles`, `xcamera`, `xthemes`, `xmodem`, `xnetworks`, `xbluetooth`, `xringtones`, `xwallpapers`, `xbackground`, `xmusic`, `xplayer`, `xsip`, `xemail`, `xmail`, `xirc`, `xtox`, `xkopher`, `kopher`, `xsmallweb`, `webarchy`, `xwebarchy`, `xgps`, `xmaps`, `xnav`, `dmenu`, and `xdmenu`. + - `locker_plugin.cpp` (`locker.so` / `xlocker`) + `verify_passcode.c` (`/usr/bin/bananarchy-verify-passcode`), `passcode_plugin.cpp` (`passcode.so` / `xpasscode`), `dialer_plugin.cpp` (`dialer.so` / `xdialer`), `calllog_plugin.cpp` (`calllog.so` / `xcalllog`), `callscreen_plugin.cpp` (`callscreen.so` / `xcallscreen`), `contacts_plugin.cpp` (`contacts.so` / `xcontacts`), `sms_plugin.cpp` (`sms.so` / `xsms`), `files_plugin.cpp` (`files.so` / `xfiles`), `camera_plugin.cpp` (`camera.so` / `xcamera`), `themes_plugin.cpp` (`themes.so` / `xthemes`), `modem_plugin.cpp` (`modem.so` / `xmodem`), `networks_plugin.cpp` (`networks.so` / `xnetworks` / `xbluetooth`), `ringtones_plugin.cpp` (`ringtones.so` / `xringtones`), `wallpapers_plugin.cpp` (`wallpapers.so` / `xwallpapers` / `xbackground`), `music_plugin.cpp` (`music.so` / `xmusic` / `xplayer`), `sip_plugin.cpp` (`sip.so` / `xsip`), `email_plugin.cpp` (`email.so` / `xemail` / `xmail`), `irc_plugin.cpp` (`irc.so` / `xirc`), `tox_plugin.cpp` (`tox.so` / `xtox`), `smallweb_plugin.cpp` (`smallweb.so` / `xkopher` / `kopher` / `xsmallweb`), `webarchy_plugin.cpp` (`webarchy.so` / `webarchy` / `xwebarchy`), `gps_plugin.cpp` (`gps.so` / `xgps` / `xmaps` / `xnav`), `privacy_plugin.cpp` (`privacy.so` / `xprivacy` / `privacy`). + - `dwm_plugin_runner.c`: lightweight `/usr/bin/dwm-plugin` launcher symlinked by `xlocker`, `xpasscode`, `xdrawer`, `xdialer`, `xcalllog`, `xcallscreen`, `xcontacts`, `xsms`, `xfiles`, `xcamera`, `xthemes`, `xmodem`, `xnetworks`, `xbluetooth`, `xringtones`, `xwallpapers`, `xbackground`, `xmusic`, `xplayer`, `xsip`, `xemail`, `xmail`, `xirc`, `xtox`, `xkopher`, `kopher`, `xsmallweb`, `webarchy`, `xwebarchy`, `xgps`, `xmaps`, `xnav`, `xprivacy`, `privacy`, `dmenu`, and `xdmenu`. - `src/xdrawer/`: global phone controls overlay (`xdrawer.so` / `xdrawer`), toggled by pressing both softkeys simultaneously. - `src/sxmo-st/`: patched `st` terminal with HarfBuzz OpenType ligatures (`Fira Code`), `XIM` (`fcitx5-t9`), and live `SIGUSR1` `.Xresources` reload. - `src/fcitx5-t9/`: 6-mode keypad input method (`abc`, `Abc`, `ABC`, `Sym`, `Ctl`, `123` + `*` long-press `Ctrl+` latch) with fixed bottom preedit bar (`Y=290, H=30`). - `src/games/`: standalone keypad-driven `240x320` X11 games and emulators (`snake.cpp` -> `/usr/bin/snake`, `tetris.cpp` -> `/usr/bin/tetris`, `scoundrel.cpp` -> `/usr/bin/scoundrel`, `gambatte_phone.cpp` + `gambatte/` -> `/usr/bin/gambatte` / `/usr/bin/gbemu`, and `remedy/` -> `/usr/bin/remedy` / `/usr/bin/j2me` J2ME MIDP 2.0 / CLDC 1.1 + JSR-184 M3G 3D emulator) with built-in 5x7 bitmap fonts, NeoUI integration, `timerfd`-driven pacing, and offscreen `Pixmap` / EGL double buffering. - `src/msm8905-cam/` & `src/leds-msm8905-torch/`: out-of-tree Linux `6.12.1-msm8916` kernel modules for the rear `GC2395` / `GC2385` / `GC2365` camera (`/dev/video0`) and `SY7807` torch LED (`white:torch`) / WCD codec init / PM8909 `PON` shutdown. - `overlay/rootfs/`: system configuration overlay applied over the target rootfs (kept in sync with `prebuilt/`). -- `prebuilt/`: cross-compiled `armv7` binaries and kernel modules (`sxmo-x11`, `fcitx5-t9`, `xlibre`, `kernel-6.12.1-msm8916`, `bantam`, `games`). +- `prebuilt/`: cross-compiled `armv7` binaries and kernel modules (`sxmo-x11`, `fcitx5-t9`, `xlibre`, `kernel-6.12.1-msm8916`, `bantam`, `games`, `gsocket`). - `devices/` & `patches/`: device trees (`.dts`/`.dtb`), MIPI-DBI panel init sequences, and upstream patch sets. ## 3. Build and image generation commands All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7` sysroot) and automatically update both `prebuilt/` and `overlay/rootfs/`: -- `./scripts/build-sxmo-x11.sh` — builds `libneoui.so`, `st`, `dmenu.so`, `dwm`, `dwm-plugin`, `bananarchy-verify-passcode`, `bananarchy-melody`, `sxmo_vibrate`, and all C++ `.so` plugins (`locker`, `passcode`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `webarchy`, `gps`). +- `./scripts/build-sxmo-x11.sh` — builds `libneoui.so`, `st`, `dmenu.so`, `dwm`, `dwm-plugin`, `bananarchy-verify-passcode`, `bananarchy-melody`, `sxmo_vibrate`, and all C++ `.so` plugins (`locker`, `passcode`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `webarchy`, `gps`, `privacy`). +- `./scripts/build-gsocket.sh` — fetches and cross-compiles `gsocket` (`gs-netcat`, `gsocket`, `gs-sftp`, `gs-mount`, `blitz`) for `armv7`. - `./scripts/build-dmenu.sh` — rebuilds only `dmenu.so`, `stest`, `dmenu_path`, and `dmenu_run`. - `./scripts/build-games.sh` — builds standalone X11 games and emulators in `src/games/` (`snake`, `tetris`, `scoundrel`, `gambatte` / `gbemu`, `remedy` / `j2me`). - `./scripts/build-fcitx5-t9.sh` — builds `src/fcitx5-t9` (`libt9.so` / `t9.so`). diff --git a/CHANGELOG.md b/CHANGELOG.md index 631cd3a..591b763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,23 +9,53 @@ Release versions follow the `
` format (where `2026` is `a`, --- +## Build `a1105` — codename `vendetta` (2026-11-05) + +### New features and improvements +- **Privacy Center (`privacy.so` / `xprivacy` / `privacy`) and tunneling stack (`tor`, `gsocket`, `gs-warp`, `openvpn`, `wireguard-tools`, `bananarchy-privacy-ctl`)**: + - Cross-compiled `gsocket` (`gs-netcat`, `gsocket`, `gs-sftp`, `gs-mount`, `blitz`) for `armv7` (`./scripts/build-gsocket.sh`), installed `tor`, `openvpn`, `wireguard-tools` (`wg`, `wg-quick`), `iptables`, `ip6tables`, `iproute2`, and `bash`, enabled `xt_owner.ko.zst` (`CONFIG_NETFILTER_XT_MATCH_OWNER=m`) and `nft_redir.ko.zst` (`CONFIG_NFT_REDIR=m`) in the `6.12.1-msm8916` kernel, and installed the `gs-warp` client (`/usr/bin/gs-warp-simple.sh`, `/usr/bin/gs-warp`, `/etc/gs-warp/client.ovpn`, and `~/.config/gs-warp/client.ovpn`). + - Added `/usr/bin/bananarchy-privacy-ctl` and the 5-tab NeoUI **Privacy Center (`privacy.so` / `xprivacy` / `privacy`)** DWM plugin (`1:Tor`, `2:Warp`, `3:OVPN`, `4:GS`, `5:WG`) to start/stop and route native phone traffic and/or Wi-Fi hotspot (`10.42.0.0/24`) and USB-tethered (`usb0`) traffic through **Tor** (`TransPort 9040` / `DNSPort 9053`), **GS-Warp** (`tun_gswarp`, `table 210`, custom GSocket secret string), **OpenVPN** (`tun_ovpn`, `table 220`, custom `.ovpn` file picker), **GSocket single TCP port** (`gs-netcat`, custom secret and TCP port `iptables -t nat REDIRECT`), and **WireGuard** (`wg0`, `table 230`, `fwmark 0xca6c`, keypair generator, `.conf` importer, and custom key/endpoint editor). + - Added automatic tunneled DNS resolution (`sync_dns_resolv` managing `/etc/resolv.conf` with clean backup/restore, `DNSPort 9053` UDP redirection for Tor, `dhcp-option DNS` extraction and `DNAT` through `tun_gswarp` / `tun_ovpn` / `wg0` for VPN tunnels, and `BP6_DNS_OUT` / `BP6_DNS_FWD` IPv6 port 53 leak blocking). + - Disabled all background OpenRC runlevel links for `tor`, `openvpn`, `iptables`, `ip6tables`, and `nftables` so zero background daemons or CPU wakeups occur when tunnels are off, and blocked `xprivacy` and `bananarchy-privacy-ctl` (while automatically running `bananarchy-privacy-ctl stop-all`) in Duress Mode. +- **Webarchy Web browser (`webarchy.so` / `webarchy` / `xwebarchy`)**: + - Implemented a full-featured `240x320` HTML5/CSS3/JS web browser built on WPE / WebKit (`webkit2gtk-4.1` + `libwpe-1.0` + `libwpebackend-fdo-1.0`) with Adreno 304 hardware acceleration (`WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS` and WebGL) and 512 MB RAM pressure tuning (`160 MB` WebProcess cap and lazy engine startup), `Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0` as the default User-Agent with preset and custom User-Agent override (`~/.config/sxmo/webarchy_ua.txt`), `UTF-8` default encoding fallback, default dark browser theme preference (`prefers-color-scheme: dark` and `color-scheme: light dark`), `Noto Sans` / `Noto Serif` (`font-noto` + `font-noto-emoji`) as the default non-monospace web and form control fonts and `Fira Code` with OpenType ligatures as the monospace font, full GStreamer multimedia (`MediaSource` / MSE, WebAudio, inline `
` format (where `2026` is `a`, - Locks the UI theme and wallpaper exclusively to `NordFrost.xth` and `/usr/share/wallpapers/nordic-peaks.png` inside `xthemes` and `xwallpapers`. - Spoofs `*#06#` IMEI queries in `xdialer` (`dialer.so`) with session-persistent Luhn-valid random IMEIs (`/tmp/bananarchy_duress_imei`) generated from the device's real 8-digit TAC prefix (`/tmp/bananarchy_real_tac`) plus random 6-digit serial numbers and recomputed Luhn check digits. - Keeps subsequent lock/unlock cycles during the duress session in duress mode whether the user re-enters the duress passcode or the regular passcode, restoring the normal `/home/user` profile automatically on reboot or poweroff. -- **Bluetooth audio (`A2DP`, `HSP/HFP`), HID peripherals (keyboards, mice, gamepads), discoverability & alias settings, active connection badges, and OBEX file transfer (`bananarchy-bt-obex`, `xnetworks`, `xdrawer`, `xfiles`)**: - - Configured BlueZ (`/etc/bluetooth/main.conf`, `/etc/bluetooth/input.conf`) and WirePlumber (`50-bluetooth.conf`) with full **A2DP** (`a2dp_sink`, `a2dp_source` with `sbc_xq`, `aac`, `ldac`, `aptx`, `aptx_hd`), **HSP/HFP** (`hsp_hs`, `hsp_ag`, `hfp_hf`, `hfp_ag` with `mSBC` wideband speech and hardware volume), and **HID / BLE HOGP** (`uhid`, `hidp`, `uinput`, `rfcomm`, `bnep`, `xpad`) profile support, and added `Bluetooth` as a selectable audio output/input route in `sxmo_audio.sh`, `xdrawer`, and `dmenu` Audio menu (plus automatic PipeWire `"default"` ALSA routing in `gambatte` and `remedy` when Bluetooth audio is active). - - Added **Discoverable** (`ON (Visible)` / `OFF (Hidden)`, persisted in `~/.config/sxmo/bt_discoverable`) and **Bluetooth Device Name** (`Name: [Edit]` with a multi-tap modal editor persisted in `~/.config/sxmo/bt_name` and applied via `bluetoothctl system-alias` independently of the system hostname) rows to the `3:Bluetooth` tab of `xnetworks`, alongside active connection count headers (`Bluetooth: ON (N Active)`), pinned active device cards with live profile and battery badges (`[ACTIVE: A2DP]`, `[ACTIVE: HSP/HFP]`, `[ACTIVE: HID Gamepad]`, `[ACTIVE: HID Keyboard]`, `[ACTIVE: HID Mouse]`), and a **Switch Audio (A2DP / HSP-HFP)** action. - - Added an automatic `/dev/uinput` gamepad-to-keypad bridge (`Bananarchy BT Gamepad Bridge`) inside `/usr/bin/bananarchy-bt-obex` so Bluetooth/USB gamepads (`D-Pad` / `Left Stick` -> `Up`/`Down`/`Left`/`Right`, `South/A` -> `Enter`, `East/B` -> `8`, `West/X` -> `5`, `North/Y` -> `6`, `Start` -> `2`, `Select` -> `3`, `L1`/`R1` -> `Left`/`Right softkey`, `L2`/`R2` -> `*`/`0`, `Mode` -> `Escape`) control all NeoUI apps and games (`snake`, `tetris`, `scoundrel`, `gambatte`, `remedy`) out of the box, and added dynamic `XFixes` cursor visibility in `dwm` (and `ButtonPress` handling in `dwm` and `libneoui.so`) so connecting a Bluetooth mouse shows the cursor on movement/click and hides it automatically on keypad use. - - Added `/usr/bin/bananarchy-bt-obex` (`daemon|stop|status|send|devices`) wrapping BlueZ `obexpushd` / `obexd` and `obexftp` / `bt-obex` so enabling Bluetooth (`sxmo_bluetoothtoggle.sh on` or `xnetworks`) automatically starts an OBEX Object Push receiver saving incoming files to `~/Downloads/` with toast and sound notifications, plus a live **OBEX File Receiver** status widget in `xnetworks` and **Send via Bluetooth** in `xfiles`. +- **Bluetooth OBEX file transfer (`bananarchy-bt-obex`, `xnetworks`, and `xfiles`)**: + - Added `/usr/bin/bananarchy-bt-obex` (`daemon|stop|status|send|devices`) wrapping BlueZ `obexpushd` / `obexd` and `obexftp` / `bt-obex` so enabling Bluetooth (`sxmo_bluetoothtoggle.sh on` or `xnetworks`) automatically starts an OBEX Object Push receiver saving incoming files to `~/Downloads/` with toast and sound notifications. + - Added a live **OBEX File Receiver** status widget (and `#` shortcut to open `~/Downloads/` in `xfiles`) to the `3:Bluetooth` tab of `xnetworks`, and added **Send via Bluetooth** with an interactive device-picker modal to **file manager (`xfiles`)**. - **Native Scoundrel (`scoundrel`) roguelike solitaire card game**: - Built a native `240x320` C++20 X11/NeoUI implementation of the Zach Gage / Kurt Bieg roguelike solitaire dungeon crawler (`src/games/scoundrel.cpp` -> `/usr/bin/scoundrel`, based on Luxferre's C89/GB ports), featuring custom graphical playing cards, suit icons, health bar, equipped weapon and max-monster-level display, combat choice modal (`[1] Weapon` vs `[2] Barehanded`), rules/help and pause modals, direct `neoui_poll_event()` softkey and keypad controls (`1`–`4` or `D-Pad` + `5`/`OK` to play a room card, `Left softkey` or `*` to flee the room, `#` for rules, `Right softkey` or `0` for menu, and dual-softkey `xdrawer` handoff), and persistent stats in `~/.local/share/scoundrel_scores.txt`. - **Dynamic NeoUI theme synchronization for `dunst` notifications (`bananarchy-sync-dunst-theme`)**: @@ -58,17 +86,9 @@ Release versions follow the `
` format (where `2026` is `a`, - Added a dedicated **Ringtone Viewer (`RingtoneView`)** to **file manager (`xfiles`)** for `.nrt`, `.rtttl`, `.rtx`, `.emy`, and `.imy` files, displaying melody metadata, a graphical piano-roll pitch contour, a scrollable note sequence, live audio preview (`*` / `Center OK`), `Left`/`Right` folder stepping, **Left softkey (`Set Ring`)** to set as the call ringtone, **`#`** to set as the notification/SMS sound, and **Actions** menu items (`Preview Ringtone`, `Set as Ringtone`, `Set as Notif / SMS Sound`, `Open in Ringtones App`, `Play in Music Player`, `View Ringtone Text`, `Edit in Text Editor`), plus `.nrt`/`.rtttl`/`.rtx`/`.emy`/`.imy` playback in `xmusic`. - Expanded **ringtones manager (`xringtones`)** to 3 tabs (`1:Ringtone`, `2:Notif/SMS`, `3:Settings`, plus `xringtones --notif` and **Notification Sound** in the `Notifs` menu) with a dedicated **Notification / SMS Sound** configuration (`~/.config/sxmo/notif_sound` and `SXMO_TEXTSOUND` in `~/.config/sxmo/ringsettings`, including `None (Mute Sound)`) wired directly into the system notification manager (`sxmo_notifs.sh`, `sxmo_hook_notification.sh`, `sxmo_hook_sms.sh`, `xirc`, and `xtox`) and incoming call ringer (`sxmo_hook_ring.sh`). - **Battery and idle power optimizations**: - - Added `msm8905_cam_hw_deinit()` to the rear camera kernel driver (`src/msm8905-cam/msm8905-cam.c`) and wired it into `streamoff`, last-file-handle `release`, and module `exit` so closing `xcamera` (or stopping V4L2 streaming) immediately stops the CSI-2 stream, asserts sensor hardware standby (`GPIO_CAM_RESET=0`, `GPIO_CAM_STANDBY=0`, `GPIO_CAM_VDIG=0`, `GPIO_CAM_MCLK0=0x0001`), gates all 20 `CAMSS` `CBCR` branch clocks and 6 `RCG` roots (`200 MHz` `vfe0` / `csi0` / `camss_top_ahb` and `24 MHz` `mclk0`), releases `SMMU` vote clocks, and powers down the `VFE GDSC` domain. - - Enabled `workqueue.power_efficient=Y` and `printk.console_suspend=Y` in `/etc/local.d/10-power-save.start`, lowered `78b9000.spi` runtime PM `autosuspend_delay_ms` from `1000 ms` to `50 ms`, enabled runtime PM (`power/control=auto`) across `1c00000.gpu`, `*.spi`, `*.sdhci`, and `*.serial`, and removed the legacy `ttyMSM0` serial `getty` rule from `scripts/configure-rootfs-from-scratch.sh`. - - Added VM writeback (`dirty_writeback_centisecs=6000`), `printk` throttling, `sched_autogroup_enabled=0`, `nmi_watchdog=0`, `schedutil` governor rate-limit tuning (`rate_limit_us=2000`, fixing the 6.44s default caused by `qcom-cpufreq` `UINT_MAX` transition latency so cores downclock to `200 MHz` within `2 ms`), Wi-Fi powersave (`iw dev wlan0 set power_save on`), USB/platform runtime PM (`power/control = auto`), and `runtime_status = suspended` power management on the `7864900.sdhci` microSD host controller (with `bias-pull-up` on `sdc2-cd-off-state`, hardware GPIO 38 hotplug detection, and unified Adreno 304 GPU / IOMMU device-tree nodes across all 5 device `.dts`/`.dtb` files). - - Replaced the 120ms busy-wait loop in `gps.so` (`OsmTileCache::workerLoop`) with `std::condition_variable`, cached Dual-SIM status in `/tmp/sxmo_dsds_active` to avoid repeated `qmicli` wakes on single-SIM setups, set the DSDS `msm-modem-uim-selection` `select()` timeout to infinite (`None`, pure `AF_QIPCRTR` event-driven wait) while the screen is locked and `600s` when unlocked, and set display framebuffer `bl_power = 4` (`FB_BLANK_POWERDOWN`) across `dwm`, `locker.so`, and `sxmo_wm.sh` whenever the screen is blanked. - - Added `neoui_next_timeout_ms()` to `libneoui.so`, wired GLib `GMainContext` file descriptors and `"load-failed"` / `closeWindow()` load-stop handling into `webarchy.so` (along with `NO_AT_BRIDGE=1` and `GTK_A11Y=none`), added `inotify` directory watching to `sms.so`, and eliminated idle periodic `poll()` timers across `dialer.so`, `calllog.so`, `contacts.so`, `sms.so`, `xdrawer.so`, `locker.so`, `email.so`, `irc.so`, `smallweb.so`, `tox.so`, `sip.so`, and `webarchy.so` so visible and background plugins sleep at `0%` CPU unless a transient timer (`softkey` chord, multi-tap window, or toast expiry) is active. - - Increased `conky` desktop clock refresh interval to `15.0s` and froze `conky` (`SIGSTOP`/`SIGCONT`) whenever the screen is off or locked (`sxmo_hook_screenoff.sh`, `sxmo_hook_lock.sh`, `dwm`, and `locker.so`), skipped `dwm` `drawbar()` Xorg/Glamor/SPI redraws and `sxmo_hook_statusbar.sh` process spawns whenever `bl_power != 0` or `/tmp/bananarchy_screen_locked` exists (with immediate bar refresh on wake/unlock), wrapped background spawns in double-fork subshells `( ... & )` across `bananarchy-x11-session.sh`, `sxmo_modemmonitor.sh`, `sxmo_hook_start.sh`, `sxmo_hook_postwake.sh`, and `msm-modem-uim-selection` to eliminate zombie child accumulation, and drained queued X11 `UnmapNotify` events in `neoui_hide()` so all resident DWM plugins sleep at `0%` CPU when hidden. -- **Universal Power button (`dmenu power`) access, ReMEdy `Call (green)` pause menu, JSR expansion, and 64 MB mark-and-sweep GC**: - - Updated `dwm`, `dmenu`, `xdrawer`, `libneoui.so`, `sxmo_multikey.sh`, all standalone Xlib DWM plugins, and standalone games (`scoundrel`, `gambatte`, `remedy`) so pressing **End / Power (red)** (`XF86PowerOff`, keycode `124`) from any active window or menu immediately opens (or toggles) the system **Power menu (`dmenu power`)** while mapped **Call (green)** (`XF86Phone` / `XF86PickupPhone`) and `500 ms` **Right softkey** hold in `remedy` open the **ReMEdy Pause Menu**. - - Upgraded **ReMEdy (`remedy` / `j2me`)** with a `64 MB` heap budget and mark-and-sweep garbage collector (`System.gc()` / `Runtime.gc()`, `freeSlots_` object reuse, and full heap/JAR release on MIDlet exit), synchronous `Canvas.serviceRepaints()`, `Thread.yield()` / `Thread.sleep()` background thread stepping, synthetic native static field storage (`System.out`, `System.err`, `List.SELECT_COMMAND`, `AlertType.*`, `Boolean.TRUE/FALSE`), exact `String` reference preservation in `List.getString()` and `ChoiceGroup.getString()` (for `MeBoy` / `GTA 2` GBC-to-J2ME cartridges), `java.io.InputStreamReader` / `OutputStreamWriter`, `java.lang.Float` / `Double` / `Character`, **JSR-75** (`FileSystemRegistry` / `FileConnection`), **JSR-82** (`javax.bluetooth.*`), **JSR-120** (`javax.wireless.messaging.*`), **JSR-135** (`MIDIControl`), full **Nokia `DirectGraphics`** (`drawPixels`, `getPixels`, `fillPolygon`, `drawPolygon`, `fillTriangle`, `drawTriangle`, `setARGBColor`), and automatic/configurable sub-QVGA (`128x128`, `128x160`, `176x208`, `176x220`) canvas scaling (`Asphalt 6: Adrenaline`). -- **Literal caller ID contact matching (`sxmo_contacts.sh`, `sxmo_common.sh`, `sxmo_modemsendsms.sh`)**: - - Replaced unescaped `grep -i "$NUMBER"` contact lookups with literal matching so carrier service numbers containing regex metacharacters (such as `*121#`) never match arbitrary contact entries. + - Added VM writeback (`dirty_writeback_centisecs=6000`), `printk` throttling, `sched_autogroup_enabled=0`, `nmi_watchdog=0`, `schedutil` governor rate-limit tuning (`rate_limit_us=2000`, fixing the 6.44s default caused by `qcom-cpufreq` `UINT_MAX` transition latency so cores downclock to `200 MHz` within `2 ms`), Wi-Fi powersave (`iw dev wlan0 set power_save on`), USB/platform runtime PM (`power/control = auto`), and automatic unbinding of the `7864900.sdhci` microSD host controller when no card is inserted (along with `bias-pull-up` on `sdc2-cd-off-state` and unified Adreno 304 GPU / IOMMU device-tree nodes across all 5 device `.dts`/`.dtb` files). + - Replaced the 120ms busy-wait loop in `gps.so` (`OsmTileCache::workerLoop`) with `std::condition_variable`, cached Dual-SIM status in `/tmp/sxmo_dsds_active` to avoid repeated `qmicli` wakes on single-SIM setups, increased the DSDS idle `select()` timeout to `300s`, and set display framebuffer `bl_power = 4` (`FB_BLANK_POWERDOWN`) whenever the screen is blanked. + - Increased `conky` desktop clock refresh interval to `15.0s` and froze `conky` (`SIGSTOP`/`SIGCONT`) whenever the screen is off or locked, replaced polling in `sxmo_modemmonitor.sh` with event-driven `dbus-monitor`, skipped redundant `sxmo_hook_statusbar.sh` updates while `screenoff` or locked, and drained queued X11 `UnmapNotify` events in `neoui_hide()` so all resident DWM plugins sleep at `0%` CPU when hidden. --- diff --git a/MANUAL.md b/MANUAL.md index d0ebbcb..c0bf7a0 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -291,7 +291,7 @@ All twenty-four phone applications are compiled as shared-object plugins (`/usr/ 23. **Passcode phone locker (`locker.so` / `xlocker`)**: - **Activate**: select **Power -> Lock** or **Power -> Lock (Screen off)**, double-press **End / Power**, close the physical slider, or run `xlocker [lock|screenoff|wake|status]`. - - **Controls, verification, and duress mode**: renders a fullscreen `240x320` (`X=0, Y=0`) lock screen showing the live clock, date, battery percentage, and unread SMS/notification count. Enter your numeric system password (`147147` by default, 4 or more digits) using `0`–`9`; when 4 or more digits are entered and match the user's `/etc/shadow` password hash (verified via `/usr/bin/bananarchy-verify-passcode`), the phone unlocks immediately. If a separate **duress passcode** has been configured and is entered on the lock screen (`exit 2`), `/usr/bin/bananarchy-duress-activate` silently activates **duress mode** (`/tmp/bananarchy_duress_mode` and blank profile `/tmp/duress_home`): contacts, call logs, and SMS history are blanked, the microSD card is unmounted and blocked, the UI theme and wallpaper are locked to `NordFrost.xth` and `/usr/share/wallpapers/nordic-peaks.png`, `*#06#` displays a session-persistent random Luhn-valid IMEI derived from the device's preconfigured 8-digit TAC, `xfiles` is clamped inside `/tmp/duress_home`, and `xpasscode`, `xtox`, `xirc`, `xsip`, and `st` are disabled and hidden from all menus until the phone is powered off or rebooted. Press `BackSpace`, `Left`, or **Right softkey (`Clear`)** to delete a digit; press **End / Power** (or **Right softkey (`Sleep`)** when the input field is empty) to blank the display while staying locked. Repeated wrong attempts enforce a 5-second lockout cooldown. + - **Controls, verification, and duress mode**: renders a fullscreen `240x320` (`X=0, Y=0`) lock screen showing the live clock, date, battery percentage, and unread SMS/notification count. Enter your numeric system password (`147147` by default, 4 or more digits) using `0`–`9`; when 4 or more digits are entered and match the user's `/etc/shadow` password hash (verified via `/usr/bin/bananarchy-verify-passcode`), the phone unlocks immediately. If a separate **duress passcode** has been configured and is entered on the lock screen (`exit 2`), `/usr/bin/bananarchy-duress-activate` silently activates **duress mode** (`/tmp/bananarchy_duress_mode` and blank profile `/tmp/duress_home`): contacts, call logs, and SMS history are blanked, the microSD card is unmounted and blocked, all active privacy/VPN tunnels are stopped (`bananarchy-privacy-ctl stop-all`), the UI theme and wallpaper are locked to `NordFrost.xth` and `/usr/share/wallpapers/nordic-peaks.png`, `*#06#` displays a session-persistent random Luhn-valid IMEI derived from the device's preconfigured 8-digit TAC, `xfiles` is clamped inside `/tmp/duress_home`, and `xpasscode`, `xprivacy`, `xtox`, `xirc`, `xsip`, and `st` are disabled and hidden from all menus until the phone is powered off or rebooted. Press `BackSpace`, `Left`, or **Right softkey (`Clear`)** to delete a digit; press **End / Power** (or **Right softkey (`Sleep`)** when the input field is empty) to blank the display while staying locked. Repeated wrong attempts enforce a 5-second lockout cooldown. 24. **Passcode and duress configurator (`passcode.so` / `xpasscode`)**: - **Open**: select **Passcode** from the **Config** or **Applications** menu, or run `xpasscode`. @@ -299,6 +299,16 @@ All twenty-four phone applications are compiled as shared-object plugins (`/usr/ - **`1:User PIN`**: enter your current numeric passcode (`0`–`9`), enter and confirm a new user passcode of any length starting at `4` numeric digits, and press **Center `OK`** on **Save User Passcode** to update the real Linux system password (`user` in `/etc/shadow`). - **`2:Duress PIN`**: verify your current user passcode and set or clear a separate numeric duress passcode (`4+` digits, stored as a salted hash in `/etc/bananarchy/duress.hash`, never matching the user passcode). Press `*` at any time to toggle masked vs. visible digits. +25. **Privacy Center (`privacy.so` / `xprivacy` / `privacy`)**: + - **Open**: select **Privacy Center** from the **System**, **Applications**, or **Config** menu, or run `xprivacy` / `privacy` (hidden and blocked in Duress Mode). + - **Five tabs (`1:Tor`, `2:Warp`, `3:OVPN`, `4:GS`, `5:WG` — switch with `Left`/`Right` or `1`–`5`; `Call` toggles the active tab's service; `*` refreshes status; `0` stops all active tunnels)**: + - **`1:Tor`**: start/stop the Tor anonymity daemon (`SocksPort 127.0.0.1:9050`, `TransPort 0.0.0.0:9040`, `DNSPort 0.0.0.0:9053`) with live bootstrap progress (`0%`–`100%`), and independently toggle **Route Native Traffic** (`OUTPUT` TCP + DNS redirection) and **Route Wi-Fi/USB Tether** (`PREROUTING` TCP + DNS redirection for `usb0` and `10.42.0.0/24`). + - **`2:Warp` (GS-Warp)**: start/stop the GSocket-tunneled OpenVPN client (`gs-warp` / `gs-warp-simple.sh` + `/etc/gs-warp/client.ovpn` over `tun_gswarp`), edit the custom **GSocket Secret** string (or reset to the MD5 of `client.ovpn`), pick a custom `.ovpn` profile, and independently toggle **Route Native Traffic** and **Route Wi-Fi/USB Tether** (`table 210`). + - **`3:OVPN` (OpenVPN)**: start/stop OpenVPN (`tun_ovpn`) using any `.ovpn` configuration file selected via the built-in file picker or path editor, and independently toggle **Route Native Traffic** and **Route Wi-Fi/USB Tether** (`table 220`). + - **`4:GS` (GSocket single TCP port)**: start/stop `gs-netcat` (`gsocket`) for a single configurable **TCP Port** (`1`–`65535`) with a custom **GSocket Secret** (or generate a random secret via `gs-netcat -g`), switch between `Client (Out)` and `Server (In)` mode, and independently toggle **Route Native Port** and **Route Tethered Port** (`iptables -t nat REDIRECT` for that TCP port). + - **`5:WG` (WireGuard)**: start/stop a kernel WireGuard interface (`wg0`), generate a fresh Curve25519 keypair (`Generate New Keypair`), import a standard WireGuard `.conf` file, edit custom `PrivateKey`, `Peer PublicKey`, optional `PresharedKey`, `Endpoint (host:port)`, `Interface IP/CIDR`, and `Tunnel DNS`, and independently toggle **Route Native Traffic** and **Route Wi-Fi/USB Tether** (`table 230` with `fwmark 0xca6c` loop avoidance). + - **Zero-drain standby**: no background OpenRC daemons run when services are turned off, and `privacy.so` sleeps at `0%` CPU on `poll()` when hidden. + #### 3.1.3 Standalone keypad games (`Snake`, `Tetris`, `Scoundrel`), Game Boy emulator (`Gambatte`), and J2ME emulator (`ReMEdy`) Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoundrel`), the **Gambatte (`gambatte` / `gbemu`)** Game Boy / Game Boy Color emulator, and the **ReMEdy (`remedy` / `j2me`)** J2ME (MIDP 2.0 / CLDC 1.1) emulator are accessible from **System menu -> Games** (and **System menu -> Applications** for ReMEdy, or by opening `.gb`/`.gbc` and `.jar`/`.jad` files directly in **Files (`xfiles`)**): - **Snake (`snake`)**: steer with `2`/`8`/`4`/`6` or D-Pad; pause or restart with `5`/`Return`/`#`/`*`; quit with `Right softkey`/`BackSpace`/`Escape`. diff --git a/README.md b/README.md index 448c060..7d64b4e 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,15 @@ - **Pure X11 graphical stack with GPU acceleration**: cross-compiled **Xlibre** (`X11Libre/xserver`) display server offloading 2D/3D screen rendering to the **Adreno 304 GPU** via **Glamor, DRI3, GLX, and Mesa Freedreno (`FD304`, OpenGL 3.1 / OpenGL ES 3.0)** over `panel-mipi-dbi` KMSRO, paired with a customized **Sxmo (`sxmo-de-dwm`)** window manager (`240x320` vertical stack layout, Conky desktop clock and system status widget, `< 2 ms` slider/key wake latency, and zero Wayland overhead). ### Keypad-first user experience and native DWM plugins -Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs a suite of 23 preloaded C/C++ plugins inside DWM that sleep at 0% CPU and open in `< 2 ms`: +Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs a suite of 25 preloaded C/C++ plugins inside DWM that sleep at 0% CPU and open in `< 2 ms`: - **System and context menus (`dmenu`)**: instant full-screen 10-line vertical menus with live T9 filtering, built-in submenus, and hardware toggles. -- **Passcode-based fullscreen phone locker (`xlocker`), GUI passcode configurator (`xpasscode`), and Duress Mode**: zero-bypass `240x320` fullscreen numeric passcode lock screen verified against the current user's system shadow password (`/usr/bin/bananarchy-verify-passcode`), blocking all desktop, menu, drawer, terminal, and power actions while locked and automatically handing off the display only during incoming calls. Includes a NeoUI **Passcode Configurator (`xpasscode` / `passcode.so`)** in `Config -> Passcode` to change the real Linux user password (`user`, any numeric length `>= 4` digits) and configure a separate **Duress Passcode**. Entering the duress passcode on the lock screen switches the session into **Duress Mode** (`/tmp/duress_home` blank profile with no contacts, SMS, call logs, or personal files, microSD unmounted and disabled, `xfiles` clamped to the profile directory, Passcode/Tox/IRC/SIP/`st` terminal hidden and blocked, `*#06#` displaying a session-persistent random Luhn-valid IMEI derived from the device's TAC, and theme/wallpaper locked to `NordFrost.xth` and `nordic-peaks.png` until poweroff or reboot). +- **Passcode-based fullscreen phone locker (`xlocker`), GUI passcode configurator (`xpasscode`), and Duress Mode**: zero-bypass `240x320` fullscreen numeric passcode lock screen verified against the current user's system shadow password (`/usr/bin/bananarchy-verify-passcode`), blocking all desktop, menu, drawer, terminal, and power actions while locked and automatically handing off the display only during incoming calls. Includes a NeoUI **Passcode Configurator (`xpasscode` / `passcode.so`)** in `Config -> Passcode` to change the real Linux user password (`user`, any numeric length `>= 4` digits) and configure a separate **Duress Passcode**. Entering the duress passcode on the lock screen switches the session into **Duress Mode** (`/tmp/duress_home` blank profile with no contacts, SMS, call logs, or personal files, microSD unmounted and disabled, `xfiles` clamped to the profile directory, Passcode/Privacy Center/Engineering Menu/Tox/IRC/SIP/`st` terminal hidden and blocked, `*#06#` displaying a session-persistent random Luhn-valid IMEI derived from the device's TAC, and theme/wallpaper locked to `NordFrost.xth` and `nordic-peaks.png` until poweroff or reboot). +- **Privacy Center (`xprivacy` / `privacy` / `privacy.so`) and `/usr/bin/bananarchy-privacy-ctl`**: 5-tab NeoUI privacy and tunneling control center (`1:Tor`, `2:Warp`, `3:OVPN`, `4:GS`, `5:WG`, hidden and disabled in Duress Mode) with zero background CPU or battery consumption when services are turned off: + - **Tor (`1:Tor`)**: start/stop the Tor anonymity daemon (`SocksPort 9050`, `TransPort 9040`, `DNSPort 9053`) and transparently route all native phone traffic and/or Wi-Fi hotspot (`10.42.0.0/24`) and USB-tethered (`usb0`) traffic through Tor. + - **GS-Warp (`2:Warp`)**: start/stop the GSocket-tunneled OpenVPN client (`gs-warp` / `gs-warp-simple.sh` + `/etc/gs-warp/client.ovpn` over `tun_gswarp`), configure a custom GSocket secret string (defaulting to the MD5 of `client.ovpn`), and route native and/or Wi-Fi/USB-tethered traffic through it. + - **OpenVPN (`3:OVPN`)**: start/stop OpenVPN (`tun_ovpn`) with a custom `.ovpn` configuration file selected via the built-in file picker and route native and/or Wi-Fi/USB-tethered traffic through it. + - **GSocket single TCP port (`4:GS`)**: start/stop `gs-netcat` (`gsocket`) for a single configurable TCP port with a custom GSocket secret string (`client` or `server` mode) and transparently redirect native and/or Wi-Fi/USB-tethered traffic for that TCP port through GSocket. + - **WireGuard (`5:WG`)**: start/stop a kernel WireGuard tunnel (`wg0`), generate keypairs (`wg genkey` / `wg pubkey`) or import `.conf` profiles, edit custom `PrivateKey`, peer `PublicKey`, optional `PresharedKey`, `Endpoint`, `Address`, and `DNS`, and route native and/or Wi-Fi/USB-tethered traffic through it. - **Global controls drawer (`xdrawer`) and `*` + `#` screenshot combo**: press **both softkeys together** from anywhere to adjust linear (`1%`–`100%`) speaker, earpiece, and ringtone volume, audio output routing (`Speaker`, `Earpiece`, `Headphones` with automatic 3.5mm jack plug/unplug routing), ringer mode (`Ring+Vib` / `Vibrate` / `Silent` / `DND`), 3-level vibration intensity (`Light` / `Medium` / `Strong`), flashlight, sound and microphone mute, screen brightness, and keypad backlight; press **`*` and `#` together** from anywhere to capture a `240x320` PNG screenshot (`scrot` via `bananarchy-screenshot`) to `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png`. - **Phone dialer (`xdialer`), call log (`xcalllog`), and call screen (`xcallscreen`)**: press any digit on the home screen to start dialing with live T9 contact matching, run interactive carrier USSD codes (`*100#`, etc.), or type `*#06#` to inspect both IMEIs. When two SIM cards are active in Dual-SIM Dual Standby (DSDS), placing a call or running a USSD code prompts to choose between `SIM 1` and `SIM 2`. Incoming and active calls on either SIM (as well as incoming/active VoIP calls from `xsip` and `xtox`) open a dedicated call screen with an active `[SIM 1]`/`[SIM 2]`/`[SIP]`/`[TOX]` badge, earpiece/speaker switching, microphone mute, DTMF keypad, and one-key normalized WAV call recording (`~/Recordings/rec_HHMMSS_.wav`). The call log includes a 5-tab view (`All`, `Miss`, `In`, `Out`, `Spam`) with integrated anti-spam number blocking (`~/.config/sxmo/block.tsv`) that automatically hangs up blocked callers and logs them to the `Spam` tab without triggering missed-call notifications. - **Contacts (`xcontacts`) and SMS manager (`xsms`)**: full phonebook editor with direct Qualcomm QMI SIM card contact import and export across SIM 1 and SIM 2, paired with a threaded SMS conversation view, multi-tap message composer with outgoing `SIM 1` / `SIM 2` selection when two SIMs are active, and built-in anti-spam blocklist / spam folder (`~/.local/share/sxmo/block`) with one-key thread blocking and restoration. @@ -82,7 +88,7 @@ bananarchy/ │ ├── sxmo-dwm/ # Patched sxmo-dwm (240x320 bstack, Pango bar, softkey bar, and plugin API) │ ├── dwm-plugins/ # DWM plugins (locker, passcode, dialer, calllog, callscreen, contacts, sms, │ │ # files, camera, themes, modem, networks, ringtones, wallpapers, music, sip, -│ │ # email, irc, tox, smallweb, webarchy, gps), net_tls.h, theme.h, and runner +│ │ # email, irc, tox, smallweb, webarchy, gps, privacy) and runner │ ├── xdrawer/ # XDrawer global phone controls DWM plugin (xdrawer.so / xdrawer) │ ├── sxmo-dmenu/ # Resident DWM menu plugin (dmenu.so) and client (dmenu / xdmenu) │ ├── sxmo-st/ # Patched sxmo-st terminal with HarfBuzz Fira Code ligatures and XIM diff --git a/overlay/rootfs/etc/doas.d/50-sxmo.conf b/overlay/rootfs/etc/doas.d/50-sxmo.conf index 69f5525..6576d4a 100644 --- a/overlay/rootfs/etc/doas.d/50-sxmo.conf +++ b/overlay/rootfs/etc/doas.d/50-sxmo.conf @@ -45,6 +45,8 @@ permit nopass :wheel as root cmd /usr/bin/bananarchy-engmenu-exec permit nopass :wheel as root cmd bananarchy-engmenu-exec permit nopass :wheel as root cmd /usr/bin/bananarchy-bt-obex permit nopass :wheel as root cmd bananarchy-bt-obex +permit nopass :wheel as root cmd /usr/bin/bananarchy-privacy-ctl +permit nopass :wheel as root cmd bananarchy-privacy-ctl permit nopass :wheel as root cmd /usr/bin/plymouth args quit permit nopass :wheel as root cmd plymouth args quit permit nopass :wheel as root cmd rc-service args hexagonrpcd-adsp-sensorspd stop diff --git a/overlay/rootfs/etc/gs-warp/client.ovpn b/overlay/rootfs/etc/gs-warp/client.ovpn new file mode 100644 index 0000000..f9010c6 --- /dev/null +++ b/overlay/rootfs/etc/gs-warp/client.ovpn @@ -0,0 +1,137 @@ +client +dev tun +proto tcp-client +remote 127.0.0.1 1194 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +cipher AES-256-GCM +tun-mtu 1300 +mssfix 1200 + +# Native OpenVPN routes to bypass GSocket relay nodes via physical default gateway +route gs.thc.org 255.255.255.255 net_gateway +route a.gs.thc.org 255.255.255.255 net_gateway +route b.gs.thc.org 255.255.255.255 net_gateway +route c.gs.thc.org 255.255.255.255 net_gateway +route d.gs.thc.org 255.255.255.255 net_gateway +route e.gs.thc.org 255.255.255.255 net_gateway +route f.gs.thc.org 255.255.255.255 net_gateway +route g.gs.thc.org 255.255.255.255 net_gateway +route h.gs.thc.org 255.255.255.255 net_gateway +route i.gs.thc.org 255.255.255.255 net_gateway +route j.gs.thc.org 255.255.255.255 net_gateway +route k.gs.thc.org 255.255.255.255 net_gateway +route l.gs.thc.org 255.255.255.255 net_gateway +route m.gs.thc.org 255.255.255.255 net_gateway +route n.gs.thc.org 255.255.255.255 net_gateway +route o.gs.thc.org 255.255.255.255 net_gateway +route p.gs.thc.org 255.255.255.255 net_gateway +route q.gs.thc.org 255.255.255.255 net_gateway +route r.gs.thc.org 255.255.255.255 net_gateway +route s.gs.thc.org 255.255.255.255 net_gateway +route t.gs.thc.org 255.255.255.255 net_gateway +route u.gs.thc.org 255.255.255.255 net_gateway +route v.gs.thc.org 255.255.255.255 net_gateway +route w.gs.thc.org 255.255.255.255 net_gateway +route x.gs.thc.org 255.255.255.255 net_gateway +route y.gs.thc.org 255.255.255.255 net_gateway +route z.gs.thc.org 255.255.255.255 net_gateway + + +-----BEGIN CERTIFICATE----- +MIIDGzCCAgOgAwIBAgIUXVuSSqgV+VLegn2E3XMf/EnI6MwwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBUxEzARBgNVBAMMCkdTb2NrZXQtQ0EwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQCQvoFs1QCyB9TalGLCIRRB/pG59U7f3qNPk31dPhO+ +8SfyAEDirvL09g06n3IBGDMqeEJ7rr8bcHICcOAm+mtkxEtEcDt56hJRGMXRJ83o +tZ4/o0PRUsOcBzmipQ9YROnC9+Ec8cJcgiPYeLwslVlrZK/k6lnyAkGA2PGLWPQU +wolqpceD47XCOvclU+yi2E3d8dJJtprXhcFjqrbptKS17dLYD5sPBrrHM8XOteHN +Dli1MihM5FeZ1WqoGPK9vZ366igrmUHqKN88z1Qv6GN5IRaD2i0LDOI9uEpjS0aJ +KTeSHZf2PCDuwrXh85GUctCgZ1jDyd8slnU3nlhhNJZFAgMBAAGjYzBhMB0GA1Ud +DgQWBBR9igX98IDYlvcTUcIgDGSzn5eZ8DAfBgNVHSMEGDAWgBR9igX98IDYlvcT +UcIgDGSzn5eZ8DAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkq +hkiG9w0BAQsFAAOCAQEAgY6WPfEz7mY2f6Xz4bgyDdZfma7hH0JjMaSDZaCtviiS +tWmMpDOdRuFPNKuUZvoQQviwRRB1YcjsFwdaCNmUiNp/pM3wi2qoW88LLnSk/Fff +fHA7O5/YUDRTzNoqPkhHO8Pk0psVfkuIeoc+k46IP+F/BZIxIwb9OR2p23bUbVsv +oQc1ESl8GVPkfRPL8IYIPbkMjnwq3TrNO0NwUDdLkts6Z1JzEnpUPtODczcv5jK7 +omaTmUihJ4dkclNL6py9hYH81q9dPGyxuAxLdJG7H0yqaMf03KiUHLBTzHCDw5o+ +zCj6xUp4fe+wEMuEtqy65LCbAeAX+Zx+8uY6EBnhmw== +-----END CERTIFICATE----- + + +-----BEGIN CERTIFICATE----- +MIIDKzCCAhOgAwIBAgIUJSzsy2NgewUgboWWqe0UbwZzYBAwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBkxFzAVBgNVBAMMDkdTb2NrZXQtQ2xpZW50MIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj+sGqoOSGcFVX28Q7ND6CYKz/uqg8AwAzI9J +WaclnI6ZaWLLlYmX8KoFLAUyxcZ2/9bpPuQsfCkoRTzXkqg6SCH7zJ9XeRDu7S7e +lWgXcVtDOY7KOxoCq0cn0n5NMgtbtyOVAcnt0IywneCiRhK0MxYqgtwdvedYnd4w +0De0FlMocMiQP9s7GNBLSIl4wXlOxJ5GyHjcT36IApLKmYhatVIi4b3xLWFMe2RF +n8oO6iRjXu7kvImBL4FWAniO/4pcU7A87PPvAV4nMqjEuhW1w4v8zGyXUk4/O1WZ +OrZ/PZMke1rWNWM07POfGk4cjefQQmw42BJQmNSnGNVVbpB+8wIDAQABo28wbTAJ +BgNVHRMEAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjAdBgNV +HQ4EFgQUAFunU3UYEaBjsUm7dAYtiYFPCkMwHwYDVR0jBBgwFoAUfYoF/fCA2Jb3 +E1HCIAxks5+XmfAwDQYJKoZIhvcNAQELBQADggEBACDt6t1MFzLqZHdtr/xB4GV1 +4s4LtVBiQcDq4RC6gImNZR4ZeoQPZZvH2paD2vSKtQmSSxS+N8llPklRos1a5YXc +ZWR9XqklX1ahz3FaNq4LjQzlVnl8xgr6HAUElIPD/D+nSZBff9Mk71gAFXGRwnnP +zEugQfv20JJLzJhaqAAmIM42ngiuDOeOk2VY1EXdb0CqPs3XOYw82wivC5agcKb/ +XPShEdOkay07uwjoo243fN9APuvNTyu1xWYsRj6Y10aPlbHDeSZ0Y81OuoXM9cWA +YOmUsN2F9P4YT7iZxyBrEcBztSvX7NiWkccf+wYcaqh4rJ6SCv8PQM47+cLXRTM= +-----END CERTIFICATE----- + + +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCP6waqg5IZwVVf +bxDs0PoJgrP+6qDwDADMj0lZpyWcjplpYsuViZfwqgUsBTLFxnb/1uk+5Cx8KShF +PNeSqDpIIfvMn1d5EO7tLt6VaBdxW0M5jso7GgKrRyfSfk0yC1u3I5UBye3QjLCd +4KJGErQzFiqC3B2951id3jDQN7QWUyhwyJA/2zsY0EtIiXjBeU7EnkbIeNxPfogC +ksqZiFq1UiLhvfEtYUx7ZEWfyg7qJGNe7uS8iYEvgVYCeI7/ilxTsDzs8+8BXicy +qMS6FbXDi/zMbJdSTj87VZk6tn89kyR7WtY1YzTs858aThyN59BCbDjYElCY1KcY +1VVukH7zAgMBAAECggEAK9+fQZ4ojPd2WkiWpUsz3nBdBQpsE6HlIHdSCiW9fpOu +SwVWQPkYO8LpHrla+BX/sxDGPGj88sDtSOY6ZbgpRFIv2/p7hSnXXLEcI/n+o40J +2mMgXZIZXDOt/SqJyAbUZ+lOBKSVfi1VrluLvMb47lYEka4e1wTO7BmPUfqZSPCN +xt87n+jKkgrobCUB9v+VcOCMYk+xpMveJWl9v0ch/0AAJLERdIdLuEiwYnez9j1O +Hkr4ne0fP5ISqvJpnUYYQbD44MhxR62qMaexNOvfrPnsTektWRWvmML8/SlNpqAE +25i2Y6ttqJD9IhjCmNq61nhr8TLbuyNdwe2ff+UPSQKBgQDJ0ckzoKdJPYBY5mLD +3hlGXPdJEuO4qZJYZPZkXEP0Eyf38hzCx4KTRhJ6P8GTEt0VYbEf1CmzHYAR7vXl +sGDmzUzbqiVJlVe6sgIlN59gALBLYPUusR0BJ03A8yFQ+pzteJkhVU18PRaHwYNz +lUWfzergyjaeWEpn9j+advGU1wKBgQC2jerDo+ZuFdNAzRLvHMkCAUxvXc813NJa +1PT2w+ZSLaOiXIQAzM2+EekjbVumf2aDfZRm72Y8LibopucMLo4xEL60+XIyQMsP +jLW0z37mSTmmh826yUJ0fcKAanUMBmJNkT9uradHL3ozaD78CHDwNLQoJkU3S1Pk +rl/yYPqHRQKBgHK9vvKHSBSvzqS8dzJ8t0n12PHGt4lpfzaaUCtG+atuqK6jDA8B +dw9cK20tilSfyOo7HITIDt0yzHllro/j83PFDQlmdsSbD8GpKucV9JqUSabRfRQK +xj69pcspb6umkEnC4uy8ns0fvgt4zc+M8oSkggFDdkIYWFU6/3ZGYZsJAoGAI+We +L2BQVH9YLhrlST2YzRsiQ5fnwgitGI1dqhR1et1cmvWkQ2ACaQiulnfPmNredqbA +Asm6icTtg7wmHMAe18kaJw4SBY22IFWj+Wz/4BqwCm4T51HiDnQYRhYo8/dhZy1T +ktj01sugNPGfyQGD68gBUQ/NdoUKdyJO3aNyQB0CgYALZFIK7mo3CAG077Y4QErk +Rzz8rR5Xrf59jiddP3Iyop/qUKyCGlBQo6KjFgsrDknis/v3e/uXSywlw0SbIGUo +eJW1NQ4TZSM3Xx76Faaarta7ZWWSXo4mrbIW9i1FyHNs1jR/W0PPjWD/xd6Rb7Pr +EYSDOWqfoZ5EckmvK1tang== +-----END PRIVATE KEY----- + + +# +# 2048 bit OpenVPN static key +# +-----BEGIN OpenVPN Static key V1----- +6d5c8c6f0e8112c7fec310f6981ee2db +8f416b5b1616c07aa53e1f7f2dcbbd4c +6a82eeee92eccdebc55937ae06e4ce08 +52e0779bba37c27ee471a1ec54682162 +11a20733656a5f565c6b6404b73923d8 +bfaa3d2be29ecb157c6702433b845eda +9e93c8324267bf79ce1aa590644d6380 +3aa89401fa6f1d5a9787ff1a3f6973ca +dd43a114a0eb71e8f9a6c4405c3b2ede +5a9bb31a962976da6edbd9368d5c8110 +7e125e9188776461bad73dc0cd9dbeaf +341a3277a71fa35da294cc41074bed21 +586063de3f74182ccff01ae4e7e9e107 +dbd2ecd341f8e48264db309793abe974 +2ea2fc5384afe805b97fd10493f56757 +7f5d12e7fe48dc048765c5cb363dea5d +-----END OpenVPN Static key V1----- + diff --git a/overlay/rootfs/etc/gsocket.conf b/overlay/rootfs/etc/gsocket.conf new file mode 100644 index 0000000..6cf297a --- /dev/null +++ b/overlay/rootfs/etc/gsocket.conf @@ -0,0 +1,8 @@ + + +# Global gsocket.conf file. +# This file is first looked for in /etc/gsocket.conf +# and then in /usr/etc/gsocket.conf + +GS_PREFIX=/usr + diff --git a/overlay/rootfs/etc/skel/.config/gs-warp/client.ovpn b/overlay/rootfs/etc/skel/.config/gs-warp/client.ovpn new file mode 100644 index 0000000..f9010c6 --- /dev/null +++ b/overlay/rootfs/etc/skel/.config/gs-warp/client.ovpn @@ -0,0 +1,137 @@ +client +dev tun +proto tcp-client +remote 127.0.0.1 1194 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +cipher AES-256-GCM +tun-mtu 1300 +mssfix 1200 + +# Native OpenVPN routes to bypass GSocket relay nodes via physical default gateway +route gs.thc.org 255.255.255.255 net_gateway +route a.gs.thc.org 255.255.255.255 net_gateway +route b.gs.thc.org 255.255.255.255 net_gateway +route c.gs.thc.org 255.255.255.255 net_gateway +route d.gs.thc.org 255.255.255.255 net_gateway +route e.gs.thc.org 255.255.255.255 net_gateway +route f.gs.thc.org 255.255.255.255 net_gateway +route g.gs.thc.org 255.255.255.255 net_gateway +route h.gs.thc.org 255.255.255.255 net_gateway +route i.gs.thc.org 255.255.255.255 net_gateway +route j.gs.thc.org 255.255.255.255 net_gateway +route k.gs.thc.org 255.255.255.255 net_gateway +route l.gs.thc.org 255.255.255.255 net_gateway +route m.gs.thc.org 255.255.255.255 net_gateway +route n.gs.thc.org 255.255.255.255 net_gateway +route o.gs.thc.org 255.255.255.255 net_gateway +route p.gs.thc.org 255.255.255.255 net_gateway +route q.gs.thc.org 255.255.255.255 net_gateway +route r.gs.thc.org 255.255.255.255 net_gateway +route s.gs.thc.org 255.255.255.255 net_gateway +route t.gs.thc.org 255.255.255.255 net_gateway +route u.gs.thc.org 255.255.255.255 net_gateway +route v.gs.thc.org 255.255.255.255 net_gateway +route w.gs.thc.org 255.255.255.255 net_gateway +route x.gs.thc.org 255.255.255.255 net_gateway +route y.gs.thc.org 255.255.255.255 net_gateway +route z.gs.thc.org 255.255.255.255 net_gateway + + +-----BEGIN CERTIFICATE----- +MIIDGzCCAgOgAwIBAgIUXVuSSqgV+VLegn2E3XMf/EnI6MwwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBUxEzARBgNVBAMMCkdTb2NrZXQtQ0EwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQCQvoFs1QCyB9TalGLCIRRB/pG59U7f3qNPk31dPhO+ +8SfyAEDirvL09g06n3IBGDMqeEJ7rr8bcHICcOAm+mtkxEtEcDt56hJRGMXRJ83o +tZ4/o0PRUsOcBzmipQ9YROnC9+Ec8cJcgiPYeLwslVlrZK/k6lnyAkGA2PGLWPQU +wolqpceD47XCOvclU+yi2E3d8dJJtprXhcFjqrbptKS17dLYD5sPBrrHM8XOteHN +Dli1MihM5FeZ1WqoGPK9vZ366igrmUHqKN88z1Qv6GN5IRaD2i0LDOI9uEpjS0aJ +KTeSHZf2PCDuwrXh85GUctCgZ1jDyd8slnU3nlhhNJZFAgMBAAGjYzBhMB0GA1Ud +DgQWBBR9igX98IDYlvcTUcIgDGSzn5eZ8DAfBgNVHSMEGDAWgBR9igX98IDYlvcT +UcIgDGSzn5eZ8DAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkq +hkiG9w0BAQsFAAOCAQEAgY6WPfEz7mY2f6Xz4bgyDdZfma7hH0JjMaSDZaCtviiS +tWmMpDOdRuFPNKuUZvoQQviwRRB1YcjsFwdaCNmUiNp/pM3wi2qoW88LLnSk/Fff +fHA7O5/YUDRTzNoqPkhHO8Pk0psVfkuIeoc+k46IP+F/BZIxIwb9OR2p23bUbVsv +oQc1ESl8GVPkfRPL8IYIPbkMjnwq3TrNO0NwUDdLkts6Z1JzEnpUPtODczcv5jK7 +omaTmUihJ4dkclNL6py9hYH81q9dPGyxuAxLdJG7H0yqaMf03KiUHLBTzHCDw5o+ +zCj6xUp4fe+wEMuEtqy65LCbAeAX+Zx+8uY6EBnhmw== +-----END CERTIFICATE----- + + +-----BEGIN CERTIFICATE----- +MIIDKzCCAhOgAwIBAgIUJSzsy2NgewUgboWWqe0UbwZzYBAwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBkxFzAVBgNVBAMMDkdTb2NrZXQtQ2xpZW50MIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj+sGqoOSGcFVX28Q7ND6CYKz/uqg8AwAzI9J +WaclnI6ZaWLLlYmX8KoFLAUyxcZ2/9bpPuQsfCkoRTzXkqg6SCH7zJ9XeRDu7S7e +lWgXcVtDOY7KOxoCq0cn0n5NMgtbtyOVAcnt0IywneCiRhK0MxYqgtwdvedYnd4w +0De0FlMocMiQP9s7GNBLSIl4wXlOxJ5GyHjcT36IApLKmYhatVIi4b3xLWFMe2RF +n8oO6iRjXu7kvImBL4FWAniO/4pcU7A87PPvAV4nMqjEuhW1w4v8zGyXUk4/O1WZ +OrZ/PZMke1rWNWM07POfGk4cjefQQmw42BJQmNSnGNVVbpB+8wIDAQABo28wbTAJ +BgNVHRMEAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjAdBgNV +HQ4EFgQUAFunU3UYEaBjsUm7dAYtiYFPCkMwHwYDVR0jBBgwFoAUfYoF/fCA2Jb3 +E1HCIAxks5+XmfAwDQYJKoZIhvcNAQELBQADggEBACDt6t1MFzLqZHdtr/xB4GV1 +4s4LtVBiQcDq4RC6gImNZR4ZeoQPZZvH2paD2vSKtQmSSxS+N8llPklRos1a5YXc +ZWR9XqklX1ahz3FaNq4LjQzlVnl8xgr6HAUElIPD/D+nSZBff9Mk71gAFXGRwnnP +zEugQfv20JJLzJhaqAAmIM42ngiuDOeOk2VY1EXdb0CqPs3XOYw82wivC5agcKb/ +XPShEdOkay07uwjoo243fN9APuvNTyu1xWYsRj6Y10aPlbHDeSZ0Y81OuoXM9cWA +YOmUsN2F9P4YT7iZxyBrEcBztSvX7NiWkccf+wYcaqh4rJ6SCv8PQM47+cLXRTM= +-----END CERTIFICATE----- + + +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCP6waqg5IZwVVf +bxDs0PoJgrP+6qDwDADMj0lZpyWcjplpYsuViZfwqgUsBTLFxnb/1uk+5Cx8KShF +PNeSqDpIIfvMn1d5EO7tLt6VaBdxW0M5jso7GgKrRyfSfk0yC1u3I5UBye3QjLCd +4KJGErQzFiqC3B2951id3jDQN7QWUyhwyJA/2zsY0EtIiXjBeU7EnkbIeNxPfogC +ksqZiFq1UiLhvfEtYUx7ZEWfyg7qJGNe7uS8iYEvgVYCeI7/ilxTsDzs8+8BXicy +qMS6FbXDi/zMbJdSTj87VZk6tn89kyR7WtY1YzTs858aThyN59BCbDjYElCY1KcY +1VVukH7zAgMBAAECggEAK9+fQZ4ojPd2WkiWpUsz3nBdBQpsE6HlIHdSCiW9fpOu +SwVWQPkYO8LpHrla+BX/sxDGPGj88sDtSOY6ZbgpRFIv2/p7hSnXXLEcI/n+o40J +2mMgXZIZXDOt/SqJyAbUZ+lOBKSVfi1VrluLvMb47lYEka4e1wTO7BmPUfqZSPCN +xt87n+jKkgrobCUB9v+VcOCMYk+xpMveJWl9v0ch/0AAJLERdIdLuEiwYnez9j1O +Hkr4ne0fP5ISqvJpnUYYQbD44MhxR62qMaexNOvfrPnsTektWRWvmML8/SlNpqAE +25i2Y6ttqJD9IhjCmNq61nhr8TLbuyNdwe2ff+UPSQKBgQDJ0ckzoKdJPYBY5mLD +3hlGXPdJEuO4qZJYZPZkXEP0Eyf38hzCx4KTRhJ6P8GTEt0VYbEf1CmzHYAR7vXl +sGDmzUzbqiVJlVe6sgIlN59gALBLYPUusR0BJ03A8yFQ+pzteJkhVU18PRaHwYNz +lUWfzergyjaeWEpn9j+advGU1wKBgQC2jerDo+ZuFdNAzRLvHMkCAUxvXc813NJa +1PT2w+ZSLaOiXIQAzM2+EekjbVumf2aDfZRm72Y8LibopucMLo4xEL60+XIyQMsP +jLW0z37mSTmmh826yUJ0fcKAanUMBmJNkT9uradHL3ozaD78CHDwNLQoJkU3S1Pk +rl/yYPqHRQKBgHK9vvKHSBSvzqS8dzJ8t0n12PHGt4lpfzaaUCtG+atuqK6jDA8B +dw9cK20tilSfyOo7HITIDt0yzHllro/j83PFDQlmdsSbD8GpKucV9JqUSabRfRQK +xj69pcspb6umkEnC4uy8ns0fvgt4zc+M8oSkggFDdkIYWFU6/3ZGYZsJAoGAI+We +L2BQVH9YLhrlST2YzRsiQ5fnwgitGI1dqhR1et1cmvWkQ2ACaQiulnfPmNredqbA +Asm6icTtg7wmHMAe18kaJw4SBY22IFWj+Wz/4BqwCm4T51HiDnQYRhYo8/dhZy1T +ktj01sugNPGfyQGD68gBUQ/NdoUKdyJO3aNyQB0CgYALZFIK7mo3CAG077Y4QErk +Rzz8rR5Xrf59jiddP3Iyop/qUKyCGlBQo6KjFgsrDknis/v3e/uXSywlw0SbIGUo +eJW1NQ4TZSM3Xx76Faaarta7ZWWSXo4mrbIW9i1FyHNs1jR/W0PPjWD/xd6Rb7Pr +EYSDOWqfoZ5EckmvK1tang== +-----END PRIVATE KEY----- + + +# +# 2048 bit OpenVPN static key +# +-----BEGIN OpenVPN Static key V1----- +6d5c8c6f0e8112c7fec310f6981ee2db +8f416b5b1616c07aa53e1f7f2dcbbd4c +6a82eeee92eccdebc55937ae06e4ce08 +52e0779bba37c27ee471a1ec54682162 +11a20733656a5f565c6b6404b73923d8 +bfaa3d2be29ecb157c6702433b845eda +9e93c8324267bf79ce1aa590644d6380 +3aa89401fa6f1d5a9787ff1a3f6973ca +dd43a114a0eb71e8f9a6c4405c3b2ede +5a9bb31a962976da6edbd9368d5c8110 +7e125e9188776461bad73dc0cd9dbeaf +341a3277a71fa35da294cc41074bed21 +586063de3f74182ccff01ae4e7e9e107 +dbd2ecd341f8e48264db309793abe974 +2ea2fc5384afe805b97fd10493f56757 +7f5d12e7fe48dc048765c5cb363dea5d +-----END OpenVPN Static key V1----- + diff --git a/overlay/rootfs/home/user/.config/gs-warp/client.ovpn b/overlay/rootfs/home/user/.config/gs-warp/client.ovpn new file mode 100644 index 0000000..f9010c6 --- /dev/null +++ b/overlay/rootfs/home/user/.config/gs-warp/client.ovpn @@ -0,0 +1,137 @@ +client +dev tun +proto tcp-client +remote 127.0.0.1 1194 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +cipher AES-256-GCM +tun-mtu 1300 +mssfix 1200 + +# Native OpenVPN routes to bypass GSocket relay nodes via physical default gateway +route gs.thc.org 255.255.255.255 net_gateway +route a.gs.thc.org 255.255.255.255 net_gateway +route b.gs.thc.org 255.255.255.255 net_gateway +route c.gs.thc.org 255.255.255.255 net_gateway +route d.gs.thc.org 255.255.255.255 net_gateway +route e.gs.thc.org 255.255.255.255 net_gateway +route f.gs.thc.org 255.255.255.255 net_gateway +route g.gs.thc.org 255.255.255.255 net_gateway +route h.gs.thc.org 255.255.255.255 net_gateway +route i.gs.thc.org 255.255.255.255 net_gateway +route j.gs.thc.org 255.255.255.255 net_gateway +route k.gs.thc.org 255.255.255.255 net_gateway +route l.gs.thc.org 255.255.255.255 net_gateway +route m.gs.thc.org 255.255.255.255 net_gateway +route n.gs.thc.org 255.255.255.255 net_gateway +route o.gs.thc.org 255.255.255.255 net_gateway +route p.gs.thc.org 255.255.255.255 net_gateway +route q.gs.thc.org 255.255.255.255 net_gateway +route r.gs.thc.org 255.255.255.255 net_gateway +route s.gs.thc.org 255.255.255.255 net_gateway +route t.gs.thc.org 255.255.255.255 net_gateway +route u.gs.thc.org 255.255.255.255 net_gateway +route v.gs.thc.org 255.255.255.255 net_gateway +route w.gs.thc.org 255.255.255.255 net_gateway +route x.gs.thc.org 255.255.255.255 net_gateway +route y.gs.thc.org 255.255.255.255 net_gateway +route z.gs.thc.org 255.255.255.255 net_gateway + + +-----BEGIN CERTIFICATE----- +MIIDGzCCAgOgAwIBAgIUXVuSSqgV+VLegn2E3XMf/EnI6MwwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBUxEzARBgNVBAMMCkdTb2NrZXQtQ0EwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQCQvoFs1QCyB9TalGLCIRRB/pG59U7f3qNPk31dPhO+ +8SfyAEDirvL09g06n3IBGDMqeEJ7rr8bcHICcOAm+mtkxEtEcDt56hJRGMXRJ83o +tZ4/o0PRUsOcBzmipQ9YROnC9+Ec8cJcgiPYeLwslVlrZK/k6lnyAkGA2PGLWPQU +wolqpceD47XCOvclU+yi2E3d8dJJtprXhcFjqrbptKS17dLYD5sPBrrHM8XOteHN +Dli1MihM5FeZ1WqoGPK9vZ366igrmUHqKN88z1Qv6GN5IRaD2i0LDOI9uEpjS0aJ +KTeSHZf2PCDuwrXh85GUctCgZ1jDyd8slnU3nlhhNJZFAgMBAAGjYzBhMB0GA1Ud +DgQWBBR9igX98IDYlvcTUcIgDGSzn5eZ8DAfBgNVHSMEGDAWgBR9igX98IDYlvcT +UcIgDGSzn5eZ8DAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkq +hkiG9w0BAQsFAAOCAQEAgY6WPfEz7mY2f6Xz4bgyDdZfma7hH0JjMaSDZaCtviiS +tWmMpDOdRuFPNKuUZvoQQviwRRB1YcjsFwdaCNmUiNp/pM3wi2qoW88LLnSk/Fff +fHA7O5/YUDRTzNoqPkhHO8Pk0psVfkuIeoc+k46IP+F/BZIxIwb9OR2p23bUbVsv +oQc1ESl8GVPkfRPL8IYIPbkMjnwq3TrNO0NwUDdLkts6Z1JzEnpUPtODczcv5jK7 +omaTmUihJ4dkclNL6py9hYH81q9dPGyxuAxLdJG7H0yqaMf03KiUHLBTzHCDw5o+ +zCj6xUp4fe+wEMuEtqy65LCbAeAX+Zx+8uY6EBnhmw== +-----END CERTIFICATE----- + + +-----BEGIN CERTIFICATE----- +MIIDKzCCAhOgAwIBAgIUJSzsy2NgewUgboWWqe0UbwZzYBAwDQYJKoZIhvcNAQEL +BQAwFTETMBEGA1UEAwwKR1NvY2tldC1DQTAeFw0yNjA3MjYwNzI4MTBaFw0zNjA3 +MjMwNzI4MTBaMBkxFzAVBgNVBAMMDkdTb2NrZXQtQ2xpZW50MIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj+sGqoOSGcFVX28Q7ND6CYKz/uqg8AwAzI9J +WaclnI6ZaWLLlYmX8KoFLAUyxcZ2/9bpPuQsfCkoRTzXkqg6SCH7zJ9XeRDu7S7e +lWgXcVtDOY7KOxoCq0cn0n5NMgtbtyOVAcnt0IywneCiRhK0MxYqgtwdvedYnd4w +0De0FlMocMiQP9s7GNBLSIl4wXlOxJ5GyHjcT36IApLKmYhatVIi4b3xLWFMe2RF +n8oO6iRjXu7kvImBL4FWAniO/4pcU7A87PPvAV4nMqjEuhW1w4v8zGyXUk4/O1WZ +OrZ/PZMke1rWNWM07POfGk4cjefQQmw42BJQmNSnGNVVbpB+8wIDAQABo28wbTAJ +BgNVHRMEAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjAdBgNV +HQ4EFgQUAFunU3UYEaBjsUm7dAYtiYFPCkMwHwYDVR0jBBgwFoAUfYoF/fCA2Jb3 +E1HCIAxks5+XmfAwDQYJKoZIhvcNAQELBQADggEBACDt6t1MFzLqZHdtr/xB4GV1 +4s4LtVBiQcDq4RC6gImNZR4ZeoQPZZvH2paD2vSKtQmSSxS+N8llPklRos1a5YXc +ZWR9XqklX1ahz3FaNq4LjQzlVnl8xgr6HAUElIPD/D+nSZBff9Mk71gAFXGRwnnP +zEugQfv20JJLzJhaqAAmIM42ngiuDOeOk2VY1EXdb0CqPs3XOYw82wivC5agcKb/ +XPShEdOkay07uwjoo243fN9APuvNTyu1xWYsRj6Y10aPlbHDeSZ0Y81OuoXM9cWA +YOmUsN2F9P4YT7iZxyBrEcBztSvX7NiWkccf+wYcaqh4rJ6SCv8PQM47+cLXRTM= +-----END CERTIFICATE----- + + +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCP6waqg5IZwVVf +bxDs0PoJgrP+6qDwDADMj0lZpyWcjplpYsuViZfwqgUsBTLFxnb/1uk+5Cx8KShF +PNeSqDpIIfvMn1d5EO7tLt6VaBdxW0M5jso7GgKrRyfSfk0yC1u3I5UBye3QjLCd +4KJGErQzFiqC3B2951id3jDQN7QWUyhwyJA/2zsY0EtIiXjBeU7EnkbIeNxPfogC +ksqZiFq1UiLhvfEtYUx7ZEWfyg7qJGNe7uS8iYEvgVYCeI7/ilxTsDzs8+8BXicy +qMS6FbXDi/zMbJdSTj87VZk6tn89kyR7WtY1YzTs858aThyN59BCbDjYElCY1KcY +1VVukH7zAgMBAAECggEAK9+fQZ4ojPd2WkiWpUsz3nBdBQpsE6HlIHdSCiW9fpOu +SwVWQPkYO8LpHrla+BX/sxDGPGj88sDtSOY6ZbgpRFIv2/p7hSnXXLEcI/n+o40J +2mMgXZIZXDOt/SqJyAbUZ+lOBKSVfi1VrluLvMb47lYEka4e1wTO7BmPUfqZSPCN +xt87n+jKkgrobCUB9v+VcOCMYk+xpMveJWl9v0ch/0AAJLERdIdLuEiwYnez9j1O +Hkr4ne0fP5ISqvJpnUYYQbD44MhxR62qMaexNOvfrPnsTektWRWvmML8/SlNpqAE +25i2Y6ttqJD9IhjCmNq61nhr8TLbuyNdwe2ff+UPSQKBgQDJ0ckzoKdJPYBY5mLD +3hlGXPdJEuO4qZJYZPZkXEP0Eyf38hzCx4KTRhJ6P8GTEt0VYbEf1CmzHYAR7vXl +sGDmzUzbqiVJlVe6sgIlN59gALBLYPUusR0BJ03A8yFQ+pzteJkhVU18PRaHwYNz +lUWfzergyjaeWEpn9j+advGU1wKBgQC2jerDo+ZuFdNAzRLvHMkCAUxvXc813NJa +1PT2w+ZSLaOiXIQAzM2+EekjbVumf2aDfZRm72Y8LibopucMLo4xEL60+XIyQMsP +jLW0z37mSTmmh826yUJ0fcKAanUMBmJNkT9uradHL3ozaD78CHDwNLQoJkU3S1Pk +rl/yYPqHRQKBgHK9vvKHSBSvzqS8dzJ8t0n12PHGt4lpfzaaUCtG+atuqK6jDA8B +dw9cK20tilSfyOo7HITIDt0yzHllro/j83PFDQlmdsSbD8GpKucV9JqUSabRfRQK +xj69pcspb6umkEnC4uy8ns0fvgt4zc+M8oSkggFDdkIYWFU6/3ZGYZsJAoGAI+We +L2BQVH9YLhrlST2YzRsiQ5fnwgitGI1dqhR1et1cmvWkQ2ACaQiulnfPmNredqbA +Asm6icTtg7wmHMAe18kaJw4SBY22IFWj+Wz/4BqwCm4T51HiDnQYRhYo8/dhZy1T +ktj01sugNPGfyQGD68gBUQ/NdoUKdyJO3aNyQB0CgYALZFIK7mo3CAG077Y4QErk +Rzz8rR5Xrf59jiddP3Iyop/qUKyCGlBQo6KjFgsrDknis/v3e/uXSywlw0SbIGUo +eJW1NQ4TZSM3Xx76Faaarta7ZWWSXo4mrbIW9i1FyHNs1jR/W0PPjWD/xd6Rb7Pr +EYSDOWqfoZ5EckmvK1tang== +-----END PRIVATE KEY----- + + +# +# 2048 bit OpenVPN static key +# +-----BEGIN OpenVPN Static key V1----- +6d5c8c6f0e8112c7fec310f6981ee2db +8f416b5b1616c07aa53e1f7f2dcbbd4c +6a82eeee92eccdebc55937ae06e4ce08 +52e0779bba37c27ee471a1ec54682162 +11a20733656a5f565c6b6404b73923d8 +bfaa3d2be29ecb157c6702433b845eda +9e93c8324267bf79ce1aa590644d6380 +3aa89401fa6f1d5a9787ff1a3f6973ca +dd43a114a0eb71e8f9a6c4405c3b2ede +5a9bb31a962976da6edbd9368d5c8110 +7e125e9188776461bad73dc0cd9dbeaf +341a3277a71fa35da294cc41074bed21 +586063de3f74182ccff01ae4e7e9e107 +dbd2ecd341f8e48264db309793abe974 +2ea2fc5384afe805b97fd10493f56757 +7f5d12e7fe48dc048765c5cb363dea5d +-----END OpenVPN Static key V1----- + diff --git a/overlay/rootfs/usr/bin/bananarchy-duress-activate b/overlay/rootfs/usr/bin/bananarchy-duress-activate index 7f3176c..11ffe73 100755 --- a/overlay/rootfs/usr/bin/bananarchy-duress-activate +++ b/overlay/rootfs/usr/bin/bananarchy-duress-activate @@ -101,11 +101,12 @@ if [ -r "$DURESS_HOME/.Xresources" ]; then fi feh --no-fehbg --bg-fill /usr/share/wallpapers/nordic-peaks.png >/dev/null 2>&1 /dev/null 2>&1 || true +doas -n /usr/bin/bananarchy-privacy-ctl stop-all >/dev/null 2>&1 || true # Notify all plugins to close overlays and reload theme/profile -for p in dmenu xdrawer passcode tox irc sip engmenu dialer calllog contacts sms files camera themes modem networks ringtones wallpapers music email smallweb webarchy gps; do +for p in dmenu xdrawer passcode tox irc sip engmenu privacy dialer calllog contacts sms files camera themes modem networks ringtones wallpapers music email smallweb webarchy gps; do fifo="/tmp/dwm_plugin_${p}.fifo" if [ -p "$fifo" ]; then printf 'CLOSE\nRELOAD_THEME\n' > "$fifo" 2>/dev/null || true diff --git a/overlay/rootfs/usr/bin/bananarchy-privacy-ctl b/overlay/rootfs/usr/bin/bananarchy-privacy-ctl new file mode 100755 index 0000000..d6bdd7a --- /dev/null +++ b/overlay/rootfs/usr/bin/bananarchy-privacy-ctl @@ -0,0 +1,1172 @@ +#!/bin/sh +# Bananarchy Linux — Privacy Center Service & Routing Controller +# Manages Tor, GS-Warp, OpenVPN, GSocket (single TCP port), and WireGuard +# with zero background CPU/battery drain when services are turned off. +set -u + +STATE_DIR="/tmp/bananarchy-privacy" +USER_HOME="/home/user" +CONF_DIR="$USER_HOME/.config/bananarchy" +CONF_FILE="$CONF_DIR/privacy.conf" +DEFAULT_GSWARP_OVPN="$USER_HOME/.config/gs-warp/client.ovpn" +if [ ! -f "$DEFAULT_GSWARP_OVPN" ] && [ -f "/etc/gs-warp/client.ovpn" ]; then + DEFAULT_GSWARP_OVPN="/etc/gs-warp/client.ovpn" +fi + +CMD="${1:-status}" + +# Block all operations except stop-all when in duress mode or screen locked +if [ "$CMD" != "stop-all" ] && [ "$CMD" != "_ovpn_up" ] && [ "$CMD" != "_tor_up" ]; then + if [ -e "/tmp/bananarchy_duress_mode" ] || [ -e "/tmp/bananarchy_screen_locked" ]; then + echo "Error: Privacy Center is unavailable." >&2 + exit 1 + fi +fi + +# Escalate to root via doas or bananarchy-engmenu-exec if invoked as normal user +if [ "$(id -u)" -ne 0 ]; then + if command -v doas >/dev/null 2>&1; then + exec doas -n /usr/bin/bananarchy-privacy-ctl "$@" + elif [ -x /usr/bin/bananarchy-engmenu-exec ]; then + ESCAPED="" + for arg in "$@"; do + ESCAPED="$ESCAPED '$(printf "%s" "$arg" | sed "s/'/'\\\\''/g")'" + done + exec /usr/bin/bananarchy-engmenu-exec --exec "/usr/bin/bananarchy-privacy-ctl $ESCAPED" + fi + echo "Error: root privileges required." >&2 + exit 1 +fi + +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +mkdir -p "$STATE_DIR" "$CONF_DIR" + +# Default configuration values +TOR_NATIVE=0 +TOR_TETHER=0 + +GSWARP_NATIVE=0 +GSWARP_TETHER=0 +GSWARP_OVPN="$DEFAULT_GSWARP_OVPN" +GSWARP_SECRET="" + +OVPN_NATIVE=0 +OVPN_TETHER=0 +OVPN_CONFIG="$DEFAULT_GSWARP_OVPN" + +GSOCKET_NATIVE=0 +GSOCKET_TETHER=0 +GSOCKET_SECRET="" +GSOCKET_PORT="1080" +GSOCKET_MODE="client" + +WG_NATIVE=0 +WG_TETHER=0 +WG_PRIVKEY="" +WG_PUBKEY="" +WG_PEER_PUBKEY="" +WG_PSK="" +WG_ENDPOINT="" +WG_ADDRESS="10.66.66.2/32" +WG_DNS="1.1.1.1" + +load_conf() { + if [ -f "$CONF_FILE" ]; then + while IFS= read -r line; do + case "$line" in + *=*) + k="${line%%=*}" + v="${line#*=}" + ;; + *) + continue + ;; + esac + case "$k" in + TOR_NATIVE|TOR_TETHER|GSWARP_NATIVE|GSWARP_TETHER|GSWARP_OVPN|GSWARP_SECRET|\ + OVPN_NATIVE|OVPN_TETHER|OVPN_CONFIG|GSOCKET_NATIVE|GSOCKET_TETHER|GSOCKET_SECRET|\ + GSOCKET_PORT|GSOCKET_MODE|WG_NATIVE|WG_TETHER|WG_PRIVKEY|WG_PUBKEY|WG_PEER_PUBKEY|\ + WG_PSK|WG_ENDPOINT|WG_ADDRESS|WG_DNS) + eval "$k=\$v" + ;; + esac + done < "$CONF_FILE" + fi + if [ -z "$GSWARP_OVPN" ] || [ ! -f "$GSWARP_OVPN" ]; then + GSWARP_OVPN="$DEFAULT_GSWARP_OVPN" + fi + if [ -z "$GSWARP_SECRET" ] && [ -f "$GSWARP_OVPN" ]; then + GSWARP_SECRET="$(md5sum "$GSWARP_OVPN" 2>/dev/null | awk '{print $1}')" + fi + if [ -z "$GSOCKET_SECRET" ]; then + GSOCKET_SECRET="$GSWARP_SECRET" + fi + if [ -n "$WG_PRIVKEY" ] && [ -z "$WG_PUBKEY" ] && command -v wg >/dev/null 2>&1; then + WG_PUBKEY="$(printf "%s\n" "$WG_PRIVKEY" | wg pubkey 2>/dev/null || true)" + fi +} + +save_conf() { + mkdir -p "$CONF_DIR" + cat > "$CONF_FILE.tmp" </dev/null || true + chmod 0600 "$CONF_FILE" 2>/dev/null || true +} + +ensure_netfilter_modules() { + for mod in iptable_nat iptable_filter iptable_mangle xt_REDIRECT xt_MASQUERADE xt_mark xt_owner tun wireguard; do + modprobe "$mod" 2>/dev/null || true + done +} + +get_tor_uid() { + awk -F: '/^tor:/ {print $3; exit}' /etc/passwd 2>/dev/null || echo "109" +} + +get_openvpn_gid() { + awk -F: '/^openvpn:/ {print $3; exit}' /etc/group 2>/dev/null || echo "113" +} + +is_tor_active() { + if [ -f "$STATE_DIR/tor.pid" ]; then + pid="$(cat "$STATE_DIR/tor.pid" 2>/dev/null || true)" + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + return 0 + fi + fi + pgrep -x tor >/dev/null 2>&1 +} + +is_gswarp_active() { + if [ -f "$STATE_DIR/gswarp-gs.pid" ]; then + pid="$(cat "$STATE_DIR/gswarp-gs.pid" 2>/dev/null || true)" + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + return 0 + fi + fi + if [ -f "/tmp/gswarp-gs.pid" ]; then + pid="$(cat "/tmp/gswarp-gs.pid" 2>/dev/null || true)" + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + return 0 + fi + fi + return 1 +} + +is_ovpn_active() { + if [ -f "$STATE_DIR/ovpn.pid" ]; then + pid="$(cat "$STATE_DIR/ovpn.pid" 2>/dev/null || true)" + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + return 0 + fi + fi + ip link show dev tun_ovpn >/dev/null 2>&1 +} + +is_gsocket_active() { + if [ -f "$STATE_DIR/gsocket-port.pid" ]; then + pid="$(cat "$STATE_DIR/gsocket-port.pid" 2>/dev/null || true)" + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + return 0 + fi + fi + return 1 +} + +is_wg_active() { + ip link show dev wg0 >/dev/null 2>&1 +} + +# Remove an iptables chain from a table and all references from hook chains +flush_and_delete_chain() { + tbl="$1" + chain="$2" + shift 2 + for hook in "$@"; do + while iptables -t "$tbl" -D "$hook" -j "$chain" 2>/dev/null; do :; done + done + iptables -t "$tbl" -F "$chain" 2>/dev/null || true + iptables -t "$tbl" -X "$chain" 2>/dev/null || true +} + +flush_and_delete_chain6() { + command -v ip6tables >/dev/null 2>&1 || return 0 + tbl="$1" + chain="$2" + shift 2 + for hook in "$@"; do + while ip6tables -t "$tbl" -D "$hook" -j "$chain" 2>/dev/null; do :; done + done + ip6tables -t "$tbl" -F "$chain" 2>/dev/null || true + ip6tables -t "$tbl" -X "$chain" 2>/dev/null || true +} + +# Synchronize /etc/resolv.conf and IPv6 DNS leak protection with active tunnels +sync_dns_resolv() { + flush_and_delete_chain6 filter BP6_DNS_OUT OUTPUT + flush_and_delete_chain6 filter BP6_DNS_FWD FORWARD + + active_dns="" + need_v6_out_block=0 + + if is_tor_active && [ "$TOR_NATIVE" = "1" ] && grep -q 'Bootstrapped 100%' "$STATE_DIR/tor.log" 2>/dev/null; then + active_dns="127.0.0.1" + need_v6_out_block=1 + elif is_gswarp_active && [ "$GSWARP_NATIVE" = "1" ] && ip -4 addr show dev tun_gswarp 2>/dev/null | grep -q 'inet '; then + active_dns="$(cat "$STATE_DIR/gswarp.dns" 2>/dev/null || true)" + [ -z "$active_dns" ] && active_dns="1.1.1.1" + need_v6_out_block=1 + elif is_ovpn_active && [ "$OVPN_NATIVE" = "1" ] && ip -4 addr show dev tun_ovpn 2>/dev/null | grep -q 'inet '; then + active_dns="$(cat "$STATE_DIR/ovpn.dns" 2>/dev/null || true)" + [ -z "$active_dns" ] && active_dns="1.1.1.1" + need_v6_out_block=1 + elif is_wg_active && [ "$WG_NATIVE" = "1" ] && ip -4 addr show dev wg0 2>/dev/null | grep -q 'inet '; then + active_dns="${WG_DNS:-1.1.1.1}" + need_v6_out_block=1 + fi + + if [ "$need_v6_out_block" = "1" ] && command -v ip6tables >/dev/null 2>&1; then + ip6tables -t filter -N BP6_DNS_OUT 2>/dev/null || true + ip6tables -t filter -F BP6_DNS_OUT + ip6tables -t filter -A BP6_DNS_OUT -p udp --dport 53 -j REJECT 2>/dev/null || \ + ip6tables -t filter -A BP6_DNS_OUT -p udp --dport 53 -j DROP 2>/dev/null || true + ip6tables -t filter -A BP6_DNS_OUT -p tcp --dport 53 -j REJECT 2>/dev/null || \ + ip6tables -t filter -A BP6_DNS_OUT -p tcp --dport 53 -j DROP 2>/dev/null || true + ip6tables -t filter -I OUTPUT 1 -j BP6_DNS_OUT 2>/dev/null || true + fi + + if (is_tor_active && [ "$TOR_TETHER" = "1" ]) || \ + (is_gswarp_active && [ "$GSWARP_TETHER" = "1" ] && ip -4 addr show dev tun_gswarp 2>/dev/null | grep -q 'inet ') || \ + (is_ovpn_active && [ "$OVPN_TETHER" = "1" ] && ip -4 addr show dev tun_ovpn 2>/dev/null | grep -q 'inet ') || \ + (is_wg_active && [ "$WG_TETHER" = "1" ] && ip -4 addr show dev wg0 2>/dev/null | grep -q 'inet '); then + if command -v ip6tables >/dev/null 2>&1; then + ip6tables -t filter -N BP6_DNS_FWD 2>/dev/null || true + ip6tables -t filter -F BP6_DNS_FWD + ip6tables -t filter -A BP6_DNS_FWD -p udp --dport 53 -j REJECT 2>/dev/null || \ + ip6tables -t filter -A BP6_DNS_FWD -p udp --dport 53 -j DROP 2>/dev/null || true + ip6tables -t filter -A BP6_DNS_FWD -p tcp --dport 53 -j REJECT 2>/dev/null || \ + ip6tables -t filter -A BP6_DNS_FWD -p tcp --dport 53 -j DROP 2>/dev/null || true + ip6tables -t filter -I FORWARD 1 -j BP6_DNS_FWD 2>/dev/null || true + fi + fi + + if [ -n "$active_dns" ]; then + if [ ! -f "$STATE_DIR/resolv.conf.orig" ] && [ -f /etc/resolv.conf ]; then + cp -f /etc/resolv.conf "$STATE_DIR/resolv.conf.orig" 2>/dev/null || true + fi + { + echo "# Managed by bananarchy-privacy-ctl (tunneled DNS)" + echo "nameserver $active_dns" + if [ "$active_dns" != "1.1.1.1" ]; then + echo "nameserver 1.1.1.1" + fi + if [ "$active_dns" != "127.0.0.1" ]; then + echo "nameserver 127.0.0.1" + fi + } > "$STATE_DIR/resolv.conf.new" + cp -f "$STATE_DIR/resolv.conf.new" /etc/resolv.conf 2>/dev/null || true + else + if [ -f "$STATE_DIR/resolv.conf.orig" ]; then + cp -f "$STATE_DIR/resolv.conf.orig" /etc/resolv.conf 2>/dev/null || true + rm -f "$STATE_DIR/resolv.conf.orig" + fi + if ! grep -q '^nameserver ' /etc/resolv.conf 2>/dev/null; then + { + echo "nameserver 127.0.0.1" + echo "nameserver 1.1.1.1" + } > /etc/resolv.conf 2>/dev/null || true + fi + fi +} + +# Clean or install base policy-routing rules for VPN tunnels +sync_base_vpn_rules() { + while ip rule del prio 85 2>/dev/null; do :; done + while ip rule del prio 86 2>/dev/null; do :; done + while ip rule del prio 90 2>/dev/null; do :; done + flush_and_delete_chain mangle BP_BYPASS_OUT OUTPUT + + if is_gswarp_active || is_ovpn_active || is_wg_active; then + ensure_netfilter_modules + ovpn_gid="$(get_openvpn_gid)" + iptables -t mangle -N BP_BYPASS_OUT 2>/dev/null || true + iptables -t mangle -F BP_BYPASS_OUT + if [ -n "$ovpn_gid" ]; then + iptables -t mangle -A BP_BYPASS_OUT -m owner --gid-owner "$ovpn_gid" -j MARK --set-mark 0x191 2>/dev/null || true + fi + iptables -t mangle -I OUTPUT 1 -j BP_BYPASS_OUT + ip rule add prio 85 fwmark 0x191 lookup main 2>/dev/null || true + ip rule add prio 86 fwmark 0xca6c lookup main 2>/dev/null || true + ip rule add prio 90 lookup main suppress_prefixlength 0 2>/dev/null || true + fi +} + +# Add local/private network exemptions to a NAT chain +add_private_exemptions() { + chain="$1" + for net in \ + 127.0.0.0/8 \ + 10.0.0.0/8 \ + 172.16.0.0/12 \ + 192.168.0.0/16 \ + 100.64.0.0/10 \ + 169.254.0.0/16 \ + 224.0.0.0/4 \ + 255.255.255.255/32; do + iptables -t nat -A "$chain" -d "$net" -j RETURN + done +} + +# ============================================================================== +# 1. TOR SERVICE & ROUTING +# ============================================================================== +clear_tor_routing() { + flush_and_delete_chain nat BP_TOR_OUT OUTPUT + flush_and_delete_chain nat BP_TOR_PRE PREROUTING + flush_and_delete_chain filter BP_TOR_IN INPUT + sync_dns_resolv +} + +apply_tor_routing() { + flush_and_delete_chain nat BP_TOR_OUT OUTPUT + flush_and_delete_chain nat BP_TOR_PRE PREROUTING + flush_and_delete_chain filter BP_TOR_IN INPUT + if ! is_tor_active; then + sync_dns_resolv + return 0 + fi + if ! grep -q 'Bootstrapped 100%' "$STATE_DIR/tor.log" 2>/dev/null; then + sync_dns_resolv + return 0 + fi + if [ "$TOR_NATIVE" != "1" ] && [ "$TOR_TETHER" != "1" ]; then + sync_dns_resolv + return 0 + fi + + ensure_netfilter_modules + tor_uid="$(get_tor_uid)" + ovpn_gid="$(get_openvpn_gid)" + + if [ "$TOR_NATIVE" = "1" ]; then + iptables -t nat -N BP_TOR_OUT 2>/dev/null || true + iptables -t nat -F BP_TOR_OUT + if [ -n "$tor_uid" ]; then + iptables -t nat -A BP_TOR_OUT -m owner --uid-owner "$tor_uid" -j RETURN + fi + if [ -n "$ovpn_gid" ]; then + iptables -t nat -A BP_TOR_OUT -m owner --gid-owner "$ovpn_gid" -j RETURN + fi + # Redirect UDP DNS (including queries to 127.0.0.1:53) to Tor DNSPort 9053 before -o lo RETURN + iptables -t nat -A BP_TOR_OUT -p udp --dport 53 -j REDIRECT --to-ports 9053 + iptables -t nat -A BP_TOR_OUT -d 10.192.0.0/10 -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -A BP_TOR_OUT -o lo -j RETURN + # Tunnel TCP DNS (port 53) to external servers via TransPort 9040 (Tor DNSPort is UDP-only) + iptables -t nat -A BP_TOR_OUT -p tcp -m tcp --syn --dport 53 -j REDIRECT --to-ports 9040 + add_private_exemptions BP_TOR_OUT + iptables -t nat -A BP_TOR_OUT -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -I OUTPUT 1 -j BP_TOR_OUT + fi + + if [ "$TOR_TETHER" = "1" ]; then + sysctl -w net.ipv4.ip_forward=1 >/dev/null 2>&1 || true + iptables -t nat -N BP_TOR_PRE 2>/dev/null || true + iptables -t nat -F BP_TOR_PRE + # Never redirect SSH to the phone itself over USB or hotspot + iptables -t nat -A BP_TOR_PRE -p tcp --dport 22 -j RETURN + iptables -t nat -A BP_TOR_PRE -i usb0 -d 10.192.0.0/10 -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -A BP_TOR_PRE -s 10.42.0.0/24 -d 10.192.0.0/10 -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -A BP_TOR_PRE -i usb0 -p udp --dport 53 -j REDIRECT --to-ports 9053 + iptables -t nat -A BP_TOR_PRE -i usb0 -p tcp -m tcp --syn --dport 53 -j REDIRECT --to-ports 9040 + iptables -t nat -A BP_TOR_PRE -s 10.42.0.0/24 -p udp --dport 53 -j REDIRECT --to-ports 9053 + iptables -t nat -A BP_TOR_PRE -s 10.42.0.0/24 -p tcp -m tcp --syn --dport 53 -j REDIRECT --to-ports 9040 + add_private_exemptions BP_TOR_PRE + iptables -t nat -A BP_TOR_PRE -i usb0 -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -A BP_TOR_PRE -s 10.42.0.0/24 -p tcp -m tcp --syn -j REDIRECT --to-ports 9040 + iptables -t nat -I PREROUTING 1 -j BP_TOR_PRE + + iptables -t filter -N BP_TOR_IN 2>/dev/null || true + iptables -t filter -F BP_TOR_IN + iptables -t filter -A BP_TOR_IN -i usb0 -p tcp --dport 9040 -j ACCEPT + iptables -t filter -A BP_TOR_IN -i usb0 -p udp --dport 9053 -j ACCEPT + iptables -t filter -A BP_TOR_IN -s 10.42.0.0/24 -p tcp --dport 9040 -j ACCEPT + iptables -t filter -A BP_TOR_IN -s 10.42.0.0/24 -p udp --dport 9053 -j ACCEPT + iptables -t filter -I INPUT 1 -j BP_TOR_IN + fi + + sync_dns_resolv +} + +start_tor() { + if is_tor_active; then + apply_tor_routing + return 0 + fi + tor_uid="$(get_tor_uid)" + tor_gid="$(awk -F: '/^tor:/ {print $4; exit}' /etc/passwd 2>/dev/null || echo "114")" + mkdir -p /var/lib/tor "$STATE_DIR" + chmod 0755 "$STATE_DIR" 2>/dev/null || true + chown -R "${tor_uid:-109}:${tor_gid:-114}" /var/lib/tor 2>/dev/null || true + chmod 0700 /var/lib/tor 2>/dev/null || true + + cat > "$STATE_DIR/torrc" < "$STATE_DIR/tor.log" + : > "$STATE_DIR/tor.pid" + chown "${tor_uid:-109}:${tor_gid:-114}" "$STATE_DIR/tor.log" "$STATE_DIR/tor.pid" "$STATE_DIR/torrc" 2>/dev/null || true + chmod 0644 "$STATE_DIR/tor.log" "$STATE_DIR/tor.pid" "$STATE_DIR/torrc" 2>/dev/null || true + /usr/bin/tor -f "$STATE_DIR/torrc" >/dev/null 2>&1 + # Wait up to 4 seconds for cached Tor bootstrap; if still bootstrapping, finish asynchronously + i=0 + while [ "$i" -lt 20 ]; do + if grep -q 'Bootstrapped 100%' "$STATE_DIR/tor.log" 2>/dev/null; then + break + fi + sleep 0.2 + i="$((i + 1))" + done + if grep -q 'Bootstrapped 100%' "$STATE_DIR/tor.log" 2>/dev/null; then + apply_tor_routing + else + sync_dns_resolv + ( + j=0 + while [ "$j" -lt 120 ]; do + if ! is_tor_active; then + exit 0 + fi + if grep -q 'Bootstrapped 100%' "$STATE_DIR/tor.log" 2>/dev/null; then + /usr/bin/bananarchy-privacy-ctl _tor_up >/dev/null 2>&1 + exit 0 + fi + sleep 0.5 + j="$((j + 1))" + done + ) >/dev/null 2>&1 /dev/null)" 2>/dev/null || true + rm -f "$STATE_DIR/tor.pid" + fi + pkill -x tor 2>/dev/null || true + sync_dns_resolv +} + +# ============================================================================== +# SHARED VPN TUNNEL ROUTING HELPER (GS-Warp, OpenVPN, WireGuard) +# ============================================================================== +clear_vpn_routing() { + dev="$1" + table="$2" + prio_base="$3" + tag="$4" + + for p in "$prio_base" "$((prio_base + 1))" "$((prio_base + 2))" "$((prio_base + 3))"; do + while ip rule del prio "$p" 2>/dev/null; do :; done + done + ip route flush table "$table" 2>/dev/null || true + flush_and_delete_chain nat "BP_${tag}_POST" POSTROUTING + flush_and_delete_chain filter "BP_${tag}_FWD" FORWARD + flush_and_delete_chain nat "BP_${tag}_DNS_O" OUTPUT + flush_and_delete_chain nat "BP_${tag}_DNS_P" PREROUTING + sync_base_vpn_rules + sync_dns_resolv +} + +apply_vpn_routing() { + dev="$1" + table="$2" + prio_base="$3" + tag="$4" + native="$5" + tether="$6" + dns_ip="${7:-1.1.1.1}" + + for p in "$prio_base" "$((prio_base + 1))" "$((prio_base + 2))" "$((prio_base + 3))"; do + while ip rule del prio "$p" 2>/dev/null; do :; done + done + ip route flush table "$table" 2>/dev/null || true + flush_and_delete_chain nat "BP_${tag}_POST" POSTROUTING + flush_and_delete_chain filter "BP_${tag}_FWD" FORWARD + flush_and_delete_chain nat "BP_${tag}_DNS_O" OUTPUT + flush_and_delete_chain nat "BP_${tag}_DNS_P" PREROUTING + + # Only activate tunnel default routes and DNS redirection once the tunnel has an IPv4 address + if ! ip -4 addr show dev "$dev" 2>/dev/null | grep -q 'inet '; then + sync_base_vpn_rules + sync_dns_resolv + return 0 + fi + + sync_base_vpn_rules + ip route replace default dev "$dev" table "$table" 2>/dev/null || true + ovpn_gid="$(get_openvpn_gid)" + tor_uid="$(get_tor_uid)" + + if [ "$native" = "1" ]; then + ip rule add prio "$prio_base" iif lo lookup "$table" 2>/dev/null || true + if [ -n "$dns_ip" ]; then + iptables -t nat -N "BP_${tag}_DNS_O" 2>/dev/null || true + iptables -t nat -F "BP_${tag}_DNS_O" + if [ -n "$ovpn_gid" ]; then + iptables -t nat -A "BP_${tag}_DNS_O" -m owner --gid-owner "$ovpn_gid" -j RETURN + fi + if [ -n "$tor_uid" ]; then + iptables -t nat -A "BP_${tag}_DNS_O" -m owner --uid-owner "$tor_uid" -j RETURN + fi + # Allow local queries to 127.0.0.1:53 (dnsmasq) so saddr=127.0.0.1 is never DNATed off-loopback + iptables -t nat -A "BP_${tag}_DNS_O" -d 127.0.0.0/8 -j RETURN + iptables -t nat -A "BP_${tag}_DNS_O" -p udp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -A "BP_${tag}_DNS_O" -p tcp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -I OUTPUT 1 -j "BP_${tag}_DNS_O" + fi + fi + + if [ "$tether" = "1" ]; then + sysctl -w net.ipv4.ip_forward=1 >/dev/null 2>&1 || true + ip rule add prio "$((prio_base + 1))" iif usb0 lookup "$table" 2>/dev/null || true + ip rule add prio "$((prio_base + 2))" from 10.42.0.0/24 lookup "$table" 2>/dev/null || true + ip rule add prio "$((prio_base + 3))" from 172.16.0.0/16 lookup "$table" 2>/dev/null || true + + iptables -t nat -N "BP_${tag}_POST" 2>/dev/null || true + iptables -t nat -F "BP_${tag}_POST" + iptables -t nat -A "BP_${tag}_POST" -o "$dev" -j MASQUERADE + iptables -t nat -I POSTROUTING 1 -j "BP_${tag}_POST" + + iptables -t filter -N "BP_${tag}_FWD" 2>/dev/null || true + iptables -t filter -F "BP_${tag}_FWD" + iptables -t filter -A "BP_${tag}_FWD" -o "$dev" -j ACCEPT + iptables -t filter -A "BP_${tag}_FWD" -i "$dev" -j ACCEPT + iptables -t filter -I FORWARD 1 -j "BP_${tag}_FWD" + + if [ -n "$dns_ip" ]; then + iptables -t nat -N "BP_${tag}_DNS_P" 2>/dev/null || true + iptables -t nat -F "BP_${tag}_DNS_P" + iptables -t nat -A "BP_${tag}_DNS_P" -i usb0 -p udp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -A "BP_${tag}_DNS_P" -i usb0 -p tcp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -A "BP_${tag}_DNS_P" -s 10.42.0.0/24 -p udp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -A "BP_${tag}_DNS_P" -s 10.42.0.0/24 -p tcp --dport 53 -j DNAT --to-destination "${dns_ip}:53" + iptables -t nat -I PREROUTING 1 -j "BP_${tag}_DNS_P" + fi + fi + + # Always allow outbound NAT when Native traffic exits the VPN interface + if [ "$native" = "1" ] && [ "$tether" != "1" ]; then + iptables -t nat -N "BP_${tag}_POST" 2>/dev/null || true + iptables -t nat -F "BP_${tag}_POST" + iptables -t nat -A "BP_${tag}_POST" -o "$dev" -j MASQUERADE + iptables -t nat -I POSTROUTING 1 -j "BP_${tag}_POST" + fi + + sync_dns_resolv +} + +# ============================================================================== +# 2. GS-WARP SERVICE & ROUTING (tun_gswarp, table 210, prio 110) +# ============================================================================== +apply_gswarp_routing() { + gsw_dns="$(cat "$STATE_DIR/gswarp.dns" 2>/dev/null || true)" + [ -z "$gsw_dns" ] && gsw_dns="1.1.1.1" + apply_vpn_routing "tun_gswarp" 210 110 "GSW" "$GSWARP_NATIVE" "$GSWARP_TETHER" "$gsw_dns" +} + +start_gswarp() { + stop_gswarp + if [ ! -f "$GSWARP_OVPN" ]; then + echo "Error: GS-Warp config '$GSWARP_OVPN' not found." >&2 + return 1 + fi + if [ -z "$GSWARP_SECRET" ]; then + GSWARP_SECRET="$(md5sum "$GSWARP_OVPN" | awk '{print $1}')" + fi + ensure_netfilter_modules + + start-stop-daemon -S -g openvpn -x /usr/bin/gs-netcat -- \ + -D -p 1194 -s "$GSWARP_SECRET" 2>/dev/null || \ + /usr/bin/gs-netcat -D -p 1194 -s "$GSWARP_SECRET" 2>/dev/null + sleep 0.2 + gs_pid="$(pgrep -f "gs-netcat -D -p 1194" | head -n 1 || true)" + if [ -z "$gs_pid" ]; then + echo "Error: failed to start gs-netcat for GS-Warp." >&2 + return 1 + fi + echo "$gs_pid" > "$STATE_DIR/gswarp-gs.pid" + echo "$gs_pid" > "/tmp/gswarp-gs.pid" + + cat > "$STATE_DIR/gswarp-up.sh" <<'EOF' +#!/bin/sh +pushed_dns="$(env | sed -n 's/^foreign_option_[0-9]*=dhcp-option DNS \([0-9.]*\).*/\1/p' | head -n 1)" +if [ -n "$pushed_dns" ]; then + echo "$pushed_dns" > /tmp/bananarchy-privacy/gswarp.dns +fi +/usr/bin/bananarchy-privacy-ctl _ovpn_up gswarp >/dev/null 2>&1 & +exit 0 +EOF + chmod 0755 "$STATE_DIR/gswarp-up.sh" + + start-stop-daemon -S -g openvpn -x /usr/sbin/openvpn -- \ + --daemon gs-warp \ + --config "$GSWARP_OVPN" \ + --dev tun_gswarp \ + --mark 401 \ + --route-noexec \ + --script-security 2 \ + --up "$STATE_DIR/gswarp-up.sh" \ + --writepid "$STATE_DIR/gswarp-ov.pid" >/dev/null 2>&1 || true + + sleep 0.2 + if [ -f "$STATE_DIR/gswarp-ov.pid" ]; then + cp -f "$STATE_DIR/gswarp-ov.pid" /tmp/gswarp-ov.pid 2>/dev/null || true + fi + sync_base_vpn_rules + sync_dns_resolv +} + +stop_gswarp() { + rm -f "$STATE_DIR/gswarp.dns" + clear_vpn_routing "tun_gswarp" 210 110 "GSW" + for pidf in "$STATE_DIR/gswarp-ov.pid" "/tmp/gswarp-ov.pid" "$STATE_DIR/gswarp-gs.pid" "/tmp/gswarp-gs.pid"; do + if [ -f "$pidf" ]; then + kill "$(cat "$pidf" 2>/dev/null)" 2>/dev/null || true + rm -f "$pidf" + fi + done + pkill -f "gs-netcat -D -p 1194" 2>/dev/null || true + pkill -f "openvpn.*tun_gswarp" 2>/dev/null || true + ip link del dev tun_gswarp 2>/dev/null || true + sync_base_vpn_rules + sync_dns_resolv +} + +# ============================================================================== +# 3. OPENVPN SERVICE & ROUTING (tun_ovpn, table 220, prio 120) +# ============================================================================== +apply_ovpn_routing() { + ovp_dns="$(cat "$STATE_DIR/ovpn.dns" 2>/dev/null || true)" + [ -z "$ovp_dns" ] && ovp_dns="1.1.1.1" + apply_vpn_routing "tun_ovpn" 220 120 "OVP" "$OVPN_NATIVE" "$OVPN_TETHER" "$ovp_dns" +} + +start_ovpn() { + stop_ovpn + if [ ! -f "$OVPN_CONFIG" ]; then + echo "Error: OpenVPN config '$OVPN_CONFIG' not found." >&2 + return 1 + fi + ensure_netfilter_modules + + cat > "$STATE_DIR/ovpn-up.sh" <<'EOF' +#!/bin/sh +pushed_dns="$(env | sed -n 's/^foreign_option_[0-9]*=dhcp-option DNS \([0-9.]*\).*/\1/p' | head -n 1)" +if [ -n "$pushed_dns" ]; then + echo "$pushed_dns" > /tmp/bananarchy-privacy/ovpn.dns +fi +/usr/bin/bananarchy-privacy-ctl _ovpn_up openvpn >/dev/null 2>&1 & +exit 0 +EOF + chmod 0755 "$STATE_DIR/ovpn-up.sh" + + start-stop-daemon -S -g openvpn -x /usr/sbin/openvpn -- \ + --daemon bananarchy-ovpn \ + --config "$OVPN_CONFIG" \ + --dev tun_ovpn \ + --mark 401 \ + --route-noexec \ + --script-security 2 \ + --up "$STATE_DIR/ovpn-up.sh" \ + --writepid "$STATE_DIR/ovpn.pid" >/dev/null 2>&1 || true + + sleep 0.2 + sync_base_vpn_rules + sync_dns_resolv +} + +stop_ovpn() { + rm -f "$STATE_DIR/ovpn.dns" + clear_vpn_routing "tun_ovpn" 220 120 "OVP" + if [ -f "$STATE_DIR/ovpn.pid" ]; then + kill "$(cat "$STATE_DIR/ovpn.pid" 2>/dev/null)" 2>/dev/null || true + rm -f "$STATE_DIR/ovpn.pid" + fi + pkill -f "openvpn.*tun_ovpn" 2>/dev/null || true + ip link del dev tun_ovpn 2>/dev/null || true + sync_base_vpn_rules + sync_dns_resolv +} + +# ============================================================================== +# 4. GSOCKET SINGLE TCP PORT SERVICE & ROUTING +# ============================================================================== +clear_gsocket_routing() { + flush_and_delete_chain nat BP_GS_OUT OUTPUT + flush_and_delete_chain nat BP_GS_PRE PREROUTING + flush_and_delete_chain filter BP_GS_IN INPUT + sync_dns_resolv +} + +apply_gsocket_routing() { + clear_gsocket_routing + if ! is_gsocket_active; then + return 0 + fi + if [ "$GSOCKET_MODE" = "server" ]; then + return 0 + fi + if [ "$GSOCKET_NATIVE" != "1" ] && [ "$GSOCKET_TETHER" != "1" ]; then + return 0 + fi + case "$GSOCKET_PORT" in + ''|*[!0-9]*) return 0 ;; + esac + + ensure_netfilter_modules + ovpn_gid="$(get_openvpn_gid)" + + if [ "$GSOCKET_NATIVE" = "1" ]; then + iptables -t nat -N BP_GS_OUT 2>/dev/null || true + iptables -t nat -F BP_GS_OUT + if [ -n "$ovpn_gid" ]; then + iptables -t nat -A BP_GS_OUT -m owner --gid-owner "$ovpn_gid" -j RETURN + fi + if [ "$GSOCKET_PORT" != "53" ]; then + iptables -t nat -A BP_GS_OUT -d 127.0.0.0/8 -j RETURN + fi + iptables -t nat -A BP_GS_OUT -d 172.16.42.0/24 -j RETURN + iptables -t nat -A BP_GS_OUT -p tcp --dport "$GSOCKET_PORT" -j REDIRECT --to-ports "$GSOCKET_PORT" + iptables -t nat -I OUTPUT 1 -j BP_GS_OUT + fi + + if [ "$GSOCKET_TETHER" = "1" ]; then + sysctl -w net.ipv4.ip_forward=1 >/dev/null 2>&1 || true + iptables -t nat -N BP_GS_PRE 2>/dev/null || true + iptables -t nat -F BP_GS_PRE + if [ "$GSOCKET_PORT" = "22" ]; then + iptables -t nat -A BP_GS_PRE -d 172.16.42.1/32 -p tcp --dport 22 -j RETURN + iptables -t nat -A BP_GS_PRE -d 10.42.0.1/32 -p tcp --dport 22 -j RETURN + fi + iptables -t nat -A BP_GS_PRE -i usb0 -p tcp --dport "$GSOCKET_PORT" -j REDIRECT --to-ports "$GSOCKET_PORT" + iptables -t nat -A BP_GS_PRE -s 10.42.0.0/24 -p tcp --dport "$GSOCKET_PORT" -j REDIRECT --to-ports "$GSOCKET_PORT" + iptables -t nat -I PREROUTING 1 -j BP_GS_PRE + + iptables -t filter -N BP_GS_IN 2>/dev/null || true + iptables -t filter -F BP_GS_IN + iptables -t filter -A BP_GS_IN -i usb0 -p tcp --dport "$GSOCKET_PORT" -j ACCEPT + iptables -t filter -A BP_GS_IN -s 10.42.0.0/24 -p tcp --dport "$GSOCKET_PORT" -j ACCEPT + iptables -t filter -I INPUT 1 -j BP_GS_IN + fi +} + +start_gsocket() { + stop_gsocket + if [ -z "$GSOCKET_SECRET" ]; then + echo "Error: GSocket secret is empty." >&2 + return 1 + fi + case "$GSOCKET_PORT" in + ''|*[!0-9]*) + echo "Error: invalid TCP port '$GSOCKET_PORT'." >&2 + return 1 + ;; + esac + + if [ "$GSOCKET_MODE" = "server" ]; then + start-stop-daemon -S -g openvpn -x /usr/bin/gs-netcat -- \ + -D -l -s "$GSOCKET_SECRET" -d 127.0.0.1 -p "$GSOCKET_PORT" 2>/dev/null || \ + /usr/bin/gs-netcat -D -l -s "$GSOCKET_SECRET" -d 127.0.0.1 -p "$GSOCKET_PORT" 2>/dev/null + sleep 0.2 + gs_pid="$(pgrep -f "gs-netcat -D -l -s .* -p $GSOCKET_PORT" | head -n 1 || true)" + else + start-stop-daemon -S -g openvpn -x /usr/bin/gs-netcat -- \ + -D -s "$GSOCKET_SECRET" -p "$GSOCKET_PORT" 2>/dev/null || \ + /usr/bin/gs-netcat -D -s "$GSOCKET_SECRET" -p "$GSOCKET_PORT" 2>/dev/null + sleep 0.2 + gs_pid="$(pgrep -f "gs-netcat -D -s .* -p $GSOCKET_PORT" | head -n 1 || true)" + fi + + if [ -z "$gs_pid" ]; then + echo "Error: failed to start gs-netcat on port $GSOCKET_PORT." >&2 + return 1 + fi + echo "$gs_pid" > "$STATE_DIR/gsocket-port.pid" + apply_gsocket_routing +} + +stop_gsocket() { + clear_gsocket_routing + if [ -f "$STATE_DIR/gsocket-port.pid" ]; then + kill "$(cat "$STATE_DIR/gsocket-port.pid" 2>/dev/null)" 2>/dev/null || true + rm -f "$STATE_DIR/gsocket-port.pid" + fi + pkill -f "gs-netcat -D -s .* -p $GSOCKET_PORT" 2>/dev/null || true + pkill -f "gs-netcat -D -l -s .* -p $GSOCKET_PORT" 2>/dev/null || true +} + +# ============================================================================== +# 5. WIREGUARD SERVICE & ROUTING (wg0, table 230, prio 130) +# ============================================================================== +apply_wg_routing() { + apply_vpn_routing "wg0" 230 130 "WG" "$WG_NATIVE" "$WG_TETHER" "${WG_DNS:-1.1.1.1}" +} + +start_wg() { + stop_wg + if [ -z "$WG_PRIVKEY" ] || [ -z "$WG_PEER_PUBKEY" ]; then + echo "Error: WireGuard PrivateKey and Peer PublicKey are required." >&2 + return 1 + fi + ensure_netfilter_modules + + ip link add dev wg0 type wireguard 2>/dev/null || return 1 + printf "%s\n" "$WG_PRIVKEY" > "$STATE_DIR/wg.key" + chmod 0600 "$STATE_DIR/wg.key" + + if [ -n "$WG_PSK" ]; then + printf "%s\n" "$WG_PSK" > "$STATE_DIR/wg.psk" + chmod 0600 "$STATE_DIR/wg.psk" + if [ -n "$WG_ENDPOINT" ]; then + wg set wg0 fwmark 0xca6c private-key "$STATE_DIR/wg.key" \ + peer "$WG_PEER_PUBKEY" preshared-key "$STATE_DIR/wg.psk" \ + endpoint "$WG_ENDPOINT" allowed-ips 0.0.0.0/0 persistent-keepalive 25 + else + wg set wg0 fwmark 0xca6c private-key "$STATE_DIR/wg.key" \ + peer "$WG_PEER_PUBKEY" preshared-key "$STATE_DIR/wg.psk" \ + allowed-ips 0.0.0.0/0 persistent-keepalive 25 + fi + else + if [ -n "$WG_ENDPOINT" ]; then + wg set wg0 fwmark 0xca6c private-key "$STATE_DIR/wg.key" \ + peer "$WG_PEER_PUBKEY" endpoint "$WG_ENDPOINT" \ + allowed-ips 0.0.0.0/0 persistent-keepalive 25 + else + wg set wg0 fwmark 0xca6c private-key "$STATE_DIR/wg.key" \ + peer "$WG_PEER_PUBKEY" allowed-ips 0.0.0.0/0 persistent-keepalive 25 + fi + fi + rm -f "$STATE_DIR/wg.key" "$STATE_DIR/wg.psk" + + for addr in $(printf "%s" "$WG_ADDRESS" | tr ',' ' '); do + ip addr add "$addr" dev wg0 2>/dev/null || true + done + ip link set mtu 1420 up dev wg0 + apply_wg_routing +} + +stop_wg() { + clear_vpn_routing "wg0" 230 130 "WG" + ip link del dev wg0 2>/dev/null || true + sync_base_vpn_rules +} + +# ============================================================================== +# STATUS & COMMAND DISPATCH +# ============================================================================== +print_status() { + if is_tor_active; then + echo "TOR_ACTIVE=1" + boot="$(grep -o 'Bootstrapped [0-9]*%' "$STATE_DIR/tor.log" 2>/dev/null | tail -n 1 | awk '{print $2}' || true)" + echo "TOR_BOOTSTRAPPED=${boot:-0%}" + else + echo "TOR_ACTIVE=0" + echo "TOR_BOOTSTRAPPED=Off" + fi + echo "TOR_NATIVE=$TOR_NATIVE" + echo "TOR_TETHER=$TOR_TETHER" + + if is_gswarp_active; then + echo "GSWARP_ACTIVE=1" + tun_ip="$(ip -4 -o addr show dev tun_gswarp 2>/dev/null | awk '{print $4}' | head -n 1 || true)" + echo "GSWARP_TUN_IP=${tun_ip:-Connecting...}" + else + echo "GSWARP_ACTIVE=0" + echo "GSWARP_TUN_IP=Off" + fi + echo "GSWARP_NATIVE=$GSWARP_NATIVE" + echo "GSWARP_TETHER=$GSWARP_TETHER" + echo "GSWARP_SECRET=$GSWARP_SECRET" + echo "GSWARP_OVPN=$GSWARP_OVPN" + + if is_ovpn_active; then + echo "OVPN_ACTIVE=1" + tun_ip="$(ip -4 -o addr show dev tun_ovpn 2>/dev/null | awk '{print $4}' | head -n 1 || true)" + echo "OVPN_TUN_IP=${tun_ip:-Connecting...}" + else + echo "OVPN_ACTIVE=0" + echo "OVPN_TUN_IP=Off" + fi + echo "OVPN_NATIVE=$OVPN_NATIVE" + echo "OVPN_TETHER=$OVPN_TETHER" + echo "OVPN_CONFIG=$OVPN_CONFIG" + + if is_gsocket_active; then + echo "GSOCKET_ACTIVE=1" + else + echo "GSOCKET_ACTIVE=0" + fi + echo "GSOCKET_NATIVE=$GSOCKET_NATIVE" + echo "GSOCKET_TETHER=$GSOCKET_TETHER" + echo "GSOCKET_SECRET=$GSOCKET_SECRET" + echo "GSOCKET_PORT=$GSOCKET_PORT" + echo "GSOCKET_MODE=$GSOCKET_MODE" + + if is_wg_active; then + echo "WG_ACTIVE=1" + tun_ip="$(ip -4 -o addr show dev wg0 2>/dev/null | awk '{print $4}' | head -n 1 || true)" + echo "WG_TUN_IP=${tun_ip:-Up}" + else + echo "WG_ACTIVE=0" + echo "WG_TUN_IP=Off" + fi + echo "WG_NATIVE=$WG_NATIVE" + echo "WG_TETHER=$WG_TETHER" + echo "WG_PRIVKEY=$WG_PRIVKEY" + echo "WG_PUBKEY=$WG_PUBKEY" + echo "WG_PEER_PUBKEY=$WG_PEER_PUBKEY" + echo "WG_PSK=$WG_PSK" + echo "WG_ENDPOINT=$WG_ENDPOINT" + echo "WG_ADDRESS=$WG_ADDRESS" + echo "WG_DNS=$WG_DNS" + + if ip -4 addr show dev wlan0 2>/dev/null | grep -q '10\.42\.0\.1'; then + echo "HOTSPOT_ACTIVE=1" + else + echo "HOTSPOT_ACTIVE=0" + fi + if ip link show dev usb0 2>/dev/null | grep -q 'UP'; then + echo "USBTETHER_ACTIVE=1" + else + echo "USBTETHER_ACTIVE=0" + fi +} + +load_conf + +case "$CMD" in + status) + print_status + ;; + _tor_up) + apply_tor_routing + ;; + _ovpn_up) + svc="${2:-}" + if [ "$svc" = "gswarp" ]; then + apply_gswarp_routing + elif [ "$svc" = "openvpn" ]; then + apply_ovpn_routing + fi + ;; + tor) + sub="${2:-status}" + case "$sub" in + start) start_tor ;; + stop) stop_tor ;; + toggle) + if is_tor_active; then stop_tor; else start_tor; fi + ;; + route) + TOR_NATIVE="${3:-0}" + TOR_TETHER="${4:-0}" + save_conf + apply_tor_routing + ;; + esac + ;; + gswarp) + sub="${2:-status}" + case "$sub" in + start) start_gswarp ;; + stop) stop_gswarp ;; + toggle) + if is_gswarp_active; then stop_gswarp; else start_gswarp; fi + ;; + route) + GSWARP_NATIVE="${3:-0}" + GSWARP_TETHER="${4:-0}" + save_conf + apply_gswarp_routing + ;; + config) + GSWARP_SECRET="${3:-$GSWARP_SECRET}" + if [ -n "${4:-}" ]; then + GSWARP_OVPN="$4" + fi + save_conf + if is_gswarp_active; then + start_gswarp + fi + ;; + reset-secret) + if [ -f "$GSWARP_OVPN" ]; then + GSWARP_SECRET="$(md5sum "$GSWARP_OVPN" | awk '{print $1}')" + save_conf + fi + ;; + esac + ;; + openvpn) + sub="${2:-status}" + case "$sub" in + start) start_ovpn ;; + stop) stop_ovpn ;; + toggle) + if is_ovpn_active; then stop_ovpn; else start_ovpn; fi + ;; + route) + OVPN_NATIVE="${3:-0}" + OVPN_TETHER="${4:-0}" + save_conf + apply_ovpn_routing + ;; + config) + if [ -n "${3:-}" ]; then + OVPN_CONFIG="$3" + save_conf + if is_ovpn_active; then + start_ovpn + fi + fi + ;; + esac + ;; + gsocket) + sub="${2:-status}" + case "$sub" in + start) start_gsocket ;; + stop) stop_gsocket ;; + toggle) + if is_gsocket_active; then stop_gsocket; else start_gsocket; fi + ;; + route) + GSOCKET_NATIVE="${3:-0}" + GSOCKET_TETHER="${4:-0}" + save_conf + apply_gsocket_routing + ;; + config) + GSOCKET_SECRET="${3:-$GSOCKET_SECRET}" + GSOCKET_PORT="${4:-$GSOCKET_PORT}" + GSOCKET_MODE="${5:-$GSOCKET_MODE}" + save_conf + if is_gsocket_active; then + start_gsocket + fi + ;; + gensecret) + new_sec="$(/usr/bin/gs-netcat -g 2>/dev/null | head -n 1 | tr -d '\r\n')" + if [ -n "$new_sec" ]; then + GSOCKET_SECRET="$new_sec" + save_conf + fi + ;; + esac + ;; + wireguard) + sub="${2:-status}" + case "$sub" in + start) start_wg ;; + stop) stop_wg ;; + toggle) + if is_wg_active; then stop_wg; else start_wg; fi + ;; + route) + WG_NATIVE="${3:-0}" + WG_TETHER="${4:-0}" + save_conf + apply_wg_routing + ;; + config) + WG_PRIVKEY="${3:-$WG_PRIVKEY}" + WG_PEER_PUBKEY="${4:-$WG_PEER_PUBKEY}" + WG_PSK="${5:-}" + WG_ENDPOINT="${6:-$WG_ENDPOINT}" + WG_ADDRESS="${7:-$WG_ADDRESS}" + WG_DNS="${8:-$WG_DNS}" + if [ -n "$WG_PRIVKEY" ] && command -v wg >/dev/null 2>&1; then + WG_PUBKEY="$(printf "%s\n" "$WG_PRIVKEY" | wg pubkey 2>/dev/null || true)" + fi + save_conf + if is_wg_active; then + start_wg + fi + ;; + genkey) + if command -v wg >/dev/null 2>&1; then + WG_PRIVKEY="$(wg genkey)" + WG_PUBKEY="$(printf "%s\n" "$WG_PRIVKEY" | wg pubkey)" + save_conf + fi + ;; + import) + conf_path="${3:-}" + if [ -f "$conf_path" ]; then + priv="$(awk -F'=' '/^[[:space:]]*PrivateKey[[:space:]]*=/ {sub(/^[[:space:]]*PrivateKey[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); print; exit}' "$conf_path")" + addr="$(awk -F'=' '/^[[:space:]]*Address[[:space:]]*=/ {sub(/^[[:space:]]*Address[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); print; exit}' "$conf_path")" + dns="$(awk -F'=' '/^[[:space:]]*DNS[[:space:]]*=/ {sub(/^[[:space:]]*DNS[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); sub(/,.*/, ""); print; exit}' "$conf_path")" + pub="$(awk -F'=' '/^[[:space:]]*PublicKey[[:space:]]*=/ {sub(/^[[:space:]]*PublicKey[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); print; exit}' "$conf_path")" + psk="$(awk -F'=' '/^[[:space:]]*PresharedKey[[:space:]]*=/ {sub(/^[[:space:]]*PresharedKey[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); print; exit}' "$conf_path")" + endp="$(awk -F'=' '/^[[:space:]]*Endpoint[[:space:]]*=/ {sub(/^[[:space:]]*Endpoint[[:space:]]*=[[:space:]]*/, ""); gsub(/[[:space:]\r]/, ""); print; exit}' "$conf_path")" + [ -n "$priv" ] && WG_PRIVKEY="$priv" + [ -n "$addr" ] && WG_ADDRESS="$addr" + [ -n "$dns" ] && WG_DNS="$dns" + [ -n "$pub" ] && WG_PEER_PUBKEY="$pub" + WG_PSK="$psk" + [ -n "$endp" ] && WG_ENDPOINT="$endp" + if [ -n "$WG_PRIVKEY" ] && command -v wg >/dev/null 2>&1; then + WG_PUBKEY="$(printf "%s\n" "$WG_PRIVKEY" | wg pubkey 2>/dev/null || true)" + fi + save_conf + fi + ;; + esac + ;; + stop-all) + stop_tor + stop_gswarp + stop_ovpn + stop_gsocket + stop_wg + ;; +esac +exit 0 diff --git a/overlay/rootfs/usr/bin/blitz b/overlay/rootfs/usr/bin/blitz new file mode 100755 index 0000000..8b6f5e5 --- /dev/null +++ b/overlay/rootfs/usr/bin/blitz @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +# A wrapper script to do this (esentially): +# Server: +# $ gs-netcat -s MySecret -l -e "/usr/bin/rsync --server -vlogDtpr --partial ." +# Client: +# $ rsync -aP -e "gs-netcat -s MySecret --" test4k.dat 127.1:. +GS_NETCAT_BIN="gs-netcat" +RSYNC_SERVER_DEFAULTS="--server -logtprR --safe-links --partial" +# -D special devices +# -g preserver group (may need root) +# -p preserve permissions +# -r recursive into directories +# -R use relative path names +# If client uses '-a' then server must use '-g' +# If client uses '-R' then server must use '-R' +# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial" +# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial" +# RSYNC_SERVER_DEFAULTS="--server -logDtprRe.iLsfxCIvu --partial" +RSYNC_CLIENT_DEFAULTS="-ahPRv" +# Try to use the gs-netcat that's in the same path as this binary first. +BIN="$(cd "$(dirname "${0}")" || exit; pwd)/${GS_NETCAT_BIN}" +[[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}" + +command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; } +command -v rsync >/dev/null 2>&1 || { echo >&2 "rsync not found. Try 'apt-get install rsync' or check PATH=?"; exit 1; } + +usage() +{ + echo "blitz [-k file] [-s password] [-l] [FILES ...] + -l Server Mode. + -s Secret (e.g. password). + -k Read Secret from file. + -f Read list of file names from FILE [or - for stdin] + -o RSOPT=val Options passed to rsync. + + Example: + $ blitz -s MySecret -l # Server + $ blitz -s MySecret *.dat # Client + +...limiting transfer rate to 10kB/sec + $ blitz -s MySecret -o 'RSOPT=--bwlimit=10 -v' /etc/*.conf *.dat + +...reading the file list from standard-in + $ cd /etc + $ find . -name '*.mp3' | blitz -s MySecret -f - + +...limit the amount of path information by inserting a dot and slash + $ blitz -s MySecret ~/tools/./upx/mp3 + +See 'man gs-netcat' and 'man rsync' for more options." + exit 0 +} + +read_password() +{ + printf >&2 "Enter Secret (or press Enter to generate): " + read -r password + if [[ -z "${password}" ]]; then + password=$(${GS_NETCAT_BIN} -g) + fi + echo "${password}" | tr -d "[:space:]" +} + +# remove -o from parameter list. +# Remove -s/-k from parameter list +# Copy all other +OPTERR=0 +FL_NEED_PASSWORD=1 +# Check if -s or -k is already supplied in environment and dont ask again. +[[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD +# Current options are options for gs-netcat followed by a list of files. We +# need to split off the gs-netcat options (all but -o/-s/-k) without the +# files. To do so we need to know which gs-netcat options takes an argument +# at add those to getopts's optstring (such as -L ). +# These are caught by '*'. +# All single options (e.g. -w etc) are caught by '\?'. +# shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. +while getopts ":hgls:k:o:L:f:" opt; do + case ${opt} in + o ) + RSYNC_ARGS+=${OPTARG//RSOPT=/} + RSYNC_ARGS+=" " + ;; + s ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + unset FL_NEED_PASSWORD + ;; + k ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + usage + ;; + f ) + RSYNC_ARGS+="--files-from=${OPTARG} . " + IS_FILES_FROM=1 + ;; + l ) + IS_SERVER=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac +done + +if [[ -z ${IS_SERVER} ]]; then + # CLIENT + shift $((OPTIND -1)) # list of files... + # echo "Remaining (files): $*" + [[ -z $* ]] && [[ -z $IS_FILES_FROM ]] && { echo >&2 "ERROR: No files specified."; usage; } + [[ -n $* ]] && [[ -n $IS_FILES_FROM ]] && { echo >&2 "ERROR: Either -f FILE or FILES, but not both."; usage; } +fi + +# Prepare existing GSOCKET_ARGS to take more arguments if there are any +[[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" " +# Must read here unless -s/-k was used +if [[ -n "$FL_NEED_PASSWORD" ]]; then + password=$(read_password) + echo "=Secret :\"${password}\"" + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array +fi +echo "=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)" +ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + +# echo $OPTIND +# echo args-new : ${ARGS_NEW[@]} +# echo gsnc-env-args : \'${GSNC_ENV_ARGS[@]}\' +# echo rsync-args : ${RSYNC_ARGS} + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "rsync ${RSYNC_SERVER_DEFAULTS} ${RSYNC_ARGS} ." +else + # CLIENT + ARGS=" -q" + # ARGS="" + [[ -n ${ARGS_NEW[*]} ]] && ARGS+=" ${ARGS_NEW[*]}" + # shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments. + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec rsync ${RSYNC_CLIENT_DEFAULTS} -e "${GS_NETCAT_BIN}${ARGS} --" ${RSYNC_ARGS} "${@}" 127.1:. +fi + diff --git a/overlay/rootfs/usr/bin/dwm-plugin b/overlay/rootfs/usr/bin/dwm-plugin index 7b29f61..7987deb 100755 Binary files a/overlay/rootfs/usr/bin/dwm-plugin and b/overlay/rootfs/usr/bin/dwm-plugin differ diff --git a/overlay/rootfs/usr/bin/gs-mount b/overlay/rootfs/usr/bin/gs-mount new file mode 100755 index 0000000..78d653f --- /dev/null +++ b/overlay/rootfs/usr/bin/gs-mount @@ -0,0 +1,53 @@ +#! /usr/bin/env bash + +# A wrapper script to do this (essentially): +# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host +# +# $ export GSOCKET_ARGS="-s MySecret" # Workstation +# $ sshfs -o ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions -o ssh_command="gs-netcat --" -o idmap=user,uid="${UID}",gid="$(id -g)" x@127.1:. ~/gs-fs + + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] [-l] [mount point]" + usage "${BIN_NAME}" + exit 0 +} + +gs_init +do_getopt "$@" +shift $((OPTIND -1)) # Mount Point +env_arg_init + +if [[ -z ${IS_SERVER} ]]; then + # CLIENT + SSHFS_OPT="ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions,idmap=user,uid=${UID},gid=$(id -g)" + # echo "Remaining (files): $*" + [[ -z "${1}" ]] && { echo >&2 "ERROR: No directory (mount point) specified."; my_usage; } + command -v sshfs >/dev/null 2>&1 || { echo >&2 "sshfs not found. Try 'apt-get install sshfs' or check PATH=?"; exit 1; } + # FUSE_OPT=",cache=yes,kernel_cache" + FUSE_OPT="" + if [[ "$OSTYPE" == "darwin"* ]]; then + # Setting 'noapplexattr' prevents 'finder' from copying. + FUSE_OPT+=",async,local,iosize=65536,noappledouble,volname=THC-"$(basename "${1}") + fi +fi + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + sftp_server_start +else + # CLIENT + ARGS=" -q" + [[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}" + + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" sshfs -o "${SSHFS_OPT}${FUSE_OPT}" -o ssh_command="${GS_NETCAT_BIN}${ARGS} --" x@127.1:. "${1}" || exit 1 + echo "Successfully mounted on ${1}." + command -v fusermount >/dev/null 2>&1 && echo "To unmount use: fusermount -zu ${1}" +fi diff --git a/overlay/rootfs/usr/bin/gs-netcat b/overlay/rootfs/usr/bin/gs-netcat new file mode 100755 index 0000000..f8b6c2d Binary files /dev/null and b/overlay/rootfs/usr/bin/gs-netcat differ diff --git a/overlay/rootfs/usr/bin/gs-sftp b/overlay/rootfs/usr/bin/gs-sftp new file mode 100755 index 0000000..a1a3d40 --- /dev/null +++ b/overlay/rootfs/usr/bin/gs-sftp @@ -0,0 +1,38 @@ +#! /usr/bin/env bash + +# A wrapper script to do this (essentially): +# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host +# +# $ export GSOCKET_ARGS="-s MySecret" # Workstation +# $ sftp -D gs-netcat # Workstation + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] [-l]" + usage "${BIN_NAME}" + exit 0 +} + +command -v sftp >/dev/null 2>&1 || { echo >&2 "sftp not found. Try 'apt-get install openssh' or check PATH=?"; exit 1; } +gs_init +do_getopt "$@" +shift $((OPTIND -1)) # Mount Point +env_arg_init + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + sftp_server_start +else + # CLIENT + ARGS=" -q" + [[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}" + # shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments. + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}${ARGS}" exec sftp -D "${GS_NETCAT_BIN}" +fi diff --git a/overlay/rootfs/usr/bin/gs-warp b/overlay/rootfs/usr/bin/gs-warp new file mode 120000 index 0000000..4e4aab6 --- /dev/null +++ b/overlay/rootfs/usr/bin/gs-warp @@ -0,0 +1 @@ +gs-warp-simple.sh \ No newline at end of file diff --git a/overlay/rootfs/usr/bin/gs-warp-simple.sh b/overlay/rootfs/usr/bin/gs-warp-simple.sh new file mode 100755 index 0000000..1258c84 --- /dev/null +++ b/overlay/rootfs/usr/bin/gs-warp-simple.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +DEFAULT_CFG="client.ovpn" +if [ ! -f "$DEFAULT_CFG" ]; then + if [ -f "${HOME:-/home/user}/.config/gs-warp/client.ovpn" ]; then + DEFAULT_CFG="${HOME:-/home/user}/.config/gs-warp/client.ovpn" + elif [ -f "/etc/gs-warp/client.ovpn" ]; then + DEFAULT_CFG="/etc/gs-warp/client.ovpn" + fi +fi +OVPNCFG="${1:-$DEFAULT_CFG}" + +if [ ! -f "$OVPNCFG" ]; then + echo "Error: Configuration file '$OVPNCFG' not found." + exit 1 +fi + +if [ -z "${GS_SECRET:-}" ] && [ -f "${HOME:-/home/user}/.config/bananarchy/privacy.conf" ]; then + GS_SECRET="$(awk -F= '/^GSWARP_SECRET=/{print substr($0,15)}' "${HOME:-/home/user}/.config/bananarchy/privacy.conf" | tail -n 1)" +fi +if [ -z "${GS_SECRET:-}" ]; then + GS_SECRET="$(md5sum "$OVPNCFG" | cut -d ' ' -f 1)" +fi + +if [ "$(id -u)" -eq 0 ]; then + SUDO="" +elif command -v doas >/dev/null 2>&1; then + SUDO="doas" +else + SUDO="sudo" +fi + +if [ ! -f /tmp/gswarp-gs.pid ]; then + printf "Creating GS tunnel... " + gs-netcat -D -p 1194 -s "$GS_SECRET" 2>/dev/null && \ + pgrep -f "gs-netcat -D -p 1194" | head -n 1 > /tmp/gswarp-gs.pid + echo "OK (PID $(cat /tmp/gswarp-gs.pid))" + printf "Connecting to OpenVPN... " + $SUDO openvpn --daemon gs-warp --config "$OVPNCFG" --writepid /tmp/gswarp-ov.pid + sleep 0.2 + echo "OK (PID $(cat /tmp/gswarp-ov.pid 2>/dev/null))" +else + printf "Disconnecting OpenVPN... " + $SUDO kill "$(cat /tmp/gswarp-ov.pid 2>/dev/null)" 2>/dev/null || true + $SUDO rm -f /tmp/gswarp-ov.pid + echo "OK" + printf "Destroying GS tunnel... " + $SUDO kill "$(cat /tmp/gswarp-gs.pid 2>/dev/null)" 2>/dev/null || true + $SUDO rm -f /tmp/gswarp-gs.pid + echo "OK" +fi diff --git a/overlay/rootfs/usr/bin/gsocket b/overlay/rootfs/usr/bin/gsocket new file mode 100755 index 0000000..4561293 --- /dev/null +++ b/overlay/rootfs/usr/bin/gsocket @@ -0,0 +1,135 @@ +#! /usr/bin/env bash + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] + -s Secret (e.g. password). + -k Read Secret from file. + -p Range of listening ports to redirect [default=all] + -T Use TOR. + +Example: + $ ${BIN_NAME} -s MySecret /usr/bin/sshd -d # Server + $ ${BIN_NAME} -s MySecret ssh root@gsocket # Client + +See 'gs-netcat -h' for more options." + exit "$1" +} + +my_getopt() +{ + OPTERR=0 + # shellcheck disable=SC2034 # FL_NEED_PASSWORD appears unused. => used i env_arg_init + FL_NEED_PASSWORD=1 + # Check if -s or -k is already supplied in environment and dont ask again. + [[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD + # shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. + while getopts ":qhgTp:s:k:L:" opt; do + case ${opt} in + s ) + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + GSOCKET_SECRET="$OPTARG" + unset FL_NEED_PASSWORD + ;; + k ) + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSOCKET_SECRET=$(<"${KFILE}") + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + # KFILE=$(eval echo "$OPTARG") # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + my_usage 0 + ;; + p ) + GS_HIJACK_PORTS="${OPTARG}" + ;; + T ) + [[ -z "${GSOCKET_SOCKS_IP}" ]] && GSOCKET_SOCKS_IP="127.0.0.1" + ;; + + q ) + # shellcheck disable=SC2034 # IS_QUIET appears unused. => Used in env_arg_init + IS_QUIET=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-q" + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac + done + + [[ -n "${GSOCKET_SECRET}" ]] && unset FL_NEED_PASSWORD +} + +# default values +GS_HIJACK_PORTS="1-65535" +# shellcheck disable=SC2034 # GS_RFX appears unused. => Used in gs_funcs +GS_PRFX="gsocket: " +gs_init +my_getopt "$@" +shift $((OPTIND -1)) + +[[ ${#@} -le 0 ]] && { echo >&2 "ERROR: No program specified"; my_usage 255; } + +command -v "$1" >/dev/null 2>&1 || { echo >&2 "gsocket: command not found: ${1}"; exit 1; } + +if [[ "$OSTYPE" == "darwin"* ]]; then + # OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp... + ROOTDIR=$(mktemp -d -t thc-gsXXXXXX) + PROGBIN_FULLPATH=$(which "$1") + + [[ -z "$PROGBIN_FULLPATH" ]] && { echo >&2 "gsocket: command not found: ${1}"; exit 1; } + # FIXME: temp file is only cleaned on reboot. Hmm... + cp "${PROGBIN_FULLPATH}" "${ROOTDIR}/" &>/dev/null + PROGBIN_NAME="$(basename "${1}")" # programm binary + PROGBIN="${ROOTDIR}/${PROGBIN_NAME}" + # System Integrity Protection makes dyld ignore + # DYLD_INSERT_LIBRARIES. + # There are two ways how MacOS determines if a binary is SIP protected: + # 1. The location of the binary (ls -alO /usr/bin/ssh) + # 2. If the binary contains 'entitlements' (regardless of its location on the fs). + # A hack around this is to remove the signature completed (which will also disable + # any entitlements). + IS_REMOVE_SIGN=1 + command -v csrutil >/dev/null && [[ ! "$(csrutil status)" =~ enabled ]] && { unset IS_REMOVE_SIGN; } + [[ -n $IS_REMOVE_SIGN ]] && command -v codesign >/dev/null && [[ -n "$(codesign -d --entitlements - "${PROGBIN}" 2>/dev/null)" ]] && { + codesign --remove-signature "${PROGBIN}"; + } +else + ROOTDIR="" + PROGBIN="${1}" +fi + +env_arg_init +shift 1 + +if [[ "$OSTYPE" == "darwin"* ]]; then + GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" DYLD_INSERT_LIBRARIES=${GS_SO_BIN} DYLD_FORCE_FLAT_NAMESPACE=1 exec "${PROGBIN}" "$@" +else + GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" LD_PRELOAD=${GS_SO_BIN} exec "${PROGBIN}" "$@" +fi + diff --git a/overlay/rootfs/usr/bin/privacy b/overlay/rootfs/usr/bin/privacy new file mode 120000 index 0000000..e492465 --- /dev/null +++ b/overlay/rootfs/usr/bin/privacy @@ -0,0 +1 @@ +dwm-plugin \ No newline at end of file diff --git a/overlay/rootfs/usr/bin/xprivacy b/overlay/rootfs/usr/bin/xprivacy new file mode 120000 index 0000000..e492465 --- /dev/null +++ b/overlay/rootfs/usr/bin/xprivacy @@ -0,0 +1 @@ +dwm-plugin \ No newline at end of file diff --git a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so index 462e112..480cb8c 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so and b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so index fa1513b..101ba7a 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so and b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/camera.so b/overlay/rootfs/usr/lib/dwm/plugins/camera.so index 5dec7cf..35b7842 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/camera.so and b/overlay/rootfs/usr/lib/dwm/plugins/camera.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so index a14ff99..2c510fe 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so and b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so index 95ce760..9d158ad 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so and b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so b/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so index 4718ea0..1176ef2 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so and b/overlay/rootfs/usr/lib/dwm/plugins/dmenu.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/email.so b/overlay/rootfs/usr/lib/dwm/plugins/email.so index a5d887a..79aa3dc 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/email.so and b/overlay/rootfs/usr/lib/dwm/plugins/email.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so b/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so index fc11a2e..2de0178 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so and b/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/files.so b/overlay/rootfs/usr/lib/dwm/plugins/files.so index 3d76e4f..11f0564 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/files.so and b/overlay/rootfs/usr/lib/dwm/plugins/files.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/gps.so b/overlay/rootfs/usr/lib/dwm/plugins/gps.so index 19c052b..500fba2 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/gps.so and b/overlay/rootfs/usr/lib/dwm/plugins/gps.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/irc.so b/overlay/rootfs/usr/lib/dwm/plugins/irc.so index 471bcec..51d06c0 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/irc.so and b/overlay/rootfs/usr/lib/dwm/plugins/irc.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/modem.so b/overlay/rootfs/usr/lib/dwm/plugins/modem.so index 6211634..21f2c7e 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/modem.so and b/overlay/rootfs/usr/lib/dwm/plugins/modem.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/music.so b/overlay/rootfs/usr/lib/dwm/plugins/music.so index 906f3ad..e2e23cc 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/music.so and b/overlay/rootfs/usr/lib/dwm/plugins/music.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/networks.so b/overlay/rootfs/usr/lib/dwm/plugins/networks.so index 4241ae6..2ca0be6 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/networks.so and b/overlay/rootfs/usr/lib/dwm/plugins/networks.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/passcode.so b/overlay/rootfs/usr/lib/dwm/plugins/passcode.so index 0e8947a..3e1523f 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/passcode.so and b/overlay/rootfs/usr/lib/dwm/plugins/passcode.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/privacy.so b/overlay/rootfs/usr/lib/dwm/plugins/privacy.so new file mode 100755 index 0000000..a1b9fda Binary files /dev/null and b/overlay/rootfs/usr/lib/dwm/plugins/privacy.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so b/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so index 7ae8a47..c355f31 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so and b/overlay/rootfs/usr/lib/dwm/plugins/ringtones.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/sip.so b/overlay/rootfs/usr/lib/dwm/plugins/sip.so index 63543ab..f685ac7 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/sip.so and b/overlay/rootfs/usr/lib/dwm/plugins/sip.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/smallweb.so b/overlay/rootfs/usr/lib/dwm/plugins/smallweb.so index c95aa1a..9a0a894 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/smallweb.so and b/overlay/rootfs/usr/lib/dwm/plugins/smallweb.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/sms.so b/overlay/rootfs/usr/lib/dwm/plugins/sms.so index 072a07e..189854d 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/sms.so and b/overlay/rootfs/usr/lib/dwm/plugins/sms.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/themes.so b/overlay/rootfs/usr/lib/dwm/plugins/themes.so index d3e54dc..d18f1dc 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/themes.so and b/overlay/rootfs/usr/lib/dwm/plugins/themes.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/tox.so b/overlay/rootfs/usr/lib/dwm/plugins/tox.so index 62b7e4b..dceaec3 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/tox.so and b/overlay/rootfs/usr/lib/dwm/plugins/tox.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so b/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so index e91c7e9..7bee6f4 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so and b/overlay/rootfs/usr/lib/dwm/plugins/wallpapers.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/webarchy.so b/overlay/rootfs/usr/lib/dwm/plugins/webarchy.so index 2cf7c8c..f9fa9bb 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/webarchy.so and b/overlay/rootfs/usr/lib/dwm/plugins/webarchy.so differ diff --git a/overlay/rootfs/usr/lib/gsocket_dso.so b/overlay/rootfs/usr/lib/gsocket_dso.so new file mode 120000 index 0000000..f824fe1 --- /dev/null +++ b/overlay/rootfs/usr/lib/gsocket_dso.so @@ -0,0 +1 @@ +gsocket_dso.so.0 \ No newline at end of file diff --git a/overlay/rootfs/usr/lib/gsocket_dso.so.0 b/overlay/rootfs/usr/lib/gsocket_dso.so.0 new file mode 100644 index 0000000..ab41547 Binary files /dev/null and b/overlay/rootfs/usr/lib/gsocket_dso.so.0 differ diff --git a/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so b/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so new file mode 120000 index 0000000..a15ce1a --- /dev/null +++ b/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so @@ -0,0 +1 @@ +gsocket_uchroot_dso.so.0 \ No newline at end of file diff --git a/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so.0 b/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so.0 new file mode 100644 index 0000000..67bac0b Binary files /dev/null and b/overlay/rootfs/usr/lib/gsocket_uchroot_dso.so.0 differ diff --git a/overlay/rootfs/usr/lib/libneoui.so b/overlay/rootfs/usr/lib/libneoui.so index 874cc91..134b401 100755 Binary files a/overlay/rootfs/usr/lib/libneoui.so and b/overlay/rootfs/usr/lib/libneoui.so differ diff --git a/overlay/rootfs/usr/share/gsocket/gs_funcs b/overlay/rootfs/usr/share/gsocket/gs_funcs new file mode 100644 index 0000000..c9b0e75 --- /dev/null +++ b/overlay/rootfs/usr/share/gsocket/gs_funcs @@ -0,0 +1,389 @@ +#! /usr/bin/env bash + + +[[ $(basename -- "$0") == "gs_funcs" ]] && { echo "Use gsocket, gs-netcat, gs-sftp, gs-mount or blitz instead."; exit 1; } + +# Find a sftp-server binary +find_binary() +{ + bin=$1 + command -v "${bin}" && { echo "${bin}"; return; } + shift 1 + for dir in "$@"; do + file="${dir}/${bin}" + if [[ -f "$file" ]]; then + echo "${file}" + return + fi + done + echo "" + return +} + +read_password() +{ + echo -n >&2 "${GS_PRFX}Enter Secret (or press Enter to generate): " + read -r password + if [[ -z "${password}" ]]; then + password=$(${GS_NETCAT_BIN} -g) + fi + echo "${password}" | tr -d "[:space:]" +} + +# haystack1 haystack2 needle +ucheck_fail() +{ + [[ "$1" =~ $3 ]] || { echo >&2 "Symbol $3 not found in sftp-server."; exit 255; } + [[ "$2" =~ $3 ]] || { echo >&2 "Symbol $3 not found (2)."; exit 255; } +} + +test_sftp() +{ + echo "${1}" | ./gs-sftp -k id_sec.txt -wq 2>&1 | grep -c "Permission denied" +} + +first_symbol() +{ + for func in "$@"; do + if [[ "$sym_sftp" =~ $func ]]; then + echo "$func " + return + fi + done + echo ">>>$*-NOT-FOUND<<< " +} + +uchroot_check_sym() +{ + command -v nm >/dev/null 2>&1 || { echo >&2 "chroot failed (nm not found. apt-get install binutils?). Try -U to disable."; exit 255; } + + # Extract symbols from .so and sftp-server binary + if [[ "$OSTYPE" == "darwin"* ]]; then + # on OSX remove the starting "_" from symboles + sym_sftp="$(nm -pu "${SFTP_SERVER_BIN}" | sed 's/^_//g')" + sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T " | sed 's/^_//g')" + elif [[ "$OSTYPE" == "solaris"* ]]; then + sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")" + sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T ")" + else + sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")" + sym_uchr="$(nm -D "${UCHROOT_BIN}" | grep " T ")" + fi + + [[ -n "$sym_uchr" ]] || { echo >&2 "chroot self-test failed (nm bad1). Try -U to disable."; exit 255; } + [[ -n "$sym_sftp" ]] || { echo >&2 "chroot self-test failed (nm bad2). Try -U to disable."; exit 255; } + funclist+=$(first_symbol lstat\$INODE64 __lxstat64 __lxstat lstat64 lstat) + funclist+=$(first_symbol stat\$INODE64 __xstat64 __xstat stat64 stat) + funclist+=$(first_symbol opendir\$INODE64 opendir64 opendir) + funclist+=$(first_symbol open64 open) + if [[ ! "$OSTYPE" == "solaris2.10"* ]]; then + # On solaris 10 the stock OpenSSH install does not use statvfs64 (older version) + funclist+=$(first_symbol statvfs64 statvfs) + fi + [[ "${funclist}" =~ "NOT-FOUND"* ]] && { echo >&2 "Missing symbol...${funclist}"; exit 255; } + + funclist+="chmod link mkdir rename rmdir symlink unlink" + # echo "funclist = $funclist" # DEBUG + for func in ${funclist}; do + ucheck_fail "${sym_sftp}" "${sym_uchr}" "${func}" + done +} + +failed() +{ + echo >&2 "ERROR: Self test failed: $1. Try -U to disable." + + exit 255 +} +# Verify that all symboles will get hijacked. exit on failure. +# linux osx solaris +# sftp -Du -pu -Du +# .so -D|T -p|T -p|T +uchroot_check() +{ + local VALID_CMD + local FAIL_CMD + + # skip nm-style symbol check on cygwin + # (sftp-server does not like nm on cygwin?!) + if [[ x"$OSTYPE" != "xcygwin"* ]]; then + # NOT cygwin + uchroot_check_sym + fi + + # Run a self test (sftp -D sftp-server) + command -v sftp >/dev/null 2>&1 || { failed "sftp not found"; } + mkdir -p "${ROOTDIR}/ok" + mkdir -p "${ROOTDIR}/denied" + # echo "ROOTDIR=${ROOTDIR}" # DEBUG + echo hello exist-allowed.txt >"${ROOTDIR}/ok/exist-allowed.txt" + echo hello exist-denied.txt >"${ROOTDIR}/denied/exist-denied.txt" + dd if=/dev/urandom bs=1k count=1 2>/dev/null >"${ROOTDIR}/ok/test1k.dat" + echo "\ +#! /bin/bash +cd \"${ROOTDIR}\"/ok +${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]}" >"${ROOTDIR}/sftp-server.sh" + chmod 755 "${ROOTDIR}/sftp-server.sh" + + # Run GOOD commands that should work + VALID_CMD=" +mkdir dir1 +cd dir1 +cd .. +cd dir1 +cd ../ +ls ${ROOTDIR}/ok +ls ${ROOTDIR}/ok/exist-allowed.txt +put test1k.dat dir1 +mkdir ./dir2/ +" + [[ $(cd "${ROOTDIR}/ok"; echo "$VALID_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 0 ]] || { failed "valid cmd 0"; } + [[ -d "${ROOTDIR}/ok/dir1" ]] || { failed "valid-cmd 1"; } + [[ -d "${ROOTDIR}/ok/dir2" ]] || { failed "valid-cmd 2"; } + [[ -f "${ROOTDIR}/ok/dir1/test1k.dat" ]] || { failed "valid-cmd 3"; } + + + FAIL_CMD=" +rename exist-allowed.txt ../denied/0wned.txt +mkdir ./dir1/../../denied/0wned +cd dir1/../../denied +cd ./../denied +ls ${ROOTDIR} +cd ${ROOTDIR} +cd ${ROOTDIR}/denied +cd ${ROOTDIR}/ok/../denied +rm ./../denied/exist-denied.txt +put test1k.dat ../denied/0wned.dat +put test1k.dat ../denied/exist-denied.txt +rename exist-allowed.txt ../denied/0wned.txt +rename exist-allowed.txt /0wned.txt +" + [[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 13 ]] || { failed "fail cmd (2)"; } + + FAIL_CMD=" +ls dir1/../../denied +ls ./../denied/exist-denied.txt" + [[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "not found") -eq 2 ]] || { failed "fail cmd (3)"; } + rm -rf "${ROOTDIR}/ok" &>/dev/null + rm -rf "${ROOTDIR}/denied" &>/dev/null + rm -rf "${ROOTDIR}/sftp-server.sh" &>/dev/null +} + + +gs_find_so_single() +{ + [[ -e "${1}/${2}" ]] && { echo "$(cd "${1}" || exit; pwd)""/${2}"; } +} + +arrayContains() +{ + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +# Search for the dynamic shared object file. +# 1. Try $basedir +# 2. Try ${basedir}/../lib +# 3. Try /usr/lib +# 4. Try /usr/local/lib +# Return absolute path to DSO. +gs_find_so() +{ + local DL=("${BASEDIR}") + # Debian packaging requires libs in /usr/lib/x86_64-linux-gnu :/ + if command -v dpkg-architecture &>/dev/null; then + DL+=("/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)") + fi + + DL+=("${1}/lib") # This is either GS_PREFIX/lib or BASEDIR/../lib + arrayContains "/usr/lib" "${DL[@]}" || DL+=("/usr/lib") + arrayContains "/usr/local/lib" "${DL[@]}" || DL+=("/usr/local/lib") + + for dir in "${DL[@]}"; do + res=$(gs_find_so_single "${dir}" "${2}") + [[ -z "$res" ]] || { echo "$res"; return; } + done +} + +gs_init() +{ + GS_NETCAT_BIN="gs-netcat" + BIN="${BASEDIR}/${GS_NETCAT_BIN}" + [[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}" + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + GS_SFTP_BIN="${BASEDIR}/gs-sftp" + EXE="" + if [[ "$OSTYPE" == "cygwin"* ]]; then + EXE=".exe" + fi + + # To find sftp-server and DSO's in PREFIX/lib + PREFIX="$GS_PREFIX" + [[ -z "$PREFIX" ]] && PREFIX="$(cd "$(dirname "${0}")/../" || exit; pwd)" + + # on OSX the dl-files are called .bundle (not .dylib) but it is generally + # accepted to call them .so. OSX keep those is /System/Library/gsocket + # but automake insists on ${PREFIX}/lib + UCHROOT_BIN=$(gs_find_so "$PREFIX" "gsocket_uchroot_dso.so.0${EXE}") + [[ -z "$UCHROOT_BIN" ]] && { echo >&2 "gsocket: gsocket_uchroot_dso.so.0${EXE} not found. Try 'apt install dpkg-dev'."; exit 5; } + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + GS_SO_BIN=$(gs_find_so "$PREFIX" "gsocket_dso.so.0${EXE}") + [[ -z "$GS_SO_BIN" ]] && { echo >&2 "gsocket: gsocket_dso.so.0${EXE} not found."; exit 5; } + + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + BIN_NAME="$(basename "${0}")" + + command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; } +} + +usage() +{ + echo " + -l Server Mode. + -R Server in read-only mode. + -s Secret (e.g. password). + -k Read Secret from file. + +Example: + $ ${1} -s MySecret -l # Server + $ ${1} -s MySecret # Client + +See 'gs-netcat -h' for more options." + +} + +do_getopt() +{ + OPTERR=0 + FL_NEED_PASSWORD=1 + IS_UCHROOT=1 + # Check if -s or -k is already supplied in environment and dont ask again. + [[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD + # shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. + while getopts ":qhURgls:k:L:" opt; do + case ${opt} in + s ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + unset FL_NEED_PASSWORD + ;; + k ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + # KFILE=$(eval echo "$OPTARG") # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + my_usage + ;; + q ) + IS_QUIET=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-q" + ;; + l ) + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + IS_SERVER=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array + ;; + R ) + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + IS_READONLY=1 + SFTP_ARGS[${#SFTP_ARGS[@]}]="-R" + ;; + U ) + unset IS_UCHROOT + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac + done + # Solaris 10 problems: + # - stock sftp-server does not allow -p -> Acceptable risk + # - LD_PRELOAD does not seem to work. Does anyone still use solaris10? + if [[ "$OSTYPE" == "solaris2.10"* ]]; then + echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot not (yet) supported on solaris 10." + unset IS_UCHROOT + fi +} + +env_arg_init() +{ + # Prepare existing GSOCKET_ARGS to take more arguments if there are any + [[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" " + if [[ -n "$FL_NEED_PASSWORD" ]]; then + password=$(read_password) + # shellcheck disable=SC2034 # GSOCKET_SECRET appears unused => It's used in 'gs' + GSOCKET_SECRET="${password}" + echo "${GS_PRFX}=Secret : ${password}" + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array + fi + # Have to output it here because gs-netcat might be started from withing + # sshfs or sftpd where stderr is no longer available to gs-netcat + [[ -n "$IS_QUIET" ]] || echo >&2 "${GS_PRFX}=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)" + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" +} + +sftp_server_start() +{ + # SERVER + if [[ "$OSTYPE" == "darwin"* ]]; then + # OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp... + ROOTDIR=$(mktemp -d -t thc-gs-sftp) + # FIXME: temp file only cleaned on reboot. Hmm... + cp /usr/libexec/sftp-server "${ROOTDIR}/sftp-server" &>/dev/null + SFTP_SERVER_BIN="${ROOTDIR}/sftp-server" + PRELOAD="DYLD_INSERT_LIBRARIES=${UCHROOT_BIN} DYLD_FORCE_FLAT_NAMESPACE=1" + else + if [[ -n "${IS_UCHROOT}" ]]; then + ROOTDIR=$(mktemp -d -t thc-gs-sftp-XXXXXXXXXXXXXXX) + fi + SFTP_SERVER_BIN=$(find_binary "sftp-server${EXE}" "${PREFIX}/lib" /opt/csw/libexec /usr/lib /usr/local/lib /usr/libexec /usr/libexec/openssh /usr/lib/ssh /usr/sbin) + PRELOAD="LD_PRELOAD=${UCHROOT_BIN}" + fi + [[ -z "${SFTP_SERVER_BIN}" ]] && { echo >&2 "sftp-server binary not found."; exit 1; } + + # SFTP_ARGS[${#SFTP_ARGS[@]}]="-l" + # SFTP_ARGS[${#SFTP_ARGS[@]}]="DEBUG3" # tail /var/log/auth.log | grep 'Refusing non-whitelisted' + + # Whitelist of commands sftp-server should allow (most are not needed + # by sftp but for sshfs) + # *** WARNING ***: If you add a string here you also must make sure that + # gsocket_uchroot_dso checks the command for uchroot-escape. + SFTP_ARGS[${#SFTP_ARGS[@]}]="-p" + SFTP_ARGS[${#SFTP_ARGS[@]}]="open,opendir,mkdir,remove,rmdir,symlink,hardlink,stat,posix-rename,statvfs,setstat,fsetstat,fstat,lstat,readdir,realpath,write,read,close" + + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + + if [[ -n "${IS_UCHROOT}" ]]; then + [[ -z "${ROOTDIR}" ]] && { failed "(mktemp)"; } + uchroot_check + # Try to delete temporary directory. OSX still has sftp-server bin in there and must be deleted + rmdir "${ROOTDIR}" &>/dev/null + else + echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot disabled. Allowing access to *ALL* files on this host." + unset PRELOAD + fi + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]} 2>/dev/null" +} + + diff --git a/patches/kernel/config-bananarchy-msm8909.armv7 b/patches/kernel/config-bananarchy-msm8909.armv7 index 413afbd..4b3a539 100644 --- a/patches/kernel/config-bananarchy-msm8909.armv7 +++ b/patches/kernel/config-bananarchy-msm8909.armv7 @@ -980,7 +980,7 @@ CONFIG_NFT_CT=m CONFIG_NFT_LOG=m CONFIG_NFT_LIMIT=m CONFIG_NFT_MASQ=m -# CONFIG_NFT_REDIR is not set +CONFIG_NFT_REDIR=m CONFIG_NFT_NAT=m # CONFIG_NFT_TUNNEL is not set # CONFIG_NFT_QUOTA is not set @@ -1065,7 +1065,7 @@ CONFIG_NETFILTER_XT_MATCH_MARK=m CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m # CONFIG_NETFILTER_XT_MATCH_NFACCT is not set # CONFIG_NETFILTER_XT_MATCH_OSF is not set -# CONFIG_NETFILTER_XT_MATCH_OWNER is not set +CONFIG_NETFILTER_XT_MATCH_OWNER=m # CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set # CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set # CONFIG_NETFILTER_XT_MATCH_QUOTA is not set diff --git a/prebuilt/gsocket/etc/gsocket.conf b/prebuilt/gsocket/etc/gsocket.conf new file mode 100644 index 0000000..6cf297a --- /dev/null +++ b/prebuilt/gsocket/etc/gsocket.conf @@ -0,0 +1,8 @@ + + +# Global gsocket.conf file. +# This file is first looked for in /etc/gsocket.conf +# and then in /usr/etc/gsocket.conf + +GS_PREFIX=/usr + diff --git a/prebuilt/gsocket/usr/bin/blitz b/prebuilt/gsocket/usr/bin/blitz new file mode 100755 index 0000000..8b6f5e5 --- /dev/null +++ b/prebuilt/gsocket/usr/bin/blitz @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +# A wrapper script to do this (esentially): +# Server: +# $ gs-netcat -s MySecret -l -e "/usr/bin/rsync --server -vlogDtpr --partial ." +# Client: +# $ rsync -aP -e "gs-netcat -s MySecret --" test4k.dat 127.1:. +GS_NETCAT_BIN="gs-netcat" +RSYNC_SERVER_DEFAULTS="--server -logtprR --safe-links --partial" +# -D special devices +# -g preserver group (may need root) +# -p preserve permissions +# -r recursive into directories +# -R use relative path names +# If client uses '-a' then server must use '-g' +# If client uses '-R' then server must use '-R' +# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial" +# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial" +# RSYNC_SERVER_DEFAULTS="--server -logDtprRe.iLsfxCIvu --partial" +RSYNC_CLIENT_DEFAULTS="-ahPRv" +# Try to use the gs-netcat that's in the same path as this binary first. +BIN="$(cd "$(dirname "${0}")" || exit; pwd)/${GS_NETCAT_BIN}" +[[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}" + +command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; } +command -v rsync >/dev/null 2>&1 || { echo >&2 "rsync not found. Try 'apt-get install rsync' or check PATH=?"; exit 1; } + +usage() +{ + echo "blitz [-k file] [-s password] [-l] [FILES ...] + -l Server Mode. + -s Secret (e.g. password). + -k Read Secret from file. + -f Read list of file names from FILE [or - for stdin] + -o RSOPT=val Options passed to rsync. + + Example: + $ blitz -s MySecret -l # Server + $ blitz -s MySecret *.dat # Client + +...limiting transfer rate to 10kB/sec + $ blitz -s MySecret -o 'RSOPT=--bwlimit=10 -v' /etc/*.conf *.dat + +...reading the file list from standard-in + $ cd /etc + $ find . -name '*.mp3' | blitz -s MySecret -f - + +...limit the amount of path information by inserting a dot and slash + $ blitz -s MySecret ~/tools/./upx/mp3 + +See 'man gs-netcat' and 'man rsync' for more options." + exit 0 +} + +read_password() +{ + printf >&2 "Enter Secret (or press Enter to generate): " + read -r password + if [[ -z "${password}" ]]; then + password=$(${GS_NETCAT_BIN} -g) + fi + echo "${password}" | tr -d "[:space:]" +} + +# remove -o from parameter list. +# Remove -s/-k from parameter list +# Copy all other +OPTERR=0 +FL_NEED_PASSWORD=1 +# Check if -s or -k is already supplied in environment and dont ask again. +[[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD +[[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD +# Current options are options for gs-netcat followed by a list of files. We +# need to split off the gs-netcat options (all but -o/-s/-k) without the +# files. To do so we need to know which gs-netcat options takes an argument +# at add those to getopts's optstring (such as -L ). +# These are caught by '*'. +# All single options (e.g. -w etc) are caught by '\?'. +# shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. +while getopts ":hgls:k:o:L:f:" opt; do + case ${opt} in + o ) + RSYNC_ARGS+=${OPTARG//RSOPT=/} + RSYNC_ARGS+=" " + ;; + s ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + unset FL_NEED_PASSWORD + ;; + k ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + usage + ;; + f ) + RSYNC_ARGS+="--files-from=${OPTARG} . " + IS_FILES_FROM=1 + ;; + l ) + IS_SERVER=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac +done + +if [[ -z ${IS_SERVER} ]]; then + # CLIENT + shift $((OPTIND -1)) # list of files... + # echo "Remaining (files): $*" + [[ -z $* ]] && [[ -z $IS_FILES_FROM ]] && { echo >&2 "ERROR: No files specified."; usage; } + [[ -n $* ]] && [[ -n $IS_FILES_FROM ]] && { echo >&2 "ERROR: Either -f FILE or FILES, but not both."; usage; } +fi + +# Prepare existing GSOCKET_ARGS to take more arguments if there are any +[[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" " +# Must read here unless -s/-k was used +if [[ -n "$FL_NEED_PASSWORD" ]]; then + password=$(read_password) + echo "=Secret :\"${password}\"" + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array +fi +echo "=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)" +ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + +# echo $OPTIND +# echo args-new : ${ARGS_NEW[@]} +# echo gsnc-env-args : \'${GSNC_ENV_ARGS[@]}\' +# echo rsync-args : ${RSYNC_ARGS} + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "rsync ${RSYNC_SERVER_DEFAULTS} ${RSYNC_ARGS} ." +else + # CLIENT + ARGS=" -q" + # ARGS="" + [[ -n ${ARGS_NEW[*]} ]] && ARGS+=" ${ARGS_NEW[*]}" + # shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments. + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec rsync ${RSYNC_CLIENT_DEFAULTS} -e "${GS_NETCAT_BIN}${ARGS} --" ${RSYNC_ARGS} "${@}" 127.1:. +fi + diff --git a/prebuilt/gsocket/usr/bin/gs-mount b/prebuilt/gsocket/usr/bin/gs-mount new file mode 100755 index 0000000..78d653f --- /dev/null +++ b/prebuilt/gsocket/usr/bin/gs-mount @@ -0,0 +1,53 @@ +#! /usr/bin/env bash + +# A wrapper script to do this (essentially): +# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host +# +# $ export GSOCKET_ARGS="-s MySecret" # Workstation +# $ sshfs -o ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions -o ssh_command="gs-netcat --" -o idmap=user,uid="${UID}",gid="$(id -g)" x@127.1:. ~/gs-fs + + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] [-l] [mount point]" + usage "${BIN_NAME}" + exit 0 +} + +gs_init +do_getopt "$@" +shift $((OPTIND -1)) # Mount Point +env_arg_init + +if [[ -z ${IS_SERVER} ]]; then + # CLIENT + SSHFS_OPT="ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions,idmap=user,uid=${UID},gid=$(id -g)" + # echo "Remaining (files): $*" + [[ -z "${1}" ]] && { echo >&2 "ERROR: No directory (mount point) specified."; my_usage; } + command -v sshfs >/dev/null 2>&1 || { echo >&2 "sshfs not found. Try 'apt-get install sshfs' or check PATH=?"; exit 1; } + # FUSE_OPT=",cache=yes,kernel_cache" + FUSE_OPT="" + if [[ "$OSTYPE" == "darwin"* ]]; then + # Setting 'noapplexattr' prevents 'finder' from copying. + FUSE_OPT+=",async,local,iosize=65536,noappledouble,volname=THC-"$(basename "${1}") + fi +fi + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + sftp_server_start +else + # CLIENT + ARGS=" -q" + [[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}" + + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" sshfs -o "${SSHFS_OPT}${FUSE_OPT}" -o ssh_command="${GS_NETCAT_BIN}${ARGS} --" x@127.1:. "${1}" || exit 1 + echo "Successfully mounted on ${1}." + command -v fusermount >/dev/null 2>&1 && echo "To unmount use: fusermount -zu ${1}" +fi diff --git a/prebuilt/gsocket/usr/bin/gs-netcat b/prebuilt/gsocket/usr/bin/gs-netcat new file mode 100755 index 0000000..f8b6c2d Binary files /dev/null and b/prebuilt/gsocket/usr/bin/gs-netcat differ diff --git a/prebuilt/gsocket/usr/bin/gs-sftp b/prebuilt/gsocket/usr/bin/gs-sftp new file mode 100755 index 0000000..a1a3d40 --- /dev/null +++ b/prebuilt/gsocket/usr/bin/gs-sftp @@ -0,0 +1,38 @@ +#! /usr/bin/env bash + +# A wrapper script to do this (essentially): +# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host +# +# $ export GSOCKET_ARGS="-s MySecret" # Workstation +# $ sftp -D gs-netcat # Workstation + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] [-l]" + usage "${BIN_NAME}" + exit 0 +} + +command -v sftp >/dev/null 2>&1 || { echo >&2 "sftp not found. Try 'apt-get install openssh' or check PATH=?"; exit 1; } +gs_init +do_getopt "$@" +shift $((OPTIND -1)) # Mount Point +env_arg_init + +if [[ -n ${IS_SERVER} ]]; then + # SERVER + sftp_server_start +else + # CLIENT + ARGS=" -q" + [[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}" + # shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments. + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}${ARGS}" exec sftp -D "${GS_NETCAT_BIN}" +fi diff --git a/prebuilt/gsocket/usr/bin/gsocket b/prebuilt/gsocket/usr/bin/gsocket new file mode 100755 index 0000000..4561293 --- /dev/null +++ b/prebuilt/gsocket/usr/bin/gsocket @@ -0,0 +1,135 @@ +#! /usr/bin/env bash + +# Try to use the gs-netcat that's in the same directory as this executable. +BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)" +# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location. +# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x) +source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; } + +my_usage() +{ + echo "${BIN_NAME} [-k file] [-s password] + -s Secret (e.g. password). + -k Read Secret from file. + -p Range of listening ports to redirect [default=all] + -T Use TOR. + +Example: + $ ${BIN_NAME} -s MySecret /usr/bin/sshd -d # Server + $ ${BIN_NAME} -s MySecret ssh root@gsocket # Client + +See 'gs-netcat -h' for more options." + exit "$1" +} + +my_getopt() +{ + OPTERR=0 + # shellcheck disable=SC2034 # FL_NEED_PASSWORD appears unused. => used i env_arg_init + FL_NEED_PASSWORD=1 + # Check if -s or -k is already supplied in environment and dont ask again. + [[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD + # shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. + while getopts ":qhgTp:s:k:L:" opt; do + case ${opt} in + s ) + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + GSOCKET_SECRET="$OPTARG" + unset FL_NEED_PASSWORD + ;; + k ) + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSOCKET_SECRET=$(<"${KFILE}") + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + # KFILE=$(eval echo "$OPTARG") # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + my_usage 0 + ;; + p ) + GS_HIJACK_PORTS="${OPTARG}" + ;; + T ) + [[ -z "${GSOCKET_SOCKS_IP}" ]] && GSOCKET_SOCKS_IP="127.0.0.1" + ;; + + q ) + # shellcheck disable=SC2034 # IS_QUIET appears unused. => Used in env_arg_init + IS_QUIET=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-q" + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac + done + + [[ -n "${GSOCKET_SECRET}" ]] && unset FL_NEED_PASSWORD +} + +# default values +GS_HIJACK_PORTS="1-65535" +# shellcheck disable=SC2034 # GS_RFX appears unused. => Used in gs_funcs +GS_PRFX="gsocket: " +gs_init +my_getopt "$@" +shift $((OPTIND -1)) + +[[ ${#@} -le 0 ]] && { echo >&2 "ERROR: No program specified"; my_usage 255; } + +command -v "$1" >/dev/null 2>&1 || { echo >&2 "gsocket: command not found: ${1}"; exit 1; } + +if [[ "$OSTYPE" == "darwin"* ]]; then + # OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp... + ROOTDIR=$(mktemp -d -t thc-gsXXXXXX) + PROGBIN_FULLPATH=$(which "$1") + + [[ -z "$PROGBIN_FULLPATH" ]] && { echo >&2 "gsocket: command not found: ${1}"; exit 1; } + # FIXME: temp file is only cleaned on reboot. Hmm... + cp "${PROGBIN_FULLPATH}" "${ROOTDIR}/" &>/dev/null + PROGBIN_NAME="$(basename "${1}")" # programm binary + PROGBIN="${ROOTDIR}/${PROGBIN_NAME}" + # System Integrity Protection makes dyld ignore + # DYLD_INSERT_LIBRARIES. + # There are two ways how MacOS determines if a binary is SIP protected: + # 1. The location of the binary (ls -alO /usr/bin/ssh) + # 2. If the binary contains 'entitlements' (regardless of its location on the fs). + # A hack around this is to remove the signature completed (which will also disable + # any entitlements). + IS_REMOVE_SIGN=1 + command -v csrutil >/dev/null && [[ ! "$(csrutil status)" =~ enabled ]] && { unset IS_REMOVE_SIGN; } + [[ -n $IS_REMOVE_SIGN ]] && command -v codesign >/dev/null && [[ -n "$(codesign -d --entitlements - "${PROGBIN}" 2>/dev/null)" ]] && { + codesign --remove-signature "${PROGBIN}"; + } +else + ROOTDIR="" + PROGBIN="${1}" +fi + +env_arg_init +shift 1 + +if [[ "$OSTYPE" == "darwin"* ]]; then + GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" DYLD_INSERT_LIBRARIES=${GS_SO_BIN} DYLD_FORCE_FLAT_NAMESPACE=1 exec "${PROGBIN}" "$@" +else + GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" LD_PRELOAD=${GS_SO_BIN} exec "${PROGBIN}" "$@" +fi + diff --git a/prebuilt/gsocket/usr/lib/gsocket_dso.so b/prebuilt/gsocket/usr/lib/gsocket_dso.so new file mode 120000 index 0000000..f824fe1 --- /dev/null +++ b/prebuilt/gsocket/usr/lib/gsocket_dso.so @@ -0,0 +1 @@ +gsocket_dso.so.0 \ No newline at end of file diff --git a/prebuilt/gsocket/usr/lib/gsocket_dso.so.0 b/prebuilt/gsocket/usr/lib/gsocket_dso.so.0 new file mode 100644 index 0000000..ab41547 Binary files /dev/null and b/prebuilt/gsocket/usr/lib/gsocket_dso.so.0 differ diff --git a/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so b/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so new file mode 120000 index 0000000..a15ce1a --- /dev/null +++ b/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so @@ -0,0 +1 @@ +gsocket_uchroot_dso.so.0 \ No newline at end of file diff --git a/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so.0 b/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so.0 new file mode 100644 index 0000000..67bac0b Binary files /dev/null and b/prebuilt/gsocket/usr/lib/gsocket_uchroot_dso.so.0 differ diff --git a/prebuilt/gsocket/usr/share/gsocket/gs_funcs b/prebuilt/gsocket/usr/share/gsocket/gs_funcs new file mode 100644 index 0000000..c9b0e75 --- /dev/null +++ b/prebuilt/gsocket/usr/share/gsocket/gs_funcs @@ -0,0 +1,389 @@ +#! /usr/bin/env bash + + +[[ $(basename -- "$0") == "gs_funcs" ]] && { echo "Use gsocket, gs-netcat, gs-sftp, gs-mount or blitz instead."; exit 1; } + +# Find a sftp-server binary +find_binary() +{ + bin=$1 + command -v "${bin}" && { echo "${bin}"; return; } + shift 1 + for dir in "$@"; do + file="${dir}/${bin}" + if [[ -f "$file" ]]; then + echo "${file}" + return + fi + done + echo "" + return +} + +read_password() +{ + echo -n >&2 "${GS_PRFX}Enter Secret (or press Enter to generate): " + read -r password + if [[ -z "${password}" ]]; then + password=$(${GS_NETCAT_BIN} -g) + fi + echo "${password}" | tr -d "[:space:]" +} + +# haystack1 haystack2 needle +ucheck_fail() +{ + [[ "$1" =~ $3 ]] || { echo >&2 "Symbol $3 not found in sftp-server."; exit 255; } + [[ "$2" =~ $3 ]] || { echo >&2 "Symbol $3 not found (2)."; exit 255; } +} + +test_sftp() +{ + echo "${1}" | ./gs-sftp -k id_sec.txt -wq 2>&1 | grep -c "Permission denied" +} + +first_symbol() +{ + for func in "$@"; do + if [[ "$sym_sftp" =~ $func ]]; then + echo "$func " + return + fi + done + echo ">>>$*-NOT-FOUND<<< " +} + +uchroot_check_sym() +{ + command -v nm >/dev/null 2>&1 || { echo >&2 "chroot failed (nm not found. apt-get install binutils?). Try -U to disable."; exit 255; } + + # Extract symbols from .so and sftp-server binary + if [[ "$OSTYPE" == "darwin"* ]]; then + # on OSX remove the starting "_" from symboles + sym_sftp="$(nm -pu "${SFTP_SERVER_BIN}" | sed 's/^_//g')" + sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T " | sed 's/^_//g')" + elif [[ "$OSTYPE" == "solaris"* ]]; then + sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")" + sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T ")" + else + sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")" + sym_uchr="$(nm -D "${UCHROOT_BIN}" | grep " T ")" + fi + + [[ -n "$sym_uchr" ]] || { echo >&2 "chroot self-test failed (nm bad1). Try -U to disable."; exit 255; } + [[ -n "$sym_sftp" ]] || { echo >&2 "chroot self-test failed (nm bad2). Try -U to disable."; exit 255; } + funclist+=$(first_symbol lstat\$INODE64 __lxstat64 __lxstat lstat64 lstat) + funclist+=$(first_symbol stat\$INODE64 __xstat64 __xstat stat64 stat) + funclist+=$(first_symbol opendir\$INODE64 opendir64 opendir) + funclist+=$(first_symbol open64 open) + if [[ ! "$OSTYPE" == "solaris2.10"* ]]; then + # On solaris 10 the stock OpenSSH install does not use statvfs64 (older version) + funclist+=$(first_symbol statvfs64 statvfs) + fi + [[ "${funclist}" =~ "NOT-FOUND"* ]] && { echo >&2 "Missing symbol...${funclist}"; exit 255; } + + funclist+="chmod link mkdir rename rmdir symlink unlink" + # echo "funclist = $funclist" # DEBUG + for func in ${funclist}; do + ucheck_fail "${sym_sftp}" "${sym_uchr}" "${func}" + done +} + +failed() +{ + echo >&2 "ERROR: Self test failed: $1. Try -U to disable." + + exit 255 +} +# Verify that all symboles will get hijacked. exit on failure. +# linux osx solaris +# sftp -Du -pu -Du +# .so -D|T -p|T -p|T +uchroot_check() +{ + local VALID_CMD + local FAIL_CMD + + # skip nm-style symbol check on cygwin + # (sftp-server does not like nm on cygwin?!) + if [[ x"$OSTYPE" != "xcygwin"* ]]; then + # NOT cygwin + uchroot_check_sym + fi + + # Run a self test (sftp -D sftp-server) + command -v sftp >/dev/null 2>&1 || { failed "sftp not found"; } + mkdir -p "${ROOTDIR}/ok" + mkdir -p "${ROOTDIR}/denied" + # echo "ROOTDIR=${ROOTDIR}" # DEBUG + echo hello exist-allowed.txt >"${ROOTDIR}/ok/exist-allowed.txt" + echo hello exist-denied.txt >"${ROOTDIR}/denied/exist-denied.txt" + dd if=/dev/urandom bs=1k count=1 2>/dev/null >"${ROOTDIR}/ok/test1k.dat" + echo "\ +#! /bin/bash +cd \"${ROOTDIR}\"/ok +${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]}" >"${ROOTDIR}/sftp-server.sh" + chmod 755 "${ROOTDIR}/sftp-server.sh" + + # Run GOOD commands that should work + VALID_CMD=" +mkdir dir1 +cd dir1 +cd .. +cd dir1 +cd ../ +ls ${ROOTDIR}/ok +ls ${ROOTDIR}/ok/exist-allowed.txt +put test1k.dat dir1 +mkdir ./dir2/ +" + [[ $(cd "${ROOTDIR}/ok"; echo "$VALID_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 0 ]] || { failed "valid cmd 0"; } + [[ -d "${ROOTDIR}/ok/dir1" ]] || { failed "valid-cmd 1"; } + [[ -d "${ROOTDIR}/ok/dir2" ]] || { failed "valid-cmd 2"; } + [[ -f "${ROOTDIR}/ok/dir1/test1k.dat" ]] || { failed "valid-cmd 3"; } + + + FAIL_CMD=" +rename exist-allowed.txt ../denied/0wned.txt +mkdir ./dir1/../../denied/0wned +cd dir1/../../denied +cd ./../denied +ls ${ROOTDIR} +cd ${ROOTDIR} +cd ${ROOTDIR}/denied +cd ${ROOTDIR}/ok/../denied +rm ./../denied/exist-denied.txt +put test1k.dat ../denied/0wned.dat +put test1k.dat ../denied/exist-denied.txt +rename exist-allowed.txt ../denied/0wned.txt +rename exist-allowed.txt /0wned.txt +" + [[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 13 ]] || { failed "fail cmd (2)"; } + + FAIL_CMD=" +ls dir1/../../denied +ls ./../denied/exist-denied.txt" + [[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "not found") -eq 2 ]] || { failed "fail cmd (3)"; } + rm -rf "${ROOTDIR}/ok" &>/dev/null + rm -rf "${ROOTDIR}/denied" &>/dev/null + rm -rf "${ROOTDIR}/sftp-server.sh" &>/dev/null +} + + +gs_find_so_single() +{ + [[ -e "${1}/${2}" ]] && { echo "$(cd "${1}" || exit; pwd)""/${2}"; } +} + +arrayContains() +{ + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +# Search for the dynamic shared object file. +# 1. Try $basedir +# 2. Try ${basedir}/../lib +# 3. Try /usr/lib +# 4. Try /usr/local/lib +# Return absolute path to DSO. +gs_find_so() +{ + local DL=("${BASEDIR}") + # Debian packaging requires libs in /usr/lib/x86_64-linux-gnu :/ + if command -v dpkg-architecture &>/dev/null; then + DL+=("/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)") + fi + + DL+=("${1}/lib") # This is either GS_PREFIX/lib or BASEDIR/../lib + arrayContains "/usr/lib" "${DL[@]}" || DL+=("/usr/lib") + arrayContains "/usr/local/lib" "${DL[@]}" || DL+=("/usr/local/lib") + + for dir in "${DL[@]}"; do + res=$(gs_find_so_single "${dir}" "${2}") + [[ -z "$res" ]] || { echo "$res"; return; } + done +} + +gs_init() +{ + GS_NETCAT_BIN="gs-netcat" + BIN="${BASEDIR}/${GS_NETCAT_BIN}" + [[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}" + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + GS_SFTP_BIN="${BASEDIR}/gs-sftp" + EXE="" + if [[ "$OSTYPE" == "cygwin"* ]]; then + EXE=".exe" + fi + + # To find sftp-server and DSO's in PREFIX/lib + PREFIX="$GS_PREFIX" + [[ -z "$PREFIX" ]] && PREFIX="$(cd "$(dirname "${0}")/../" || exit; pwd)" + + # on OSX the dl-files are called .bundle (not .dylib) but it is generally + # accepted to call them .so. OSX keep those is /System/Library/gsocket + # but automake insists on ${PREFIX}/lib + UCHROOT_BIN=$(gs_find_so "$PREFIX" "gsocket_uchroot_dso.so.0${EXE}") + [[ -z "$UCHROOT_BIN" ]] && { echo >&2 "gsocket: gsocket_uchroot_dso.so.0${EXE} not found. Try 'apt install dpkg-dev'."; exit 5; } + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + GS_SO_BIN=$(gs_find_so "$PREFIX" "gsocket_dso.so.0${EXE}") + [[ -z "$GS_SO_BIN" ]] && { echo >&2 "gsocket: gsocket_dso.so.0${EXE} not found."; exit 5; } + + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + BIN_NAME="$(basename "${0}")" + + command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; } +} + +usage() +{ + echo " + -l Server Mode. + -R Server in read-only mode. + -s Secret (e.g. password). + -k Read Secret from file. + +Example: + $ ${1} -s MySecret -l # Server + $ ${1} -s MySecret # Client + +See 'gs-netcat -h' for more options." + +} + +do_getopt() +{ + OPTERR=0 + FL_NEED_PASSWORD=1 + IS_UCHROOT=1 + # Check if -s or -k is already supplied in environment and dont ask again. + [[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD + [[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD + # shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case. + while getopts ":qhURgls:k:L:" opt; do + case ${opt} in + s ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array + unset FL_NEED_PASSWORD + ;; + k ) + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array + KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG") + [[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; } + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array + # KFILE=$(eval echo "$OPTARG") # Add to end of array + # GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array + unset FL_NEED_PASSWORD + ;; + g ) + "${GS_NETCAT_BIN}" -g + exit + ;; + h ) + my_usage + ;; + q ) + IS_QUIET=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-q" + ;; + l ) + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + IS_SERVER=1 + ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array + ;; + R ) + # shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally). + IS_READONLY=1 + SFTP_ARGS[${#SFTP_ARGS[@]}]="-R" + ;; + U ) + unset IS_UCHROOT + ;; + \? ) + # UNKNOWN option. Handle before '*' (e.g. -l) + ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array + ;; + * ) + # Other (known opts from opstring) w parameters (e.g. -L ) + ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array + ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array + ;; + esac + done + # Solaris 10 problems: + # - stock sftp-server does not allow -p -> Acceptable risk + # - LD_PRELOAD does not seem to work. Does anyone still use solaris10? + if [[ "$OSTYPE" == "solaris2.10"* ]]; then + echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot not (yet) supported on solaris 10." + unset IS_UCHROOT + fi +} + +env_arg_init() +{ + # Prepare existing GSOCKET_ARGS to take more arguments if there are any + [[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" " + if [[ -n "$FL_NEED_PASSWORD" ]]; then + password=$(read_password) + # shellcheck disable=SC2034 # GSOCKET_SECRET appears unused => It's used in 'gs' + GSOCKET_SECRET="${password}" + echo "${GS_PRFX}=Secret : ${password}" + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array + GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array + fi + # Have to output it here because gs-netcat might be started from withing + # sshfs or sftpd where stderr is no longer available to gs-netcat + [[ -n "$IS_QUIET" ]] || echo >&2 "${GS_PRFX}=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)" + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" +} + +sftp_server_start() +{ + # SERVER + if [[ "$OSTYPE" == "darwin"* ]]; then + # OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp... + ROOTDIR=$(mktemp -d -t thc-gs-sftp) + # FIXME: temp file only cleaned on reboot. Hmm... + cp /usr/libexec/sftp-server "${ROOTDIR}/sftp-server" &>/dev/null + SFTP_SERVER_BIN="${ROOTDIR}/sftp-server" + PRELOAD="DYLD_INSERT_LIBRARIES=${UCHROOT_BIN} DYLD_FORCE_FLAT_NAMESPACE=1" + else + if [[ -n "${IS_UCHROOT}" ]]; then + ROOTDIR=$(mktemp -d -t thc-gs-sftp-XXXXXXXXXXXXXXX) + fi + SFTP_SERVER_BIN=$(find_binary "sftp-server${EXE}" "${PREFIX}/lib" /opt/csw/libexec /usr/lib /usr/local/lib /usr/libexec /usr/libexec/openssh /usr/lib/ssh /usr/sbin) + PRELOAD="LD_PRELOAD=${UCHROOT_BIN}" + fi + [[ -z "${SFTP_SERVER_BIN}" ]] && { echo >&2 "sftp-server binary not found."; exit 1; } + + # SFTP_ARGS[${#SFTP_ARGS[@]}]="-l" + # SFTP_ARGS[${#SFTP_ARGS[@]}]="DEBUG3" # tail /var/log/auth.log | grep 'Refusing non-whitelisted' + + # Whitelist of commands sftp-server should allow (most are not needed + # by sftp but for sshfs) + # *** WARNING ***: If you add a string here you also must make sure that + # gsocket_uchroot_dso checks the command for uchroot-escape. + SFTP_ARGS[${#SFTP_ARGS[@]}]="-p" + SFTP_ARGS[${#SFTP_ARGS[@]}]="open,opendir,mkdir,remove,rmdir,symlink,hardlink,stat,posix-rename,statvfs,setstat,fsetstat,fstat,lstat,readdir,realpath,write,read,close" + + ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}" + + if [[ -n "${IS_UCHROOT}" ]]; then + [[ -z "${ROOTDIR}" ]] && { failed "(mktemp)"; } + uchroot_check + # Try to delete temporary directory. OSX still has sftp-server bin in there and must be deleted + rmdir "${ROOTDIR}" &>/dev/null + else + echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot disabled. Allowing access to *ALL* files on this host." + unset PRELOAD + fi + GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]} 2>/dev/null" +} + + diff --git a/prebuilt/gsocket/usr/share/man/man1/blitz.1 b/prebuilt/gsocket/usr/share/man/man1/blitz.1 new file mode 100644 index 0000000..d882f25 --- /dev/null +++ b/prebuilt/gsocket/usr/share/man/man1/blitz.1 @@ -0,0 +1,88 @@ +.Dd October 12, 2020 +.Dt BLITZ 1 +.Os +.Sh NAME +.Nm blitz +.Nd Securely transfer files between two workstations through NAT/Firewall. +.Sh SYNOPSIS +.Nm blitz +.Op Fl lT +.Op Fl s Ar secret +.Op Fl k Ar keyfile +.Op Fl f Ar list +.Op Fl o Ar RSOPT= +.Op Ar files ... +.Sh DESCRIPTION +The +.Nm +utility is a wrapper script for gs-netcat and rsync. It allows one to send files from one workstation to another workstation via the Global Socket Relay Network (GSRN). +.Pp +A typical use-case is where both workstations are separated by a Firewall or NAT and not able to establish a direct connection between each other. +.Pp +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl l +Server mode. The default mode is client. +.It Fl s Ar secret +A password chosen by the user. Both users need to use the same password to connect. +.It Fl k Ar FILE +A file containing the password. +.It Fl f Ar FILE +Read list of file names from FILE. If FILE is -, the list will be read from standard input. +.It Fl o Ar RSOPT= +Options passed to rsync. See +.Xr rsync(1) +for available options. +.It Fl T +Use TOR. The +.Nm +tool will connect via TOR to the GSRN. This requires TOR to be installed and running. The IP and PORT of the TOR server can be set using environment variables. +.El +.Pp +See +.Xr gs-netcat(1) +for more options. +.Sh EXAMPLES +Listen for clients with password 'MySecret': +.Dl $ mkdir /tmp/foo && cd /tmp/foo +.Dl $ blitz -s MySecret -l +.Pp +Copy 'file.dat' to /tmp/foo/file.dat on the server: +.Dl $ blitz -s MySecret file.dat +.Pp +Copy '/etc/ssh/ssh*config' to /tmp/foo/etc/ssh/ on the server: +.Dl $ blitz -s MySecret /etc/ssh/ssh*config +.Pp +It is also possible to limit the amount of path information that is sent as implied directories for each path you specify. You can insert a dot and a slash into the source path, like this: +.Pp +.Dl $ blitz -s MySecret /etc/./ssh/ssh*config +The received files will be stored to /tmp/foo/ssh/ instead of /tmp/foo/etc/ssh. +.Pp +Copy recursively and limit bandwidth to 10kB/sec: +.Dl $ blitz -s MySecret -o 'RSOPT=--bwlimit=10' /usr/./share +.Pp +Copy the entire root file-system: +.Dl $ blitz -s MySecret -o 'RSOPT=-x' / +.Pp +Copy specific files read from standard input: +.Dl $ find\ . -name '*.conf' | blitz -s MySecret -f \- +.Pp +Run a permanent server (daemon) through TOR: +.Dl $ blitz -s MySecret -l -D -T +.Pp +.Sh ENVIRONMENT +See +.Xr gs-netcat(1) +for a list of supported environment variables. +.Pp +.Sh SEE ALSO +.Xr gsocket(1) , +.Xr gs-netcat(1) , +.Xr gs-sftp(1) , +.Xr gs-mount(1) , +.Xr rsync(1) +.Pp +.Sh BUGS +Efforts have been made to have +.Nm +"do the right thing" in all its various modes. If you believe that it is doing the wrong thing under whatever circumstances, please notify me (skyper@thc.org) and tell me how you think it should behave. diff --git a/prebuilt/gsocket/usr/share/man/man1/gs-mount.1 b/prebuilt/gsocket/usr/share/man/man1/gs-mount.1 new file mode 100644 index 0000000..740f897 --- /dev/null +++ b/prebuilt/gsocket/usr/share/man/man1/gs-mount.1 @@ -0,0 +1,60 @@ +.Dd October 12, 2020 +.Dt GS-MOUNT 1 +.Os +.Sh NAME +.Nm gs-mount +.Nd Secure filesystem client through via Global Socket. +.Sh SYNOPSIS +.Nm gs-mount +.Op Fl lTR +.Op Fl s Ar secret +.Op Fl k Ar keyfile +.Op Ar mountpoint +.Sh DESCRIPTION +The +.Nm +utility is a wrapper script for gs-netcat. It allows a user to mount and access a filesystem from another user via the Global Socket Relay Network (GSRN). This is useful in a scenario where both users are behind NAT/Firewall and unable to connect to each other directly. +.Pp +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl s Ar secret +A password chosen by the user. Both users need to use the same password to connect. +.It Fl k Ar FILE +A file containing the password. +.It Fl l +Server mode. The default mode is client. +.It Fl R +Places server (-l) into a read-only mode. Attempts to open files for writing, as well as other operations that change the state of the filesystem, will be denied. +.It Fl T +Use TOR. The +.Nm +tool will connect via TOR to the GSRN. This requires TOR to be installed and running. The IP and PORT of the TOR server can be set using environment variables. +.El +.Pp +See +.Xr gs-netcat(1) +for more options. +.Sh EXAMPLES +.Nm Example 1 +- Alice sharing her current directory: +.Dl $ gs-mount -s MySecret -l +.Pp +Bob mounting Alice's directory to ~/gs-alice: +.Dl $ gs-mount -s MySecret ~/gs-alice +.Pp +.Sh ENVIRONMENT +See +.Xr gs-netcat(1) +for a list of supported environment variables. +.Pp +.Sh SEE ALSO +.Xr gsocket(1) , +.Xr gs-netcat(1) , +.Xr gs-sftp(1) , +.Xr blitz(1) , +.Xr sshfs(1) +.Pp +.Sh BUGS +Efforts have been made to have +.Nm +"do the right thing" in all its various modes. If you believe that it is doing the wrong thing under whatever circumstances, please notify me (skyper@thc.org) and tell me how you think it should behave. diff --git a/prebuilt/gsocket/usr/share/man/man1/gs-netcat.1 b/prebuilt/gsocket/usr/share/man/man1/gs-netcat.1 new file mode 100644 index 0000000..f505f0d --- /dev/null +++ b/prebuilt/gsocket/usr/share/man/man1/gs-netcat.1 @@ -0,0 +1,256 @@ +\# .TH gs-netcat 1 "08 October 2020" "1.0" "gs-netcat man page" +.Dd October 08, 2020 +.Dt GS-NETCAT 1 +.Os +.Sh NAME +.Nm gs-netcat +.Nd transfer data, forward traffic and execute commands on a remote host. Securely. +.Sh SYNOPSIS +.Nm gs-netcat +.Op Fl rlgvqwCTSDiu +.Op Fl s Ar secret +.Op Fl k Ar keyfile +.Op Fl L Ar logfile +.Op Fl d Ar IP +.Op Fl p Ar port +.Op Fl e Ar cmd +.Sh DESCRIPTION +The +.Nm +utility is a re-implementation of netcat. It allows two or more users to establish a secure TCP connection with each other in a scenario where all users are behind NAT/Firewall and would not be able to connect to each other directly. Typically a connection between one workstation and another workstation on a different Local Area Network. +.Pp +It uses the Global Socket Relay Network (GSRN) instead of direct TCP connections. Neither workstation needs to open a port in their firewall or accept incoming TCP connections. +.Pp +The connection is end-2-end encrypted using SRP (RFC 5054) with AES-256 and a 4096 Prime. The GSRN sees only the encrypted traffic. +.Pp +Common uses include: +.Pp +.Bl -bullet -offset indent -compact +.It +simple TCP proxies +.It +PTY shell +.It +File transfer +.It +a SOCKS ProxyCommand for +.Xr ssh 1 +.It +and much, much more. +.El +.Pp +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl C +Disable encryption and use clear-text instead. Use with caution. +.It Fl d Ar ip +Destination IPv4 address for port forwarding. +.It Fl D +Daemon & Watchdog mode. Start +.Nm +as a background process and restart if killed. +.It Fl e Ar cmd +Execute command and send output to the connected client. Needs -l. +.It Fl g +Generate a secure random password and output it to standard output. +.It Fl i +Interactive login shell. The server spawns a true PTY login shell. The client acts as a true PTY client (with Ctrl-C etc working). The client can terminate the session by typing 'Ctrl-e q' at any time or by typing 'exit'. The server supports multiple clients at the same time. +.It Fl k Ar file +A file containing the password. +.It Fl l +Server/Listening mode. The default mode is client. +.It Fl L Ar file +Log file [default: standard out] +.It Fl p Ar port +Port to listen on or to forward traffic to [1-65535]. +.It Fl q +Quiet mode. Do not output any warnings or errors. +.It Fl r +Receive-only. Do not send any data. Terminate when no more data is available for reading. +.It Fl s Ar secret +A password chosen by the user. Both users need to use the same password to connect. +.It Fl S +Act as a SOCKS4/4a/5 server. The server acts as a SOCKS4/4a/5 proxy. It allows multiple +.Nm +clients to (securely) relay traffic via the server. Needs -l. +.It Fl T +Use TOR. The +.Nm +tool will connect via TOR to the GSRN. This requires TOR to be installed and running. The IP and PORT of the TOR server can be set using environment variables. +.It Fl t +Connect to the GSRN (only) and check if the peer is listening. Do not connect the peer. +.It Fl u +Use UDP instead of TCP for port forwarding. Needs -p. +.It Fl v +Prints status messages. Use -vv to be more verbose and -vvv to be insanely verbose. +.It Fl w +Client to wait for the listening server to become available. +.El +.Sh CONSOLE +The interactive login shell ( +.Ar -i +) has a command console. Pressing 'Ctrl-e c' (e for EEEElite) opens the command console. The command console displays the following information: +.Pp +.Bl -bullet -offset indent -compact +.It +Latency (in milliseconds) to the remote host +.It +Warning when a user logs into the system or becomes active +.It +Data throughput +.It +File transfer logs +.El +Type 'help' for a list of available commands. +.Sh FILETRANSFER +File transfer is available from the command console. Files are transferred with the permission and modification timestamp unchanged. Partially transferred files are re-started where the transfer was left off. +The 'put' command is used for uploading: +.Dl put foobar.txt +.Dl put $HOME/foobar.txt +.Dl put /tmp/*.log +.Dl put $(find . -type f -name '*.c') +(The above example shows Shell Variable substitution and word expansion) +It is possible to limit the amount of path information that is sent as implied directories for each path you specify. You can insert a dot and a slash into the source path, like this: +.Dl put /foo/./bar/baz.c +That would create /tmp/bar/baz.c on the remote machine. +The 'get' command is used for downloading: +.Dl get foobar.txt +.Dl get $(find /var/./ -name '*.log') +Transferring a directory automatically transfers all files and directories within that directory (recursively): +.Dl get /var/log +.Dl get / +The first command transfers all directories and files in /var/log/*. The latter command transfers the entire filesystem. +Multiple get/put commands can be scheduled at the same time. +.Sh EXAMPLES +.Nm Example 1 +- Listen for a new connection using the password 'MySecret': +.Dl $ gs-netcat -s MySecret -l +.Pp +Connect with client using the same password: +.Dl $ gs-netcat -s MySecret +.Pp +.Nm Example 2 +- spawn a PTY login shell when a client connects: +.Dl $ gs-netcat -s MySecret -l -i +.Pp +Log in to server's interactive shell: +.Dl $ gs-netcat -s MySecret -i +.Pp +Log in via TOR: +.Dl $ gs-netcat -s MySecret -i -T +.Pp +Log in via a Socks5 Proxy: +.Dl $ export GSOCKET_SOCKS_IP=127.0.0.1 +.Dl $ export GSOCKET_SOCKS_PORT=1080 +.Dl $ gs-netcat -s MySecret -i -T +.Pp +.Nm Example 3 +- Execute a command when a client connects: +.Dl $ gs-netcat -s MySecret -l -e 'echo hello world; id; exit' +.Pp +Connect client to the server: +.Dl $ gs-netcat -s MySecret +.Pp +.Nm Example 4 +- Pipe data from client to server: +.Dl $ gs-netcat -s MySecret -l -r >warez.tar.gz +.Pp +Client to read 'warez.tar.gz' and pipe it to the server. +.Dl $ gs-netcat -s MySecret