windows: AmneziaWG as a system-wide VPN

Each profile without asOutbound is a tunnel service of its own,
AmneziaWGTunnel$<interface>, as amneziawg-windows's client installs one:
amneziawg-go on Wintun, its routes and DNS, and for one peer that takes
everything its firewall blocking what would leave outside the tunnel.
It runs awg-tunnel.exe, amneziawg-windows built from its pinned commit
with a main of ours (its Run(), its log in a file) instead of its
tunnel.dll, beside Wintun's signed DLL (tools/build-amneziawg.sh).

The service writes each profile's .conf below its state root, registers
the tunnel (unrestricted service SID, which its firewall exempts it by),
starts the autostart ones with itself, and removes the tunnels of
profiles gone, and all of them on uninstall. proxy-ctl awg
list|on|off|log, and the app's AmneziaWG page: profiles (a system-wide
one switched on and off, its log), one added from a vpn:// link or a
.conf, or removed.

tools/lib.sh: clone_commit, and fetch_pinned, which fetches in pieces a
download that stalls (some networks cut TLS after about 16 KB, as
wintun.net's here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 17:23:11 +03:00
1 parent 95ec15e14a
commit 5cf3a237e6
30 files changed
+916 -12

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# AmneziaWG as a system-wide VPN: amneziawg-windows's tunnel (amneziawg-go on Wintun, its
# firewall that blocks what leaves outside a full tunnel, its DNS and routes), built from its
# pinned commit as awg-tunnel.exe rather than its tunnel.dll: the same Run() a tunnel service
# makes, with a main that takes the config's path and the tunnel's name, and its log in a
# file beside the config (not its ring log). Wintun's signed driver DLL from wintun.net,
# pinned as amneziawg-windows's own build pins it.
#
# tools/build-amneziawg.sh OUT_DIR (needs git, go, curl, unzip)
set -euo pipefail
. "$(dirname "$0")/lib.sh"
OUT=$(realpath -m "${1:?output directory}")
COMMIT=e90531d15802cb976773f3b63443bc281f738ca3
VERSION=0-unstable-2026-08-14+e90531d
WINTUN_URL=https://www.wintun.net/builds/wintun-0.14.1.zip
WINTUN_SHA256=07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
clone_commit https://github.com/amnezia-vpn/amneziawg-windows "$COMMIT" "$WORK/src"
cd "$WORK/src"
# Its exports (tunnel.dll's, through cgo) out; a main of ours in.
rm main.go
grep -q 'err = ringlogger.InitGlobalLogger("TUN")' service.go || { echo "service.go changed: no ring logger to replace"; exit 1; }
sed -i 's|err = ringlogger.InitGlobalLogger("TUN")|err = nil|' service.go
sed -i '/"github.com\/amnezia-vpn\/amneziawg-windows\/v3\/ringlogger"/d' service.go
cat > proxysuite_main.go <<'GO'
/* SPDX-License-Identifier: MIT
*
* Proxy Suite's AmneziaWG tunnel service: run by the Service Control Manager as
* `awg-tunnel <config path> <tunnel name>`, as amneziawg-windows's tunnel.dll is from its
* client's service. Its log goes to <config path>.log, written anew at each start.
*/
package main
import (
"fmt"
"log"
"os"
)
func main() {
if len(os.Args) != 3 {
fmt.Fprintln(os.Stderr, "usage: awg-tunnel <config> <tunnel name> (as a Windows service)")
os.Exit(2)
}
confPath, name := os.Args[1], os.Args[2]
if f, err := os.OpenFile(confPath+".log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600); err == nil {
log.SetOutput(f)
}
text, err := os.ReadFile(confPath)
if err != nil {
log.Printf("reading %s: %v", confPath, err)
os.Exit(1)
}
if err := Run(string(text), name); err != nil {
log.Printf("the tunnel service: %v", err)
os.Exit(1)
}
}
GO
export GOTOOLCHAIN=local GOFLAGS=-mod=mod CGO_ENABLED=0 GOOS=windows GOARCH=amd64
go build -trimpath -ldflags "-s -w" -o "$WORK/awg-tunnel.exe" .
rm -rf "$OUT" && mkdir -p "$OUT"
cp "$WORK/awg-tunnel.exe" "$OUT/"
# Its license is the MIT text in its README.
sed -n '/^```text/,/^```/p' README.md | sed '1d;$d' >"$OUT/LICENSE"
grep -q 'Permission is hereby granted' "$OUT/LICENSE" || { echo "README.md: no license text"; exit 1; }
fetch_pinned "$WINTUN_URL" "$WINTUN_SHA256" "$WORK/wintun.zip"
unzip -q -o "$WORK/wintun.zip" -d "$WORK/wintun"
cp "$WORK/wintun/wintun/bin/amd64/wintun.dll" "$OUT/"
cp "$WORK/wintun/wintun/LICENSE.txt" "$OUT/wintun-LICENSE.txt"
echo "$VERSION" >"$OUT/.version"
echo "amneziawg $VERSION (windows) in $OUT"
+60
View File
@@ -28,3 +28,63 @@ clone_tag() {
done
return 1
}
# clone_commit URL COMMIT DIR: COMMIT alone, for a project without release tags; cached and
# tried again as clone_tag is.
clone_commit() {
local url=$1 commit=$2 dir=$3 try cached=""
if [ -n "${SRC_CACHE:-}" ]; then
cached="$SRC_CACHE/$(basename "$url")@$commit"
if [ -d "$cached/.git" ]; then
rm -rf "$dir" && cp -a "$cached" "$dir" && git -C "$dir" reset -q --hard && git -C "$dir" clean -qfdx && return 0
fi
fi
for try in 1 2 3; do
rm -rf "$dir" && mkdir -p "$dir"
if git -C "$dir" init -q && git -C "$dir" remote add origin "$url" &&
git -C "$dir" -c http.lowSpeedLimit=1000 -c http.lowSpeedTime=60 fetch -q --depth 1 origin "$commit" &&
git -C "$dir" -c advice.detachedHead=false checkout -q FETCH_HEAD; then
if [ -n "$cached" ]; then
mkdir -p "$SRC_CACHE" && rm -rf "$cached.tmp" && cp -a "$dir" "$cached.tmp" && mv "$cached.tmp" "$cached"
fi
return 0
fi
echo "fetching $url ($commit) failed, try $try of 3" >&2
sleep 5
done
return 1
}
# fetch_pinned URL SHA256 FILE: a download, checked by its hash; kept in SRC_CACHE.
fetch_pinned() {
local url=$1 sha=$2 out=$3 cached=""
if [ -n "${SRC_CACHE:-}" ]; then
cached="$SRC_CACHE/$sha"
if [ -f "$cached" ] && echo "$sha $cached" | sha256sum -c --quiet 2>/dev/null; then
cp "$cached" "$out" && return 0
fi
fi
# Whole, unless it stalls: some networks cut TLS to some hosts after about 16 KB (as
# zapret2's cutoff option knows). Then in ranges below that, each on a connection of its own.
if ! curl -fsSL --connect-timeout 30 --speed-limit 1 --speed-time 15 --max-time 900 --retry 2 -o "$out" "$url"; then
echo "$url stalled; fetching it in pieces" >&2
local size from=0 step=12000 tries=0
size=$(curl -fsSIL --connect-timeout 30 --max-time 60 "$url" | tr -d '\r' | awk 'tolower($1) == "content-length:" { n = $2 } END { print n }')
[[ "$size" =~ ^[0-9]+$ ]] && [ "$size" -gt 0 ] || { echo "$url: no size to fetch it in pieces by" >&2; return 1; }
: >"$out"
while [ "$from" -lt "$size" ]; do
if curl -fsSL --connect-timeout 30 --max-time 60 -r "$from-$((from + step - 1))" "$url" >>"$out.piece" 2>/dev/null &&
[ "$(stat -c %s "$out.piece")" -gt 0 ]; then
cat "$out.piece" >>"$out"
from=$(stat -c %s "$out")
tries=0
else
tries=$((tries + 1))
[ "$tries" -lt 5 ] || { rm -f "$out.piece"; echo "$url: a piece failed five times" >&2; return 1; }
fi
rm -f "$out.piece"
done
fi
echo "$sha $out" | sha256sum -c --quiet || { echo "$url: not the pinned file" >&2; return 1; }
if [ -n "$cached" ]; then mkdir -p "$SRC_CACHE" && cp "$out" "$cached"; fi
}
+3 -1
View File
@@ -21,6 +21,7 @@ echo "== components"
tools/build-tg-ws-proxy.sh "$DIST/components/tg-ws-proxy"
tools/build-wireproxy-awg.sh "$DIST/components/wireproxy-awg" windows
tools/build-whitelist-bypass.sh "$DIST/components/whitelist-bypass" windows
tools/build-amneziawg.sh "$DIST/components/amneziawg"
cargo build -q --release -p ps-service
target/release/proxy-suite-service stage-components --to "$DIST/components" --cache "$CACHE"
rm -rf "$DIST"/components/*.old "$DIST"/components/*.staging
@@ -57,7 +58,8 @@ echo "== THIRD-PARTY.md"
echo "- **cygwin1.dll** (zapret, zapret2): LGPL-3.0, https://cygwin.com"
echo "- **zapret2** (winws2.exe, its Lua) and **nfqws2-keenetic** (its strategies, lists, blobs): MIT, https://github.com/bol-van/zapret2, https://github.com/nfqws/nfqws2-keenetic"
echo "- **wintun** (inside sing-box): WireGuard's prebuilt-binary license, https://www.wintun.net"
echo "- **amneziawg-go** (inside wireproxy-awg, with the suite's patch): MIT, https://github.com/amnezia-vpn/amneziawg-go"
echo "- **amneziawg-go** (inside wireproxy-awg, with the suite's patch, and inside amneziawg's awg-tunnel.exe): MIT, https://github.com/amnezia-vpn/amneziawg-go"
echo "- **Wintun** (amneziawg's wintun.dll, as WireGuard LLC builds and signs it): its prebuilt-binaries license, components/amneziawg/wintun-LICENSE.txt"
echo "- **Go modules** (inside wireproxy-awg and whitelist-bypass, e.g. Pion's WebRTC): as each project's go.mod pins them, under their own licenses (MIT, BSD-3-Clause, Apache-2.0)"
echo "- **lyrebird** and **conjure** (Tor's pluggable transports, in the Expert Bundle): their licenses are in components/tor/docs"
echo "- **CPython $( sed 's/.*+py//' "$DIST/components/tg-ws-proxy/.version" )** (tg-ws-proxy): PSF License, https://www.python.org"
+7 -3
View File
@@ -39,6 +39,9 @@ cat >"$STATE/config.json" <<JSON
"zapret": { "enable": true, "engine": "zapret-discord-youtube",
"zapret-discord-youtube": { "configName": "general (ALT9)", "gameFilter": "all" } },
"tgWsProxy": { "enable": false },
"amneziaWg": { "enable": true, "profiles": {
"home": { "autostart": true, "config": "[Interface]\nPrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=\nAddress = 10.8.0.2/32\nDNS = 1.1.1.1\nJc = 4\nJmin = 40\nJmax = 70\nS1 = 12\nS2 = 34\nH1 = 1\nH2 = 2\nH3 = 3\nH4 = 4\n\n[Peer]\nPublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=\nAllowedIPs = 0.0.0.0/0, ::/0\nEndpoint = 203.0.113.7:51820\n" },
"office": { "asOutbound": "singBox", "config": "[Interface]\nPrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=\nAddress = 10.8.0.2/32\nDNS = 1.1.1.1\nJc = 4\nJmin = 40\nJmax = 70\nS1 = 12\nS2 = 34\nH1 = 1\nH2 = 2\nH3 = 3\nH4 = 4\n\n[Peer]\nPublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=\nAllowedIPs = 0.0.0.0/0, ::/0\nEndpoint = 203.0.113.7:51820\n" } } },
"whitelistBypass": { "enable": true,
"joiners": { "wl": { "platform": "wbstream" } },
"creators": { "office": { "platform": "bitrix" } } } }
@@ -65,6 +68,7 @@ shot telegram 234
shot whitelist-bypass 270
shot outbounds 306
shot autoproxy 342
shot logs 378
shot settings 414
shot components 450
shot amneziawg 378
shot logs 414
shot settings 450
shot components 486
+19
View File
@@ -64,6 +64,25 @@ running || fail "the service is $(state)"
for _ in $(seq 30); do wine "$PF/proxy-ctl.exe" status >/dev/null 2>&1 && break; sleep 1; done
wine "$PF/proxy-ctl.exe" components | tr -d '\r' | sed 's/^/ /' || fail "no answer over the pipe"
echo "== an AmneziaWG system-wide profile: its tunnel service registered, then removed"
CONF='[Interface]\nPrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=\nAddress = 10.8.0.2/32\nDNS = 1.1.1.1\n\n[Peer]\nPublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=\nAllowedIPs = 0.0.0.0/0, ::/0\nEndpoint = 203.0.113.7:51820\n'
printf '{ "amneziaWg": { "enable": true, "profiles": { "home": { "config": "%s" } } } }' "$CONF" >"$WORK/awg.json"
wine "$PF/proxy-ctl.exe" config set "Z:$WORK/awg.json" | tr -d '\r' | sed 's/^/ /'
sleep 3
qc=$(wine sc qc 'AmneziaWGTunnel$home' 2>/dev/null | tr -d '\r')
grep -q 'awg-tunnel.exe' <<<"$qc" || fail "no tunnel service registered: $(wine "$PF/proxy-ctl.exe" logs proxy-suite-awg-vpn -n 20 | tr -d '\r')"
grep -i 'BINARY_PATH_NAME' <<<"$qc" | sed 's/^ */ /'
wine "$PF/proxy-ctl.exe" awg | tr -d '\r' | sed 's/^/ /'
# Wine has no Wintun driver: the tunnel itself cannot come up here, only be asked to.
wine "$PF/proxy-ctl.exe" awg on home 2>&1 | tr -d '\r' | sed 's/^/ on: /' || true
sleep 3
wine "$PF/proxy-ctl.exe" awg log home -n 5 2>&1 | tr -d '\r' | sed 's/^/ log: /' || true
printf '{}' >"$WORK/none.json"
wine "$PF/proxy-ctl.exe" config set "Z:$WORK/none.json" >/dev/null
sleep 3
wine sc query 'AmneziaWGTunnel$home' >/dev/null 2>&1 && fail "the tunnel service outlived its profile"
echo " registered, and removed with its profile"
echo "== setup /S again, over the running install"
wine "$SETUP" /S && rc=0 || rc=$?
[ "$rc" = 0 ] || fail "the upgrade exited with $rc"